2007-02-04 06:48:17 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
|
|
|
# Copyright (C) 2000-2006 Donald N. Allingham
|
|
|
|
#
|
|
|
|
# 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-02-24 19:25:55 +05:30
|
|
|
Provide the database state class
|
2007-02-04 06:48:17 +05:30
|
|
|
"""
|
|
|
|
|
2009-12-23 21:25:58 +05:30
|
|
|
from gen.db import DbBsddbRead
|
2008-02-21 10:28:56 +05:30
|
|
|
from gen.utils import Callback
|
2009-10-08 06:42:51 +05:30
|
|
|
import config
|
2010-01-03 04:31:43 +05:30
|
|
|
from gui.views.navigationview import (NAVIGATION_PERSON, NAVIGATION_FAMILY,
|
|
|
|
NAVIGATION_EVENT, NAVIGATION_PLACE,
|
|
|
|
NAVIGATION_SOURCE, NAVIGATION_REPOSITORY,
|
|
|
|
NAVIGATION_MEDIA, NAVIGATION_NOTE)
|
|
|
|
ACTIVE_SIGNALS = ['person-active',
|
|
|
|
'family-active',
|
|
|
|
'event-active',
|
|
|
|
'place-active',
|
|
|
|
'source-active',
|
|
|
|
'repository-active',
|
|
|
|
'media-active',
|
|
|
|
'note-active']
|
2007-02-04 06:48:17 +05:30
|
|
|
|
2008-02-21 10:28:56 +05:30
|
|
|
class DbState(Callback):
|
2007-05-21 09:14:18 +05:30
|
|
|
"""
|
2009-06-19 03:26:37 +05:30
|
|
|
Provide a class to encapsulate the state of the database.
|
2007-05-21 09:14:18 +05:30
|
|
|
"""
|
2007-02-04 06:48:17 +05:30
|
|
|
|
|
|
|
__signals__ = {
|
2010-01-03 04:31:43 +05:30
|
|
|
'database-changed' : (DbBsddbRead, ),
|
|
|
|
'active-changed' : (str, ),
|
|
|
|
'person-active' : (str, ),
|
|
|
|
'family-active' : (str, ),
|
|
|
|
'event-active' : (str, ),
|
|
|
|
'place-active' : (str, ),
|
|
|
|
'source-active' : (str, ),
|
|
|
|
'repository-active' : (str, ),
|
|
|
|
'media-active' : (str, ),
|
|
|
|
'note-active' : (str, ),
|
|
|
|
'no-database' : None,
|
2007-02-04 06:48:17 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
def __init__(self):
|
2007-05-21 09:14:18 +05:30
|
|
|
"""
|
2009-12-23 21:25:58 +05:30
|
|
|
Initalize the state with an empty (and useless) DbBsddbRead. This is
|
2007-05-21 09:14:18 +05:30
|
|
|
just a place holder until a real DB is assigned.
|
|
|
|
"""
|
2008-02-21 10:28:56 +05:30
|
|
|
Callback.__init__(self)
|
2009-12-23 21:25:58 +05:30
|
|
|
self.db = DbBsddbRead()
|
2007-06-13 05:01:40 +05:30
|
|
|
self.open = False
|
2010-01-03 04:31:43 +05:30
|
|
|
self.active = None # Retained for backward compatibility.
|
|
|
|
self.__active_objects = [None] * 8
|
2007-06-13 05:01:40 +05:30
|
|
|
self.sighndl = None
|
2007-02-04 06:48:17 +05:30
|
|
|
|
|
|
|
def change_active_person(self, person):
|
2007-05-21 09:14:18 +05:30
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Change the active person and emits a signal to notify those who
|
2007-05-21 09:14:18 +05:30
|
|
|
are interested.
|
|
|
|
"""
|
2010-01-03 04:31:43 +05:30
|
|
|
print 'DbState: change_active_person is deprecated, ' + \
|
|
|
|
'use set_active_person instead.'
|
2007-02-04 06:48:17 +05:30
|
|
|
if person:
|
2010-01-03 04:31:43 +05:30
|
|
|
self.set_active_person(person.get_handle())
|
2007-02-04 06:48:17 +05:30
|
|
|
|
|
|
|
def change_active_handle(self, handle):
|
2007-05-21 09:14:18 +05:30
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Change the active person based on the person's handle
|
2007-05-21 09:14:18 +05:30
|
|
|
"""
|
2010-01-03 04:31:43 +05:30
|
|
|
print 'DbState: change_active_handle is deprecated, ' + \
|
|
|
|
'use set_active_person instead.'
|
|
|
|
self.set_active_person(handle)
|
2007-02-04 06:48:17 +05:30
|
|
|
|
|
|
|
def change_database(self, database):
|
2007-05-21 09:14:18 +05:30
|
|
|
"""
|
|
|
|
Closes the existing db, and opens a new one.
|
2010-01-03 04:31:43 +05:30
|
|
|
Retained for backward compatibility.
|
2007-05-21 09:14:18 +05:30
|
|
|
"""
|
2007-02-04 06:48:17 +05:30
|
|
|
self.db.close()
|
|
|
|
self.change_database_noclose(database)
|
|
|
|
|
|
|
|
def change_database_noclose(self, database):
|
2007-05-21 09:14:18 +05:30
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Change the current database. and resets the configuration prefixes.
|
2007-05-21 09:14:18 +05:30
|
|
|
"""
|
2007-02-04 06:48:17 +05:30
|
|
|
self.db = database
|
|
|
|
self.db.set_prefixes(
|
2009-10-08 06:42:51 +05:30
|
|
|
config.get('preferences.iprefix'),
|
|
|
|
config.get('preferences.oprefix'),
|
|
|
|
config.get('preferences.fprefix'),
|
|
|
|
config.get('preferences.sprefix'),
|
|
|
|
config.get('preferences.pprefix'),
|
|
|
|
config.get('preferences.eprefix'),
|
|
|
|
config.get('preferences.rprefix'),
|
|
|
|
config.get('preferences.nprefix') )
|
2007-02-04 06:48:17 +05:30
|
|
|
|
|
|
|
self.active = None
|
|
|
|
self.open = True
|
|
|
|
|
|
|
|
def signal_change(self):
|
2007-05-21 09:14:18 +05:30
|
|
|
"""
|
|
|
|
Emits the database-changed signal with the new database
|
|
|
|
"""
|
2007-02-04 06:48:17 +05:30
|
|
|
self.emit('database-changed', (self.db, ))
|
|
|
|
|
|
|
|
def no_database(self):
|
2007-05-21 09:14:18 +05:30
|
|
|
"""
|
|
|
|
Closes the database without a new database
|
|
|
|
"""
|
2007-02-04 06:48:17 +05:30
|
|
|
self.db.close()
|
2009-12-23 21:25:58 +05:30
|
|
|
self.db = DbBsddbRead()
|
2007-06-14 04:18:28 +05:30
|
|
|
self.db.db_is_open = False
|
2010-01-03 04:31:43 +05:30
|
|
|
self.active = None # Retained for backward compatibility.
|
|
|
|
self.__active_objects = [None] * 8
|
2007-02-04 06:48:17 +05:30
|
|
|
self.open = False
|
2007-04-02 09:26:30 +05:30
|
|
|
self.emit('database-changed', (self.db, ))
|
2007-12-30 11:11:16 +05:30
|
|
|
|
|
|
|
def get_database(self):
|
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Get a reference to the current database.
|
2007-12-30 11:11:16 +05:30
|
|
|
"""
|
|
|
|
return self.db
|
2010-01-03 04:31:43 +05:30
|
|
|
|
|
|
|
def set_active(self, navigation_type, handle):
|
|
|
|
"""
|
|
|
|
Set the active handle for the given navigation type.
|
|
|
|
"""
|
|
|
|
handle = str(handle) # This is sometimes unicode.
|
|
|
|
old_handle = self.__active_objects[navigation_type]
|
|
|
|
if old_handle != handle:
|
|
|
|
self.__active_objects[navigation_type] = handle
|
|
|
|
signal = ACTIVE_SIGNALS[navigation_type]
|
|
|
|
try:
|
|
|
|
self.emit(signal, (handle, ))
|
|
|
|
except:
|
|
|
|
self.emit(signal, ("", ))
|
|
|
|
|
|
|
|
# Retained for backward compatibility.
|
|
|
|
if navigation_type == NAVIGATION_PERSON:
|
|
|
|
self.active = self.db.get_person_from_handle(handle)
|
|
|
|
try:
|
|
|
|
self.emit('active-changed', (handle, ))
|
|
|
|
except:
|
|
|
|
self.emit('active-changed', ("", ))
|
|
|
|
|
|
|
|
def get_active(self, navigation_type):
|
|
|
|
"""
|
|
|
|
Return the active handle for the given navigation type.
|
|
|
|
"""
|
|
|
|
handle = self.__active_objects[navigation_type]
|
|
|
|
if navigation_type == NAVIGATION_PERSON:
|
|
|
|
return self.db.get_person_from_handle(handle)
|
|
|
|
elif navigation_type == NAVIGATION_FAMILY:
|
|
|
|
return self.db.get_family_from_handle(handle)
|
|
|
|
elif navigation_type == NAVIGATION_EVENT:
|
|
|
|
return self.db.get_event_from_handle(handle)
|
|
|
|
elif navigation_type == NAVIGATION_PLACE:
|
|
|
|
return self.db.get_place_from_handle(handle)
|
|
|
|
elif navigation_type == NAVIGATION_SOURCE:
|
|
|
|
return self.db.get_source_from_handle(handle)
|
|
|
|
elif navigation_type == NAVIGATION_REPOSITORY:
|
|
|
|
return self.db.get_repository_from_handle(handle)
|
|
|
|
elif navigation_type == NAVIGATION_MEDIA:
|
|
|
|
return self.db.get_object_from_handle(handle)
|
|
|
|
elif navigation_type == NAVIGATION_NOTE:
|
|
|
|
return self.db.get_note_from_handle(handle)
|
|
|
|
|
|
|
|
###########################################################################
|
|
|
|
# Convenience functions
|
|
|
|
###########################################################################
|
|
|
|
def set_active_person(self, handle):
|
|
|
|
"""Set the active person to the given handle."""
|
|
|
|
self.set_active(NAVIGATION_PERSON, handle)
|
|
|
|
|
|
|
|
def get_active_person(self):
|
|
|
|
"""Return the handle for the active person."""
|
|
|
|
return self.get_active(NAVIGATION_PERSON)
|
|
|
|
|
|
|
|
def set_active_family(self, handle):
|
|
|
|
"""Set the active family to the given handle."""
|
|
|
|
self.set_active(NAVIGATION_FAMILY, handle)
|
|
|
|
|
|
|
|
def get_active_family(self):
|
|
|
|
"""Return the handle for the active family."""
|
|
|
|
return self.get_active(NAVIGATION_FAMILY)
|
|
|
|
|
|
|
|
def set_active_event(self, handle):
|
|
|
|
"""Set the active event to the given handle."""
|
|
|
|
self.set_active(NAVIGATION_EVENT, handle)
|
|
|
|
|
|
|
|
def get_active_event(self):
|
|
|
|
"""Return the handle for the active event."""
|
|
|
|
return self.get_active(NAVIGATION_EVENT)
|
|
|
|
|
|
|
|
def set_active_place(self, handle):
|
|
|
|
"""Set the active place to the given handle."""
|
|
|
|
self.set_active(NAVIGATION_PLACE, handle)
|
|
|
|
|
|
|
|
def get_active_place(self):
|
|
|
|
"""Return the handle for the active place."""
|
|
|
|
return self.get_active(NAVIGATION_PLACE)
|
|
|
|
|
|
|
|
def set_active_source(self, handle):
|
|
|
|
"""Set the active source to the given handle."""
|
|
|
|
self.set_active(NAVIGATION_SOURCE, handle)
|
|
|
|
|
|
|
|
def get_active_source(self):
|
|
|
|
"""Return the handle for the active source."""
|
|
|
|
return self.get_active(NAVIGATION_SOURCE)
|
|
|
|
|
|
|
|
def set_active_repository(self, handle):
|
|
|
|
"""Set the active repository to the given handle."""
|
|
|
|
self.set_active(NAVIGATION_REPOSITORY, handle)
|
|
|
|
|
|
|
|
def get_active_repository(self):
|
|
|
|
"""Return the handle for the active repository."""
|
|
|
|
return self.get_active(NAVIGATION_REPOSITORY)
|
|
|
|
|
|
|
|
def set_active_media(self, handle):
|
|
|
|
"""Set the active media to the given handle."""
|
|
|
|
self.set_active(NAVIGATION_MEDIA, handle)
|
|
|
|
|
|
|
|
def get_active_media(self):
|
|
|
|
"""Return the handle for the active media."""
|
|
|
|
return self.get_active(NAVIGATION_MEDIA)
|
|
|
|
|
|
|
|
def set_active_note(self, handle):
|
|
|
|
"""Set the active note to the given handle."""
|
|
|
|
self.set_active(NAVIGATION_NOTE, handle)
|
|
|
|
|
|
|
|
def get_active_note(self):
|
|
|
|
"""Return the handle for the active note."""
|
|
|
|
return self.get_active(NAVIGATION_NOTE)
|