From c8a527db21bca1ed8627727a6cff19f71490cc9f Mon Sep 17 00:00:00 2001 From: Alex Roitman Date: Tue, 13 May 2003 03:35:39 +0000 Subject: [PATCH] User input when files are lost on Import svn: r1519 --- gramps2/src/QuestionDialog.py | 25 ++++ gramps2/src/ReadXML.py | 107 +++++++++----- gramps2/src/errdialogs.glade | 265 ++++++++++++++++++++++++++++++++++ 3 files changed, 361 insertions(+), 36 deletions(-) diff --git a/gramps2/src/QuestionDialog.py b/gramps2/src/QuestionDialog.py index 7e047a0ac..af56bf8f6 100644 --- a/gramps2/src/QuestionDialog.py +++ b/gramps2/src/QuestionDialog.py @@ -143,4 +143,29 @@ class OkDialog: self.top.run() self.top.destroy() +class MissingMediaDialog: + def __init__(self,msg1,msg2,task1,task2,task3): + self.xml = gtk.glade.XML(const.errdialogsFile,"missmediadialog") + self.top = self.xml.get_widget('missmediadialog') + self.task1 = task1 + self.task2 = task2 + self.task3 = task3 + label1 = self.xml.get_widget('label4') + label1.set_text('%s' % msg1) + label1.set_use_markup(gtk.TRUE) + + label2 = self.xml.get_widget('label3') + label2.set_text(msg2) + label2.set_use_markup(gtk.TRUE) + + self.top.show() + response = self.top.run() + if response == 1: + self.task1() + elif response == 2: + self.task2() + elif response == 3: + self.task3() + self.top.destroy() + diff --git a/gramps2/src/ReadXML.py b/gramps2/src/ReadXML.py index a7a95ee18..423078389 100644 --- a/gramps2/src/ReadXML.py +++ b/gramps2/src/ReadXML.py @@ -29,6 +29,7 @@ #------------------------------------------------------------------------- import string import os +import gtk import shutil from xml.parsers.expat import ExpatError @@ -39,8 +40,9 @@ from xml.parsers.expat import ExpatError #------------------------------------------------------------------------- import RelLib from GrampsParser import GrampsParser, GrampsImportParser -from QuestionDialog import ErrorDialog, WarningDialog +from QuestionDialog import ErrorDialog, WarningDialog, MissingMediaDialog from intl import gettext as _ +import Utils #------------------------------------------------------------------------- # @@ -113,8 +115,66 @@ def importData(database, filename, callback): return 0 xml_file.close() - del parser +#------------------------------------------------------------------------- + def remove_clicked(): + # File is lost => remove all references and the object itself + mobj = ObjectMap[NewMediaID] + for p in database.getFamilyMap().values(): + nl = p.getPhotoList() + for o in nl: + if o.getReference() == mobj: + nl.remove(o) + p.setPhotoList(nl) + for key in database.getPersonKeys(): + p = database.getPerson(key) + nl = p.getPhotoList() + for o in nl: + if o.getReference() == mobj: + nl.remove(o) + p.setPhotoList(nl) + for key in database.getSourceKeys(): + p = database.getSource(key) + nl = p.getPhotoList() + for o in nl: + if o.getReference() == mobj: + nl.remove(o) + p.setPhotoList(nl) + for key in database.getPlaceKeys(): + p = database.getPlace(key) + nl = p.getPhotoList() + for o in nl: + if o.getReference() == mobj: + nl.remove(o) + p.setPhotoList(nl) + database.removeObject(NewMediaID) + + + def leave_clicked(): + # File is lost => do nothing, leave as is + pass + + + def select_clicked(): + # File is lost => select a file to replace the lost one + def fs_close_window(obj): + fs_top.destroy() + + def fs_ok_clicked(obj): + name = fs_top.get_filename() + if os.path.isfile(name): + shutil.copy2(name,newfile) + Utils.destroy_passed_object(fs_top) + + fs_top = gtk.FileSelection("%s - GRAMPS" % _("Select file")) + fs_top.hide_fileop_buttons() + fs_top.ok_button.connect('clicked',fs_ok_clicked) + fs_top.cancel_button.connect('clicked',fs_close_window) + fs_top.show() + fs_top.run() + +#------------------------------------------------------------------------- + # Rename media files if they were conflicting with existing ones ObjectMap = database.getObjectMap() newpath = database.getSavePath() @@ -125,44 +185,19 @@ def importData(database, filename, callback): (junk,oldext) = os.path.splitext(os.path.basename(oldfile)) oldfile = os.path.join(basefile,OldMediaID+oldext) newfile = os.path.join(newpath,NewMediaID+oldext) + ObjectMap[NewMediaID].setPath(newfile) + ObjectMap[NewMediaID].setLocal(1) try: shutil.copy2(oldfile,newfile) - ObjectMap[NewMediaID].setPath(os.path.join(newfile)) - ObjectMap[NewMediaID].setLocal(1) except: - # File is lost => remove all references and the object itself - mobj = ObjectMap[NewMediaID] - for p in database.getFamilyMap().values(): - nl = p.getPhotoList() - for o in nl: - if o.getReference() == mobj: - nl.remove(o) - p.setPhotoList(nl) - for key in database.getPersonKeys(): - p = database.getPerson(key) - nl = p.getPhotoList() - for o in nl: - if o.getReference() == mobj: - nl.remove(o) - p.setPhotoList(nl) - for key in database.getSourceKeys(): - p = database.getSource(key) - nl = p.getPhotoList() - for o in nl: - if o.getReference() == mobj: - nl.remove(o) - p.setPhotoList(nl) - for key in database.getPlaceKeys(): - p = database.getPlace(key) - nl = p.getPhotoList() - for o in nl: - if o.getReference() == mobj: - nl.remove(o) - p.setPhotoList(nl) - - database.removeObject(NewMediaID) - + # File is lost => ask what to do + MissingMediaDialog(_("The file %s is not found") % oldfile, + _("Please choose what you want to do.\n"), + remove_clicked, leave_clicked, select_clicked) + + del parser return 1 + #------------------------------------------------------------------------- # diff --git a/gramps2/src/errdialogs.glade b/gramps2/src/errdialogs.glade index 4ae38ef55..81f90f462 100644 --- a/gramps2/src/errdialogs.glade +++ b/gramps2/src/errdialogs.glade @@ -824,4 +824,269 @@ + + + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + False + True + False + False + + + + True + False + 0 + + + + True + GTK_BUTTONBOX_END + + + + True + Remove object and all references to it from the database + True + True + GTK_RELIEF_NORMAL + 1 + + + + True + 0.5 + 0.5 + 0 + 0 + + + + True + False + 2 + + + + True + gtk-delete + 4 + 0.5 + 0.5 + 0 + 0 + + + 0 + False + False + + + + + + True + _Remove object + True + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + 0 + False + False + + + + + + + + + + + + True + Leave database as is (missing the file) + True + True + _Leave as is + True + GTK_RELIEF_NORMAL + 2 + + + + + + True + Select missing file now + True + True + True + True + GTK_RELIEF_NORMAL + 3 + + + + True + 0.5 + 0.5 + 0 + 0 + + + + True + False + 2 + + + + True + gtk-find + 4 + 0.5 + 0.5 + 0 + 0 + + + 0 + False + False + + + + + + True + _Select file + True + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + 0 + False + False + + + + + + + + + + + 0 + False + True + GTK_PACK_END + + + + + + 12 + True + 2 + 3 + False + 0 + 0 + + + + True + + False + True + GTK_JUSTIFY_LEFT + True + False + 0 + 0.5 + 6 + 24 + + + 2 + 3 + 1 + 2 + fill + + + + + + + True + gtk-dialog-warning + 6 + 0.5 + 0 + 0 + 0 + + + 0 + 1 + 0 + 2 + fill + fill + + + + + + True + + False + True + GTK_JUSTIFY_LEFT + True + False + 0 + 0.5 + 6 + 0 + + + 2 + 3 + 0 + 1 + expand|shrink|fill + + + + + + 0 + True + True + + + + + +