iteration 1 - Use gobject for events in feed, summaryitem and feedlist
[straw.git] / src / lib / SummaryItem.py
blob56e05f8983c82290e04fa7c6285c56a25ed33431
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 'read' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),
37 #'unread' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),
38 'sticky' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ())
41 def __init__(self, imageCache=None):
42 gobject.GObject.__init__(self)
43 self.imageCache = imageCache
44 if not self.imageCache:
45 import ImageCache
46 self.imageCache = ImageCache.cache
48 self.title = None
49 self.link = None
50 self.description = None
51 self.guid = None
52 self.guidislink = True
53 self.pub_date = time.localtime()
54 self.source = None
55 self._images = {}
56 self._seen = 0
57 self._id = None
58 self.feed = None
59 self.fm_license = None
60 self.fm_changes = None
61 self.creator = None
62 self.contributors = list()
63 self.license_urls = list()
64 self.publication_name = None
65 self.publication_volume = None
66 self.publication_number = None
67 self.publication_section = None
68 self.publication_starting_page = None
69 self._sticky = 0
70 self.enclosures = None
72 def __eq__(self, item):
73 r = item.title == self.title and item.description == self.description
74 if r:
75 return True
76 elif item.guid and self.guid and item.guid == self.guid:
77 return True
78 return False
80 @apply
81 def seen():
82 doc = ""
83 def fget(self):
84 return self._seen
85 def fset(self, seen = True):
86 if self._seen != seen:
87 self._seen = seen
88 self.emit('read')
89 return property(**locals())
91 @apply
92 def sticky():
93 doc = ""
94 def fget(self):
95 return self._sticky
96 def fset(self, sticky):
97 if self._sticky != sticky:
98 self._sticky = sticky
99 self.emit('sticky')
100 return property(**locals())
102 @apply
103 def id():
104 doc = "Item ID (internal)"
105 def fget(self):
106 return self._id
107 def fset(self, iid):
108 self._id = iid
109 return property(**locals())
111 def _add_image(self, image_name, restore):
112 self.imageCache.add_refer(image_name, restore, self)
113 self._images[image_name] = self.imageCache.cache[image_name]
115 def add_image(self, image_name):
116 self._add_image(image_name, restore = False)
118 def restore_image(self, image_name):
119 self._add_image(image_name, restore = True)
121 def set_image(self, image_name, image):
122 self._images[image_name] = image
124 def get_image(self, image_name):
125 return self._images.get(image_name, None)
127 def clear_images(self):
128 self._images = {}
130 def image_keys(self):
131 return self._images.keys()
133 def set_seen_quiet(self, seen = 1):
134 print "XXX: DEPRECATE / FIX"
135 old = self._seen
136 self._seen = seen
137 return seen != old
139 def match(self, text):
140 def try_field(field):
141 return type(field) in (
142 type(''), type(u'')) and field.lower().find(text.lower()) > -1
143 for f in self._searchable_fields:
144 try:
145 if try_field(self.__getattribute__(f)):
146 return 1
147 except AttributeError:
148 pass
149 return 0
151 def clean_up(self):
152 for image in self._images:
153 self.imageCache.remove_refer(image)