[pitivi] check: Make GnomeDesktop a soft dependency



commit 72153211954e2952e6ac740975b27f1027e4de60
Author: Alexandru Băluț <alexandru balut gmail com>
Date:   Fri Jan 10 23:18:26 2014 +0100

    check: Make GnomeDesktop a soft dependency
    
    GnomeDesktop is used for generating thumbnails for the media library.
    
    Also handle in medialibrary when GnomeDesktop not available.

 pitivi/check.py        |   17 ++++++++++++-----
 pitivi/medialibrary.py |   18 ++++++++++++++----
 pitivi/utils/misc.py   |    1 -
 pitivi/utils/ui.py     |    1 -
 4 files changed, 26 insertions(+), 11 deletions(-)
---
diff --git a/pitivi/check.py b/pitivi/check.py
index 6d15bac..e1d2504 100644
--- a/pitivi/check.py
+++ b/pitivi/check.py
@@ -42,7 +42,6 @@ HARD_DEPS = {
     "GES": "1.0.0.0",  # packagers: in reality 1.1.90, but that GES version erronously reports itself as 
1.0.0.0
     "Gio": None,
     "gnonlin": "1.1.90",
-    "GnomeDesktop": None,
     "Gst": "1.2.0",
     "Gtk": "3.8.0",
     "numpy": None,  # using static python bindings
@@ -52,9 +51,10 @@ HARD_DEPS = {
     "gst-python": "1.1.90",
     "pygobject": "3.4.0",
 }
+
 # For the list of soft dependencies, see the "check_soft_dependencies" method,
 # near the end of this file.
-global missing_soft_deps
+# (library_name, why_we_need_it) tuples:
 missing_soft_deps = {}
 
 
@@ -232,17 +232,24 @@ def check_soft_dependencies():
     # seems to have no measurable performance impact the 2nd time:
     from gi.repository import Gst
     Gst.init(None)
-    registry = Gst.Registry.get()
-    # Description strings are translatable as they may be shown in the pitivi UI
+
+    # Description strings are translatable as they are shown in the Pitivi UI.
     if not _try_import("pycanberra"):
         missing_soft_deps["PyCanberra"] = \
             _("enables sound notifications when rendering is complete")
+
+    if not _try_import_from_gi("GnomeDesktop"):
+        missing_soft_deps["libgnome-desktop"] = \
+            _("file thumbnails provided by GNOME's thumbnailers")
     if not _try_import_from_gi("Notify"):
         missing_soft_deps["libnotify"] = \
             _("enables visual notifications when rendering is complete")
+
+    registry = Gst.Registry.get()
     if not registry.find_plugin("libav"):
         missing_soft_deps["GStreamer Libav plugin"] = \
-            _('additional multimedia codecs through the Libav library')
+            _("additional multimedia codecs through the Libav library")
+
     # Apparently, doing a registry.find_plugin("frei0r") is not enough.
     # Sometimes it still returns something even when frei0r is uninstalled,
     # and anyway we're looking specifically for the scale0tilt filter.
diff --git a/pitivi/medialibrary.py b/pitivi/medialibrary.py
index ddb6eaa..6ceea02 100644
--- a/pitivi/medialibrary.py
+++ b/pitivi/medialibrary.py
@@ -26,7 +26,11 @@ from gi.repository import Gst
 from gi.repository import GES
 from gi.repository import Gio
 from gi.repository import GLib
-from gi.repository import GnomeDesktop
+try:
+    from gi.repository import GnomeDesktop
+    has_gnome_desktop = True
+except ImportError:
+    has_gnome_desktop = False
 from gi.repository import GObject
 from gi.repository import Gtk
 from gi.repository import Gdk
@@ -305,9 +309,12 @@ class MediaLibraryWidget(Gtk.VBox, Loggable):
         self.pack_start(self.treeview_scrollwin, True, True, 0)
         self.pack_start(self._progressbar, False, True, 0)
 
-        # We need to instanciate the thumbnail factory on the main thread...
-        size_normal = GnomeDesktop.DesktopThumbnailSize.NORMAL
-        self.thumbnailer = GnomeDesktop.DesktopThumbnailFactory.new(size_normal)
+        if has_gnome_desktop:
+            # We need to instanciate the thumbnail factory on the main thread...
+            size_normal = GnomeDesktop.DesktopThumbnailSize.NORMAL
+            self.thumbnailer = GnomeDesktop.DesktopThumbnailFactory.new(size_normal)
+        else:
+            self.thumbnailer = None
 
     def getAssetForUri(self, uri):
         # Sanitization
@@ -526,6 +533,9 @@ class MediaLibraryWidget(Gtk.VBox, Loggable):
                 return None, None
 
     def _generateThumbnails(self, uri):
+        if not self.thumbnailer:
+            # TODO: Use thumbnails generated with GStreamer.
+            return None
         # This way of getting the mimetype feels awfully convoluted but
         # seems to be the proper/reliable way in a GNOME context
         asset_file = Gio.file_new_for_uri(uri)
diff --git a/pitivi/utils/misc.py b/pitivi/utils/misc.py
index 44efc86..68886ab 100644
--- a/pitivi/utils/misc.py
+++ b/pitivi/utils/misc.py
@@ -337,7 +337,6 @@ infinity = Infinity()
 
 
 def profile(func, profiler_filename="result.prof"):
-    import os.path
     counter = 1
     output_filename = profiler_filename
     while os.path.exists(output_filename):
diff --git a/pitivi/utils/ui.py b/pitivi/utils/ui.py
index d69c4ae..26b80f7 100644
--- a/pitivi/utils/ui.py
+++ b/pitivi/utils/ui.py
@@ -37,7 +37,6 @@ from gi.repository import Gst
 from gi.repository import Gtk
 from gi.repository.GstPbutils import DiscovererVideoInfo, DiscovererAudioInfo,\
     DiscovererStreamInfo, DiscovererSubtitleInfo
-from itertools import izip
 from urllib import unquote
 import cairo
 import os


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