[pitivi: 6/11] Discoverer: refactor signals.



commit abf06c32722a5cbd7f3e8e859c3942bfa694d5fe
Author: Alessandro Decina <alessandro d gmail com>
Date:   Wed May 6 15:39:36 2009 +0200

    Discoverer: refactor signals.
    
    Remove new_sourcefilefactory.
    Change finished_analyzing to discovery-done.
    Change not_media_file to discovery-error.
---
 pitivi/application.py    |    6 +++---
 pitivi/discoverer.py     |   24 +++++++++---------------
 pitivi/sourcelist.py     |   16 ++++++++--------
 pitivi/ui/sourcelist.py  |    4 ++--
 tests/test_discoverer.py |   26 +++++++++++++-------------
 5 files changed, 35 insertions(+), 41 deletions(-)

diff --git a/pitivi/application.py b/pitivi/application.py
index fa817c5..24db8f0 100644
--- a/pitivi/application.py
+++ b/pitivi/application.py
@@ -279,7 +279,7 @@ class InteractivePitivi(Pitivi):
             self._uris = uris
             self._duration = self.current.timeline.duration
             self.current.sources.connect("file_added", self._addSourceCb)
-            self.current.sources.connect("not_media_file", self._notMediaFileCb)
+            self.current.sources.connect("discovery-error", self._discoveryErrorCb)
         self.current.sources.addUris(uris)
 
     def _addSourceCb(self, unused_sourcelist, factory):
@@ -292,11 +292,11 @@ class InteractivePitivi(Pitivi):
             t.start = self._duration
             self._duration += t.duration
 
-    def _notMediaFileCb(self, sourcelist, uri, error, debug):
+    def _discoveryErrorCb(self, sourcelist, uri, error, debug):
         if uri in self._uris:
             self._uris.remove(uri)
             if not self._uris:
-                self.current.sources.disconnect_by_function(self._notMediaFileCb)
+                self.current.sources.disconnect_by_function(self._discoveryErrorCb)
 
     # properties
 
diff --git a/pitivi/discoverer.py b/pitivi/discoverer.py
index a73e501..0139ec0 100644
--- a/pitivi/discoverer.py
+++ b/pitivi/discoverer.py
@@ -51,24 +51,20 @@ class Discoverer(Signallable, Loggable):
     The discovery is done in a very fragmented way, so that it appears to be
     running in a separate thread.
 
-    The "new_sourcefilefactory" signal is emitted when a file is established
-    to be a media_file and the FileSourceFactory() is included in the signal.
-
-    The "not_media_file" signal is emitted if a file is not a media_file.
-
-    The "finished-analyzing" signal is emitted a file is finished being analyzed
-
     The "starting" signal is emitted when the discoverer starts analyzing some
     files.
 
     The "ready" signal is emitted when the discoverer has no more files to
     analyze.
+
+    The "discovery-done" signal is emitted an uri is finished being analyzed.
+    The "discovery-error" signal is emitted if an error is encountered while
+    analyzing an uri.
     """
 
     __signals__ = {
-        "new_sourcefilefactory" : ["factory"],
-        "not_media_file" : ["a", "b", "c" ],
-        "finished_analyzing" : ["factory"],
+        "discovery-error" : ["a", "b", "c" ],
+        "discovery-done" : ["factory"],
         "ready" : None,
         "starting" : None,
         "missing-plugins": ["uri", "detail", "description"]
@@ -193,9 +189,9 @@ class Discoverer(Signallable, Loggable):
             is_image = False
 
         if self.error:
-            self.emit('not_media_file', self.current_uri, self.error, self.error_debug)
+            self.emit('discovery-error', self.current_uri, self.error, self.error_debug)
         elif self.current_duration == gst.CLOCK_TIME_NONE and not is_image:
-            self.emit('not_media_file', self.current_uri,
+            self.emit('discovery-error', self.current_uri,
                       _("Could not establish the duration of the file."),
                       _("This clip seems to be in a format which cannot be accessed in a random fashion."))
         else:
@@ -216,9 +212,7 @@ class Discoverer(Signallable, Loggable):
                 for stream in self.current_streams:
                     factory.addOutputStream(stream)
 
-                self.emit('new_sourcefilefactory', factory)
-
-            self.emit('finished_analyzing', factory)
+            self.emit('discovery-done', factory)
 
         self.info("Cleaning up after finished analyzing %s", self.current_uri)
         self._resetState()
diff --git a/pitivi/sourcelist.py b/pitivi/sourcelist.py
index 230a497..1b11ea8 100644
--- a/pitivi/sourcelist.py
+++ b/pitivi/sourcelist.py
@@ -42,7 +42,7 @@ class SourceList(Signallable, Loggable):
     Signals:
      - C{file_added} : A file has been completely discovered and is valid.
      - C{file_removed} : A file was removed from the SourceList.
-     - C{not_media_file} : The given uri is not a media file.
+     - C{discovery-error} : The given uri is not a media file.
      - C{tmp_is_ready} : The temporary uri given to the SourceList is ready to use.
      - C{ready} : No more files are being discovered/added.
      - C{starting} : Some files are being discovered/added.
@@ -51,7 +51,7 @@ class SourceList(Signallable, Loggable):
     __signals__ = {
         "file_added" : ["factory"],
         "file_removed" : ["uri"],
-        "not_media_file" : ["uri", "reason"],
+        "discovery-error" : ["uri", "reason"],
         "tmp_is_ready": ["factory"],
         "ready" : None,
         "starting" : None,
@@ -66,8 +66,8 @@ class SourceList(Signallable, Loggable):
         self._sourceindex = []
         self.tempsources = {}
         self.discoverer = Discoverer()
-        self.discoverer.connect("not_media_file", self._notMediaFileCb)
-        self.discoverer.connect("finished_analyzing", self._finishedAnalyzingCb)
+        self.discoverer.connect("discovery-error", self._discoveryErrorCb)
+        self.discoverer.connect("discovery-done", self._discoveryDoneCb)
         self.discoverer.connect("starting", self._discovererStartingCb)
         self.discoverer.connect("ready", self._discovererReadyCb)
         self.discoverer.connect("missing-plugins",
@@ -166,7 +166,7 @@ class SourceList(Signallable, Loggable):
             res.append(self[i])
         return res
 
-    def _finishedAnalyzingCb(self, unused_discoverer, factory):
+    def _discoveryDoneCb(self, unused_discoverer, factory):
         # callback from finishing analyzing factory
         if factory.name in self.tempsources:
             self.tempsources[factory.name] = factory
@@ -174,11 +174,11 @@ class SourceList(Signallable, Loggable):
         elif factory.name in self.sources:
             self.addFactory(factory.name, factory)
 
-    def _notMediaFileCb(self, unused_discoverer, uri, reason, extra):
+    def _discoveryErrorCb(self, unused_discoverer, uri, reason, extra):
         if self.missing_plugins.pop(uri, None) is None:
-            # callback from the discoverer's 'not_media_file' signal
+            # callback from the discoverer's 'discovery-error' signal
             # remove it from the list
-            self.emit("not_media_file", uri, reason, extra)
+            self.emit("discovery-error", uri, reason, extra)
 
         if uri in self.sources and not self.sources[uri]:
             del self.sources[uri]
diff --git a/pitivi/ui/sourcelist.py b/pitivi/ui/sourcelist.py
index e6eca4c..52e59b3 100644
--- a/pitivi/ui/sourcelist.py
+++ b/pitivi/ui/sourcelist.py
@@ -350,7 +350,7 @@ class SourceList(gtk.VBox, Loggable):
         self.project_signals.connect(
             project.sources, "file_removed", None, self._fileRemovedCb)
         self.project_signals.connect(
-            project.sources, "not_media_file", None, self._notMediaFileCb)
+            project.sources, "discovery-error", None, self._discoveryErrorCb)
         self.project_signals.connect(
             project.sources, "missing-plugins", None, self._missingPluginsCb)
         self.project_signals.connect(
@@ -485,7 +485,7 @@ class SourceList(gtk.VBox, Loggable):
         if not len(model):
             self._displayTreeView(False)
 
-    def _notMediaFileCb(self, unused_sourcelist, uri, reason, extra):
+    def _discoveryErrorCb(self, unused_sourcelist, uri, reason, extra):
         """ The given uri isn't a media file """
         self.infostub.addErrors(uri, reason, extra)
 
diff --git a/tests/test_discoverer.py b/tests/test_discoverer.py
index 69eaf7f..b8b56d0 100644
--- a/tests/test_discoverer.py
+++ b/tests/test_discoverer.py
@@ -134,7 +134,7 @@ class TestAnalysis(TestCase):
             bag['error'] = error
 
         self.discoverer.addFile('buh://asd')
-        self.discoverer.connect('not_media_file', no_media_file_cb)
+        self.discoverer.connect('discovery-error', no_media_file_cb)
         self.discoverer._analyze()
         self.failUnlessEqual(bag['error'], 'No available source handler.')
 
@@ -148,7 +148,7 @@ class TestAnalysis(TestCase):
 
         self.discoverer.addFile('file://i/cant/possibly/exist/and/if/you/'
             'really/have/a/file/named/like/this/you/deserve/a/faillure')
-        self.discoverer.connect('not_media_file', no_media_file_cb)
+        self.discoverer.connect('discovery-error', no_media_file_cb)
         self.discoverer._analyze()
         self.failUnlessEqual(bag['error'], 'Pipeline didn\'t want '
                 'to go to PAUSED.')
@@ -158,10 +158,10 @@ class TestAnalysis(TestCase):
         Check that a timeout is set when analyzing a file.
         """
         bag = {'error': None}
-        def not_media_file_cb(disc, uri, error, error_debug):
+        def discovery_error_cb(disc, uri, error, error_debug):
             bag['error'] = error
 
-        self.discoverer.connect('not_media_file', not_media_file_cb)
+        self.discoverer.connect('discovery-error', discovery_error_cb)
         self.discoverer.addFile('foo')
         self.failUnlessEqual(bag['error'], None)
         self.discoverer._analyze()
@@ -266,13 +266,13 @@ class TestAnalysis(TestCase):
         self.failUnlessEqual(bag['called'], True)
 
     def testBusError(self):
-        def not_media_file_cb(discoverer, uri, error, debug, dic):
+        def discovery_error_cb(discoverer, uri, error, debug, dic):
             dic['uri'] = uri
             dic['error'] = error
             dic['debug'] = debug
 
         dic = {}
-        self.discoverer.connect('not_media_file', not_media_file_cb, dic)
+        self.discoverer.connect('discovery-error', discovery_error_cb, dic)
 
         src = gst.Pad('src', gst.PAD_SRC)
         gerror = gst.GError(gst.STREAM_ERROR, gst.STREAM_ERROR_FAILED, 'meh')
@@ -347,24 +347,24 @@ class TestStateChange(TestCase):
         self.error = None
         self.error_debug = None
 
-        self.discoverer.connect('not_media_file', self.notMediaFileCb)
-        self.discoverer.connect('new_sourcefilefactory',
-                self.newSourcefilefactoryCb)
+        self.discoverer.connect('discovery-error', self.discoveryErrorCb)
+        self.discoverer.connect('discovery-done',
+                self.discoveryDoneCb)
 
     def tearDown(self):
-        self.discoverer.disconnect_by_function(self.notMediaFileCb)
-        self.discoverer.disconnect_by_function(self.newSourcefilefactoryCb)
+        self.discoverer.disconnect_by_function(self.discoveryErrorCb)
+        self.discoverer.disconnect_by_function(self.discoveryDoneCb)
         self.discoverer = None
         self.factories = None
         self.error = None
         self.src = None
         TestCase.tearDown(self)
 
-    def notMediaFileCb(self, disc, uri, error, debug):
+    def discoveryErrorCb(self, disc, uri, error, debug):
         self.error = error
         self.error_debug = debug
 
-    def newSourcefilefactoryCb(self, disc, factory):
+    def discoveryDoneCb(self, disc, factory):
         self.failUnlessEqual(factory.duration, 10 * gst.SECOND)
         self.factories.append(factory)
 



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