From c4d56e551047189b8ce0ad6c1e3e744ed7c07cfc Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Mon, 13 Nov 2006 04:50:38 +0000 Subject: [PATCH] * src/Viewmanager.py: prompt before abandoning changes; enable autobackup * src/GrampsCfg.py: enable autobackup * src/Config/_GrampsConfigKeys.py: enable autobackup * data/gramps.schemas: enable autobackup svn: r7621 --- gramps2/ChangeLog | 5 ++++- gramps2/data/gramps.schemas.in | 12 ++++++++++++ gramps2/src/Config/_GrampsConfigKeys.py | 2 ++ gramps2/src/GrampsCfg.py | 18 ++++++++++-------- gramps2/src/ViewManager.py | 20 ++++++++++++++++++++ 5 files changed, 48 insertions(+), 9 deletions(-) diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index dce1652b4..20b2c49bf 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -1,5 +1,8 @@ 2006-11-12 Don Allingham - * src/Viewmanager.py: prompt before abandoning changes + * src/Viewmanager.py: prompt before abandoning changes; enable autobackup + * src/GrampsCfg.py: enable autobackup + * src/Config/_GrampsConfigKeys.py: enable autobackup + * data/gramps.schemas: enable autobackup * src/GrampsDb/_WriteGedcom.py: RepoRefs don't have a privacy flag 2006-11-11 Don Allingham diff --git a/gramps2/data/gramps.schemas.in b/gramps2/data/gramps.schemas.in index bf6bb03f5..34374e246 100644 --- a/gramps2/data/gramps.schemas.in +++ b/gramps2/data/gramps.schemas.in @@ -159,6 +159,18 @@ + + /schemas/apps/gramps/behavior/enable-autobackup + /apps/gramps/behavior/enable-autobackup + gramps + bool + 1 + + Backup database on exit + If set to True, an XML backup of the database is created on exit. + + + /schemas/apps/gramps/behavior/spellcheck /apps/gramps/behavior/spellcheck diff --git a/gramps2/src/Config/_GrampsConfigKeys.py b/gramps2/src/Config/_GrampsConfigKeys.py index 812f1f573..70db88cd5 100644 --- a/gramps2/src/Config/_GrampsConfigKeys.py +++ b/gramps2/src/Config/_GrampsConfigKeys.py @@ -32,6 +32,7 @@ HIDE_EP_MSG = ('preferences','hide-ep-msg', 0) LAST_VIEW = ('preferences','last-view', 1) USE_LAST_VIEW = ('preferences','use-last-view', 1) FAMILY_SIBLINGS = ('preferences','family-siblings', 0) +ENABLE_AUTOBACKUP = ('behavior','enable-autobackup', 1) AUTOLOAD = ('behavior','autoload', 0) SPELLCHECK = ('behavior','spellcheck', 0) BETAWARN = ('behavior','betawarn', 0) @@ -96,6 +97,7 @@ default_value = { USE_LAST_VIEW : True, FAMILY_SIBLINGS : True, AUTOLOAD : False, + ENABLE_AUTOBACKUP : True, SPELLCHECK : False, BETAWARN : False, WELCOME : 100, diff --git a/gramps2/src/GrampsCfg.py b/gramps2/src/GrampsCfg.py index 89422cb6e..8f5a5c2f7 100644 --- a/gramps2/src/GrampsCfg.py +++ b/gramps2/src/GrampsCfg.py @@ -490,22 +490,24 @@ class GrampsPreferences(ManagedWindow.ManagedWindow): table.set_col_spacings(6) table.set_row_spacings(6) + self.add_checkbox(table, _('Automatically backup database on exit'), + 0, Config.ENABLE_AUTOBACKUP) self.add_checkbox(table, _('Automatically load last database'), - 0, Config.AUTOLOAD) + 1, Config.AUTOLOAD) self.add_checkbox(table, _('Enable database transactions'), - 1, Config.TRANSACTIONS) + 2, Config.TRANSACTIONS) self.add_checkbox(table, _('Add default source on import'), - 2, Config.DEFAULT_SOURCE) + 3, Config.DEFAULT_SOURCE) self.add_checkbox(table, _('Enable spelling checker'), - 3, Config.SPELLCHECK) + 4, Config.SPELLCHECK) self.add_checkbox(table, _('Display Tip of the Day'), - 4, Config.USE_TIPS) + 5, Config.USE_TIPS) self.add_checkbox(table, _('Use shading in Relationship View'), - 5, Config.RELATION_SHADE) + 6, Config.RELATION_SHADE) self.add_checkbox(table, _('Display edit buttons on Relationship View'), - 6, Config.RELEDITBTN) + 7, Config.RELEDITBTN) self.add_checkbox(table, _('Remember last view displayed'), - 7, Config.USE_LAST_VIEW) + 8, Config.USE_LAST_VIEW) return table diff --git a/gramps2/src/ViewManager.py b/gramps2/src/ViewManager.py index 3241493d4..81b4a43d8 100644 --- a/gramps2/src/ViewManager.py +++ b/gramps2/src/ViewManager.py @@ -452,6 +452,7 @@ class ViewManager: self.uistate.push_message(self.state,_('Ready')) def quit(self, *obj): + self.backup() self.state.db.close() (width, height) = self.window.get_size() Config.set(Config.WIDTH, width) @@ -459,6 +460,25 @@ class ViewManager: Config.sync() gtk.main_quit() + def backup(self): + import GrampsDb + + if self.state.db.undoindex > 0: + bpath = self.state.db.get_save_path() + name = os.path.splitext(bpath) + + backup = name[0] + ".backup.gramps" + + if os.path.exists(backup): + os.rename(backup,backup + ".old") + self.uistate.set_busy_cursor(1) + self.uistate.progress.show() + self.uistate.push_message(self.state, _("Autobackup...")) + writer = GrampsDb.XmlWriter(self.state.db, self.uistate.pulse_progressbar, 0, 1) + writer.write(backup) + self.uistate.set_busy_cursor(0) + self.uistate.progress.hide() + def abort(self,obj=None): """ Abandon changes and quit.