[pitivi] Make Pitivi.loadProject always take an URI.



commit 6a3615baaca660fa726ed83101627684b3a71f92
Author: Alessandro Decina <alessandro d gmail com>
Date:   Tue Jun 2 16:06:37 2009 +0200

    Make Pitivi.loadProject always take an URI.
---
 pitivi/application.py   |   63 +++++++++++++++++++++--------------------------
 pitivi/ui/mainwindow.py |    2 +-
 2 files changed, 29 insertions(+), 36 deletions(-)

diff --git a/pitivi/application.py b/pitivi/application.py
index 3071ffb..19d2cd2 100644
--- a/pitivi/application.py
+++ b/pitivi/application.py
@@ -164,43 +164,36 @@ class Pitivi(Loggable, Signallable):
 
     ## old implementations
 
-    def loadProject(self, uri=None, filepath=None):
-        """ Load the given file through it's uri or filepath """
-        self.info("uri:%s, filepath:%s", uri, filepath)
-        if not uri and not filepath:
-            self.emit("new-project-failed", _("No location given."),
-                uri)
-            return
-        if filepath:
-            if not os.path.exists(filepath):
-                self.emit("new-project-failed",
-                          _("File does not exist"), filepath)
-                return
-            uri = "file://" + filepath
+    def loadProject(self, uri):
+        """ Load the given project file"""
         # is the given filepath a valid pitivi project
         formatter = get_formatter_for_uri(uri)
         if not formatter:
-            self.emit("new-project-failed", _("Not a valid project file."),
-                uri)
+            self.emit("new-project-failed",
+                    _("Not a valid project file."), uri)
             return
-        # 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 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)
+
+        if not self._closeRunningProject():
+            self.emit("new-project-failed",
+                    _("Couldn't close current project"), uri)
+            return
+
+        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 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)
@@ -309,8 +302,8 @@ class InteractivePitivi(Pitivi):
 
         if not options.import_sources and args:
             # load a project file
-            project = args[0]
-            self.loadProject(filepath=project)
+            project = "file://%s" % os.path.abspath(args[0])
+            self.loadProject(project)
         else:
             # load the passed filenames, optionally adding them to the timeline
             # (useful during development)
diff --git a/pitivi/ui/mainwindow.py b/pitivi/ui/mainwindow.py
index 85bd75d..aa5992b 100644
--- a/pitivi/ui/mainwindow.py
+++ b/pitivi/ui/mainwindow.py
@@ -499,7 +499,7 @@ class PitiviMainWindow(gtk.Window, Loggable):
         if response == gtk.RESPONSE_OK:
             uri = chooser.get_uri()
             uri = unquote(uri)
-            self.app.loadProject(uri = uri)
+            self.app.loadProject(uri)
 
         chooser.destroy()
         return True



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