[pitivi] mainwindow: Use AssetThumbnail to get the thumbnails from cache



commit 5772bba614439953ebb55f9c46d782954f961e75
Author: namanyadav12 <namanyadav128 gmail com>
Date:   Thu Feb 16 00:48:20 2017 +0530

    mainwindow: Use AssetThumbnail to get the thumbnails from cache
    
    Had to make __get_thumbnails_from_xdg_cache a public static method so it
    can be used in a different module.
    
    Reviewed-by: Alex Băluț <alexandru balut gmail com>
    Differential Revision: https://phabricator.freedesktop.org/D1662

 pitivi/mainwindow.py   |   14 ++++----------
 pitivi/medialibrary.py |    5 +++--
 2 files changed, 7 insertions(+), 12 deletions(-)
---
diff --git a/pitivi/mainwindow.py b/pitivi/mainwindow.py
index ea3447b..b9f6fa3 100644
--- a/pitivi/mainwindow.py
+++ b/pitivi/mainwindow.py
@@ -18,7 +18,6 @@
 # Boston, MA 02110-1301, USA.
 import os
 from gettext import gettext as _
-from hashlib import md5
 from time import time
 from urllib.parse import unquote
 
@@ -40,6 +39,7 @@ from pitivi.configure import VERSION
 from pitivi.dialogs.prefs import PreferencesDialog
 from pitivi.effects import EffectListWidget
 from pitivi.mediafilespreviewer import PreviewWidget
+from pitivi.medialibrary import AssetThumbnail
 from pitivi.medialibrary import MediaLibraryWidget
 from pitivi.project import ProjectSettingsDialog
 from pitivi.settings import GlobalSettings
@@ -934,16 +934,10 @@ class MainWindow(Gtk.ApplicationWindow, Loggable):
         hbox.set_orientation(Gtk.Orientation.HORIZONTAL)
         hbox.set_spacing(SPACING)
 
-        # Check if we have a thumbnail available.
-        # This can happen if the file was moved or deleted by an application
-        # that does not manage Freedesktop thumbnails. The user is in luck!
-        # This is based on medialibrary's addDiscovererInfo method.
-        thumbnail_hash = md5(uri.encode()).hexdigest()
-        thumb_dir = os.path.expanduser("~/.thumbnails/normal/")
-        thumb_path_normal = thumb_dir + thumbnail_hash + ".png"
-        if os.path.exists(thumb_path_normal):
+        small_thumb, large_thumb = AssetThumbnail.get_thumbnails_from_xdg_cache(uri)
+        if large_thumb:
             self.debug("A thumbnail file was found for %s", uri)
-            thumbnail = Gtk.Image.new_from_file(thumb_path_normal)
+            thumbnail = Gtk.Image.new_from_pixbuf(large_thumb)
             thumbnail.set_padding(0, SPACING)
             hbox.pack_start(thumbnail, False, False, 0)
 
diff --git a/pitivi/medialibrary.py b/pitivi/medialibrary.py
index a1f5cb2..145f9ff 100644
--- a/pitivi/medialibrary.py
+++ b/pitivi/medialibrary.py
@@ -210,7 +210,7 @@ class AssetThumbnail(Loggable):
         if video_streams:
             # Check if the files have thumbnails in the user's cache directory.
             real_uri = get_proxy_target(self.__asset).props.id
-            small_thumb, large_thumb = self.__get_thumbnails_from_xdg_cache(real_uri)
+            small_thumb, large_thumb = self.get_thumbnails_from_xdg_cache(real_uri)
             if not small_thumb:
                 if self.__asset.is_image():
                     path = Gst.uri_get_location(real_uri)
@@ -251,7 +251,8 @@ class AssetThumbnail(Loggable):
             small_thumb, large_thumb = self.__get_icons("audio-x-generic")
         return small_thumb, large_thumb
 
-    def __get_thumbnails_from_xdg_cache(self, real_uri):
+    @staticmethod
+    def get_thumbnails_from_xdg_cache(real_uri):
         """Gets pixbufs for the specified thumbnail from the user's cache dir.
 
         Looks for thumbnails according to the [Thumbnail Managing 
Standard](https://specifications.freedesktop.org/thumbnail-spec/thumbnail-spec-latest.html#DIRECTORY).


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]