[pitivi] Application: forward missing-uri signal from formatter. Partially fixes #580654



commit a465b19e592e1e8678e007c7ccb6ab6a6051db04
Author: Brandon Lewis <brandon_lewis berkeley edu>
Date:   Tue May 19 00:22:30 2009 -0700

    Application: forward missing-uri signal from formatter. Partially fixes #580654
---
 pitivi/application.py   |   10 +++++++++-
 pitivi/ui/mainwindow.py |   36 ++++++++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+), 1 deletions(-)

diff --git a/pitivi/application.py b/pitivi/application.py
index 24db8f0..9ad9500 100644
--- a/pitivi/application.py
+++ b/pitivi/application.py
@@ -45,6 +45,7 @@ from pitivi.log.loggable import Loggable
 from pitivi.log import log
 from pitivi.project import Project
 from pitivi.formatters.format import get_formatter_for_uri
+from pitivi.formatters.base import FormatterError
 
 # FIXME : Speedup loading time
 # Currently we load everything in one go
@@ -90,6 +91,7 @@ class Pitivi(Loggable, Signallable):
         "closing-project" : ["project"],
         "project-closed" : ["project"],
         "new-project-failed" : ["reason", "uri"],
+        "missing-uri" : ["formatter", "uri"],
         "shutdown" : None
         }
 
@@ -180,18 +182,24 @@ class Pitivi(Loggable, Signallable):
         # if current project, try to close it
         if self._closeRunningProject():
             project = formatter.newProject()
+            formatter.connect("missing-uri", self._missingURICb)
             self.emit("new-project-loading", project)
             self.info("Got a new project %r, calling loadProject", project)
             try:
                 formatter.loadProject(uri, project)
                 self.current = project
                 self.emit("new-project-loaded", self.current)
-            except Exception, e:
+            except FormatterError, e:
                 self.handleException(e)
                 self.warning("error loading the project")
                 self.current = None
                 self.emit("new-project-failed",
                     _("There was an error loading the file."), uri)
+            finally:
+                formatter.disconnect_by_function(self._missingURICb)
+
+    def _missingURICb(self, formatter, uri):
+        self.emit("missing-uri", formatter, uri)
 
     def _closeRunningProject(self):
         """ close the current project """
diff --git a/pitivi/ui/mainwindow.py b/pitivi/ui/mainwindow.py
index 398db37..63bc497 100644
--- a/pitivi/ui/mainwindow.py
+++ b/pitivi/ui/mainwindow.py
@@ -679,6 +679,42 @@ class PitiviMainWindow(gtk.Window, Loggable):
         dialog.destroy()
         self.set_sensitive(True)
 
+    @handler(app, "missing-uri")
+    def _missingUriCb(self, instance, formatter, uri):
+        dialog = gtk.Dialog(_("Locate missing file..."), 
+            self,
+            gtk.DIALOG_MODAL,
+            buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
+            gtk.STOCK_OPEN, gtk.RESPONSE_OK))
+        dialog.set_border_width(12)
+        dialog.get_content_area().set_spacing(6)
+
+        label = gtk.Label(_("Please locate the missing file, '%s'" % uri))
+        dialog.get_content_area().pack_start(label, False, False)
+        label.show()
+
+        chooser = gtk.FileChooserWidget(action=gtk.FILE_CHOOSER_ACTION_OPEN)
+        chooser.set_select_multiple(False)
+        chooser.set_current_folder(self.settings.lastProjectFolder)
+        dialog.get_content_area().pack_start(chooser, True, True)
+        chooser.show()
+
+        response = dialog.run()
+
+        if response == gtk.RESPONSE_OK:
+            self.log("User chose a URI to save project to")
+            new = chooser.get_uri()
+            formatter.addMapping(uri, new)
+        else:
+            self.log("User didn't choose a URI to save project to")
+            # FIXME: not calling addMapping doesn't keep the formatter from
+            # re-emitting the same signal. How do we get out of this
+            # situation?
+            pass
+
+        dialog.destroy()
+
+
 ## PiTiVi current project callbacks
 
     def _setProject(self):



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