~ubuntu-branches/ubuntu/utopic/gramps/utopic

« back to all changes in this revision

Viewing changes to src/gen/lib/srcref.py

  • Committer: Package Import Robot
  • Author(s): James A. Treacy
  • Date: 2012-05-22 17:18:36 UTC
  • mfrom: (39.1.4 sid)
  • Revision ID: package-import@ubuntu.com-20120522171836-35fi62lp4w7jnrd7
Tags: 3.4.0-1
* New upstream version
* Updated desktop file. Closes: #667472

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#
2
 
# Gramps - a GTK+/GNOME based genealogy program
3
 
#
4
 
# Copyright (C) 2000-2007  Donald N. Allingham
5
 
# Copyright (C) 2010       Michiel D. Nauta
6
 
#
7
 
# This program is free software; you can redistribute it and/or modify
8
 
# it under the terms of the GNU General Public License as published by
9
 
# the Free Software Foundation; either version 2 of the License, or
10
 
# (at your option) any later version.
11
 
#
12
 
# This program is distributed in the hope that it will be useful,
13
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 
# GNU General Public License for more details.
16
 
#
17
 
# You should have received a copy of the GNU General Public License
18
 
# along with this program; if not, write to the Free Software
19
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20
 
#
21
 
 
22
 
# $Id: srcref.py 15645 2010-07-22 02:16:32Z dsblank $
23
 
 
24
 
"""
25
 
Source Reference class for GRAMPS.
26
 
"""
27
 
 
28
 
#-------------------------------------------------------------------------
29
 
#
30
 
# Python modules
31
 
#
32
 
#-------------------------------------------------------------------------
33
 
from warnings import warn
34
 
 
35
 
#-------------------------------------------------------------------------
36
 
#
37
 
# GRAMPS modules
38
 
#
39
 
#-------------------------------------------------------------------------
40
 
from gen.lib.secondaryobj import SecondaryObject
41
 
from gen.lib.datebase import DateBase
42
 
from gen.lib.privacybase import PrivacyBase
43
 
from gen.lib.notebase import NoteBase
44
 
from gen.lib.refbase import RefBase
45
 
from gen.lib.const import IDENTICAL, EQUAL, DIFFERENT
46
 
 
47
 
#-------------------------------------------------------------------------
48
 
#
49
 
# Source References for all primary objects
50
 
#
51
 
#-------------------------------------------------------------------------
52
 
class SourceRef(SecondaryObject, DateBase, PrivacyBase, NoteBase, RefBase):
53
 
    """
54
 
    Source reference, containing detailed information about how a referenced 
55
 
    source relates to it.
56
 
    """
57
 
    
58
 
    CONF_VERY_HIGH = 4
59
 
    CONF_HIGH      = 3
60
 
    CONF_NORMAL    = 2
61
 
    CONF_LOW       = 1
62
 
    CONF_VERY_LOW  = 0
63
 
 
64
 
    def __init__(self, source=None):
65
 
        """Create a new SourceRef, copying from the source if present."""
66
 
        DateBase.__init__(self, source)
67
 
        PrivacyBase.__init__(self, source)
68
 
        NoteBase.__init__(self, source)
69
 
        RefBase.__init__(self, source)
70
 
        if source:
71
 
            self.confidence = source.confidence
72
 
            self.page = source.page
73
 
        else:
74
 
            self.confidence = SourceRef.CONF_NORMAL
75
 
            self.page = ""
76
 
 
77
 
    def serialize(self):
78
 
        """
79
 
        Convert the object to a serialized tuple of data.
80
 
        """
81
 
        return (DateBase.serialize(self),
82
 
                PrivacyBase.serialize(self),
83
 
                NoteBase.serialize(self),
84
 
                self.confidence,
85
 
                RefBase.serialize(self),
86
 
                self.page)
87
 
 
88
 
    def unserialize(self, data):
89
 
        """
90
 
        Convert a serialized tuple of data to an object.
91
 
        """
92
 
        (date, privacy, note_list,
93
 
         self.confidence, ref, self.page) = data
94
 
        DateBase.unserialize(self, date)
95
 
        PrivacyBase.unserialize(self, privacy)
96
 
        NoteBase.unserialize(self, note_list)
97
 
        RefBase.unserialize(self, ref)
98
 
        return self
99
 
 
100
 
    def get_text_data_list(self):
101
 
        """
102
 
        Return the list of all textual attributes of the object.
103
 
 
104
 
        :returns: Returns the list of all textual attributes of the object.
105
 
        :rtype: list
106
 
        """
107
 
        return [self.page]
108
 
 
109
 
    def get_referenced_handles(self):
110
 
        """
111
 
        Return the list of (classname, handle) tuples for all directly
112
 
        referenced primary objects.
113
 
        
114
 
        :returns: List of (classname, handle) tuples for referenced objects.
115
 
        :rtype: list
116
 
        """
117
 
        ret = self.get_referenced_note_handles()
118
 
        if self.ref:
119
 
            ret += [('Source', self.ref)]
120
 
        return ret
121
 
 
122
 
    def is_equivalent(self, other):
123
 
        """
124
 
        Return if this source reference is equivalent, that is agreees in
125
 
        reference, source page and date, to other.
126
 
 
127
 
        :param other: The source reference to compare this one to.
128
 
        :rtype other: SourceRef
129
 
        ;returns: Constant indicating degree of equivalence.
130
 
        :rtype: int
131
 
        """
132
 
        if self.ref != other.ref or \
133
 
            self.page != other.page or \
134
 
            self.get_date_object() != other.get_date_object():
135
 
            return DIFFERENT
136
 
        else:
137
 
            if self.is_equal(other):
138
 
                return IDENTICAL
139
 
            else:
140
 
                return EQUAL
141
 
 
142
 
    def merge(self, acquisition):
143
 
        """
144
 
        Merge the content of acquisition into this source reference.
145
 
 
146
 
        :param acquisition: The source reference to merge with the present one.
147
 
        :rtype acquisition: SourceRef
148
 
        """
149
 
        self._merge_privacy(acquisition)
150
 
        self._merge_note_list(acquisition)
151
 
        # merge confidence
152
 
        level_priority = [0, 4, 1, 3, 2]
153
 
        idx = min(level_priority.index(self.confidence),
154
 
                  level_priority.index(acquisition.confidence))
155
 
        self.confidence = level_priority[idx]
156
 
 
157
 
    def set_confidence_level(self, val):
158
 
        """Set the confidence level."""
159
 
        self.confidence = val
160
 
 
161
 
    def get_confidence_level(self):
162
 
        """Return the confidence level."""
163
 
        return self.confidence
164
 
        
165
 
    def set_page(self, page):
166
 
        """Set the page indicator of the SourceRef."""
167
 
        self.page = page
168
 
 
169
 
    def get_page(self):
170
 
        """Get the page indicator of the SourceRef."""
171
 
        return self.page
172
 
 
173
 
    def are_equal(self, other):
174
 
        """Deprecated function - use is_equal instead."""
175
 
        warn( "Use is_equal instead of are_equal", DeprecationWarning, 2)
176
 
        return self.is_equal(other)