2007-02-13 23:26:31 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2008-03-29 04:52:46 +05:30
|
|
|
# Copyright (C) 2000-2007 Donald N. Allingham
|
2010-10-23 04:52:33 +05:30
|
|
|
# Copyright (C) 2010 Nick Hall
|
2007-02-13 23:26:31 +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-03-28 03:17:18 +05:30
|
|
|
# $Id$
|
2007-02-13 23:26:31 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# python modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import logging
|
2009-11-08 22:11:49 +05:30
|
|
|
_LOG = logging.getLogger(".gui.notemodel")
|
2010-10-23 04:52:33 +05:30
|
|
|
import locale
|
2007-02-13 23:26:31 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GNOME/GTK modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import gtk
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2010-05-20 23:17:31 +05:30
|
|
|
import Utils
|
2009-06-29 02:45:10 +05:30
|
|
|
from gui.views.treemodels.flatbasemodel import FlatBaseModel
|
2010-10-23 04:52:33 +05:30
|
|
|
from gen.lib import (Note, NoteType, StyledText)
|
2007-02-13 23:26:31 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
2008-03-29 04:52:46 +05:30
|
|
|
# NoteModel
|
2007-02-13 23:26:31 +05:30
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2009-06-29 02:45:10 +05:30
|
|
|
class NoteModel(FlatBaseModel):
|
2008-03-29 04:52:46 +05:30
|
|
|
"""
|
|
|
|
"""
|
|
|
|
def __init__(self, db, scol=0, order=gtk.SORT_ASCENDING, search=None,
|
2007-02-13 23:26:31 +05:30
|
|
|
skip=set(), sort_map=None):
|
2008-03-29 04:52:46 +05:30
|
|
|
"""Setup initial values for instance variables."""
|
2007-02-20 10:05:34 +05:30
|
|
|
self.gen_cursor = db.get_note_cursor
|
|
|
|
self.map = db.get_raw_note_data
|
2007-02-13 23:26:31 +05:30
|
|
|
self.fmap = [
|
2008-01-10 02:45:28 +05:30
|
|
|
self.column_preview,
|
2007-02-13 23:26:31 +05:30
|
|
|
self.column_id,
|
2007-02-20 10:05:34 +05:30
|
|
|
self.column_type,
|
2010-10-23 04:52:33 +05:30
|
|
|
self.column_tags,
|
2010-02-01 12:31:45 +05:30
|
|
|
self.column_change,
|
2007-02-13 23:26:31 +05:30
|
|
|
self.column_handle,
|
2010-10-23 04:52:33 +05:30
|
|
|
self.column_tag_color
|
2008-03-29 04:52:46 +05:30
|
|
|
]
|
2007-02-13 23:26:31 +05:30
|
|
|
self.smap = [
|
2008-01-10 02:45:28 +05:30
|
|
|
self.column_preview,
|
2007-02-13 23:26:31 +05:30
|
|
|
self.column_id,
|
2007-02-20 10:05:34 +05:30
|
|
|
self.column_type,
|
2010-10-23 04:52:33 +05:30
|
|
|
self.column_tags,
|
2010-02-01 20:44:17 +05:30
|
|
|
self.sort_change,
|
2007-02-13 23:26:31 +05:30
|
|
|
self.column_handle,
|
2010-10-23 04:52:33 +05:30
|
|
|
self.column_tag_color
|
2008-03-29 04:52:46 +05:30
|
|
|
]
|
2009-06-29 02:45:10 +05:30
|
|
|
FlatBaseModel.__init__(self, db, scol, order, search=search,
|
2008-03-29 04:52:46 +05:30
|
|
|
skip=skip, sort_map=sort_map)
|
2007-02-13 23:26:31 +05:30
|
|
|
|
2010-10-31 13:03:17 +05:30
|
|
|
def destroy(self):
|
|
|
|
"""
|
|
|
|
Unset all elements that can prevent garbage collection
|
|
|
|
"""
|
|
|
|
self.db = None
|
|
|
|
self.gen_cursor = None
|
|
|
|
self.map = None
|
|
|
|
self.fmap = None
|
|
|
|
self.smap = None
|
|
|
|
FlatBaseModel.destroy(self)
|
|
|
|
|
2010-10-23 04:52:33 +05:30
|
|
|
def color_column(self):
|
2010-07-03 20:34:36 +05:30
|
|
|
"""
|
2010-10-23 04:52:33 +05:30
|
|
|
Return the color column.
|
2010-07-03 20:34:36 +05:30
|
|
|
"""
|
|
|
|
return 6
|
|
|
|
|
2007-02-13 23:26:31 +05:30
|
|
|
def on_get_n_columns(self):
|
2008-03-29 04:52:46 +05:30
|
|
|
"""Return the column number of the Note tab."""
|
|
|
|
return len(self.fmap) + 1
|
2007-02-13 23:26:31 +05:30
|
|
|
|
2008-03-29 04:52:46 +05:30
|
|
|
def column_handle(self, data):
|
|
|
|
"""Return the handle of the Note."""
|
|
|
|
return data[Note.POS_HANDLE]
|
2007-02-13 23:26:31 +05:30
|
|
|
|
2008-03-29 04:52:46 +05:30
|
|
|
def column_id(self, data):
|
|
|
|
"""Return the id of the Note."""
|
|
|
|
return unicode(data[Note.POS_ID])
|
2007-02-13 23:26:31 +05:30
|
|
|
|
2008-03-29 04:52:46 +05:30
|
|
|
def column_type(self, data):
|
|
|
|
"""Return the type of the Note in readable format."""
|
|
|
|
temp = NoteType()
|
|
|
|
temp.set(data[Note.POS_TYPE])
|
2007-02-20 10:05:34 +05:30
|
|
|
return unicode(str(temp))
|
2007-02-13 23:26:31 +05:30
|
|
|
|
2008-03-29 04:52:46 +05:30
|
|
|
def column_preview(self, data):
|
|
|
|
"""Return a shortend version of the Note's text."""
|
2008-02-14 14:28:37 +05:30
|
|
|
#data is the encoding in the database, make it a unicode object
|
|
|
|
#for universal work
|
2008-03-29 04:52:46 +05:30
|
|
|
note = unicode(data[Note.POS_TEXT][StyledText.POS_TEXT])
|
|
|
|
note = " ".join(note.split())
|
2007-02-20 10:05:34 +05:30
|
|
|
if len(note) > 80:
|
2008-03-29 04:52:46 +05:30
|
|
|
return note[:80] + "..."
|
2007-02-20 10:05:34 +05:30
|
|
|
else:
|
|
|
|
return note
|
2007-02-13 23:26:31 +05:30
|
|
|
|
2010-02-01 20:44:17 +05:30
|
|
|
def sort_change(self, data):
|
2010-02-02 01:18:09 +05:30
|
|
|
return "%012x" % data[Note.POS_CHANGE]
|
2010-02-01 20:44:17 +05:30
|
|
|
|
2010-02-01 12:31:45 +05:30
|
|
|
def column_change(self,data):
|
2010-05-20 23:17:31 +05:30
|
|
|
return Utils.format_time(data[Note.POS_CHANGE])
|
2010-10-23 04:52:33 +05:30
|
|
|
|
|
|
|
def get_tag_name(self, tag_handle):
|
|
|
|
"""
|
|
|
|
Return the tag name from the given tag handle.
|
|
|
|
"""
|
|
|
|
return self.db.get_tag_from_handle(tag_handle).get_name()
|
|
|
|
|
|
|
|
def column_tag_color(self, data):
|
|
|
|
"""
|
|
|
|
Return the tag color.
|
|
|
|
"""
|
2011-03-17 00:03:09 +05:30
|
|
|
tag_color = None
|
2010-10-23 04:52:33 +05:30
|
|
|
tag_priority = None
|
|
|
|
for handle in data[Note.POS_TAGS]:
|
|
|
|
tag = self.db.get_tag_from_handle(handle)
|
|
|
|
this_priority = tag.get_priority()
|
|
|
|
if tag_priority is None or this_priority < tag_priority:
|
|
|
|
tag_color = tag.get_color()
|
|
|
|
tag_priority = this_priority
|
|
|
|
return tag_color
|
|
|
|
|
|
|
|
def column_tags(self, data):
|
|
|
|
"""
|
|
|
|
Return the sorted list of tags.
|
|
|
|
"""
|
|
|
|
tag_list = map(self.get_tag_name, data[Note.POS_TAGS])
|
|
|
|
return ', '.join(sorted(tag_list, key=locale.strxfrm))
|