Beispiel #1
0
 def isRemoveButtonSensitive(self):
     """Check if Remove buttons should be sensitive"""
     if not self.cur_preset or self.cur_preset == _("No preset"):
         return False
     try:
         full_path = self.presets[self.cur_preset]["filepath"]
         (dir, name) = os.path.split(full_path)
     except KeyError:
         # This is a newly created preset that has not yet been saved
         # We cannot remove it since it does not exist
         return False
     if dir == self.default_path or not isWritable(full_path):
         # default_path is the system-wide directory where the default
         # presets are installed; they are not expected to be editable.
         return False
     return True
Beispiel #2
0
    def saveProject(self, project, uri=None, overwrite=False, formatter=None, backup=False):
        """
        Save the L{Project} to the given location.

        If specified, use the given formatter.

        @type project: L{Project}
        @param project: The L{Project} to save.
        @type uri: L{str}
        @param uri: The absolute URI of the location to store the project to.
        @param overwrite: Whether to overwrite existing location.
        @type overwrite: C{bool}
        @type formatter: L{Formatter}
        @param formatter: The L{Formatter} to use to store the project if specified.
        If it is not specified, then it will be saved at its original format.
        @param backup: Whether the requested save operation is for a backup
        @type backup: C{bool}

        @see: L{Formatter.saveProject}
        """
        if formatter is None:
            formatter = GES.PitiviFormatter()
        if backup:
            if project.uri and self.current.uri is not None:
                # Ignore whatever URI that is passed on to us. It's a trap.
                uri = self._makeBackupURI(project.uri)
            else:
                # Do not try to save backup files for blank projects.
                # It is possible that self.current.uri == None when the backup
                # timer sent us an old instance of the (now closed) project.
                return
        elif uri is None:
            # This allows calling saveProject without specifying the target URI
            uri = project.uri
        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 formatter.can_save_uri(uri):
            self.emit("save-project-failed", uri,
                    _("Cannot save with this file format."))
            return

        if overwrite or not os.path.exists(path_from_uri(uri)):
            formatter.set_sources(project.medialibrary.getSources())
            saved = formatter.save_to_uri(project.timeline, uri)
            if saved:
                if not backup:
                    # Do not emit the signal when autosaving a backup file
                    self.emit("project-saved", project, uri)
                    self.debug('Saved project "%s"' % uri)
                else:
                    self.debug('Saved backup "%s"' % uri)
            return saved