[pitivi/ges: 280/287] Handle pipeline state change messages in mainwindow



commit 10a29171d2eae49baf1f45311c341cae66da63db
Author: Jean-FranÃois Fortin Tam <nekohayo gmail com>
Date:   Tue Feb 14 20:41:47 2012 -0500

    Handle pipeline state change messages in mainwindow
    
    Stop playback when reaching the end of the timeline

 pitivi/mainwindow.py |   18 ++++++++++++------
 pitivi/viewer.py     |   18 +++---------------
 2 files changed, 15 insertions(+), 21 deletions(-)
---
diff --git a/pitivi/mainwindow.py b/pitivi/mainwindow.py
index 83713ac..181aab8 100644
--- a/pitivi/mainwindow.py
+++ b/pitivi/mainwindow.py
@@ -675,13 +675,14 @@ class PitiviMainWindow(gtk.Window, Loggable):
             self.prefsdialog.dialog.set_transient_for(self)
         self.prefsdialog.run()
 
-    def _projectManagerNewProjectLoadedCb(self, projectManager, unused_project):
+    def _projectManagerNewProjectLoadedCb(self, projectManager, project):
         """
         Once a new project has been loaded, wait for media library's
         "ready" signal to populate the timeline.
         """
         self.log("A new project is loaded, wait for clips")
         self._connectToProjectSources(self.app.current.medialibrary)
+        self.setProjectPipeline(project.pipeline)
         self.app.current.timeline.connect("notify::duration",
                 self._timelineDurationChangedCb)
 
@@ -1045,16 +1046,21 @@ class PitiviMainWindow(gtk.Window, Loggable):
         """
         The pipeline has sent us a message. It could be that it reached the end
         of the stream or that the pipeline state changed (ex: playback started
-        or stopped). In that case, tell the timeline UI about the new state.
+        or stopped).
+
+        In that case, tell the timeline UI and viewer about the new state.
         """
         if message.type == gst.MESSAGE_EOS:
-            self.warning("eos")
+            # Playback reached the end of the timeline. Pause the pipeline
+            # to prevent playback from resuming when the user seeks somewhere.
+            self.app.current.pipeline.set_state(gst.STATE_PAUSED)
         elif message.type == gst.MESSAGE_STATE_CHANGED:
             prev, new, pending = message.parse_state_changed()
             if message.src == self._project_pipeline:
-                self.debug("Pipeline change state prev:%r, new:%r, pending:%r", prev, new, pending)
-                state_change = pending == gst.STATE_VOID_PENDING
-                if state_change:
+                self.debug("Pipeline state changed. Prev:%r, new:%r, pending:%r", prev, new, pending)
+                state_really_changed = pending == gst.STATE_VOID_PENDING
+                if state_really_changed:
+                    self.viewer.pipelineStateChanged(new)
                     self.timeline_ui.pipeline_state = new
 
 ## other
diff --git a/pitivi/viewer.py b/pitivi/viewer.py
index 051ca17..275a734 100644
--- a/pitivi/viewer.py
+++ b/pitivi/viewer.py
@@ -128,7 +128,6 @@ class PitiviViewer(gtk.VBox, Loggable):
         if self.pipeline:
             bus = self.pipeline.get_bus()
             bus.add_signal_watch()
-            bus.connect('message', self._busMessageCb)
             bus.set_sync_handler(self._elementMessageCb)
             self.pipeline.set_state(gst.STATE_PAUSED)
             self.currentState = gst.STATE_PAUSED
@@ -150,7 +149,6 @@ class PitiviViewer(gtk.VBox, Loggable):
 
         self.pipeline.disconnect_by_function(self._elementMessageCb)
         self.pipeline.disconnect_by_function(self._durationChangedCb)
-        self.pipeline.disconnect_by_function(self._eosCb)
         self.pipeline.stop()
 
         self.pipeline = None
@@ -480,10 +478,12 @@ class PitiviViewer(gtk.VBox, Loggable):
             return False
         return True
 
-    def _currentStateCb(self, state):
+    def pipelineStateChanged(self, state):
         """
         When playback starts/stops, update the viewer widget,
         play/pause button and (un)inhibit the screensaver.
+
+        This is meant to be called by mainwindow.
         """
         self.info("current state changed : %s", state)
         if int(state) == int(gst.STATE_PLAYING):
@@ -499,18 +499,6 @@ class PitiviViewer(gtk.VBox, Loggable):
         self.internal._currentStateCb(self.pipeline, state)
         self.currentState = state
 
-    def _busMessageCb(self, unused_bus, message):
-        if message.type == gst.MESSAGE_EOS:
-            # Playback (or rendering) reached the end of the timeline
-            self.playpause_button.setPlay()
-            self.system.uninhibitScreensaver(self.INHIBIT_REASON)
-        elif message.type == gst.MESSAGE_STATE_CHANGED:
-            prev, new, pending = message.parse_state_changed()
-
-            if message.src == self.pipeline:
-                self.debug("Pipeline change state prev:%r, new:%r, pending:%r", prev, new, pending)
-                self._currentStateCb(new)
-
     def _elementMessageCb(self, unused_bus, message):
         """
         When the pipeline sends us a message to prepare-xwindow-id,



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