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
|
|
|
|
#
|
|
|
|
|
|
|
|
"""
|
|
|
|
Provides the database state class
|
|
|
|
"""
|
|
|
|
|
|
|
|
__author__ = "Donald N. Allingham"
|
|
|
|
__revision__ = "$Revision: 8032 $"
|
|
|
|
|
2007-10-12 07:59:45 +05:30
|
|
|
from gen.db import GrampsDbBase
|
|
|
|
from gen.utils import GrampsDBCallback
|
2007-02-04 06:48:17 +05:30
|
|
|
import Config
|
|
|
|
|
|
|
|
class DbState(GrampsDBCallback):
|
2007-05-21 09:14:18 +05:30
|
|
|
"""
|
|
|
|
Provides a class to encapsulate the state of the database..
|
|
|
|
"""
|
2007-02-04 06:48:17 +05:30
|
|
|
|
|
|
|
__signals__ = {
|
|
|
|
'database-changed' : (GrampsDbBase, ),
|
|
|
|
'active-changed' : (str, ),
|
|
|
|
'no-database' : None,
|
|
|
|
}
|
|
|
|
|
|
|
|
def __init__(self):
|
2007-05-21 09:14:18 +05:30
|
|
|
"""
|
|
|
|
Initalize the state with an empty (and useless) GrampsDbBase. This is
|
|
|
|
just a place holder until a real DB is assigned.
|
|
|
|
"""
|
2007-02-04 06:48:17 +05:30
|
|
|
GrampsDBCallback.__init__(self)
|
2007-06-13 05:01:40 +05:30
|
|
|
self.db = GrampsDbBase()
|
|
|
|
self.open = False
|
|
|
|
self.active = None
|
|
|
|
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
|
|
|
"""
|
|
|
|
Changes the active person and emits a signal to notify those who
|
|
|
|
are interested.
|
|
|
|
"""
|
2007-02-04 06:48:17 +05:30
|
|
|
self.active = person
|
|
|
|
if person:
|
|
|
|
try:
|
|
|
|
self.emit('active-changed', (person.handle, ))
|
|
|
|
except:
|
|
|
|
self.emit('active-changed', ("", ))
|
|
|
|
|
|
|
|
def change_active_handle(self, handle):
|
2007-05-21 09:14:18 +05:30
|
|
|
"""
|
|
|
|
Changes the active person based on the person's handle
|
|
|
|
"""
|
2007-02-04 06:48:17 +05:30
|
|
|
self.change_active_person(self.db.get_person_from_handle(handle))
|
|
|
|
|
|
|
|
def get_active_person(self):
|
2007-05-21 09:14:18 +05:30
|
|
|
"""
|
|
|
|
Gets the current active person. Creates a new instance to make sure that
|
|
|
|
the data is active.
|
|
|
|
"""
|
|
|
|
if self.active:
|
2007-02-04 06:48:17 +05:30
|
|
|
self.active = self.db.get_person_from_handle(self.active.handle)
|
|
|
|
return self.active
|
|
|
|
|
|
|
|
def change_database(self, database):
|
2007-05-21 09:14:18 +05:30
|
|
|
"""
|
|
|
|
Closes the existing db, and opens a new one.
|
|
|
|
"""
|
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
|
|
|
"""
|
|
|
|
Changes the current database. and resets the configuration prefixes.
|
|
|
|
"""
|
2007-02-04 06:48:17 +05:30
|
|
|
self.db = database
|
|
|
|
self.db.set_prefixes(
|
|
|
|
Config.get(Config.IPREFIX),
|
|
|
|
Config.get(Config.OPREFIX),
|
|
|
|
Config.get(Config.FPREFIX),
|
|
|
|
Config.get(Config.SPREFIX),
|
|
|
|
Config.get(Config.PPREFIX),
|
|
|
|
Config.get(Config.EPREFIX),
|
2007-02-20 06:09:10 +05:30
|
|
|
Config.get(Config.RPREFIX),
|
|
|
|
Config.get(Config.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()
|
|
|
|
self.db = GrampsDbBase()
|
2007-06-14 04:18:28 +05:30
|
|
|
self.db.db_is_open = False
|
2007-02-04 06:48:17 +05:30
|
|
|
self.active = None
|
|
|
|
self.open = False
|
2007-04-02 09:26:30 +05:30
|
|
|
self.emit('database-changed', (self.db, ))
|