[pitivi] Handle project save errors properly



commit eddd525a6de5fce90783d7631ccd3721c3516537
Author: Jean-FranÃois Fortin Tam <nekohayo gmail com>
Date:   Sat Jul 14 18:50:16 2012 -0400

    Handle project save errors properly
    
    Show an error dialog to alert the user that saving failed.

 pitivi/mainwindow.py |   17 ++++++++++++++---
 pitivi/project.py    |   16 +++++++++++++---
 2 files changed, 27 insertions(+), 6 deletions(-)
---
diff --git a/pitivi/mainwindow.py b/pitivi/mainwindow.py
index a2c8c77..f3dd610 100644
--- a/pitivi/mainwindow.py
+++ b/pitivi/mainwindow.py
@@ -766,9 +766,20 @@ class PitiviMainWindow(gtk.Window, Loggable):
             self.recent_manager.add_item(uri)
         self.log("A NEW project is loading, deactivate UI")
 
-    def _projectManagerSaveProjectFailedCb(self, projectManager,
-            unused_project, uri):
-        # FIXME: do something here
+    def _projectManagerSaveProjectFailedCb(self, projectManager, uri, exception=None):
+        project_filename = unquote(uri.split("/")[-1])
+        dialog = gtk.MessageDialog(self,
+            gtk.DIALOG_MODAL,
+            gtk.MESSAGE_ERROR,
+            gtk.BUTTONS_OK,
+            _('Unable to save project "%s"') % project_filename)
+        dialog.set_title(_("Error Saving Project"))
+        if exception:
+            dialog.set_property("secondary-use-markup", True)
+            dialog.set_property("secondary-text", unquote(str(exception)))
+        dialog.set_transient_for(self)
+        dialog.run()
+        dialog.destroy()
         self.error("failed to save project")
 
     def _projectManagerProjectSavedCb(self, projectManager, project, uri):
diff --git a/pitivi/project.py b/pitivi/project.py
index 213209e..6e459f9 100644
--- a/pitivi/project.py
+++ b/pitivi/project.py
@@ -41,7 +41,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, path_from_uri
+from pitivi.utils.misc import quote_uri, path_from_uri, isWritable
 from pitivi.utils.pipeline import Seeker
 from pitivi.utils.loggable import Loggable
 from pitivi.utils.signal import Signallable
@@ -102,7 +102,7 @@ class ProjectManager(Signallable, Loggable):
         "new-project-created": ["project"],
         "new-project-failed": ["uri", "exception"],
         "new-project-loaded": ["project"],
-        "save-project-failed": ["project", "uri", "exception"],
+        "save-project-failed": ["uri", "exception"],
         "project-saved": ["project", "uri"],
         "closing-project": ["project"],
         "project-closed": ["project"],
@@ -253,12 +253,22 @@ class ProjectManager(Signallable, Loggable):
         else:
             # Ensure the URI we are given is properly encoded, or GIO will fail
             uri = quote_uri(uri)
+
+            # The following needs to happen before we change project.uri:
+            if not isWritable(path_from_uri(uri)):
+                # TODO: this will not be needed when GTK+ bug #601451 is fixed
+                self.emit("save-project-failed", uri,
+                        _("You do not have permissions to write to this folder."))
+                return
+
             # Update the project instance's uri for the "Save as" scenario.
             # Otherwise, subsequent saves will be to the old uri.
             if not backup:
                 project.uri = uri
+
         if uri is None or not ges.formatter_can_save_uri(uri):
-            self.emit("save-project-failed", project, uri)
+            self.emit("save-project-failed", uri,
+                    _("Cannot save with this file format."))
             return
 
         # FIXME Using query_exist is not the best thing to do, but makes



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