User input when files are lost on Import

svn: r1519
This commit is contained in:
Alex Roitman 2003-05-13 03:35:39 +00:00
parent 8fe2ef9602
commit 72cb88a487
3 changed files with 361 additions and 36 deletions

View File

@ -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('<span weight="bold" size="larger">%s</span>' % 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()

View File

@ -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
#-------------------------------------------------------------------------
#

View File

@ -824,4 +824,269 @@
</child>
</widget>
<widget class="GtkDialog" id="missmediadialog">
<property name="title" translatable="yes"></property>
<property name="type">GTK_WINDOW_TOPLEVEL</property>
<property name="window_position">GTK_WIN_POS_NONE</property>
<property name="modal">False</property>
<property name="resizable">True</property>
<property name="destroy_with_parent">False</property>
<property name="has_separator">False</property>
<child internal-child="vbox">
<widget class="GtkVBox" id="vbox5">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child internal-child="action_area">
<widget class="GtkHButtonBox" id="hbuttonbox5">
<property name="visible">True</property>
<property name="layout_style">GTK_BUTTONBOX_END</property>
<child>
<widget class="GtkButton" id="button8">
<property name="visible">True</property>
<property name="tooltip" translatable="yes">Remove object and all references to it from the database</property>
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="response_id">1</property>
<child>
<widget class="GtkAlignment" id="alignment4">
<property name="visible">True</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xscale">0</property>
<property name="yscale">0</property>
<child>
<widget class="GtkHBox" id="hbox4">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">2</property>
<child>
<widget class="GtkImage" id="image11">
<property name="visible">True</property>
<property name="stock">gtk-delete</property>
<property name="icon_size">4</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label8">
<property name="visible">True</property>
<property name="label" translatable="yes">_Remove object</property>
<property name="use_underline">True</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
</widget>
</child>
</widget>
</child>
</widget>
</child>
<child>
<widget class="GtkButton" id="button9">
<property name="visible">True</property>
<property name="tooltip" translatable="yes">Leave database as is (missing the file)</property>
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">_Leave as is</property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="response_id">2</property>
</widget>
</child>
<child>
<widget class="GtkButton" id="button11">
<property name="visible">True</property>
<property name="tooltip" translatable="yes">Select missing file now</property>
<property name="can_default">True</property>
<property name="has_default">True</property>
<property name="can_focus">True</property>
<property name="has_focus">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="response_id">3</property>
<child>
<widget class="GtkAlignment" id="alignment3">
<property name="visible">True</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xscale">0</property>
<property name="yscale">0</property>
<child>
<widget class="GtkHBox" id="hbox3">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">2</property>
<child>
<widget class="GtkImage" id="image10">
<property name="visible">True</property>
<property name="stock">gtk-find</property>
<property name="icon_size">4</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label7">
<property name="visible">True</property>
<property name="label" translatable="yes">_Select file</property>
<property name="use_underline">True</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
</widget>
</child>
</widget>
</child>
</widget>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">GTK_PACK_END</property>
</packing>
</child>
<child>
<widget class="GtkTable" id="table7">
<property name="border_width">12</property>
<property name="visible">True</property>
<property name="n_rows">2</property>
<property name="n_columns">3</property>
<property name="homogeneous">False</property>
<property name="row_spacing">0</property>
<property name="column_spacing">0</property>
<child>
<widget class="GtkLabel" id="label3">
<property name="visible">True</property>
<property name="label" translatable="yes"></property>
<property name="use_underline">False</property>
<property name="use_markup">True</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">True</property>
<property name="selectable">False</property>
<property name="xalign">0</property>
<property name="yalign">0.5</property>
<property name="xpad">6</property>
<property name="ypad">24</property>
</widget>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">fill</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkImage" id="image7">
<property name="visible">True</property>
<property name="stock">gtk-dialog-warning</property>
<property name="icon_size">6</property>
<property name="xalign">0.5</property>
<property name="yalign">0</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
<packing>
<property name="left_attach">0</property>
<property name="right_attach">1</property>
<property name="top_attach">0</property>
<property name="bottom_attach">2</property>
<property name="x_options">fill</property>
<property name="y_options">fill</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label4">
<property name="visible">True</property>
<property name="label" translatable="yes"></property>
<property name="use_underline">False</property>
<property name="use_markup">True</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">True</property>
<property name="selectable">False</property>
<property name="xalign">0</property>
<property name="yalign">0.5</property>
<property name="xpad">6</property>
<property name="ypad">0</property>
</widget>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
<property name="top_attach">0</property>
<property name="bottom_attach">1</property>
<property name="x_options">expand|shrink|fill</property>
<property name="y_options"></property>
</packing>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
</widget>
</child>
</widget>
</glade-interface>