Updated TODO.
[straw.git] / straw / SummaryItem.py
blob376f98392cb352dbab7c5cb0611fc58b83e4b7ca
1 """ SummaryItem.py
3 """
4 __copyright__ = "Copyright (c) 2002-2005 Free Software Foundation, Inc."
5 __license__ = """
6 Straw is free software; you can redistribute it and/or modify it under the
7 terms of the GNU General Public License as published by the Free Software
8 Foundation; either version 2 of the License, or (at your option) any later
9 version.
11 Straw is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
17 Place - Suite 330, Boston, MA 02111-1307, USA. """
19 import gobject
20 import time
21 import locale
23 class SummaryItem(gobject.GObject):
24 __slots__ = ('title', 'link', 'description', 'guid', 'pub_date', 'source',
25 '_images', '_seen', '_id', 'feed', '_slots',
26 'fm_license', 'fm_changes', 'creator', 'license_urls',
27 '_searchable_fields', '_sticky', 'publication_name',
28 'publication_volume', 'publication_number',
29 'publication_section', 'publication_starting_page',
30 'guidislink', 'contributors', 'enclosures')
32 _searchable_fields = ('title', 'description', 'fm_license', 'fm_changes',
33 'creator', 'contributors')
35 __gsignals__ = {
36 'changed' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),
39 def __init__(self, imageCache=None):
40 gobject.GObject.__init__(self)
41 self.imageCache = imageCache
42 if not self.imageCache:
43 import ImageCache
44 self.imageCache = ImageCache.cache
46 self.title = None
47 self.link = None
48 self.description = None
49 self.guid = None
50 self.guidislink = True
51 self.pub_date = time.localtime()
52 self.source = None
53 self._images = {}
54 self._seen = 0
55 self._id = None
56 self.feed = None
57 self.fm_license = None
58 self.fm_changes = None
59 self.creator = None
60 self.contributors = list()
61 self.license_urls = list()
62 self.publication_name = None
63 self.publication_volume = None
64 self.publication_number = None
65 self.publication_section = None
66 self.publication_starting_page = None
67 self._sticky = 0
68 self.enclosures = None
70 def __eq__(self, item):
71 r = item.title == self.title and item.description == self.description
72 if r:
73 return True
74 elif item.guid and self.guid and item.guid == self.guid:
75 return True
76 return False
78 @apply
79 def seen():
80 doc = ""
81 def fget(self):
82 return self._seen
83 def fset(self, seen = True):
84 if self._seen != seen:
85 self._seen = seen
86 self.emit('changed')
87 return property(**locals())
89 @apply
90 def sticky():
91 doc = ""
92 def fget(self):
93 return self._sticky
94 def fset(self, sticky):
95 if self._sticky != sticky:
96 self._sticky = sticky
97 self.emit('changed')
98 return property(**locals())
100 @apply
101 def id():
102 doc = "Item ID (internal)"
103 def fget(self):
104 return self._id
105 def fset(self, iid):
106 self._id = iid
107 return property(**locals())
109 def _add_image(self, image_name, restore):
110 pass
111 #self.imageCache.add_refer(image_name, restore, self)
112 #self._images[image_name] = self.imageCache[image_name]
114 def add_image(self, image_name):
115 self._add_image(image_name, restore = False)
117 def restore_image(self, image_name):
118 self._add_image(image_name, restore = True)
120 def set_image(self, image_name, image):
121 self._images[image_name] = image
123 def get_image(self, image_name):
124 return self._images.get(image_name, None)
126 def clear_images(self):
127 self._images = {}
129 def image_keys(self):
130 return self._images.keys()
132 def match(self, text):
133 def try_field(field):
134 return type(field) in (
135 type(''), type(u'')) and field.lower().find(text.lower()) > -1
136 for f in self._searchable_fields:
137 try:
138 if try_field(self.__getattribute__(f)):
139 return 1
140 except AttributeError:
141 pass
142 return 0
144 def clean_up(self):
145 for image in self._images:
146 self.imageCache.remove_refer(image)