Handle image imports that are abandoned
svn: r1506
This commit is contained in:
parent
9af70c93a4
commit
8fd080f8c9
@ -1,7 +1,7 @@
|
|||||||
#
|
#
|
||||||
# Gramps - a GTK+/GNOME based genealogy program
|
# Gramps - a GTK+/GNOME based genealogy program
|
||||||
#
|
#
|
||||||
# Copyright (C) 2000 Donald N. Allingham
|
# Copyright (C) 2000, 2003 Donald N. Allingham
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# This program is free software; you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
@ -147,7 +147,7 @@ class ImageSelect:
|
|||||||
if os.path.exists(filename) == 0:
|
if os.path.exists(filename) == 0:
|
||||||
msgstr = _("Cannot import %s")
|
msgstr = _("Cannot import %s")
|
||||||
msgstr2 = _("The filename supplied could not be found.")
|
msgstr2 = _("The filename supplied could not be found.")
|
||||||
ErrorDialog(msgstr,msgstr2)
|
ErrorDialog(msgstr % filename, msgstr2)
|
||||||
return
|
return
|
||||||
|
|
||||||
already_imported = None
|
already_imported = None
|
||||||
@ -958,4 +958,3 @@ class DeleteMediaQuery:
|
|||||||
|
|
||||||
if self.update:
|
if self.update:
|
||||||
self.update(0)
|
self.update(0)
|
||||||
|
|
||||||
|
@ -1924,6 +1924,13 @@ class GrampsDB(Persistent):
|
|||||||
self.sourceMap = {}
|
self.sourceMap = {}
|
||||||
self.placeMap = {}
|
self.placeMap = {}
|
||||||
self.new()
|
self.new()
|
||||||
|
self.added_files = []
|
||||||
|
|
||||||
|
def get_added_media_objects(self):
|
||||||
|
return self.added_files
|
||||||
|
|
||||||
|
def clear_added_media_objects(self):
|
||||||
|
self.added_files = []
|
||||||
|
|
||||||
def get_type(self):
|
def get_type(self):
|
||||||
return 'GrampsDB'
|
return 'GrampsDB'
|
||||||
@ -2306,6 +2313,8 @@ class GrampsDB(Persistent):
|
|||||||
object.setId(index)
|
object.setId(index)
|
||||||
self.objectMap[index] = object
|
self.objectMap[index] = object
|
||||||
self.omapIndex = self.omapIndex + 1
|
self.omapIndex = self.omapIndex + 1
|
||||||
|
self.added_files.append(object)
|
||||||
|
|
||||||
return index
|
return index
|
||||||
|
|
||||||
def getObject(self,id):
|
def getObject(self,id):
|
||||||
@ -2354,6 +2363,7 @@ class GrampsDB(Persistent):
|
|||||||
object.setId(index)
|
object.setId(index)
|
||||||
self.objectMap[index] = object
|
self.objectMap[index] = object
|
||||||
self.omapIndex = self.omapIndex + 1
|
self.omapIndex = self.omapIndex + 1
|
||||||
|
self.added_files.append(object)
|
||||||
return index
|
return index
|
||||||
|
|
||||||
def findObjectNoMap(self,idVal):
|
def findObjectNoMap(self,idVal):
|
||||||
|
@ -534,20 +534,46 @@ class Gramps:
|
|||||||
self.quit,
|
self.quit,
|
||||||
self.save_query)
|
self.save_query)
|
||||||
else:
|
else:
|
||||||
|
self.delete_abandoned_photos()
|
||||||
self.db.close()
|
self.db.close()
|
||||||
gtk.mainquit()
|
gtk.mainquit()
|
||||||
|
|
||||||
def save_query(self):
|
def save_query(self):
|
||||||
"""Catch the reponse to the save on exit question"""
|
"""Catch the reponse to the save on exit question"""
|
||||||
self.on_save_activate_quit()
|
self.on_save_activate_quit()
|
||||||
|
self.delete_abandoned_photos()
|
||||||
self.db.close()
|
self.db.close()
|
||||||
gtk.mainquit()
|
gtk.mainquit()
|
||||||
|
|
||||||
def quit(self):
|
def quit(self):
|
||||||
"""Catch the reponse to the save on exit question"""
|
"""Catch the reponse to the save on exit question"""
|
||||||
|
self.delete_abandoned_photos()
|
||||||
self.db.close()
|
self.db.close()
|
||||||
gtk.mainquit()
|
gtk.mainquit()
|
||||||
|
|
||||||
|
def delete_abandoned_photos(self):
|
||||||
|
"""
|
||||||
|
We only want to delete local objects, not external objects, however, we
|
||||||
|
can delete any thumbnail images. The thumbnails may or may not exist, depending
|
||||||
|
on if the image was previewed.
|
||||||
|
"""
|
||||||
|
for obj in self.db.get_added_media_objects():
|
||||||
|
if obj.getLocal():
|
||||||
|
try:
|
||||||
|
os.unlink(obj.getPath())
|
||||||
|
except IOError:
|
||||||
|
pass
|
||||||
|
except:
|
||||||
|
DisplayTrace.DisplayTrace()
|
||||||
|
thumb = "%s/.thumb/%s.jpg" % (self.db.getSavePath(),obj.getId())
|
||||||
|
if os.path.isfile(thumb):
|
||||||
|
try:
|
||||||
|
os.unlink(thumb)
|
||||||
|
except IOError:
|
||||||
|
pass
|
||||||
|
except:
|
||||||
|
DisplayTrace.DisplayTrace()
|
||||||
|
|
||||||
def on_about_activate(self,obj):
|
def on_about_activate(self,obj):
|
||||||
"""Displays the about box. Called from Help menu"""
|
"""Displays the about box. Called from Help menu"""
|
||||||
pixbuf = gtk.gdk.pixbuf_new_from_file(const.logo)
|
pixbuf = gtk.gdk.pixbuf_new_from_file(const.logo)
|
||||||
@ -585,6 +611,26 @@ class Gramps:
|
|||||||
self.clear_database(2)
|
self.clear_database(2)
|
||||||
DbPrompter.DbPrompter(self,1)
|
DbPrompter.DbPrompter(self,1)
|
||||||
|
|
||||||
|
def clear_person_tabs(self):
|
||||||
|
|
||||||
|
for i in range(0,len(self.tab_list)):
|
||||||
|
self.ptabs.remove_page(0)
|
||||||
|
self.ptabs.set_show_tabs(0)
|
||||||
|
self.id2col = {}
|
||||||
|
self.tab_list = []
|
||||||
|
self.alpha_page = {}
|
||||||
|
self.model2page = {}
|
||||||
|
self.model_used = {}
|
||||||
|
|
||||||
|
self.default_list.clear()
|
||||||
|
self.pl_page = [
|
||||||
|
self.default_list
|
||||||
|
]
|
||||||
|
|
||||||
|
self.person_tree = self.pl_page[-1]
|
||||||
|
self.person_list = self.pl_page[-1].tree
|
||||||
|
self.person_model = self.pl_page[-1].model
|
||||||
|
|
||||||
def clear_database(self,zodb=1):
|
def clear_database(self,zodb=1):
|
||||||
"""Clear out the database if permission was granted"""
|
"""Clear out the database if permission was granted"""
|
||||||
const.personalEvents = const.init_personal_event_list()
|
const.personalEvents = const.init_personal_event_list()
|
||||||
@ -593,19 +639,7 @@ class Gramps:
|
|||||||
const.familyAttributes = const.init_family_attribute_list()
|
const.familyAttributes = const.init_family_attribute_list()
|
||||||
const.familyRelations = const.init_family_relation_list()
|
const.familyRelations = const.init_family_relation_list()
|
||||||
|
|
||||||
for i in range(0,len(self.tab_list)):
|
self.clear_person_tabs()
|
||||||
self.ptabs.remove_page(0)
|
|
||||||
self.ptabs.set_show_tabs(0)
|
|
||||||
self.tab_list = []
|
|
||||||
self.alpha_page = {}
|
|
||||||
self.model2page = {}
|
|
||||||
self.model_used = {}
|
|
||||||
|
|
||||||
self.pl_page = [ self.pl_page[-1] ]
|
|
||||||
|
|
||||||
self.person_tree = self.pl_page[-1]
|
|
||||||
self.person_list = self.pl_page[-1].tree
|
|
||||||
self.person_model = self.pl_page[-1].model
|
|
||||||
|
|
||||||
if zodb == 1:
|
if zodb == 1:
|
||||||
self.db = GrampsZODB.GrampsZODB()
|
self.db = GrampsZODB.GrampsZODB()
|
||||||
@ -643,20 +677,7 @@ class Gramps:
|
|||||||
def tool_callback(self,val):
|
def tool_callback(self,val):
|
||||||
if val:
|
if val:
|
||||||
Utils.modified()
|
Utils.modified()
|
||||||
for i in range(0,len(self.tab_list)):
|
self.complete_rebuild()
|
||||||
self.ptabs.remove_page(0)
|
|
||||||
self.ptabs.set_show_tabs(0)
|
|
||||||
|
|
||||||
self.pl_page = [
|
|
||||||
ListModel.ListModel(self.pl_other, self.pl_titles, self.row_changed,
|
|
||||||
self.alpha_event, _sel_mode),
|
|
||||||
]
|
|
||||||
|
|
||||||
self.tab_list = []
|
|
||||||
self.alpha_page = {}
|
|
||||||
self.model2page = {}
|
|
||||||
self.model_used = {}
|
|
||||||
self.full_update()
|
|
||||||
|
|
||||||
def full_update(self):
|
def full_update(self):
|
||||||
"""Brute force display update, updating all the pages"""
|
"""Brute force display update, updating all the pages"""
|
||||||
@ -856,6 +877,7 @@ class Gramps:
|
|||||||
filename = "%s/%s" % (filename,self.db.get_base())
|
filename = "%s/%s" % (filename,self.db.get_base())
|
||||||
try:
|
try:
|
||||||
self.db.save(filename,self.load_progress)
|
self.db.save(filename,self.load_progress)
|
||||||
|
self.db.clear_added_media_objects()
|
||||||
except (OSError,IOError), msg:
|
except (OSError,IOError), msg:
|
||||||
emsg = _("Could not create %s") % filename
|
emsg = _("Could not create %s") % filename
|
||||||
ErrorDialog(emsg,_("An error was detected while trying to create the file"))
|
ErrorDialog(emsg,_("An error was detected while trying to create the file"))
|
||||||
@ -1060,7 +1082,6 @@ class Gramps:
|
|||||||
else:
|
else:
|
||||||
return ""
|
return ""
|
||||||
except:
|
except:
|
||||||
import DisplayTrace
|
|
||||||
DisplayTrace.DisplayTrace()
|
DisplayTrace.DisplayTrace()
|
||||||
|
|
||||||
def on_open_activate(self,obj):
|
def on_open_activate(self,obj):
|
||||||
@ -1406,6 +1427,7 @@ class Gramps:
|
|||||||
self.status_text('')
|
self.status_text('')
|
||||||
return 0
|
return 0
|
||||||
self.status_text('')
|
self.status_text('')
|
||||||
|
self.db.clear_added_media_objects()
|
||||||
return self.post_load(name)
|
return self.post_load(name)
|
||||||
|
|
||||||
def load_revision(self,f,name,revision):
|
def load_revision(self,f,name,revision):
|
||||||
@ -1413,6 +1435,7 @@ class Gramps:
|
|||||||
self.status_text(_('Loading %s...' % name))
|
self.status_text(_('Loading %s...' % name))
|
||||||
if ReadXML.loadRevision(self.db,f,filename,revision,self.load_progress) == 0:
|
if ReadXML.loadRevision(self.db,f,filename,revision,self.load_progress) == 0:
|
||||||
return 0
|
return 0
|
||||||
|
self.db.clear_added_media_objects()
|
||||||
return self.post_load(name)
|
return self.post_load(name)
|
||||||
|
|
||||||
def setup_bookmarks(self):
|
def setup_bookmarks(self):
|
||||||
@ -1426,14 +1449,6 @@ class Gramps:
|
|||||||
|
|
||||||
def complete_rebuild(self):
|
def complete_rebuild(self):
|
||||||
self.topWindow.set_resizable(gtk.FALSE)
|
self.topWindow.set_resizable(gtk.FALSE)
|
||||||
for i in range(0,len(self.tab_list)):
|
|
||||||
self.ptabs.remove_page(0)
|
|
||||||
self.ptabs.set_show_tabs(0)
|
|
||||||
self.id2col = {}
|
|
||||||
self.model_used = {}
|
|
||||||
self.model2page = {}
|
|
||||||
self.alpha_page = {}
|
|
||||||
self.tab_list = []
|
|
||||||
self.apply_filter()
|
self.apply_filter()
|
||||||
self.goto_active_person()
|
self.goto_active_person()
|
||||||
self.modify_statusbar()
|
self.modify_statusbar()
|
||||||
|
Loading…
Reference in New Issue
Block a user