2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2005-03-27 11:44:06 +05:30
|
|
|
# Copyright (C) 2000-2005 Donald N. Allingham
|
2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
# 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
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
#
|
|
|
|
|
2008-01-22 14:47:46 +05:30
|
|
|
# $Id$
|
2004-07-15 08:24:04 +05:30
|
|
|
|
2002-11-17 04:52:33 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Standard python modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GNOME
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2009-04-18 08:40:50 +05:30
|
|
|
import gtk
|
2002-11-17 04:52:33 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2008-02-21 14:26:39 +05:30
|
|
|
from TransUtils import sgettext as _
|
2002-10-20 19:55:16 +05:30
|
|
|
import const
|
2005-12-06 12:08:09 +05:30
|
|
|
import GrampsDisplay
|
2006-05-26 01:09:44 +05:30
|
|
|
import ManagedWindow
|
2009-05-15 01:45:59 +05:30
|
|
|
from glade import Glade
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-03-09 09:28:44 +05:30
|
|
|
#-------------------------------------------------------------------------
|
2009-02-26 15:32:00 +05:30
|
|
|
#
|
|
|
|
# GRAMPS constants
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
WIKI_HELP_PAGE = '%s_-_Entering_and_Editing_Data:_Detailed_-_part_3' % const.URL_MANUAL_PAGE
|
|
|
|
WIKI_HELP_SEC = _('manual|Merge_Sources')
|
2009-05-15 01:45:59 +05:30
|
|
|
_GLADE_FILE = 'mergedata.glade'
|
2009-02-26 15:32:00 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
2005-03-09 09:28:44 +05:30
|
|
|
#
|
|
|
|
# Merge Sources
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2006-05-26 02:05:04 +05:30
|
|
|
class MergeSources(ManagedWindow.ManagedWindow):
|
2005-03-09 09:28:44 +05:30
|
|
|
"""
|
2005-05-24 18:38:06 +05:30
|
|
|
Merges to sources into a single source. Displays a dialog box that
|
|
|
|
allows the sources to be combined into one.
|
2005-03-09 09:28:44 +05:30
|
|
|
"""
|
2006-05-26 02:05:04 +05:30
|
|
|
def __init__(self, dbstate, uistate, new_handle, old_handle):
|
|
|
|
|
|
|
|
ManagedWindow.ManagedWindow.__init__(self, uistate, [], self.__class__)
|
|
|
|
|
|
|
|
self.db = dbstate.db
|
|
|
|
|
2005-03-28 09:52:09 +05:30
|
|
|
self.new_handle = new_handle
|
|
|
|
self.old_handle = old_handle
|
2006-05-26 08:37:48 +05:30
|
|
|
self.s1 = self.db.get_source_from_handle(self.new_handle)
|
|
|
|
self.s2 = self.db.get_source_from_handle(self.old_handle)
|
2005-03-09 09:28:44 +05:30
|
|
|
|
2009-05-15 01:45:59 +05:30
|
|
|
self.glade = Glade(_GLADE_FILE, toplevel='mergesource')
|
2006-05-26 02:05:04 +05:30
|
|
|
|
2009-05-15 01:45:59 +05:30
|
|
|
self.set_window(self.glade.toplevel,
|
2009-04-18 08:40:50 +05:30
|
|
|
self.glade.get_object('source_title'),
|
2006-05-26 02:05:04 +05:30
|
|
|
_("Merge Sources"))
|
2005-03-09 09:28:44 +05:30
|
|
|
|
2009-04-18 08:40:50 +05:30
|
|
|
self.title1 = self.glade.get_object("title1")
|
|
|
|
self.title2 = self.glade.get_object("title2")
|
2006-05-26 08:37:48 +05:30
|
|
|
self.title1.set_text(self.s1.get_title())
|
|
|
|
self.title2.set_text(self.s2.get_title())
|
2005-03-09 09:28:44 +05:30
|
|
|
|
2009-04-18 08:40:50 +05:30
|
|
|
self.author1 = self.glade.get_object("author1")
|
|
|
|
self.author2 = self.glade.get_object("author2")
|
2006-05-26 08:37:48 +05:30
|
|
|
self.author1.set_text(self.s1.get_author())
|
|
|
|
self.author2.set_text(self.s2.get_author())
|
2005-03-09 09:28:44 +05:30
|
|
|
|
2009-04-18 08:40:50 +05:30
|
|
|
self.abbrev1 = self.glade.get_object("abbrev1")
|
|
|
|
self.abbrev2 = self.glade.get_object("abbrev2")
|
2006-05-26 08:37:48 +05:30
|
|
|
self.abbrev1.set_text(self.s1.get_abbreviation())
|
|
|
|
self.abbrev2.set_text(self.s2.get_abbreviation())
|
2005-03-09 09:28:44 +05:30
|
|
|
|
2009-04-18 08:40:50 +05:30
|
|
|
self.pub1 = self.glade.get_object("pub1")
|
|
|
|
self.pub2 = self.glade.get_object("pub2")
|
2006-05-26 08:37:48 +05:30
|
|
|
self.pub1.set_text(self.s1.get_publication_info())
|
|
|
|
self.pub2.set_text(self.s2.get_publication_info())
|
2005-03-09 09:28:44 +05:30
|
|
|
|
2009-04-18 08:40:50 +05:30
|
|
|
self.gramps1 = self.glade.get_object("gramps1")
|
|
|
|
self.gramps2 = self.glade.get_object("gramps2")
|
2006-05-26 08:37:48 +05:30
|
|
|
self.gramps1.set_text(self.s1.get_gramps_id())
|
|
|
|
self.gramps2.set_text(self.s2.get_gramps_id())
|
2005-03-09 09:28:44 +05:30
|
|
|
|
2009-04-18 08:40:50 +05:30
|
|
|
self.glade.get_object('source_ok').connect('clicked',self.merge)
|
|
|
|
self.glade.get_object('source_cancel').connect('clicked',self.close_window)
|
|
|
|
self.glade.get_object('source_help').connect('clicked',self.help)
|
2006-05-26 02:05:04 +05:30
|
|
|
self.show()
|
2005-03-09 09:28:44 +05:30
|
|
|
|
2008-02-24 19:25:55 +05:30
|
|
|
def close_window(self, obj):
|
2006-05-26 02:05:04 +05:30
|
|
|
self.close()
|
2005-03-09 09:28:44 +05:30
|
|
|
|
2008-02-24 19:25:55 +05:30
|
|
|
def help(self, obj):
|
2005-05-11 19:34:47 +05:30
|
|
|
"""Display the relevant portion of GRAMPS manual"""
|
2008-04-05 19:47:15 +05:30
|
|
|
GrampsDisplay.help(webpage = WIKI_HELP_PAGE, section = WIKI_HELP_SEC)
|
2005-05-11 19:34:47 +05:30
|
|
|
|
2008-02-24 19:25:55 +05:30
|
|
|
def merge(self, obj):
|
2005-03-09 09:28:44 +05:30
|
|
|
"""
|
2005-03-28 09:52:09 +05:30
|
|
|
Performs the merge of the sources when the merge button is clicked.
|
2005-03-09 09:28:44 +05:30
|
|
|
"""
|
|
|
|
|
2009-04-18 08:40:50 +05:30
|
|
|
use_title1 = self.glade.get_object("title_btn1").get_active()
|
|
|
|
use_author1 = self.glade.get_object("author_btn1").get_active()
|
|
|
|
use_abbrev1 = self.glade.get_object("abbrev_btn1").get_active()
|
|
|
|
use_pub1 = self.glade.get_object("pub_btn1").get_active()
|
|
|
|
use_gramps1 = self.glade.get_object("gramps_btn1").get_active()
|
2005-03-09 09:28:44 +05:30
|
|
|
|
|
|
|
if not use_title1:
|
2006-05-26 08:37:48 +05:30
|
|
|
self.s1.set_title(self.s2.get_title())
|
2005-03-09 09:28:44 +05:30
|
|
|
|
|
|
|
if not use_author1:
|
2006-05-26 08:37:48 +05:30
|
|
|
self.s1.set_author(self.s2.get_author())
|
2005-03-09 09:28:44 +05:30
|
|
|
|
|
|
|
if not use_abbrev1:
|
2006-05-26 08:37:48 +05:30
|
|
|
self.s1.set_abbreviation(self.s2.get_abbreviation())
|
2005-03-09 09:28:44 +05:30
|
|
|
|
|
|
|
if not use_pub1:
|
2006-05-26 08:37:48 +05:30
|
|
|
self.s1.set_publication_info(self.s2.get_publication_info())
|
2005-03-09 09:28:44 +05:30
|
|
|
|
|
|
|
if not use_gramps1:
|
2006-05-26 08:37:48 +05:30
|
|
|
self.s1.set_gramps_id(self.s2.get_gramps_id())
|
2005-03-09 09:28:44 +05:30
|
|
|
|
|
|
|
# Copy photos from src2 to src1
|
2006-05-26 08:37:48 +05:30
|
|
|
for photo in self.s2.get_media_list():
|
|
|
|
self.s1.add_media_reference(photo)
|
|
|
|
|
|
|
|
# Add notes from S2 to S1
|
2007-07-19 10:03:10 +05:30
|
|
|
self.s1.set_note_list(self.s1.get_note_list() + self.s2.get_note_list())
|
2006-05-26 08:37:48 +05:30
|
|
|
|
|
|
|
src2_map = self.s2.get_data_map()
|
|
|
|
src1_map = self.s1.get_data_map()
|
2009-05-27 02:18:09 +05:30
|
|
|
for key in src2_map:
|
2008-07-17 23:40:32 +05:30
|
|
|
if key not in src1_map:
|
2005-03-09 09:28:44 +05:30
|
|
|
src1_map[key] = src2_map[key]
|
|
|
|
|
2005-03-28 09:52:09 +05:30
|
|
|
# replace references in other objetcs
|
2006-05-26 02:05:04 +05:30
|
|
|
trans = self.db.transaction_begin()
|
|
|
|
|
|
|
|
self.db.remove_source(self.old_handle,trans)
|
2006-05-26 08:37:48 +05:30
|
|
|
self.db.commit_source(self.s1,trans)
|
2005-03-28 09:52:09 +05:30
|
|
|
|
2005-03-09 09:28:44 +05:30
|
|
|
# replace handles
|
|
|
|
|
2005-03-27 11:44:06 +05:30
|
|
|
# people
|
2009-07-08 00:28:47 +05:30
|
|
|
for handle in self.db.iter_person_handles():
|
2005-03-27 11:44:06 +05:30
|
|
|
person = self.db.get_person_from_handle(handle)
|
2005-03-28 09:52:09 +05:30
|
|
|
if person.has_source_reference(self.old_handle):
|
2009-04-18 08:40:50 +05:30
|
|
|
person.replace_source_references(self.old_handle,
|
|
|
|
self.new_handle)
|
2006-05-26 02:05:04 +05:30
|
|
|
self.db.commit_person(person,trans)
|
2005-03-09 09:28:44 +05:30
|
|
|
|
2005-03-27 11:44:06 +05:30
|
|
|
# family
|
|
|
|
for handle in self.db.get_family_handles():
|
|
|
|
family = self.db.get_family_from_handle(handle)
|
2005-03-28 09:52:09 +05:30
|
|
|
if family.has_source_reference(self.old_handle):
|
2009-04-18 08:40:50 +05:30
|
|
|
family.replace_source_references(self.old_handle,
|
|
|
|
self.new_handle)
|
2006-05-26 02:05:04 +05:30
|
|
|
self.db.commit_family(family,trans)
|
2005-03-09 09:28:44 +05:30
|
|
|
|
2005-03-27 11:44:06 +05:30
|
|
|
# events
|
|
|
|
for handle in self.db.get_event_handles():
|
|
|
|
event = self.db.get_event_from_handle(handle)
|
2005-03-28 09:52:09 +05:30
|
|
|
if event.has_source_reference(self.old_handle):
|
2009-04-18 08:40:50 +05:30
|
|
|
event.replace_source_references(self.old_handle,
|
|
|
|
self.new_handle)
|
2007-02-11 05:10:48 +05:30
|
|
|
self.db.commit_event(event,trans)
|
2005-03-09 09:28:44 +05:30
|
|
|
|
2005-03-27 11:44:06 +05:30
|
|
|
# sources
|
|
|
|
for handle in self.db.get_source_handles():
|
|
|
|
source = self.db.get_source_from_handle(handle)
|
2005-03-28 09:52:09 +05:30
|
|
|
if source.has_source_reference(self.old_handle):
|
2009-04-18 08:40:50 +05:30
|
|
|
source.replace_source_references(self.old_handle,
|
|
|
|
self.new_handle)
|
2006-05-26 02:05:04 +05:30
|
|
|
self.db.commit_source(source,trans)
|
2005-03-27 11:44:06 +05:30
|
|
|
|
|
|
|
# places
|
|
|
|
for handle in self.db.get_place_handles():
|
|
|
|
place = self.db.get_place_from_handle(handle)
|
2005-03-28 09:52:09 +05:30
|
|
|
if place.has_source_reference(self.old_handle):
|
2009-04-18 08:40:50 +05:30
|
|
|
place.replace_source_references(self.old_handle,
|
|
|
|
self.new_handle)
|
2006-05-26 02:05:04 +05:30
|
|
|
self.db.commit_place(place,trans)
|
2005-03-27 11:44:06 +05:30
|
|
|
|
|
|
|
# media
|
|
|
|
for handle in self.db.get_media_object_handles():
|
|
|
|
obj = self.db.get_object_from_handle(handle)
|
2005-03-28 09:52:09 +05:30
|
|
|
if obj.has_source_reference(self.old_handle):
|
2009-04-18 08:40:50 +05:30
|
|
|
obj.replace_source_references(self.old_handle,
|
|
|
|
self.new_handle)
|
2006-05-26 02:05:04 +05:30
|
|
|
self.db.commit_media_object(obj,trans)
|
2005-03-27 11:44:06 +05:30
|
|
|
|
2006-05-26 02:05:04 +05:30
|
|
|
self.db.transaction_commit(trans,_("Merge Sources"))
|
|
|
|
self.close()
|