[pitivi/ges: 258/287] Properly handle URIs and paths when loading projects



commit 7bfea0837ec8a803d3ab1cd51736bca3bb44aa5c
Author: Jean-FranÃois Fortin Tam <nekohayo gmail com>
Date:   Sat Feb 11 21:26:13 2012 -0500

    Properly handle URIs and paths when loading projects
    
    Remove a hack that made the startup wizard behave differently than the "Open project..." dialog

 pitivi/dialogs/startupwizard.py |   13 ++++++-------
 pitivi/mainwindow.py            |    4 +---
 pitivi/project.py               |   22 +++++++++++-----------
 pitivi/utils/misc.py            |   11 ++++++++++-
 4 files changed, 28 insertions(+), 22 deletions(-)
---
diff --git a/pitivi/dialogs/startupwizard.py b/pitivi/dialogs/startupwizard.py
index 7e3ff77..55ede5a 100644
--- a/pitivi/dialogs/startupwizard.py
+++ b/pitivi/dialogs/startupwizard.py
@@ -75,13 +75,12 @@ class StartUpWizard(object):
         self.app.gui.showProjectSettingsDialog()
 
     def _loadCb(self, unused_recent_chooser):
-        """Handle a double-click on the recent chooser."""
-        self.app.projectManager.loadProject(self._getFileName())
-
-    def _getFileName(self):
-        """Get the URI of the project selected in the recent chooser."""
-        uri = self.recent_chooser.get_current_uri()[7:]
-        return unquote(uri)
+        """
+        Handle choosing a project on the recent chooser.
+        This calls the project manager to load the associated URI.
+        """
+        uri = self.recent_chooser.get_current_uri()
+        self.app.projectManager.loadProject(uri)
 
     def _keyPressCb(self, widget, event):
         """Handle a key press event on the dialog."""
diff --git a/pitivi/mainwindow.py b/pitivi/mainwindow.py
index b597822..83713ac 100644
--- a/pitivi/mainwindow.py
+++ b/pitivi/mainwindow.py
@@ -657,9 +657,7 @@ class PitiviMainWindow(gtk.Window, Loggable):
         response = chooser.run()
         self.settings.lastProjectFolder = chooser.get_current_folder()
         if response == gtk.RESPONSE_OK:
-            uri = chooser.get_uri()
-            uri = unquote(uri)
-            self.app.projectManager.loadProject(uri)
+            self.app.projectManager.loadProject(chooser.get_uri())
 
         chooser.destroy()
         return True
diff --git a/pitivi/project.py b/pitivi/project.py
index adfd2d2..a0657c1 100644
--- a/pitivi/project.py
+++ b/pitivi/project.py
@@ -33,8 +33,6 @@ import gobject
 from time import time
 from datetime import datetime
 from gettext import gettext as _
-from urllib import unquote
-from urlparse import urlparse
 from pwd import getpwuid
 
 from pitivi.medialibrary import MediaLibrary
@@ -42,7 +40,7 @@ from pitivi.settings import MultimediaSettings
 from pitivi.undo.undo import UndoableAction
 from pitivi.configure import get_ui_dir
 
-from pitivi.utils.misc import quote_uri
+from pitivi.utils.misc import quote_uri, path_from_uri
 from pitivi.utils.playback import Seeker
 from pitivi.utils.loggable import Loggable
 from pitivi.utils.signal import Signallable
@@ -148,18 +146,21 @@ class ProjectManager(Signallable, Loggable):
         """
         self.emit("new-project-loading", uri)
 
-        backup_path = self._makeBackupURI(uri)
+        # We really want a path for os.path to work
+        path = path_from_uri(uri)
+        backup_path = self._makeBackupURI(path)
         use_backup = False
         try:
-            time_diff = os.path.getmtime(backup_path) - os.path.getmtime(uri)
+            time_diff = os.path.getmtime(backup_path) - os.path.getmtime(path)
+            self.debug('Backup file "%s" is %d secs newer' % (backup_path, time_diff))
         except OSError:
             self.debug('Backup file "%s" does not exist' % backup_path)
         else:
             if time_diff > 0:
                 use_backup = self._restoreFromBackupDialog(time_diff)
         if use_backup:
-            uri = backup_path
-            self.debug('Loading project from backup file "%s"' % uri)
+            path = backup_path
+            self.debug('Loading project from backup file "%s"' % path)
             # Make a new project instance, but don't specify the URI.
             # That way, we force the user to "Save as" (which ensures that the
             # changes in the loaded backup file are approved by the user).
@@ -167,13 +168,13 @@ class ProjectManager(Signallable, Loggable):
         else:
             # Load the project normally.
             # The "old" backup file will eventually be deleted or overwritten.
-            self.current = Project(uri=uri)
+            self.current = Project(uri=path)
 
         self.timeline = self.current.timeline
         self.formatter = ges.PitiviFormatter()
         self.formatter.connect("source-moved", self._formatterMissingURICb)
         self.formatter.connect("loaded", self._projectLoadedCb)
-        if self.formatter.load_from_uri(self.timeline, uri):
+        if self.formatter.load_from_uri(self.timeline, path):
             self.current.connect("project-changed", self._projectChangedCb)
 
     def _restoreFromBackupDialog(self, time_diff):
@@ -373,8 +374,7 @@ class ProjectManager(Signallable, Loggable):
     def _cleanBackup(self, uri):
         if uri is None:
             return
-        location = self._makeBackupURI(uri)
-        path = unquote(urlparse(location).netloc)
+        path = path_from_uri(self._makeBackupURI(uri))
         if os.path.exists(path):
             os.remove(path)
             self.debug('Removed backup file "%s"' % path)
diff --git a/pitivi/utils/misc.py b/pitivi/utils/misc.py
index dfb5c88..ddff098 100644
--- a/pitivi/utils/misc.py
+++ b/pitivi/utils/misc.py
@@ -32,7 +32,7 @@ import struct
 import time
 import threading
 
-from urlparse import urlsplit, urlunsplit
+from urlparse import urlsplit, urlunsplit, urlparse
 from urllib import quote, unquote
 
 import pitivi.utils.loggable as log
@@ -134,6 +134,15 @@ def get_filesystem_encoding():
     return sys.getfilesystemencoding() or "utf-8"
 
 
+def path_from_uri(uri):
+    """
+    Return a human-readable path that can be used with python's os.path
+    """
+    foo = urlparse(uri)
+    path = foo.netloc + foo.path
+    return unquote(path)
+
+
 def quote_uri(uri):
     """
     Encode a URI according to RFC 2396, without touching the file:/// part.



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