2006-11-06 08:21:09 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2007-01-31 07:35:01 +05:30
|
|
|
# Copyright (C) 2000-2007 Donald N. Allingham
|
2008-05-19 00:54:28 +05:30
|
|
|
# Copyright (C) 2008 Brian G. Matherly
|
2008-06-24 23:21:55 +05:30
|
|
|
# Copyright (C) 2008 Stephane Charette
|
2006-11-06 08:21:09 +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
|
|
|
|
#
|
|
|
|
|
2007-06-24 06:56:48 +05:30
|
|
|
# $Id$
|
2006-11-06 08:21:09 +05:30
|
|
|
|
2009-08-11 02:53:38 +05:30
|
|
|
"Find unused objects and remove with the user's permission."
|
2006-11-06 08:21:09 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# python modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2009-06-16 21:19:17 +05:30
|
|
|
from __future__ import with_statement
|
2006-11-06 08:21:09 +05:30
|
|
|
from gettext import gettext as _
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Set up logging
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
import logging
|
|
|
|
log = logging.getLogger(".RemoveUnused")
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# gtk modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import gtk
|
2008-01-22 03:33:43 +05:30
|
|
|
import gobject
|
2006-11-06 08:21:09 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2007-01-31 07:35:01 +05:30
|
|
|
import Errors
|
2006-11-06 08:21:09 +05:30
|
|
|
import ManagedWindow
|
2008-06-24 23:21:55 +05:30
|
|
|
from DateHandler import displayer as _dd
|
2007-01-31 07:35:01 +05:30
|
|
|
from BasicUtils import UpdateCallback
|
2008-10-02 09:32:10 +05:30
|
|
|
from PluginUtils import Tool
|
2009-05-15 01:45:59 +05:30
|
|
|
from glade import Glade
|
2009-04-16 00:57:17 +05:30
|
|
|
|
2006-11-06 08:21:09 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# runTool
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2009-08-11 02:53:38 +05:30
|
|
|
class RemoveUnused(Tool.Tool, ManagedWindow.ManagedWindow, UpdateCallback):
|
2007-06-24 06:56:48 +05:30
|
|
|
MARK_COL = 0
|
|
|
|
OBJ_ID_COL = 1
|
|
|
|
OBJ_NAME_COL = 2
|
|
|
|
OBJ_TYPE_COL = 3
|
|
|
|
OBJ_HANDLE_COL = 4
|
|
|
|
|
2006-11-06 08:21:09 +05:30
|
|
|
def __init__(self, dbstate, uistate, options_class, name, callback=None):
|
2007-06-24 06:56:48 +05:30
|
|
|
self.title = _('Unused Objects')
|
2007-01-31 07:35:01 +05:30
|
|
|
|
|
|
|
Tool.Tool.__init__(self, dbstate, options_class, name)
|
2007-06-24 06:56:48 +05:30
|
|
|
|
|
|
|
if self.db.readonly:
|
|
|
|
return
|
|
|
|
|
2009-08-11 02:53:38 +05:30
|
|
|
ManagedWindow.ManagedWindow.__init__(self, uistate,[], self.__class__)
|
|
|
|
UpdateCallback.__init__(self, self.uistate.pulse_progressbar)
|
2006-11-06 08:21:09 +05:30
|
|
|
|
2006-11-06 09:53:10 +05:30
|
|
|
self.dbstate = dbstate
|
|
|
|
self.uistate = uistate
|
2006-11-06 08:21:09 +05:30
|
|
|
|
2007-06-24 06:56:48 +05:30
|
|
|
self.tables = {
|
|
|
|
'events' : {'get_func': self.db.get_event_from_handle,
|
|
|
|
'remove' : self.db.remove_event,
|
2008-06-24 23:21:55 +05:30
|
|
|
'get_text': self.get_event_text,
|
2007-06-24 06:56:48 +05:30
|
|
|
'editor' : 'EditEvent',
|
|
|
|
'stock' : 'gramps-event',
|
|
|
|
'name_ix' : 4},
|
|
|
|
'sources' : {'get_func': self.db.get_source_from_handle,
|
|
|
|
'remove' : self.db.remove_source,
|
2008-06-24 23:21:55 +05:30
|
|
|
'get_text': None,
|
2007-06-24 06:56:48 +05:30
|
|
|
'editor' : 'EditSource',
|
|
|
|
'stock' : 'gramps-source',
|
|
|
|
'name_ix' : 2},
|
|
|
|
'places' : {'get_func': self.db.get_place_from_handle,
|
|
|
|
'remove' : self.db.remove_place,
|
2008-06-24 23:21:55 +05:30
|
|
|
'get_text': None,
|
2007-06-24 06:56:48 +05:30
|
|
|
'editor' : 'EditPlace',
|
|
|
|
'stock' : 'gramps-place',
|
|
|
|
'name_ix' : 2},
|
|
|
|
'media' : {'get_func': self.db.get_object_from_handle,
|
|
|
|
'remove' : self.db.remove_object,
|
2008-06-24 23:21:55 +05:30
|
|
|
'get_text': None,
|
2007-06-24 06:56:48 +05:30
|
|
|
'editor' : 'EditMedia',
|
|
|
|
'stock' : 'gramps-media',
|
|
|
|
'name_ix' : 4},
|
|
|
|
'repos' : {'get_func': self.db.get_repository_from_handle,
|
|
|
|
'remove' : self.db.remove_repository,
|
2008-06-24 23:21:55 +05:30
|
|
|
'get_text': None,
|
2007-06-24 06:56:48 +05:30
|
|
|
'editor' : 'EditRepository',
|
|
|
|
'stock' : 'gramps-repository',
|
|
|
|
'name_ix' : 3},
|
2008-04-22 02:22:39 +05:30
|
|
|
'notes' : {'get_func': self.db.get_note_from_handle,
|
|
|
|
'remove' : self.db.remove_note,
|
2008-06-24 23:21:55 +05:30
|
|
|
'get_text': self.get_note_text,
|
2008-04-22 02:22:39 +05:30
|
|
|
'editor' : 'EditNote',
|
|
|
|
'stock' : 'gramps-notes',
|
|
|
|
'name_ix' : 2},
|
2007-06-24 06:56:48 +05:30
|
|
|
}
|
2007-01-31 07:35:01 +05:30
|
|
|
|
2006-11-08 08:50:20 +05:30
|
|
|
self.init_gui()
|
2006-11-06 09:53:10 +05:30
|
|
|
|
2007-06-26 11:32:17 +05:30
|
|
|
def init_gui(self):
|
2009-05-15 01:45:59 +05:30
|
|
|
self.top = Glade()
|
|
|
|
window = self.top.toplevel
|
2009-08-11 02:53:38 +05:30
|
|
|
self.set_window(window, self.top.get_object('title'), self.title)
|
2007-01-31 07:35:01 +05:30
|
|
|
|
2009-04-10 01:23:38 +05:30
|
|
|
self.events_box = self.top.get_object('events_box')
|
|
|
|
self.sources_box = self.top.get_object('sources_box')
|
|
|
|
self.places_box = self.top.get_object('places_box')
|
|
|
|
self.media_box = self.top.get_object('media_box')
|
|
|
|
self.repos_box = self.top.get_object('repos_box')
|
|
|
|
self.notes_box = self.top.get_object('notes_box')
|
|
|
|
self.find_button = self.top.get_object('find_button')
|
|
|
|
self.remove_button = self.top.get_object('remove_button')
|
2007-01-31 07:35:01 +05:30
|
|
|
|
|
|
|
self.events_box.set_active(self.options.handler.options_dict['events'])
|
|
|
|
self.sources_box.set_active(
|
|
|
|
self.options.handler.options_dict['sources'])
|
|
|
|
self.places_box.set_active(
|
|
|
|
self.options.handler.options_dict['places'])
|
|
|
|
self.media_box.set_active(self.options.handler.options_dict['media'])
|
|
|
|
self.repos_box.set_active(self.options.handler.options_dict['repos'])
|
2008-04-22 02:22:39 +05:30
|
|
|
self.notes_box.set_active(self.options.handler.options_dict['notes'])
|
2007-01-31 07:35:01 +05:30
|
|
|
|
2009-04-10 01:23:38 +05:30
|
|
|
self.warn_tree = self.top.get_object('warn_tree')
|
2007-06-24 06:56:48 +05:30
|
|
|
self.warn_tree.connect('button_press_event', self.double_click)
|
2007-01-31 07:35:01 +05:30
|
|
|
|
2007-06-24 06:56:48 +05:30
|
|
|
self.selection = self.warn_tree.get_selection()
|
|
|
|
|
2009-04-10 01:23:38 +05:30
|
|
|
self.mark_button = self.top.get_object('mark_button')
|
2009-08-11 02:53:38 +05:30
|
|
|
self.mark_button.connect('clicked', self.mark_clicked)
|
2007-01-31 07:35:01 +05:30
|
|
|
|
2009-04-10 01:23:38 +05:30
|
|
|
self.unmark_button = self.top.get_object('unmark_button')
|
2009-08-11 02:53:38 +05:30
|
|
|
self.unmark_button.connect('clicked', self.unmark_clicked)
|
2007-06-24 06:56:48 +05:30
|
|
|
|
2009-04-10 01:23:38 +05:30
|
|
|
self.invert_button = self.top.get_object('invert_button')
|
2009-08-11 02:53:38 +05:30
|
|
|
self.invert_button.connect('clicked', self.invert_clicked)
|
2007-06-24 06:56:48 +05:30
|
|
|
|
2008-01-22 03:33:43 +05:30
|
|
|
self.real_model = gtk.ListStore(gobject.TYPE_BOOLEAN,
|
|
|
|
gobject.TYPE_STRING,
|
|
|
|
gobject.TYPE_STRING,
|
|
|
|
gobject.TYPE_STRING,
|
|
|
|
gobject.TYPE_STRING)
|
2007-06-24 06:56:48 +05:30
|
|
|
self.sort_model = gtk.TreeModelSort(self.real_model)
|
|
|
|
self.warn_tree.set_model(self.sort_model)
|
|
|
|
|
|
|
|
self.renderer = gtk.CellRendererText()
|
|
|
|
self.img_renderer = gtk.CellRendererPixbuf()
|
|
|
|
self.bool_renderer = gtk.CellRendererToggle()
|
2009-08-11 02:53:38 +05:30
|
|
|
self.bool_renderer.connect('toggled', self.selection_toggled)
|
2007-06-24 06:56:48 +05:30
|
|
|
|
|
|
|
# Add mark column
|
2009-08-11 02:53:38 +05:30
|
|
|
mark_column = gtk.TreeViewColumn(_('Mark'), self.bool_renderer,
|
2007-06-24 06:56:48 +05:30
|
|
|
active=RemoveUnused.MARK_COL)
|
|
|
|
mark_column.set_sort_column_id(RemoveUnused.MARK_COL)
|
|
|
|
self.warn_tree.append_column(mark_column)
|
|
|
|
|
|
|
|
# Add image column
|
|
|
|
img_column = gtk.TreeViewColumn(None, self.img_renderer )
|
2009-08-11 02:53:38 +05:30
|
|
|
img_column.set_cell_data_func(self.img_renderer, self.get_image)
|
2007-06-24 06:56:48 +05:30
|
|
|
self.warn_tree.append_column(img_column)
|
|
|
|
|
|
|
|
# Add column with object gramps_id
|
|
|
|
id_column = gtk.TreeViewColumn(_('ID'), self.renderer,
|
|
|
|
text=RemoveUnused.OBJ_ID_COL)
|
|
|
|
id_column.set_sort_column_id(RemoveUnused.OBJ_ID_COL)
|
|
|
|
self.warn_tree.append_column(id_column)
|
|
|
|
|
|
|
|
# Add column with object name
|
|
|
|
name_column = gtk.TreeViewColumn(_('Name'), self.renderer,
|
|
|
|
text=RemoveUnused.OBJ_NAME_COL)
|
|
|
|
name_column.set_sort_column_id(RemoveUnused.OBJ_NAME_COL)
|
|
|
|
self.warn_tree.append_column(name_column)
|
|
|
|
|
2009-04-10 01:23:38 +05:30
|
|
|
self.top.connect_signals({
|
2007-06-24 06:56:48 +05:30
|
|
|
"destroy_passed_object" : self.close,
|
|
|
|
"on_remove_button_clicked": self.do_remove,
|
|
|
|
"on_find_button_clicked" : self.find,
|
2010-01-07 19:40:26 +05:30
|
|
|
"on_delete_event" : self.close,
|
2007-06-24 06:56:48 +05:30
|
|
|
})
|
|
|
|
|
2009-04-10 01:23:38 +05:30
|
|
|
self.dc_label = self.top.get_object('dc_label')
|
2006-11-06 08:21:09 +05:30
|
|
|
|
2009-08-11 02:53:38 +05:30
|
|
|
self.sensitive_list = [self.warn_tree, self.mark_button,
|
|
|
|
self.unmark_button, self.invert_button,
|
|
|
|
self.dc_label, self.remove_button]
|
2007-06-24 06:56:48 +05:30
|
|
|
|
|
|
|
for item in self.sensitive_list:
|
|
|
|
item.set_sensitive(False)
|
|
|
|
|
|
|
|
self.show()
|
2007-01-31 07:35:01 +05:30
|
|
|
|
2008-02-24 19:25:55 +05:30
|
|
|
def build_menu_names(self, obj):
|
2009-08-11 02:53:38 +05:30
|
|
|
return (self.title, None)
|
2007-01-31 07:35:01 +05:30
|
|
|
|
2008-02-24 19:25:55 +05:30
|
|
|
def find(self, obj):
|
2007-01-31 07:35:01 +05:30
|
|
|
self.options.handler.options_dict['events'] = \
|
|
|
|
int(self.events_box.get_active())
|
|
|
|
self.options.handler.options_dict['sources'] = \
|
|
|
|
int(self.sources_box.get_active())
|
|
|
|
self.options.handler.options_dict['places'] = \
|
|
|
|
int(self.places_box.get_active())
|
|
|
|
self.options.handler.options_dict['media'] = \
|
|
|
|
int(self.media_box.get_active())
|
|
|
|
self.options.handler.options_dict['repos'] = \
|
|
|
|
int(self.repos_box.get_active())
|
2008-04-22 02:22:39 +05:30
|
|
|
self.options.handler.options_dict['notes'] = \
|
|
|
|
int(self.notes_box.get_active())
|
2007-01-31 07:35:01 +05:30
|
|
|
|
2007-06-24 06:56:48 +05:30
|
|
|
for item in self.sensitive_list:
|
|
|
|
item.set_sensitive(True)
|
2007-01-31 07:35:01 +05:30
|
|
|
|
|
|
|
self.uistate.window.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH))
|
|
|
|
self.uistate.progress.show()
|
|
|
|
self.window.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH))
|
|
|
|
|
2007-06-24 06:56:48 +05:30
|
|
|
self.real_model.clear()
|
2007-01-31 07:35:01 +05:30
|
|
|
self.collect_unused()
|
|
|
|
|
|
|
|
self.uistate.progress.hide()
|
|
|
|
self.uistate.window.window.set_cursor(None)
|
|
|
|
self.window.window.set_cursor(None)
|
|
|
|
self.reset()
|
|
|
|
|
|
|
|
# Save options
|
|
|
|
self.options.handler.save_options()
|
2006-11-06 08:21:09 +05:30
|
|
|
|
2007-01-31 07:35:01 +05:30
|
|
|
def collect_unused(self):
|
|
|
|
# Run through all requested tables and check all objects
|
|
|
|
# for being referenced some place. If not, add_results on them.
|
|
|
|
|
|
|
|
tables = {
|
|
|
|
'events' : {'cursor_func': self.db.get_event_cursor,
|
|
|
|
'total_func' : self.db.get_number_of_events},
|
|
|
|
'sources' : {'cursor_func': self.db.get_source_cursor,
|
|
|
|
'total_func' : self.db.get_number_of_sources},
|
|
|
|
'places' : {'cursor_func': self.db.get_place_cursor,
|
|
|
|
'total_func' : self.db.get_number_of_places},
|
|
|
|
'media' : {'cursor_func': self.db.get_media_cursor,
|
|
|
|
'total_func' : self.db.get_number_of_media_objects},
|
|
|
|
'repos' : {'cursor_func': self.db.get_repository_cursor,
|
|
|
|
'total_func' : self.db.get_number_of_repositories},
|
2008-04-22 02:22:39 +05:30
|
|
|
'notes' : {'cursor_func': self.db.get_note_cursor,
|
|
|
|
'total_func' : self.db.get_number_of_notes},
|
2007-01-31 07:35:01 +05:30
|
|
|
}
|
|
|
|
|
2009-04-10 01:23:38 +05:30
|
|
|
for the_type, the_func in tables.iteritems():
|
2007-01-31 07:35:01 +05:30
|
|
|
if not self.options.handler.options_dict[the_type]:
|
|
|
|
# This table was not requested. Skip it.
|
|
|
|
continue
|
|
|
|
|
2009-06-16 21:19:17 +05:30
|
|
|
with the_func['cursor_func']() as cursor:
|
|
|
|
total = the_func['total_func']()
|
|
|
|
self.set_total(total)
|
|
|
|
fbh = self.db.find_backlink_handles
|
|
|
|
for handle, data in cursor:
|
|
|
|
if not any(h for h in fbh(handle)):
|
|
|
|
self.add_results((the_type, handle, data))
|
|
|
|
self.update()
|
2007-01-31 07:35:01 +05:30
|
|
|
self.reset()
|
2006-11-06 08:21:09 +05:30
|
|
|
|
2008-02-24 19:25:55 +05:30
|
|
|
def do_remove(self, obj):
|
2009-08-11 02:53:38 +05:30
|
|
|
trans = self.db.transaction_begin("", batch=False)
|
2007-01-31 07:35:01 +05:30
|
|
|
self.db.disable_signals()
|
|
|
|
|
2009-08-11 02:53:38 +05:30
|
|
|
for row_num in range(len(self.real_model)-1, -1, -1):
|
2007-01-31 07:35:01 +05:30
|
|
|
path = (row_num,)
|
|
|
|
row = self.real_model[path]
|
2007-06-24 06:56:48 +05:30
|
|
|
if not row[RemoveUnused.MARK_COL]:
|
2007-01-31 07:35:01 +05:30
|
|
|
continue
|
|
|
|
|
2007-06-24 06:56:48 +05:30
|
|
|
the_type = row[RemoveUnused.OBJ_TYPE_COL]
|
|
|
|
handle = row[RemoveUnused.OBJ_HANDLE_COL]
|
2007-01-31 07:35:01 +05:30
|
|
|
remove_func = self.tables[the_type]['remove']
|
|
|
|
remove_func(handle, trans)
|
|
|
|
|
2007-06-24 06:56:48 +05:30
|
|
|
self.real_model.remove(row.iter)
|
2007-01-31 07:35:01 +05:30
|
|
|
|
|
|
|
self.db.transaction_commit(trans, _("Remove unused objects"))
|
|
|
|
self.db.enable_signals()
|
2007-06-24 06:56:48 +05:30
|
|
|
self.db.request_rebuild()
|
2007-01-31 07:35:01 +05:30
|
|
|
|
2009-08-11 02:53:38 +05:30
|
|
|
def selection_toggled(self, cell, path_string):
|
2007-01-31 07:35:01 +05:30
|
|
|
sort_path = tuple([int (i) for i in path_string.split(':')])
|
|
|
|
real_path = self.sort_model.convert_path_to_child_path(sort_path)
|
|
|
|
row = self.real_model[real_path]
|
2007-06-24 06:56:48 +05:30
|
|
|
row[RemoveUnused.MARK_COL] = not row[RemoveUnused.MARK_COL]
|
2009-08-11 02:53:38 +05:30
|
|
|
self.real_model.row_changed(real_path, row.iter)
|
2007-01-31 07:35:01 +05:30
|
|
|
|
2009-08-11 02:53:38 +05:30
|
|
|
def mark_clicked(self, mark_button):
|
2007-01-31 07:35:01 +05:30
|
|
|
for row_num in range(len(self.real_model)):
|
|
|
|
path = (row_num,)
|
|
|
|
row = self.real_model[path]
|
2007-06-24 06:56:48 +05:30
|
|
|
row[RemoveUnused.MARK_COL] = True
|
2007-01-31 07:35:01 +05:30
|
|
|
|
2009-08-11 02:53:38 +05:30
|
|
|
def unmark_clicked(self, unmark_button):
|
2007-01-31 07:35:01 +05:30
|
|
|
for row_num in range(len(self.real_model)):
|
|
|
|
path = (row_num,)
|
|
|
|
row = self.real_model[path]
|
2007-06-24 06:56:48 +05:30
|
|
|
row[RemoveUnused.MARK_COL] = False
|
2007-01-31 07:35:01 +05:30
|
|
|
|
2009-08-11 02:53:38 +05:30
|
|
|
def invert_clicked(self, invert_button):
|
2007-01-31 07:35:01 +05:30
|
|
|
for row_num in range(len(self.real_model)):
|
|
|
|
path = (row_num,)
|
|
|
|
row = self.real_model[path]
|
2007-06-24 06:56:48 +05:30
|
|
|
row[RemoveUnused.MARK_COL] = not row[RemoveUnused.MARK_COL]
|
2007-01-31 07:35:01 +05:30
|
|
|
|
2009-08-11 02:53:38 +05:30
|
|
|
def double_click(self, obj, event):
|
2007-01-31 07:35:01 +05:30
|
|
|
if event.type == gtk.gdk._2BUTTON_PRESS and event.button == 1:
|
2008-02-24 19:25:55 +05:30
|
|
|
(model, node) = self.selection.get_selected()
|
2007-01-31 07:35:01 +05:30
|
|
|
if not node:
|
|
|
|
return
|
|
|
|
sort_path = self.sort_model.get_path(node)
|
|
|
|
real_path = self.sort_model.convert_path_to_child_path(sort_path)
|
|
|
|
row = self.real_model[real_path]
|
2007-06-24 06:56:48 +05:30
|
|
|
the_type = row[RemoveUnused.OBJ_TYPE_COL]
|
|
|
|
handle = row[RemoveUnused.OBJ_HANDLE_COL]
|
2008-02-24 19:25:55 +05:30
|
|
|
self.call_editor(the_type, handle)
|
2007-01-31 07:35:01 +05:30
|
|
|
|
2009-08-11 02:53:38 +05:30
|
|
|
def call_editor(self, the_type, handle):
|
2007-01-31 07:35:01 +05:30
|
|
|
try:
|
|
|
|
obj = self.tables[the_type]['get_func'](handle)
|
2009-12-15 11:26:12 +05:30
|
|
|
editor_str = 'from gui.editors import %s as editor' \
|
2007-01-31 07:35:01 +05:30
|
|
|
% self.tables[the_type]['editor']
|
|
|
|
exec(editor_str)
|
|
|
|
editor(self.dbstate, self.uistate, [], obj)
|
|
|
|
except Errors.WindowActiveError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
def get_image(self, column, cell, model, iter, user_data=None):
|
2007-06-24 06:56:48 +05:30
|
|
|
the_type = model.get_value(iter, RemoveUnused.OBJ_TYPE_COL)
|
2007-01-31 07:35:01 +05:30
|
|
|
the_stock = self.tables[the_type]['stock']
|
|
|
|
cell.set_property('stock-id', the_stock)
|
|
|
|
|
2008-06-24 23:21:55 +05:30
|
|
|
def add_results(self, results):
|
|
|
|
(the_type, handle, data) = results
|
2007-01-31 07:35:01 +05:30
|
|
|
gramps_id = data[1]
|
2008-06-24 23:21:55 +05:30
|
|
|
|
|
|
|
# if we have a function that will return to us some type
|
|
|
|
# of text summary, then we should use it; otherwise we'll
|
|
|
|
# use the generic field index provided in the tables above
|
|
|
|
if self.tables[the_type]['get_text']:
|
|
|
|
text = self.tables[the_type]['get_text'](the_type, handle, data)
|
2008-04-22 02:22:39 +05:30
|
|
|
else:
|
2008-06-24 23:21:55 +05:30
|
|
|
# grab the text field index we know about, and hope
|
|
|
|
# it represents something useful to the user
|
|
|
|
name_ix = self.tables[the_type]['name_ix']
|
|
|
|
text = data[name_ix]
|
|
|
|
|
|
|
|
# insert a new row into the table
|
|
|
|
self.real_model.append(row=[False, gramps_id, text, the_type, handle])
|
|
|
|
|
|
|
|
def get_event_text(self, the_type, handle, data):
|
|
|
|
"""
|
|
|
|
Come up with a short line of text that we can use as
|
|
|
|
a summary to represent this event.
|
|
|
|
"""
|
|
|
|
|
|
|
|
# get the event:
|
|
|
|
event = self.tables[the_type]['get_func'](handle)
|
|
|
|
|
|
|
|
# first check to see if the event has a descriptive name
|
|
|
|
text = event.get_description() # (this is rarely set for events)
|
|
|
|
|
|
|
|
# if we don't have a description...
|
|
|
|
if text == '':
|
|
|
|
# ... then we merge together several fields
|
|
|
|
|
|
|
|
# get the event type (marriage, birth, death, etc.)
|
|
|
|
text = str(event.get_type())
|
|
|
|
|
|
|
|
# see if there is a date
|
|
|
|
date = _dd.display(event.get_date_object())
|
|
|
|
if date != '':
|
|
|
|
text += '; %s' % date
|
|
|
|
|
|
|
|
# see if there is a place
|
|
|
|
place_handle = event.get_place_handle()
|
|
|
|
if place_handle:
|
|
|
|
place = self.db.get_place_from_handle(place_handle)
|
|
|
|
text += '; %s' % place.get_title()
|
|
|
|
|
|
|
|
return text
|
2007-01-31 07:35:01 +05:30
|
|
|
|
2008-06-24 23:21:55 +05:30
|
|
|
def get_note_text(self, the_type, handle, data):
|
|
|
|
"""
|
|
|
|
We need just the first few words of a note as a summary.
|
|
|
|
"""
|
|
|
|
# get the note object
|
|
|
|
note = self.tables[the_type]['get_func'](handle)
|
|
|
|
|
|
|
|
# get the note text; this ignores (discards) formatting
|
|
|
|
text = note.get()
|
|
|
|
|
|
|
|
# convert whitespace to a single space
|
|
|
|
text = " ".join(text.split())
|
|
|
|
|
|
|
|
# if the note is too long, truncate it
|
2009-09-08 01:37:05 +05:30
|
|
|
# but first set type of text to unicode, otherwise the sliceing might go wrong.
|
|
|
|
text = unicode(text)
|
2008-06-24 23:21:55 +05:30
|
|
|
if len(text) > 80:
|
|
|
|
text = text[:80] + "..."
|
|
|
|
|
|
|
|
return text
|
|
|
|
|
2006-11-06 08:21:09 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
class CheckOptions(Tool.ToolOptions):
|
|
|
|
"""
|
|
|
|
Defines options and provides handling interface.
|
|
|
|
"""
|
|
|
|
|
2009-08-11 02:53:38 +05:30
|
|
|
def __init__(self, name, person_id=None):
|
|
|
|
Tool.ToolOptions.__init__(self, name, person_id)
|
2006-11-06 08:21:09 +05:30
|
|
|
|
2007-01-31 07:35:01 +05:30
|
|
|
# Options specific for this report
|
|
|
|
self.options_dict = {
|
|
|
|
'events' : 1,
|
|
|
|
'sources' : 1,
|
|
|
|
'places' : 1,
|
|
|
|
'media' : 1,
|
|
|
|
'repos' : 1,
|
2008-04-22 02:22:39 +05:30
|
|
|
'notes' : 1,
|
2007-01-31 07:35:01 +05:30
|
|
|
}
|
|
|
|
self.options_help = {
|
|
|
|
'events' : ("=0/1","Whether to use check for unused events",
|
|
|
|
["Do not check events","Check events"],
|
|
|
|
True),
|
|
|
|
'sources' : ("=0/1","Whether to use check for unused sources",
|
|
|
|
["Do not check sources","Check sources"],
|
|
|
|
True),
|
|
|
|
'places' : ("=0/1","Whether to use check for unused places",
|
|
|
|
["Do not check places","Check places"],
|
|
|
|
True),
|
|
|
|
'media' : ("=0/1","Whether to use check for unused media",
|
|
|
|
["Do not check media","Check media"],
|
|
|
|
True),
|
|
|
|
'repos' : ("=0/1","Whether to use check for unused repositories",
|
|
|
|
["Do not check repositories","Check repositories"],
|
|
|
|
True),
|
2008-04-22 02:22:39 +05:30
|
|
|
'notes' : ("=0/1","Whether to use check for unused notes",
|
|
|
|
["Do not check notes","Check notes"],
|
|
|
|
True),
|
2007-01-31 07:35:01 +05:30
|
|
|
}
|