[pitivi/ges: 40/287] Better usage of the DiscovererInfo so we can actually kill the file factories



commit 0d7fb4ca4654897a43fbebb5653a74bb060d71c6
Author: Thibault Saunier <thibault saunier collabora com>
Date:   Mon Oct 3 20:28:36 2011 -0300

    Better usage of the DiscovererInfo so we can actually kill the file factories

 pitivi/sourcelist.py      |   42 +++++++++++------------
 pitivi/sourcelist_undo.py |    4 +-
 pitivi/ui/common.py       |   60 ++++++++++++++-------------------
 pitivi/ui/mainwindow.py   |   12 +++---
 pitivi/ui/sourcelist.py   |   81 +++++++++++++++++++++++----------------------
 pitivi/utils.py           |    2 +-
 6 files changed, 96 insertions(+), 105 deletions(-)
---
diff --git a/pitivi/sourcelist.py b/pitivi/sourcelist.py
index e52e54b..35a0afc 100644
--- a/pitivi/sourcelist.py
+++ b/pitivi/sourcelist.py
@@ -25,11 +25,9 @@ Handles the list of source for a project
 """
 
 import urllib
-from pitivi.discoverer import Discoverer
 from pitivi.signalinterface import Signallable
 from pitivi.log.loggable import Loggable
 import gst
-from pitivi.factories.file import FileSourceFactory
 
 
 class SourceListError(Exception):
@@ -61,7 +59,7 @@ class SourceList(Signallable, Loggable):
     __signals__ = {
         "ready": [],
         "starting": [],
-        "source-added": ["factory"],
+        "source-added": ["info"],
         "source-removed": ["uri"],
         "discovery-error": ["uri", "reason"],
         }
@@ -90,13 +88,12 @@ class SourceList(Signallable, Loggable):
         self._sources[uri] = None
 
         try:
-            self.discoverer.discover_uri(uri)
+            info = self.discoverer.discover_uri(uri)
         except Exception, e:
             self.emit("discovery-error", uri, e, "")
             return
 
-        factory = FileSourceFactory(uri)
-        self.addFactory(factory)
+        self.addDiscovererInfo(info)
 
     def addUris(self, uris):
         """
@@ -112,40 +109,41 @@ class SourceList(Signallable, Loggable):
 
     def removeUri(self, uri):
         """
-        Remove the factory for c{uri} from the source list.
+        Remove the info for c{uri} from the source list.
         """
         try:
-            factory = self._sources.pop(uri)
+            info = self._sources.pop(uri)
         except KeyError:
             raise SourceListError("URI not in the sourcelist", uri)
         try:
-            self._ordered_sources.remove(factory)
+            self._ordered_sources.remove(info)
         except ValueError:
             # this can only happen if discoverer hasn't finished scanning the
-            # source, so factory must be None
-            assert factory is None
-        self.emit("source-removed", uri, factory)
+            # source, so info must be None
+            assert info is None
+        self.emit("source-removed", uri, info)
 
     def getUri(self, uri):
         """
         Get the source corresponding to C{uri}.
         """
-        factory = self._sources.get(uri)
-        if factory is None:
+        info = self._sources.get(uri)
+        if info is None:
             raise SourceListError("URI not in the sourcelist", uri)
-        return factory
+        return info
 
-    def addFactory(self, factory):
+    def addDiscovererInfo(self, info):
         """
         Add the specified SourceFactory to the list of sources.
         """
-        if self._sources.get(factory.uri, None) is not None:
-            raise SourceListError("We already have a factory for this URI",
-                    factory.uri)
-        self._sources[factory.uri] = factory
-        self._ordered_sources.append(factory)
+        uri = info.get_uri()
+        if self._sources.get(uri, None) is not None:
+            raise SourceListError("We already have a info for this URI",
+                    uri)
+        self._sources[uri] = info
+        self._ordered_sources.append(info)
         self.nb_imported_files += 1
-        self.emit("source-added", factory)
+        self.emit("source-added", info)
 
     def getSources(self):
         """ Returns the list of sources used.
diff --git a/pitivi/sourcelist_undo.py b/pitivi/sourcelist_undo.py
index 29bd096..efbef16 100644
--- a/pitivi/sourcelist_undo.py
+++ b/pitivi/sourcelist_undo.py
@@ -32,7 +32,7 @@ class SourceListSourceAddedAction(UndoableAction):
         self._undone()
 
     def do(self):
-        self.sourcelist.addFactory(self.source)
+        self.sourcelist.addDiscovererInfo(self.source)
         self._done()
 
 
@@ -43,7 +43,7 @@ class SourceListSourceRemovedAction(UndoableAction):
         self.source = source
 
     def undo(self):
-        self.sourcelist.addFactory(self.source)
+        self.sourcelist.addDiscovererInfo(self.source)
         self._undone()
 
     def do(self):
diff --git a/pitivi/ui/common.py b/pitivi/ui/common.py
index fa0fce3..976fd5f 100644
--- a/pitivi/ui/common.py
+++ b/pitivi/ui/common.py
@@ -1,14 +1,13 @@
 # -*- coding: utf-8 -*-
 from pitivi.settings import GlobalSettings
 import cairo
-from pitivi.stream import VideoStream, AudioStream, TextStream, \
-        MultimediaStream
 from xml.sax.saxutils import escape
 from urllib import unquote
 from gettext import gettext as _
 from gettext import ngettext
 import gst
 import gtk
+import os
 
 GlobalSettings.addConfigSection("user-interface")
 LAYER_HEIGHT_EXPANDED = 50
@@ -93,47 +92,40 @@ def unpack_cairo_gradient(value):
     return gradient
 
 
-def beautify_factory(factory):
-    ranks = {VideoStream: 0, AudioStream: 1, TextStream: 2, MultimediaStream: 3}
+def beautify_info(info):
+    ranks = {gst.pbutils.DiscovererVideoInfo: 0, gst.pbutils.DiscovererAudioInfo: 1}
 
     def stream_sort_key(stream):
         return ranks[type(stream)]
 
-    streams = factory.getOutputStreams()
-    streams.sort(key=stream_sort_key)
-    return ("<b>" + escape(unquote(factory.name)) + "</b>\n" +
-        "\n".join((beautify_stream(stream) for stream in streams)))
+    info.get_stream_list().sort(key=stream_sort_key)
+    return ("<b>" + info_name(info) + "</b>\n" +
+        "\n".join((beautify_stream(stream) for stream in info.get_stream_list())))
 
 
-def factory_name(factory):
-    return escape(unquote(factory.name))
+def info_name(info):
+    return escape(unquote(os.path.basename(info.get_uri())))
 
 
 def beautify_stream(stream):
-    if type(stream) == AudioStream:
-        if stream.raw:
-            templ = ngettext("<b>Audio:</b> %d channel at %d <i>Hz</i> (%d <i>bits</i>)",
-                    "<b>Audio:</b> %d channels at %d <i>Hz</i> (%d <i>bits</i>)",
-                    stream.channels)
-            templ = templ % (stream.channels, stream.rate, stream.width)
-            return templ
-
-        return _("<b>Unknown Audio format:</b> %s") % stream.audiotype
-
-    elif type(stream) == VideoStream:
-        if stream.raw:
-            if stream.framerate.num:
-                templ = _(u"<b>Video:</b> %dÃ%d <i>pixels</i> at %.2f<i>fps</i>")
-                templ = templ % (stream.par * stream.width, stream.height,
-                        float(stream.framerate))
-            else:
-                templ = _(u"<b>Image:</b> %dÃ%d <i>pixels</i>")
-                templ = templ % (stream.par * stream.width, stream.height)
-            return templ
-        return _("<b>Unknown Video format:</b> %s") % stream.videotype
-
-    elif type(stream) == TextStream:
-        return _("<b>Text:</b> %s") % stream.texttype
+    if type(stream) == gst.pbutils.DiscovererAudioInfo:
+        templ = ngettext("<b>Audio:</b> %d channel at %d <i>Hz</i> (%d <i>bits</i>)",
+                "<b>Audio:</b> %d channels at %d <i>Hz</i> (%d <i>bits</i>)",
+                stream.get_channels())
+        templ = templ % (stream.get_channels(), stream.get_bitrate(),
+            stream.get_depth())
+        return templ
+
+    elif type(stream) == gst.pbutils.DiscovererVideoInfo:
+        par = stream.get_par_num() / stream.get_par_denom()
+        if not stream.is_image():
+            templ = _(u"<b>Video:</b> %dÃ%d <i>pixels</i> at %.2f<i>fps</i>")
+            templ = templ % (par * stream.get_height(), stream.get_height(),
+                float(stream.get_framerate_num() / stream.get_framerate_num()))
+        else:
+            templ = _(u"<b>Image:</b> %dÃ%d <i>pixels</i>")
+            templ = templ % (par * stream.get_height(), stream.get_height())
+        return templ
 
     raise NotImplementedError
 
diff --git a/pitivi/ui/mainwindow.py b/pitivi/ui/mainwindow.py
index fae258f..e4a32b2 100644
--- a/pitivi/ui/mainwindow.py
+++ b/pitivi/ui/mainwindow.py
@@ -52,7 +52,7 @@ from pitivi.ui.sourcelist import SourceList
 from pitivi.ui.effectlist import EffectList
 from pitivi.ui.clipproperties import ClipProperties
 from pitivi.ui.common import SPACING
-from pitivi.ui.common import factory_name
+from pitivi.ui.common import info_name
 from pitivi.utils import beautify_length, show_user_manual
 from pitivi.ui.zoominterface import Zoomable
 from pitivi.ui.filechooserpreview import PreviewWidget
@@ -849,7 +849,7 @@ class PitiviMainWindow(gtk.Window, Loggable):
         dialog.destroy()
         self.set_sensitive(True)
 
-    def _projectManagerMissingUriCb(self, instance, formatter, uri, factory):
+    def _projectManagerMissingUriCb(self, instance, formatter, uri, info):
         dialog = gtk.Dialog(_("Locate missing file..."),
             self,
             gtk.DIALOG_MODAL,
@@ -861,16 +861,16 @@ class PitiviMainWindow(gtk.Window, Loggable):
         dialog.set_transient_for(self)
 
         # TODO: display the filesize to help the user identify the file
-        if not factory.duration or factory.duration == gst.CLOCK_TIME_NONE:
+        if info.get_duration() == gst.CLOCK_TIME_NONE:
             # The file is probably an image, not video or audio.
             text = _('The following file has moved: "<b>%s</b>"'
                      '\nPlease specify its new location:'
-                     % factory_name(factory))
+                     % info_name(info))
         else:
-            length = beautify_length(factory.duration)
+            length = beautify_length(info.get_duration())
             text = _('The following file has moved: "<b>%s</b>" (duration: %s)'
                      '\nPlease specify its new location:'
-                     % (factory_name(factory), length))
+                     % (info_name(info), length))
 
         label = gtk.Label()
         label.set_markup(text)
diff --git a/pitivi/ui/sourcelist.py b/pitivi/ui/sourcelist.py
index 8cd0185..68a1aa9 100644
--- a/pitivi/ui/sourcelist.py
+++ b/pitivi/ui/sourcelist.py
@@ -35,12 +35,11 @@ from pitivi.ui.pathwalker import PathWalker, quote_uri
 from pitivi.ui.filelisterrordialog import FileListErrorDialog
 from pitivi.configure import get_pixmap_dir
 from pitivi.signalgroup import SignalGroup
-from pitivi.stream import VideoStream, AudioStream, TextStream, \
-        MultimediaStream
+
 from pitivi.settings import GlobalSettings
 from pitivi.utils import beautify_length
-from pitivi.ui.common import beautify_factory, factory_name, \
-    beautify_stream, SPACING, PADDING
+from pitivi.ui.common import beautify_info, info_name, \
+    SPACING, PADDING
 from pitivi.log.loggable import Loggable
 from pitivi.sourcelist import SourceListError
 from pitivi.ui.filechooserpreview import PreviewWidget
@@ -554,56 +553,58 @@ class SourceList(gtk.VBox, Loggable):
         elif total_clips != 0:
             self._progressbar.set_fraction((current_clip_iter - 1) / float(total_clips))
 
-    def _addFactory(self, factory):
-        video = factory.getOutputStreams(VideoStream)
-        if video and video[0].thumbnail:
-            thumbnail_file = video[0].thumbnail
-            try:
-                self.debug("attempting to open thumbnail file '%s'",
-                        thumbnail_file)
-                pixbuf = gtk.gdk.pixbuf_new_from_file(thumbnail_file)
-            except:
-                self.error("Failure to create thumbnail from file '%s'",
-                        thumbnail_file)
-                thumbnail = self.videofilepixbuf
-                thumbnail_large = self.videofilepixbuf
-            else:
-                desiredheight = int(64 / float(video[0].dar))
-                thumbnail = pixbuf.scale_simple(64,
-                        desiredheight, gtk.gdk.INTERP_BILINEAR)
-                desiredheight = int(96 / float(video[0].dar))
-                thumbnail_large = pixbuf.scale_simple(96,
-                        desiredheight, gtk.gdk.INTERP_BILINEAR)
+    def _addDiscovererInfo(self, info):
+        #FIXME GES port reimplement thunbnails
+        #video = factory.getOutputStreams()
+        #if video and video[0].thumbnail:
+            #thumbnail_file = video[0].thumbnail
+            #try:
+                #self.debug("attempting to open thumbnail file '%s'",
+                        #thumbnail_file)
+                #pixbuf = gtk.gdk.pixbuf_new_from_file(thumbnail_file)
+            #except:
+                #self.error("Failure to create thumbnail from file '%s'",
+                        #thumbnail_file)
+                #thumbnail = self.videofilepixbuf
+                #thumbnail_large = self.videofilepixbuf
+            #else:
+                #desiredheight = int(64 / float(video[0].dar))
+                #thumbnail = pixbuf.scale_simple(64,
+                        #desiredheight, gtk.gdk.INTERP_BILINEAR)
+                #desiredheight = int(96 / float(video[0].dar))
+                #thumbnail_large = pixbuf.scale_simple(96,
+                        #desiredheight, gtk.gdk.INTERP_BILINEAR)
+        #else:
+        if [i for i in info.get_stream_list() if\
+            isinstance(i, gst.pbutils.DiscovererVideoInfo)]:
+            thumbnail = self.videofilepixbuf
+            thumbnail_large = self.videofilepixbuf
         else:
-            if video:
-                thumbnail = self.videofilepixbuf
-                thumbnail_large = self.videofilepixbuf
-            else:
-                thumbnail = self.audiofilepixbuf
-                thumbnail_large = self.audiofilepixbuf
+            thumbnail = self.audiofilepixbuf
+            thumbnail_large = self.audiofilepixbuf
 
-        if not factory.duration or factory.duration == gst.CLOCK_TIME_NONE:
+        if info.get_duration() == gst.CLOCK_TIME_NONE:
             duration = ''
         else:
-            duration = beautify_length(factory.duration)
+            duration = beautify_length(info.get_duration())
 
         short_text = None
-        uni = unicode(factory_name(factory), 'utf-8')
+        uni = unicode(info_name(info), 'utf-8')
 
         if len(uni) > 34:
             short_uni = uni[0:29]
             short_uni += unicode('...')
             short_text = short_uni.encode('utf-8')
         else:
-            short_text = factory_name(factory)
+            short_text = info_name(info)
 
         self.storemodel.append([thumbnail,
             thumbnail_large,
-            beautify_factory(factory),
-            factory,
-            factory.uri,
+            beautify_info(info),
+            info,
+            info.get_uri(),
             duration,
-            factory_name(factory),
+            info_name(info),
             short_text])
         self._displayClipView()
 
@@ -612,7 +613,7 @@ class SourceList(gtk.VBox, Loggable):
     def _sourceAddedCb(self, sourcelist, factory):
         """ a file was added to the sourcelist """
         self._updateProgressbar()
-        self._addFactory(factory)
+        self._addDiscovererInfo(factory)
         if len(self.storemodel):
             self.infobar.hide_all()
             self.search_hbox.show_all()
diff --git a/pitivi/utils.py b/pitivi/utils.py
index 95e91d6..b98ef66 100644
--- a/pitivi/utils.py
+++ b/pitivi/utils.py
@@ -341,7 +341,7 @@ class PropertyChangeTracker(Signallable):
         properties = {}
         for property_name in self.property_names:
             properties[property_name] = \
-                    obj.get_property (property_name.replace("-", "_"))
+                    obj.get_property(property_name.replace("-", "_"))
 
         return properties
 



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