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
|
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-11 00:49:33 +05:30
|
|
|
'database-changed' : (DbBsddbRead, ),
|
|
|
|
'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
|
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.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
|
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
|