2007-02-13 17:56:31 +00:00
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2008-03-28 23:22:46 +00:00
|
|
|
# Copyright (C) 2000-2007 Donald N. Allingham
|
2010-10-22 23:22:33 +00:00
|
|
|
# Copyright (C) 2010 Nick Hall
|
2007-02-13 17:56:31 +00:00
|
|
|
#
|
|
|
|
# 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-27 21:47:18 +00:00
|
|
|
# $Id$
|
2007-02-13 17:56:31 +00:00
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# python modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import logging
|
2009-11-08 16:41:49 +00:00
|
|
|
_LOG = logging.getLogger(".gui.notemodel")
|
2010-10-22 23:22:33 +00:00
|
|
|
import locale
|
2007-02-13 17:56:31 +00:00
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GNOME/GTK modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2012-06-17 21:25:37 +00:00
|
|
|
from gi.repository import Gtk
|
2007-02-13 17:56:31 +00:00
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2012-10-02 19:34:37 +00:00
|
|
|
from gramps.gen.datehandler import format_time
|
2012-11-07 17:53:14 +00:00
|
|
|
from gramps.gen.constfunc import cuni
|
2012-10-03 15:55:24 +00:00
|
|
|
from .flatbasemodel import FlatBaseModel
|
2012-10-02 21:08:19 +00:00
|
|
|
from gramps.gen.lib import (Note, NoteType, StyledText)
|
2007-02-13 17:56:31 +00:00
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
2008-03-28 23:22:46 +00:00
|
|
|
# NoteModel
|
2007-02-13 17:56:31 +00:00
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2009-06-28 21:15:10 +00:00
|
|
|
class NoteModel(FlatBaseModel):
|
2008-03-28 23:22:46 +00:00
|
|
|
"""
|
|
|
|
"""
|
2012-06-17 21:25:37 +00:00
|
|
|
def __init__(self, db, scol=0, order=Gtk.SortType.ASCENDING, search=None,
|
2007-02-13 17:56:31 +00:00
|
|
|
skip=set(), sort_map=None):
|
2008-03-28 23:22:46 +00:00
|
|
|
"""Setup initial values for instance variables."""
|
2007-02-20 04:35:34 +00:00
|
|
|
self.gen_cursor = db.get_note_cursor
|
|
|
|
self.map = db.get_raw_note_data
|
2007-02-13 17:56:31 +00:00
|
|
|
self.fmap = [
|
2008-01-09 21:15:28 +00:00
|
|
|
self.column_preview,
|
2007-02-13 17:56:31 +00:00
|
|
|
self.column_id,
|
2007-02-20 04:35:34 +00:00
|
|
|
self.column_type,
|
2013-01-14 16:49:52 +00:00
|
|
|
self.column_private,
|
2010-10-22 23:22:33 +00:00
|
|
|
self.column_tags,
|
2010-02-01 07:01:45 +00:00
|
|
|
self.column_change,
|
2010-10-22 23:22:33 +00:00
|
|
|
self.column_tag_color
|
2008-03-28 23:22:46 +00:00
|
|
|
]
|
2007-02-13 17:56:31 +00:00
|
|
|
self.smap = [
|
2008-01-09 21:15:28 +00:00
|
|
|
self.column_preview,
|
2007-02-13 17:56:31 +00:00
|
|
|
self.column_id,
|
2007-02-20 04:35:34 +00:00
|
|
|
self.column_type,
|
2013-01-14 16:49:52 +00:00
|
|
|
self.column_private,
|
2010-10-22 23:22:33 +00:00
|
|
|
self.column_tags,
|
2010-02-01 15:14:17 +00:00
|
|
|
self.sort_change,
|
2010-10-22 23:22:33 +00:00
|
|
|
self.column_tag_color
|
2008-03-28 23:22:46 +00:00
|
|
|
]
|
2013-01-17 21:58:53 +00:00
|
|
|
FlatBaseModel.__init__(self, db, scol, order, search=search, skip=skip,
|
|
|
|
sort_map=sort_map)
|
2007-02-13 17:56:31 +00:00
|
|
|
|
2010-10-31 07:33:17 +00:00
|
|
|
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-22 23:22:33 +00:00
|
|
|
def color_column(self):
|
2010-07-03 15:04:36 +00:00
|
|
|
"""
|
2010-10-22 23:22:33 +00:00
|
|
|
Return the color column.
|
2010-07-03 15:04:36 +00:00
|
|
|
"""
|
2013-01-17 21:58:53 +00:00
|
|
|
return 6
|
2010-07-03 15:04:36 +00:00
|
|
|
|
2012-06-17 21:25:37 +00:00
|
|
|
def do_get_n_columns(self):
|
2008-03-28 23:22:46 +00:00
|
|
|
"""Return the column number of the Note tab."""
|
|
|
|
return len(self.fmap) + 1
|
2007-02-13 17:56:31 +00:00
|
|
|
|
2008-03-28 23:22:46 +00:00
|
|
|
def column_id(self, data):
|
|
|
|
"""Return the id of the Note."""
|
2012-11-07 17:53:14 +00:00
|
|
|
return cuni(data[Note.POS_ID])
|
2007-02-13 17:56:31 +00:00
|
|
|
|
2008-03-28 23:22:46 +00:00
|
|
|
def column_type(self, data):
|
|
|
|
"""Return the type of the Note in readable format."""
|
|
|
|
temp = NoteType()
|
|
|
|
temp.set(data[Note.POS_TYPE])
|
2012-11-07 17:53:14 +00:00
|
|
|
return cuni(str(temp))
|
2007-02-13 17:56:31 +00:00
|
|
|
|
2008-03-28 23:22:46 +00:00
|
|
|
def column_preview(self, data):
|
|
|
|
"""Return a shortend version of the Note's text."""
|
2008-02-14 08:58:37 +00:00
|
|
|
#data is the encoding in the database, make it a unicode object
|
|
|
|
#for universal work
|
2012-11-07 17:53:14 +00:00
|
|
|
note = cuni(data[Note.POS_TEXT][StyledText.POS_TEXT])
|
2008-03-28 23:22:46 +00:00
|
|
|
note = " ".join(note.split())
|
2007-02-20 04:35:34 +00:00
|
|
|
if len(note) > 80:
|
2008-03-28 23:22:46 +00:00
|
|
|
return note[:80] + "..."
|
2007-02-20 04:35:34 +00:00
|
|
|
else:
|
|
|
|
return note
|
2007-02-13 17:56:31 +00:00
|
|
|
|
2013-01-14 16:49:52 +00:00
|
|
|
def column_private(self, data):
|
|
|
|
if data[Note.POS_PRIVATE]:
|
|
|
|
return 'gramps-lock'
|
|
|
|
else:
|
|
|
|
# There is a problem returning None here.
|
|
|
|
return ''
|
|
|
|
|
2010-02-01 15:14:17 +00:00
|
|
|
def sort_change(self, data):
|
2010-02-01 19:48:09 +00:00
|
|
|
return "%012x" % data[Note.POS_CHANGE]
|
2010-02-01 15:14:17 +00:00
|
|
|
|
2010-02-01 07:01:45 +00:00
|
|
|
def column_change(self,data):
|
2012-10-02 19:34:37 +00:00
|
|
|
return format_time(data[Note.POS_CHANGE])
|
2010-10-22 23:22:33 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
"""
|
2012-06-17 21:25:37 +00:00
|
|
|
tag_color = "#000000000000"
|
2010-10-22 23:22:33 +00:00
|
|
|
tag_priority = None
|
|
|
|
for handle in data[Note.POS_TAGS]:
|
|
|
|
tag = self.db.get_tag_from_handle(handle)
|
2013-01-03 15:09:39 +00:00
|
|
|
if tag:
|
|
|
|
this_priority = tag.get_priority()
|
|
|
|
if tag_priority is None or this_priority < tag_priority:
|
|
|
|
tag_color = tag.get_color()
|
|
|
|
tag_priority = this_priority
|
2010-10-22 23:22:33 +00:00
|
|
|
return tag_color
|
|
|
|
|
|
|
|
def column_tags(self, data):
|
|
|
|
"""
|
|
|
|
Return the sorted list of tags.
|
|
|
|
"""
|
2012-11-07 17:53:14 +00:00
|
|
|
tag_list = list(map(self.get_tag_name, data[Note.POS_TAGS]))
|
2010-10-22 23:22:33 +00:00
|
|
|
return ', '.join(sorted(tag_list, key=locale.strxfrm))
|