From 5b1675d0dc954a8004ffe6c346052ed0e95cd67d Mon Sep 17 00:00:00 2001 From: Alex Roitman Date: Sat, 12 Mar 2005 00:44:11 +0000 Subject: [PATCH] * src/Utils.py (get_media_referents): Add function; Add generic data recovery message. * src/gramps_main.py (delete_person_clicked): Use generic data recovery message. * src/SourceView.py (on_delete_clicked): Use generic data recovery message. * src/EditSource.py (display_references): Change list headings. * src/MediaView.py (on_delete_clicked): Use new mediaref detector; Use generic data recovery message; (delete_objectmis-object_used): Remove functions. * src/ImageSelect.py (GlobalMediaProperties.display_ref): Use new sourceref detection; (DeleteMediaQuery__init__): Accept object handle and lists; (DeleteMediaQuery.query_response): Use new mediaref removal. svn: r4161 --- gramps2/ChangeLog | 14 +++ gramps2/src/EditSource.py | 2 +- gramps2/src/ImageSelect.py | 184 ++++++++++++++++--------------------- gramps2/src/MediaView.py | 55 +++-------- gramps2/src/SourceView.py | 29 ++---- gramps2/src/Utils.py | 49 ++++++++++ gramps2/src/gramps_main.py | 10 +- 7 files changed, 168 insertions(+), 175 deletions(-) diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index 74802b1a3..8af80ef3f 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -10,6 +10,20 @@ * src/SourceView.py (on_delete_clicked): Use new sourceref detection; (delete_source,is_used): Remove functions. + * src/Utils.py (get_media_referents): Add function; + Add generic data recovery message. + * src/gramps_main.py (delete_person_clicked): Use generic data recovery + message. + * src/SourceView.py (on_delete_clicked): Use generic data recovery + message. + * src/EditSource.py (display_references): Change list headings. + * src/MediaView.py (on_delete_clicked): Use new mediaref detector; + Use generic data recovery message; (delete_objectmis-object_used): + Remove functions. + * src/ImageSelect.py (GlobalMediaProperties.display_ref): Use new + sourceref detection; (DeleteMediaQuery__init__): Accept object handle + and lists; (DeleteMediaQuery.query_response): Use new mediaref removal. + 2005-03-11 Martin Hawlisch * src/GenericFilter.py (PersonWithIncompleteEvent, FamilyWithIncompleteEvent, ProbablyAlive,PeoplePrivate): diff --git a/gramps2/src/EditSource.py b/gramps2/src/EditSource.py index ecce50a57..77df4edbf 100644 --- a/gramps2/src/EditSource.py +++ b/gramps2/src/EditSource.py @@ -266,7 +266,7 @@ class EditSource: slist = self.top_window.get_widget('slist') - titles = [(_('Object Type'),0,150),(_('ID'),1,50),(_('Name'),2,150)] + titles = [(_('Type'),0,150),(_('ID'),1,75),(_('Name'),2,150)] self.model = ListModel.ListModel(slist,titles) diff --git a/gramps2/src/ImageSelect.py b/gramps2/src/ImageSelect.py index 500060640..e151351de 100644 --- a/gramps2/src/ImageSelect.py +++ b/gramps2/src/ImageSelect.py @@ -1106,59 +1106,46 @@ class GlobalMediaProperties: return self.refs = 1 - titles = [(_('Type'),0,150),(_('ID'),1,75),(_('Value'),2,100)] - self.refmodel = ListModel.ListModel(self.change_dialog.get_widget("refinfo"), - titles,event_func=self.button_press) - any = 0 - for key in self.db.get_person_handles(sort_handles=False): - p = self.db.get_person_from_handle(key) - for o in p.get_media_list(): - if o.get_reference_handle() == self.obj.get_handle(): - self.refmodel.add([_("Person"), - p.get_gramps_id(), - NameDisplay.displayer.display(p)]) - any = 1 - for event_handle in p.get_event_list() + [p.get_birth_handle(),p.get_death_handle()]: - if event_handle: - event = self.db.get_event_from_handle(event_handle) - for o in event.get_media_list(): - if o.get_reference_handle() == self.obj.get_handle(): - self.refmodel.add([_("Personal event"), - "%s: %s" % (p.get_gramps_id(),event.get_gramps_id()), - "%s: %s" % (NameDisplay.displayer.display(p), - _(event.get_name()))]) - any = 1 - for key in self.db.get_family_handles(): - p = self.db.get_family_from_handle(key) - for o in p.get_media_list(): - if o.get_reference_handle() == self.obj.get_handle(): - self.refmodel.add([_("Family"), - p.get_gramps_id(), - Utils.family_name(p,self.db)]) - any = 1 - for event_handle in p.get_event_list(): - if event_handle: - event = self.db.get_event_from_handle(event_handle) - for o in event.get_media_list(): - if o.get_reference_handle() == self.obj.get_handle(): - self.refmodel.add([_("Family event"), - "%s: %s" % (p.get_gramps_id(), - event.get_gramps_id()), - "%s: %s" % (Utils.family_name(p,self.db), - _(event.get_name()))]) - any = 1 - for key in self.db.get_source_handles(): - p = self.db.get_source_from_handle(key) - for o in p.get_media_list(): - if o.get_reference_handle() == self.obj.get_handle(): - self.refmodel.add([_("Source"),p.get_gramps_id(),p.get_title()]) - any = 1 - for key in self.db.get_place_handles(): - p = self.db.get_place_from_handle(key) - for o in p.get_media_list(): - if o.get_reference_handle() == self.obj.get_handle(): - self.refmodel.add([_("Place"),p.get_gramps_id(),p.get_title()]) - any = 1 + (person_list,family_list,event_list,place_list,source_list + ) = Utils.get_media_referents(self.obj.get_handle(),self.db) + + any = person_list or family_list or event_list or place_list or source_list + + titles = [(_('Type'),0,150),(_('ID'),1,75),(_('Name'),2,150)] + self.refmodel = ListModel.ListModel( + self.change_dialog.get_widget("refinfo"), + titles,event_func=self.button_press) + + for handle in person_list: + person = self.db.get_person_from_handle(handle) + name = NameDisplay.displayer.display(person) + gramps_id = person.get_gramps_id() + self.refmodel.add([_("Person"),gramps_id,name]) + + for handle in family_list: + family = self.db.get_family_from_handle(handle) + name = Utils.family_name(family,self.db) + gramps_id = family.get_gramps_id() + self.model.add([_("Family"),gramps_id,name]) + + for handle in event_list: + event = self.db.get_event_from_handle(handle) + name = event.get_name() + gramps_id = event.get_gramps_id() + self.model.add([_("Event"),gramps_id,name]) + + for handle in place_list: + place = self.db.get_place_from_handle(handle) + name = place.get_title() + gramps_id = place.get_gramps_id() + self.model.add([_("Place"),gramps_id,name]) + + for handle in source_list: + source = self.db.get_source_from_handle(handle) + name = source.get_title() + gramps_id = source.get_gramps_id() + self.model.add([_("Source"),gramps_id,name]) + if any: Utils.bold_label(self.refs_label) else: @@ -1267,70 +1254,57 @@ class GlobalMediaProperties: class DeleteMediaQuery: - def __init__(self,media,db,update): + def __init__(self,media_handle,db,the_lists,update): self.db = db - self.media = media + self.media_handle = media_handle + self.the_lists = the_lists self.update = update def query_response(self): trans = self.db.transaction_begin() - for key in self.db.get_person_handles(sort_handles=False): - p = self.db.get_person_from_handle(key) - nl = [] - change = 0 - for photo in p.get_media_list(): - if photo.get_reference_handle() != self.media.get_handle(): - nl.append(photo) - else: - change = 1 - if change: - p.set_media_list(nl) - self.db.commit_person(p,trans) + (person_list,family_list,event_list, + place_list,source_list) = self.the_lists - for fid in self.db.get_family_handles(): - p = self.db.get_family_from_handle(fid) - nl = [] - change = 0 - for photo in p.get_media_list(): - if photo.get_reference_handle() != self.media.get_handle(): - nl.append(photo) - else: - change = 1 - if change: - p.set_media_list(nl) - self.db.commit_family(p,trans) + for handle in person_list: + person = self.db.get_person_from_handle(handle) + new_list = [ photo for photo in person.get_media_list() \ + if photo.get_reference_handle() != self.media_handle ] + person.set_media_list(new_list) + self.db.commit_person(person,trans) - for key in self.db.get_source_handles(): - sid = self.db.get_source_from_handle(key) - nl = [] - change = 0 - for photo in p.get_media_list(): - if photo.get_reference_handle() != self.media.get_handle(): - nl.append(photo) - else: - change = 1 - if change: - p.set_media_list(nl) - self.db.commit_source(p,trans) + for handle in family_list: + family = self.db.get_family_from_handle(handle) + new_list = [ photo for photo in family.get_media_list() \ + if photo.get_reference_handle() != self.media_handle ] + family.set_media_list(new_list) + self.db.commit_family(family,trans) - for key in self.db.get_place_handles(): - p = self.db.get_place_from_handle(key) - nl = [] - change = 0 - for photo in p.get_media_list(): - if photo.get_reference_handle() != self.media.get_handle(): - nl.append(photo) - else: - change = 1 - if change: - p.set_media_list(nl) - self.db.commit_place(p,trans) + for handle in event_list: + event = self.db.get_event_from_handle(handle) + new_list = [ photo for photo in event.get_media_list() \ + if photo.get_reference_handle() != self.media_handle ] + event.set_media_list(new_list) + self.db.commit_event(event,trans) - self.db.remove_object(self.media.get_handle(),trans) + for handle in place_list: + place = self.db.get_place_from_handle(handle) + new_list = [ photo for photo in place.get_media_list() \ + if photo.get_reference_handle() != self.media_handle ] + place.set_media_list(new_list) + self.db.commit_place(place,trans) + + for handle in source_list: + source = self.db.get_source_from_handle(handle) + new_list = [ photo for photo in source.get_media_list() \ + if photo.get_reference_handle() != self.media_handle ] + source.set_media_list(new_list) + self.db.commit_source(source,trans) + + self.db.remove_object(self.media_handle,trans) self.db.transaction_commit(trans,_("Remove Media Object")) if self.update: - self.update(self.media.get_handle()) + self.update(self.media_handle) def build_dropdown(entry,strings): store = gtk.ListStore(str) diff --git a/gramps2/src/MediaView.py b/gramps2/src/MediaView.py index 6b9c14d24..c698c4dcc 100644 --- a/gramps2/src/MediaView.py +++ b/gramps2/src/MediaView.py @@ -312,51 +312,20 @@ class MediaView: return handle = store.get_value(node,_HANDLE_COL) - mobj = self.db.get_object_from_handle(handle) - if self.is_object_used(mobj): - ans = ImageSelect.DeleteMediaQuery(mobj,self.db, - self.model.delete_row_by_handle) - QuestionDialog(_('Delete Media Object?'), - _('This media object is currently being used. ' - 'If you delete this object, it will be removed ' - 'from the database and from all records that ' - 'reference it.'), - _('_Delete Media Object'), - ans.query_response) + the_lists = Utils.get_media_referents(handle,self.db) + + ans = ImageSelect.DeleteMediaQuery(handle,self.db,the_lists, + self.model.delete_row_by_handle) + if filter(None,the_lists): # quick test for non-emptiness + msg = _('This media object is currently being used. ' + 'If you delete this object, it will be removed from ' + 'the database and from all records that reference it.') else: - self.delete_object(mobj) + msg = _('Deleting media object will remove it from the database.') - def delete_object(self,media_obj): - trans = self.parent.db.transaction_begin() - mobj_handle = media_obj.get_handle() - self.parent.db.remove_object(mobj_handle,trans) - title_msg = _("Delete Media Object?") - self.parent.db.transaction_commit(trans,title_msg) - self.model.delete_row_by_handle(mobj_handle) - - def is_object_used(self,mobj): - mhandle = mobj.get_handle() - for family_handle in self.db.get_family_handles(): - p = self.db.get_family_from_handle(family_handle) - for o in p.get_media_list(): - if o.get_reference_handle() == mhandle: - return True - for key in self.db.get_person_handles(sort_handles=False): - p = self.db.get_person_from_handle(key) - for o in p.get_media_list(): - if o.get_reference_handle() == mhandle: - return True - for key in self.db.get_source_handles(sort_handles=False): - p = self.db.get_source_from_handle(key) - for o in p.get_media_list(): - if o.get_reference_handle() == mhandle: - return True - for key in self.db.get_place_handles(sort_handles=False): - p = self.db.get_place_from_handle(key) - for o in p.get_media_list(): - if o.get_reference_handle() == mhandle: - return True - return False + msg = "%s %s" % (msg,Utils.data_recover_msg) + QuestionDialog(_('Delete Media Object?'),msg, + _('_Delete Media Object'),ans.query_response) def on_drag_drop(self, tree, context, x, y, time): self.list.emit_stop_by_name('drag-drop') diff --git a/gramps2/src/SourceView.py b/gramps2/src/SourceView.py index 1abdcaff2..d328906c4 100644 --- a/gramps2/src/SourceView.py +++ b/gramps2/src/SourceView.py @@ -173,30 +173,19 @@ class SourceView: source = self.parent.db.get_source_from_handle(handle) the_lists = Utils.get_source_referents(handle,self.parent.db) - - used = the_lists[0] or the_lists[1] or the_lists[2] \ - or the_lists[3] or the_lists[4] or the_lists[5] - ans = EditSource.DelSrcQuery(source,self.parent.db,the_lists, self.model.delete_row_by_handle) - if used: - QuestionDialog(_('Delete %s?') % source.get_title(), - _('This source is currently being used. Deleting it ' - 'will remove it from the database and from all ' - 'records that reference it. The data can only ' - 'be recovered by Undo operation or by quitting ' - 'with abandoning changes.'), - _('_Delete Source'), - ans.query_response,self.topWindow) + if filter(None,the_lists): # quick test for non-emptiness + msg = _('This source is currently being used. Deleting it ' + 'will remove it from the database and from all ' + 'records that reference it.') else: - QuestionDialog(_('Delete %s?') % source.get_title(), - _('Deleting source will remove it from the ' - 'database. The data can only be recovered by ' - 'Undo operation or by quitting with abandoning ' - 'changes.'), - _('_Delete Source'), - ans.query_response,self.topWindow) + msg = _('Deleting source will remove it from the database.') + + msg = "%s %s" % (msg,Utils.data_recover_msg) + QuestionDialog(_('Delete %s?') % source.get_title(), msg, + _('_Delete Source'),ans.query_response,self.topWindow) def on_edit_clicked(self,obj): list_store, node = self.selection.get_selected() diff --git a/gramps2/src/Utils.py b/gramps2/src/Utils.py index 7cdf2c7b5..becb4022f 100644 --- a/gramps2/src/Utils.py +++ b/gramps2/src/Utils.py @@ -69,6 +69,9 @@ def history_broken(): global _history_brokenFlag _history_brokenFlag = 1 +data_recover_msg = _('The data can only be recovered by Undo operation ' + 'or by quitting with abandoning changes.') + #------------------------------------------------------------------------- # # force_unicode @@ -540,6 +543,52 @@ def get_source_referents(source_handle,db): return (person_list,family_list,event_list, place_list,source_list,media_list) +def get_media_referents(media_handle,db): + """ + Find objects that refer the media object. + + This function finds all primary objects that refer + to a given media handle in a given database. + """ + + # Persons + person_list = [ handle \ + for handle in db.get_person_handles(sort_handles=False) \ + if media_handle in \ + [photo.get_reference_handle() for photo \ + in db.get_person_from_handle(handle).get_media_list()] + ] + + # Families + family_list = [ handle for handle in db.get_family_handles() \ + if media_handle in \ + [photo.get_reference_handle() for photo \ + in db.get_family_from_handle(handle).get_media_list()] + ] + + # Events + event_list = [ handle for handle in db.get_event_handles() \ + if media_handle in \ + [photo.get_reference_handle() for photo \ + in db.get_event_from_handle(handle).get_media_list()] + ] + + # Places + place_list = [ handle for handle in db.get_place_handles() \ + if media_handle in \ + [photo.get_reference_handle() for photo \ + in db.get_place_from_handle(handle).get_media_list()] + ] + + # Sources + source_list = [ handle for handle in db.get_source_handles() \ + if media_handle in \ + [photo.get_reference_handle() for photo \ + in db.get_source_from_handle(handle).get_media_list()] + ] + + return (person_list,family_list,event_list,place_list,source_list) + #------------------------------------------------------------------------- # # diff --git a/gramps2/src/gramps_main.py b/gramps2/src/gramps_main.py index 135149f88..f723e487c 100755 --- a/gramps2/src/gramps_main.py +++ b/gramps2/src/gramps_main.py @@ -1316,12 +1316,10 @@ class Gramps: self.active_person = p name = NameDisplay.displayer.display(p) - QuestionDialog(_('Delete %s?') % name, - _('Deleting the person will remove the person ' - 'from the database. The data can only be ' - 'recovered by closing the database without saving ' - 'changes. This change will become permanent ' - 'after you save the database.'), + msg = _('Deleting the person will remove the person ' + 'from the database.') + msg = "%s %s" % (msg,Utils.data_recover_msg) + QuestionDialog(_('Delete %s?') % name,msg, _('_Delete Person'), self.delete_person_response)