[pitivi: 1/9] projectmanager: saves backup/recovery files when project changes
- From: Edward Hervey <edwardrv src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pitivi: 1/9] projectmanager: saves backup/recovery files when project changes
- Date: Sun, 5 Sep 2010 09:07:32 +0000 (UTC)
commit 2a8321d66c3900c45e7e900d6a0d125fa4cca1f2
Author: Luis de Bethencourt <luis debethencourt com>
Date: Tue Aug 24 12:45:59 2010 +0200
projectmanager: saves backup/recovery files when project changes
pitivi/formatters/base.py | 10 +++++-----
pitivi/project.py | 3 +++
pitivi/projectmanager.py | 35 +++++++++++++++++++++++++++++++++--
pitivi/settings.py | 2 +-
4 files changed, 42 insertions(+), 8 deletions(-)
---
diff --git a/pitivi/formatters/base.py b/pitivi/formatters/base.py
index 2a0c12f..9ad93f5 100644
--- a/pitivi/formatters/base.py
+++ b/pitivi/formatters/base.py
@@ -175,7 +175,7 @@ class Formatter(Signallable, Loggable):
# finally return the project.
return self.project
- def saveProject(self, project, location, overwrite=False):
+ def saveProject(self, project, location, overwrite=False, backup=False):
"""
Saves the given project to the given location.
@@ -194,11 +194,11 @@ class Formatter(Signallable, Loggable):
raise FormatterURIError()
if overwrite == False and uri_is_reachable(location):
raise FormatterOverwriteError()
- old_uri = project.uri
if self._saveProject(project, location):
- project.uri = location
- project.name = self._projectNameFromURI(location)
- self.emit("project-saved", project, location)
+ if not backup:
+ project.uri = location
+ project.name = self._projectNameFromURI(location)
+ self.emit("project-saved", project, location)
return True
return False
diff --git a/pitivi/project.py b/pitivi/project.py
index 0872cbc..670c466 100644
--- a/pitivi/project.py
+++ b/pitivi/project.py
@@ -66,6 +66,7 @@ class Project(Signallable, Loggable):
__signals__ = {
"settings-changed" : ['old', 'new'],
+ "project-changed" : [],
}
def __init__(self, name="", uri=None, **kwargs):
@@ -184,6 +185,8 @@ class Project(Signallable, Loggable):
def setModificationState(self, state):
self._dirty = state
+ if state:
+ self.emit('project-changed')
def hasUnsavedModifications(self):
return self._dirty
diff --git a/pitivi/projectmanager.py b/pitivi/projectmanager.py
index ff7a97c..a8fcf1c 100644
--- a/pitivi/projectmanager.py
+++ b/pitivi/projectmanager.py
@@ -23,6 +23,7 @@ from gettext import gettext as _
import gobject
gobject.threads_init()
import gst
+import os
from pitivi.project import Project
from pitivi.formatters.format import get_formatter_for_uri
@@ -85,6 +86,7 @@ class ProjectManager(Signallable, Loggable):
Loggable.__init__(self)
self.current = None
+ self.backup_lock = 0
def loadProject(self, uri):
""" Load the given project file"""
@@ -105,7 +107,7 @@ class ProjectManager(Signallable, Loggable):
# start loading the project, from now on everything is async
formatter.loadProject(uri)
- def saveProject(self, project, uri=None, overwrite=False, formatter=None):
+ def saveProject(self, project, uri=None, overwrite=False, formatter=None, backup=False):
"""
Save the L{Project} to the given location.
@@ -141,7 +143,7 @@ class ProjectManager(Signallable, Loggable):
uri = project.uri
self._connectToFormatter(formatter)
- return formatter.saveProject(project, uri, overwrite)
+ return formatter.saveProject(project, uri, overwrite, backup)
def closeRunningProject(self):
""" close the current project """
@@ -154,6 +156,7 @@ class ProjectManager(Signallable, Loggable):
return False
self.emit("project-closed", self.current)
+ self.current.disconnect_by_function(self._projectChangedCb)
self.current.release()
self.current = None
@@ -179,6 +182,7 @@ class ProjectManager(Signallable, Loggable):
audio = AudioStream(gst.Caps('audio/x-raw-int; audio/x-raw-float'))
track = Track(audio)
project.timeline.addTrack(track)
+ project.connect("project-changed", self._projectChangedCb)
self.emit("new-project-loaded", self.current)
@@ -199,6 +203,32 @@ class ProjectManager(Signallable, Loggable):
self.closeRunningProject()
self.loadProject(uri)
+ def _projectChangedCb(self, project):
+ # The backup_lock is a timer, when a change in the project is done it is
+ # set to 10 seconds. If before those 10 seconds pass an other change is done
+ # 5 seconds are added in the timeout callback instead of saving the backup
+ # file. The limit is 60 seconds.
+ uri = project.uri
+ if uri != None:
+ if self.backup_lock == 0:
+ self.backup_lock = 10
+ gobject.timeout_add_seconds(self.backup_lock, self._saveBackupCb, \
+ project, uri)
+ else:
+ if self.backup_lock < 60:
+ self.backup_lock += 5
+
+ def _saveBackupCb(self, project, uri):
+ if self.backup_lock > 10:
+ self.backup_lock -= 5
+ return True
+ else:
+ name, ext = os.path.splitext(uri)
+ if ext == '.xptv':
+ uri = name + "~" + ext
+ self.saveProject(project, uri, overwrite=True, backup=True)
+ self.backup_lock = 0
+ return False
def _getFormatterForUri(self, uri):
return get_formatter_for_uri(uri)
@@ -231,6 +261,7 @@ class ProjectManager(Signallable, Loggable):
self._disconnectFromFormatter(formatter)
self.current = project
+ project.connect("project-changed", self._projectChangedCb)
self.emit("new-project-loaded", project)
def _formatterNewProjectFailed(self, formatter, uri, exception):
diff --git a/pitivi/settings.py b/pitivi/settings.py
index 1c498b3..d5e2c35 100644
--- a/pitivi/settings.py
+++ b/pitivi/settings.py
@@ -57,7 +57,7 @@ def get_bool_env(var):
def get_env_by_type(type_, var):
"""
- Returns the environement variable.
+ Returns the environment variable.
@arg type_: The type of the variable
@type type_: C{type}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]