2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2006-04-24 03:48:01 +05:30
|
|
|
# Copyright (C) 2000-2006 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
|
|
|
|
#
|
|
|
|
|
2003-11-13 00:15:07 +05:30
|
|
|
# $Id$
|
|
|
|
|
2005-02-16 19:19:32 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Python modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2006-04-07 03:32:46 +05:30
|
|
|
from gettext import gettext as _
|
2005-12-21 21:15:30 +05:30
|
|
|
|
2006-01-09 16:58:44 +05:30
|
|
|
import logging
|
|
|
|
log = logging.getLogger(".")
|
2005-02-16 19:19:32 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GTK/Gnome modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2008-02-08 20:59:28 +05:30
|
|
|
import gtk
|
|
|
|
from gtk import glade
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# gramps modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import const
|
2006-11-26 06:59:58 +05:30
|
|
|
import Config
|
2007-10-08 22:11:39 +05:30
|
|
|
import gen.lib
|
2008-02-08 20:59:28 +05:30
|
|
|
from Editors._EditPrimary import EditPrimary
|
2005-12-23 05:13:32 +05:30
|
|
|
|
2008-02-08 20:59:28 +05:30
|
|
|
from DisplayTabs import (NoteTab, GalleryTab, DataEmbedList,
|
|
|
|
SourceBackRefList, RepoEmbedList)
|
2008-05-09 01:10:56 +05:30
|
|
|
from widgets import MonitoredEntry, PrivacyButton
|
2008-02-09 06:37:23 +05:30
|
|
|
from QuestionDialog import ErrorDialog
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Constants
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2006-03-04 12:04:48 +05:30
|
|
|
class EditSource(EditPrimary):
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2008-02-09 06:37:23 +05:30
|
|
|
def __init__(self, dbstate, uistate, track, source):
|
2005-12-23 05:13:32 +05:30
|
|
|
|
2008-02-09 06:37:23 +05:30
|
|
|
EditPrimary.__init__(self, dbstate, uistate, track, source,
|
|
|
|
dbstate.db.get_source_from_handle,
|
|
|
|
dbstate.db.get_source_from_gramps_id)
|
2005-12-23 05:13:32 +05:30
|
|
|
|
2006-04-01 01:16:41 +05:30
|
|
|
def empty_object(self):
|
2007-10-08 22:11:39 +05:30
|
|
|
return gen.lib.Source()
|
2006-04-01 01:16:41 +05:30
|
|
|
|
2006-11-27 02:48:30 +05:30
|
|
|
def get_menu_title(self):
|
2006-11-26 06:59:58 +05:30
|
|
|
title = self.obj.get_title()
|
|
|
|
if title:
|
|
|
|
title = _('Source') + ": " + title
|
|
|
|
else:
|
2006-11-27 02:48:30 +05:30
|
|
|
title = _('New Source')
|
|
|
|
return title
|
2006-11-26 06:59:58 +05:30
|
|
|
|
2006-11-27 02:48:30 +05:30
|
|
|
def _local_init(self):
|
|
|
|
|
|
|
|
assert(self.obj)
|
2008-02-08 20:59:28 +05:30
|
|
|
self.glade = glade.XML(const.GLADE_FILE, "source_editor","gramps")
|
2006-11-27 02:48:30 +05:30
|
|
|
|
2008-02-08 20:59:28 +05:30
|
|
|
self.set_window(self.glade.get_widget("source_editor"), None,
|
|
|
|
self.get_menu_title())
|
2006-11-26 06:59:58 +05:30
|
|
|
width = Config.get(Config.SOURCE_WIDTH)
|
|
|
|
height = Config.get(Config.SOURCE_HEIGHT)
|
|
|
|
self.window.resize(width, height)
|
2005-12-21 21:15:30 +05:30
|
|
|
|
2006-02-23 08:43:15 +05:30
|
|
|
def _connect_signals(self):
|
2006-03-01 10:38:11 +05:30
|
|
|
self.define_ok_button(self.glade.get_widget('ok'),self.save)
|
|
|
|
self.define_cancel_button(self.glade.get_widget('cancel'))
|
2008-04-05 19:47:15 +05:30
|
|
|
self.define_help_button(self.glade.get_widget('help'))
|
2006-02-23 08:43:15 +05:30
|
|
|
|
|
|
|
def _setup_fields(self):
|
2008-02-09 06:37:23 +05:30
|
|
|
self.author = MonitoredEntry(self.glade.get_widget("author"),
|
|
|
|
self.obj.set_author, self.obj.get_author,
|
|
|
|
self.db.readonly)
|
|
|
|
|
|
|
|
self.pubinfo = MonitoredEntry(self.glade.get_widget("pubinfo"),
|
|
|
|
self.obj.set_publication_info,
|
|
|
|
self.obj.get_publication_info,
|
|
|
|
self.db.readonly)
|
|
|
|
|
|
|
|
self.gid = MonitoredEntry(self.glade.get_widget("gid"),
|
|
|
|
self.obj.set_gramps_id,
|
|
|
|
self.obj.get_gramps_id, self.db.readonly)
|
|
|
|
|
|
|
|
self.priv = PrivacyButton(self.glade.get_widget("private"), self.obj,
|
|
|
|
self.db.readonly)
|
|
|
|
|
|
|
|
self.abbrev = MonitoredEntry(self.glade.get_widget("abbrev"),
|
|
|
|
self.obj.set_abbreviation,
|
|
|
|
self.obj.get_abbreviation,
|
|
|
|
self.db.readonly)
|
|
|
|
|
|
|
|
self.title = MonitoredEntry(self.glade.get_widget("source_title"),
|
|
|
|
self.obj.set_title, self.obj.get_title,
|
|
|
|
self.db.readonly)
|
2006-02-23 08:43:15 +05:30
|
|
|
|
|
|
|
def _create_tabbed_pages(self):
|
2006-03-01 10:38:11 +05:30
|
|
|
notebook = gtk.Notebook()
|
|
|
|
|
|
|
|
self.note_tab = self._add_tab(
|
|
|
|
notebook,
|
|
|
|
NoteTab(self.dbstate, self.uistate, self.track,
|
2007-05-08 02:11:16 +05:30
|
|
|
self.obj.get_note_list(), self.get_menu_title(),
|
2007-10-08 22:11:39 +05:30
|
|
|
gen.lib.NoteType.SOURCE))
|
2006-02-23 08:43:15 +05:30
|
|
|
|
2006-03-01 10:38:11 +05:30
|
|
|
self.gallery_tab = self._add_tab(
|
|
|
|
notebook,
|
|
|
|
GalleryTab(self.dbstate, self.uistate, self.track,
|
|
|
|
self.obj.get_media_list()))
|
2006-02-23 08:43:15 +05:30
|
|
|
|
2006-03-01 10:38:11 +05:30
|
|
|
self.data_tab = self._add_tab(
|
|
|
|
notebook,
|
|
|
|
DataEmbedList(self.dbstate, self.uistate, self.track,
|
|
|
|
self.obj))
|
2006-02-23 08:43:15 +05:30
|
|
|
|
2006-03-01 10:38:11 +05:30
|
|
|
self.repo_tab = self._add_tab(
|
|
|
|
notebook,
|
|
|
|
RepoEmbedList(self.dbstate, self.uistate, self.track,
|
|
|
|
self.obj.get_reporef_list()))
|
2006-02-23 08:43:15 +05:30
|
|
|
|
2006-03-01 10:38:11 +05:30
|
|
|
self.backref_tab = self._add_tab(
|
|
|
|
notebook,
|
|
|
|
SourceBackRefList(self.dbstate, self.uistate, self.track,
|
2006-04-22 02:04:26 +05:30
|
|
|
self.db.find_backlink_handles(self.obj.handle)))
|
2006-01-25 10:37:10 +05:30
|
|
|
|
2007-01-16 12:42:10 +05:30
|
|
|
self._setup_notebook_tabs( notebook)
|
2006-03-01 10:38:11 +05:30
|
|
|
notebook.show_all()
|
2008-02-08 20:59:28 +05:30
|
|
|
self.glade.get_widget('vbox').pack_start(notebook, True)
|
2005-12-23 05:13:32 +05:30
|
|
|
|
2008-02-08 20:59:28 +05:30
|
|
|
def build_menu_names(self, source):
|
2006-11-27 02:48:30 +05:30
|
|
|
return (_('Edit Source'), self.get_menu_title())
|
2005-12-23 05:13:32 +05:30
|
|
|
|
2008-02-08 19:10:04 +05:30
|
|
|
def save(self, *obj):
|
2007-04-08 09:54:38 +05:30
|
|
|
self.ok_button.set_sensitive(False)
|
2006-04-01 01:16:41 +05:30
|
|
|
if self.object_is_empty():
|
|
|
|
ErrorDialog(_("Cannot save source"),
|
|
|
|
_("No data exists for this source. Please "
|
|
|
|
"enter data or cancel the edit."))
|
2007-04-08 09:54:38 +05:30
|
|
|
self.ok_button.set_sensitive(True)
|
2006-04-01 01:16:41 +05:30
|
|
|
return
|
2008-02-09 06:37:23 +05:30
|
|
|
|
|
|
|
(uses_dupe_id, id) = self._uses_duplicate_id()
|
|
|
|
if uses_dupe_id:
|
|
|
|
prim_object = self.get_from_gramps_id(id)
|
|
|
|
name = prim_object.get_title()
|
|
|
|
msg1 = _("Cannot save source. ID already exists.")
|
|
|
|
msg2 = _("You have attempted to use the existing GRAMPS ID with "
|
|
|
|
"value %(id)s. This value is already used by '"
|
|
|
|
"%(prim_object)s'. Please enter a different ID or leave "
|
|
|
|
"blank to get the next available ID value.") % {
|
|
|
|
'id' : id, 'prim_object' : name }
|
|
|
|
ErrorDialog(msg1, msg2)
|
|
|
|
self.ok_button.set_sensitive(True)
|
|
|
|
return
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-08-13 10:04:07 +05:30
|
|
|
trans = self.db.transaction_begin()
|
2008-02-08 19:10:04 +05:30
|
|
|
if not self.obj.get_handle():
|
|
|
|
self.db.add_source(self.obj, trans)
|
|
|
|
msg = _("Add Source (%s)") % self.obj.get_title()
|
2004-08-30 09:20:33 +05:30
|
|
|
else:
|
2008-02-08 19:10:04 +05:30
|
|
|
if not self.obj.get_gramps_id():
|
|
|
|
self.obj.set_gramps_id(self.db.find_next_source_gramps_id())
|
|
|
|
self.db.commit_source(self.obj, trans)
|
|
|
|
msg = _("Edit Source (%s)") % self.obj.get_title()
|
|
|
|
|
|
|
|
self.db.transaction_commit(trans, msg)
|
2006-04-22 08:53:57 +05:30
|
|
|
self.close()
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2006-11-26 06:59:58 +05:30
|
|
|
def _cleanup_on_exit(self):
|
|
|
|
self.backref_tab.close()
|
|
|
|
(width, height) = self.window.get_size()
|
|
|
|
Config.set(Config.SOURCE_WIDTH, width)
|
|
|
|
Config.set(Config.SOURCE_HEIGHT, height)
|
|
|
|
Config.sync()
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
class DelSrcQuery:
|
2008-02-08 20:59:28 +05:30
|
|
|
def __init__(self, dbstate, uistate, source, the_lists):
|
2002-10-20 19:55:16 +05:30
|
|
|
self.source = source
|
2007-01-23 09:07:13 +05:30
|
|
|
self.db = dbstate.db
|
|
|
|
self.uistate = uistate
|
2005-03-12 02:35:46 +05:30
|
|
|
self.the_lists = the_lists
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def query_response(self):
|
2004-08-13 10:04:07 +05:30
|
|
|
trans = self.db.transaction_begin()
|
2005-06-05 09:31:56 +05:30
|
|
|
self.db.disable_signals()
|
2004-03-30 10:20:24 +05:30
|
|
|
|
2008-02-08 20:59:28 +05:30
|
|
|
(person_list, family_list, event_list, place_list, source_list,
|
|
|
|
media_list, repo_list) = self.the_lists
|
2005-03-12 02:35:46 +05:30
|
|
|
|
|
|
|
src_handle_list = [self.source.get_handle()]
|
|
|
|
|
|
|
|
for handle in person_list:
|
|
|
|
person = self.db.get_person_from_handle(handle)
|
|
|
|
person.remove_source_references(src_handle_list)
|
2008-02-08 20:59:28 +05:30
|
|
|
self.db.commit_person(person, trans)
|
2005-03-12 02:35:46 +05:30
|
|
|
|
|
|
|
for handle in family_list:
|
|
|
|
family = self.db.get_family_from_handle(handle)
|
|
|
|
family.remove_source_references(src_handle_list)
|
2008-02-08 20:59:28 +05:30
|
|
|
self.db.commit_family(family, trans)
|
2005-03-12 02:35:46 +05:30
|
|
|
|
|
|
|
for handle in event_list:
|
|
|
|
event = self.db.get_event_from_handle(handle)
|
|
|
|
event.remove_source_references(src_handle_list)
|
2008-02-08 20:59:28 +05:30
|
|
|
self.db.commit_event(event, trans)
|
2005-03-12 02:35:46 +05:30
|
|
|
|
|
|
|
for handle in place_list:
|
|
|
|
place = self.db.get_place_from_handle(handle)
|
|
|
|
place.remove_source_references(src_handle_list)
|
2008-02-08 20:59:28 +05:30
|
|
|
self.db.commit_place(place, trans)
|
2005-03-12 02:35:46 +05:30
|
|
|
|
|
|
|
for handle in source_list:
|
|
|
|
source = self.db.get_source_from_handle(handle)
|
|
|
|
source.remove_source_references(src_handle_list)
|
2008-02-08 20:59:28 +05:30
|
|
|
self.db.commit_source(source, trans)
|
2005-03-12 02:35:46 +05:30
|
|
|
|
|
|
|
for handle in media_list:
|
|
|
|
media = self.db.get_object_from_handle(handle)
|
|
|
|
media.remove_source_references(src_handle_list)
|
2008-02-08 20:59:28 +05:30
|
|
|
self.db.commit_media_object(media, trans)
|
2005-04-04 06:41:50 +05:30
|
|
|
|
2007-01-23 09:07:13 +05:30
|
|
|
for handle in repo_list:
|
|
|
|
repo = self.db.get_repository_from_handle(handle)
|
|
|
|
repo.remove_source_references(src_handle_list)
|
2008-02-08 20:59:28 +05:30
|
|
|
self.db.commit_repository(repo, trans)
|
2007-01-23 09:07:13 +05:30
|
|
|
|
2005-06-05 09:31:56 +05:30
|
|
|
self.db.enable_signals()
|
2008-02-08 20:59:28 +05:30
|
|
|
self.db.remove_source(self.source.get_handle(), trans)
|
2005-04-04 06:41:50 +05:30
|
|
|
self.db.transaction_commit(
|
2008-02-08 20:59:28 +05:30
|
|
|
trans, _("Delete Source (%s)") % self.source.get_title())
|