* 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
This commit is contained in:
Alex Roitman 2005-03-12 00:44:11 +00:00
parent 82c7948f22
commit 5b1675d0dc
7 changed files with 168 additions and 175 deletions

View File

@ -10,6 +10,20 @@
* src/SourceView.py (on_delete_clicked): Use new sourceref detection; * src/SourceView.py (on_delete_clicked): Use new sourceref detection;
(delete_source,is_used): Remove functions. (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 <Martin.Hawlisch@gmx.de> 2005-03-11 Martin Hawlisch <Martin.Hawlisch@gmx.de>
* src/GenericFilter.py (PersonWithIncompleteEvent, * src/GenericFilter.py (PersonWithIncompleteEvent,
FamilyWithIncompleteEvent, ProbablyAlive,PeoplePrivate): FamilyWithIncompleteEvent, ProbablyAlive,PeoplePrivate):

View File

@ -266,7 +266,7 @@ class EditSource:
slist = self.top_window.get_widget('slist') 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) self.model = ListModel.ListModel(slist,titles)

View File

@ -1106,59 +1106,46 @@ class GlobalMediaProperties:
return return
self.refs = 1 self.refs = 1
titles = [(_('Type'),0,150),(_('ID'),1,75),(_('Value'),2,100)] (person_list,family_list,event_list,place_list,source_list
self.refmodel = ListModel.ListModel(self.change_dialog.get_widget("refinfo"), ) = Utils.get_media_referents(self.obj.get_handle(),self.db)
titles,event_func=self.button_press)
any = 0 any = person_list or family_list or event_list or place_list or source_list
for key in self.db.get_person_handles(sort_handles=False):
p = self.db.get_person_from_handle(key) titles = [(_('Type'),0,150),(_('ID'),1,75),(_('Name'),2,150)]
for o in p.get_media_list(): self.refmodel = ListModel.ListModel(
if o.get_reference_handle() == self.obj.get_handle(): self.change_dialog.get_widget("refinfo"),
self.refmodel.add([_("Person"), titles,event_func=self.button_press)
p.get_gramps_id(),
NameDisplay.displayer.display(p)]) for handle in person_list:
any = 1 person = self.db.get_person_from_handle(handle)
for event_handle in p.get_event_list() + [p.get_birth_handle(),p.get_death_handle()]: name = NameDisplay.displayer.display(person)
if event_handle: gramps_id = person.get_gramps_id()
event = self.db.get_event_from_handle(event_handle) self.refmodel.add([_("Person"),gramps_id,name])
for o in event.get_media_list():
if o.get_reference_handle() == self.obj.get_handle(): for handle in family_list:
self.refmodel.add([_("Personal event"), family = self.db.get_family_from_handle(handle)
"%s: %s" % (p.get_gramps_id(),event.get_gramps_id()), name = Utils.family_name(family,self.db)
"%s: %s" % (NameDisplay.displayer.display(p), gramps_id = family.get_gramps_id()
_(event.get_name()))]) self.model.add([_("Family"),gramps_id,name])
any = 1
for key in self.db.get_family_handles(): for handle in event_list:
p = self.db.get_family_from_handle(key) event = self.db.get_event_from_handle(handle)
for o in p.get_media_list(): name = event.get_name()
if o.get_reference_handle() == self.obj.get_handle(): gramps_id = event.get_gramps_id()
self.refmodel.add([_("Family"), self.model.add([_("Event"),gramps_id,name])
p.get_gramps_id(),
Utils.family_name(p,self.db)]) for handle in place_list:
any = 1 place = self.db.get_place_from_handle(handle)
for event_handle in p.get_event_list(): name = place.get_title()
if event_handle: gramps_id = place.get_gramps_id()
event = self.db.get_event_from_handle(event_handle) self.model.add([_("Place"),gramps_id,name])
for o in event.get_media_list():
if o.get_reference_handle() == self.obj.get_handle(): for handle in source_list:
self.refmodel.add([_("Family event"), source = self.db.get_source_from_handle(handle)
"%s: %s" % (p.get_gramps_id(), name = source.get_title()
event.get_gramps_id()), gramps_id = source.get_gramps_id()
"%s: %s" % (Utils.family_name(p,self.db), self.model.add([_("Source"),gramps_id,name])
_(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
if any: if any:
Utils.bold_label(self.refs_label) Utils.bold_label(self.refs_label)
else: else:
@ -1267,70 +1254,57 @@ class GlobalMediaProperties:
class DeleteMediaQuery: class DeleteMediaQuery:
def __init__(self,media,db,update): def __init__(self,media_handle,db,the_lists,update):
self.db = db self.db = db
self.media = media self.media_handle = media_handle
self.the_lists = the_lists
self.update = update self.update = update
def query_response(self): def query_response(self):
trans = self.db.transaction_begin() trans = self.db.transaction_begin()
for key in self.db.get_person_handles(sort_handles=False): (person_list,family_list,event_list,
p = self.db.get_person_from_handle(key) place_list,source_list) = self.the_lists
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)
for fid in self.db.get_family_handles(): for handle in person_list:
p = self.db.get_family_from_handle(fid) person = self.db.get_person_from_handle(handle)
nl = [] new_list = [ photo for photo in person.get_media_list() \
change = 0 if photo.get_reference_handle() != self.media_handle ]
for photo in p.get_media_list(): person.set_media_list(new_list)
if photo.get_reference_handle() != self.media.get_handle(): self.db.commit_person(person,trans)
nl.append(photo)
else:
change = 1
if change:
p.set_media_list(nl)
self.db.commit_family(p,trans)
for key in self.db.get_source_handles(): for handle in family_list:
sid = self.db.get_source_from_handle(key) family = self.db.get_family_from_handle(handle)
nl = [] new_list = [ photo for photo in family.get_media_list() \
change = 0 if photo.get_reference_handle() != self.media_handle ]
for photo in p.get_media_list(): family.set_media_list(new_list)
if photo.get_reference_handle() != self.media.get_handle(): self.db.commit_family(family,trans)
nl.append(photo)
else:
change = 1
if change:
p.set_media_list(nl)
self.db.commit_source(p,trans)
for key in self.db.get_place_handles(): for handle in event_list:
p = self.db.get_place_from_handle(key) event = self.db.get_event_from_handle(handle)
nl = [] new_list = [ photo for photo in event.get_media_list() \
change = 0 if photo.get_reference_handle() != self.media_handle ]
for photo in p.get_media_list(): event.set_media_list(new_list)
if photo.get_reference_handle() != self.media.get_handle(): self.db.commit_event(event,trans)
nl.append(photo)
else:
change = 1
if change:
p.set_media_list(nl)
self.db.commit_place(p,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")) self.db.transaction_commit(trans,_("Remove Media Object"))
if self.update: if self.update:
self.update(self.media.get_handle()) self.update(self.media_handle)
def build_dropdown(entry,strings): def build_dropdown(entry,strings):
store = gtk.ListStore(str) store = gtk.ListStore(str)

View File

@ -312,51 +312,20 @@ class MediaView:
return return
handle = store.get_value(node,_HANDLE_COL) handle = store.get_value(node,_HANDLE_COL)
mobj = self.db.get_object_from_handle(handle) the_lists = Utils.get_media_referents(handle,self.db)
if self.is_object_used(mobj):
ans = ImageSelect.DeleteMediaQuery(mobj,self.db, ans = ImageSelect.DeleteMediaQuery(handle,self.db,the_lists,
self.model.delete_row_by_handle) self.model.delete_row_by_handle)
QuestionDialog(_('Delete Media Object?'), if filter(None,the_lists): # quick test for non-emptiness
_('This media object is currently being used. ' msg = _('This media object is currently being used. '
'If you delete this object, it will be removed ' 'If you delete this object, it will be removed from '
'from the database and from all records that ' 'the database and from all records that reference it.')
'reference it.'),
_('_Delete Media Object'),
ans.query_response)
else: else:
self.delete_object(mobj) msg = _('Deleting media object will remove it from the database.')
def delete_object(self,media_obj): msg = "%s %s" % (msg,Utils.data_recover_msg)
trans = self.parent.db.transaction_begin() QuestionDialog(_('Delete Media Object?'),msg,
mobj_handle = media_obj.get_handle() _('_Delete Media Object'),ans.query_response)
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
def on_drag_drop(self, tree, context, x, y, time): def on_drag_drop(self, tree, context, x, y, time):
self.list.emit_stop_by_name('drag-drop') self.list.emit_stop_by_name('drag-drop')

View File

@ -173,30 +173,19 @@ class SourceView:
source = self.parent.db.get_source_from_handle(handle) source = self.parent.db.get_source_from_handle(handle)
the_lists = Utils.get_source_referents(handle,self.parent.db) 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, ans = EditSource.DelSrcQuery(source,self.parent.db,the_lists,
self.model.delete_row_by_handle) self.model.delete_row_by_handle)
if used: if filter(None,the_lists): # quick test for non-emptiness
QuestionDialog(_('Delete %s?') % source.get_title(), msg = _('This source is currently being used. Deleting it '
_('This source is currently being used. Deleting it ' 'will remove it from the database and from all '
'will remove it from the database and from all ' 'records that reference it.')
'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)
else: else:
QuestionDialog(_('Delete %s?') % source.get_title(), msg = _('Deleting source will remove it from the database.')
_('Deleting source will remove it from the '
'database. The data can only be recovered by ' msg = "%s %s" % (msg,Utils.data_recover_msg)
'Undo operation or by quitting with abandoning ' QuestionDialog(_('Delete %s?') % source.get_title(), msg,
'changes.'), _('_Delete Source'),ans.query_response,self.topWindow)
_('_Delete Source'),
ans.query_response,self.topWindow)
def on_edit_clicked(self,obj): def on_edit_clicked(self,obj):
list_store, node = self.selection.get_selected() list_store, node = self.selection.get_selected()

View File

@ -69,6 +69,9 @@ def history_broken():
global _history_brokenFlag global _history_brokenFlag
_history_brokenFlag = 1 _history_brokenFlag = 1
data_recover_msg = _('The data can only be recovered by Undo operation '
'or by quitting with abandoning changes.')
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# force_unicode # force_unicode
@ -540,6 +543,52 @@ def get_source_referents(source_handle,db):
return (person_list,family_list,event_list, return (person_list,family_list,event_list,
place_list,source_list,media_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)
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# #

View File

@ -1316,12 +1316,10 @@ class Gramps:
self.active_person = p self.active_person = p
name = NameDisplay.displayer.display(p) name = NameDisplay.displayer.display(p)
QuestionDialog(_('Delete %s?') % name, msg = _('Deleting the person will remove the person '
_('Deleting the person will remove the person ' 'from the database.')
'from the database. The data can only be ' msg = "%s %s" % (msg,Utils.data_recover_msg)
'recovered by closing the database without saving ' QuestionDialog(_('Delete %s?') % name,msg,
'changes. This change will become permanent '
'after you save the database.'),
_('_Delete Person'), _('_Delete Person'),
self.delete_person_response) self.delete_person_response)