Added task-start signal to JobManager, more work on subscribe dialog, code cleanup.
[straw/fork.git] / straw / model / __init__.py
blobed05733f4694e73e965a701a857c773cc4026b5b
1 from gobject import GObject
2 import gobject
3 import straw
5 class Category(GObject):
6 persistent_properties = [ "id", "parent_id" , "title" ]
7 persistent_table = "categories"
9 __gproperties__ = {
10 "title": (str, "title", "title", "", gobject.PARAM_READWRITE),
11 "unread-count": (int, "unread-count", "unread-count", 0, 999999, 0, gobject.PARAM_READWRITE)
14 __gsignals__ = {
15 "unread-count-changed": (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT))
18 def __init__(self):
19 GObject.__init__(self)
20 self.atr = {}
21 self.id = None
22 self.parent_id = None
23 self.title = ""
24 self.unread_count = 0
26 def do_get_property(self, property):
27 if property.name == "title":
28 return self.title
29 elif property.name == "unread-count":
30 return self.unread_count
31 else:
32 raise AttributeError, "unknown property %s" % property.name
34 def do_set_property(self, property, value):
35 if property.name == "title":
36 self.title = value
37 elif property.name == "unread-count":
38 if self.unread_count != value:
39 delta = value - self.unread_count
40 old_value = self.unread_count
41 self.unread_count = value
42 self.emit("unread-count-changed", old_value, delta)
43 else:
44 raise AttributeError, "unknown property %s" % property.name
46 def on_unread_count_changed(self, obj, old_value, delta):
47 if isinstance(obj, Feed) and obj.category_id == self.id:
48 self.props.unread_count += delta
49 elif isinstance(obj, Category):
50 self.props.unread_count += delta
52 class Feed(GObject):
53 persistent_properties = [ "id", "title", "location", "category_id", "link" ]
54 persistent_table = "feeds"
56 __gproperties__ = {
57 "title": (str, "title", "title", "", gobject.PARAM_READWRITE),
58 "location": (str, "location", "location", "", gobject.PARAM_READWRITE),
59 "status": (int, "status", "status", 0, 9999, 0, gobject.PARAM_READWRITE),
60 "unread-count": (int, "unread-count", "unread-count", 0, 9999, 0, gobject.PARAM_READWRITE)
63 __gsignals__ = {
64 "unread-count-changed": (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT))
67 def __init__(self):
68 GObject.__init__(self)
69 self.id = None
70 self.category_id = None
71 self.unread_count = 0
72 self.items = []
74 def do_get_property(self, property):
75 if property.name == "title":
76 return self.title
77 elif property.name == "location":
78 return self.title
79 elif property.name == "unread-count":
80 return self.unread_count
81 elif property.name == "status":
82 return self.status
83 else:
84 raise AttributeError, "unknown property %s" % property.name
86 def do_set_property(self, property, value):
87 if property.name == "title":
88 self.title = value
89 elif property.name == "location":
90 self.location = value
91 elif property.name == "status":
92 self.status = value
93 elif property.name == "unread-count":
94 if self.unread_count != value:
95 delta = value - self.unread_count
96 old_value = self.unread_count
97 self.unread_count = value
98 self.emit("unread-count-changed", old_value, delta)
99 else:
100 raise AttributeError, "unknown property %s" % property.name
102 def add_item(self, item):
103 self.items.append(item)
105 def on_is_read_changed(self, obj, is_read):
106 if is_read:
107 self.props.unread_count -= 1
108 else:
109 self.props.unread_count += 1
111 class Item(GObject):
112 persistent_properties = [ "id", "title", "feed_id", "is_read", "link", "pub_date", "description" ]
113 persistent_table = "items"
115 __gproperties__ = {
116 "title": (str, "title", "title", "", gobject.PARAM_READWRITE),
117 "location": (str, "location", "location", "", gobject.PARAM_READWRITE),
118 "is-read": (gobject.TYPE_BOOLEAN, "is-read", "is-read", False, gobject.PARAM_READWRITE)
121 __gsignals__ = {
122 "is-read-changed": (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,))
125 def __init__(self):
126 GObject.__init__(self)
127 self.id = None
128 self.title = ""
129 self.feed_id = None
130 self.is_read = False
132 self.link = "link"
133 self.pub_date = None
134 self.description = "description"
135 self.source = None
136 self.guid = "guid"
137 self.guidislink = False
139 self.publication_name = "publication_name"
140 self.publication_volume = "publication_volume"
141 self.publication_number = "publication_number"
142 self.publication_section = "publication_section"
143 self.publication_starting_page = "publication_starting_page"
145 self.fm_license = "fm_license"
146 self.fm_changes = "fm_changes"
148 self.creator = "creator"
150 self.contributors = []
151 self.enclosures = []
152 self.license_urls = []
154 def do_get_property(self, property):
155 if property.name == "title":
156 return self.title
157 elif property.name == "is-read":
158 return self.is_read
159 else:
160 raise AttributeError, "unknown property %s" % property.name
162 def do_set_property(self, property, value):
163 if property.name == "title":
164 self.title = value
165 elif property.name == "is-read":
166 old_value = bool(self.is_read)
167 self.is_read = value
168 if old_value != value:
169 self.emit("is-read-changed", int(value))
170 else:
171 raise AttributeError, "unknown property %s" % property.name
173 class TreeViewNode(GObject):
174 persistent_properties = [ "id", "obj_id", "norder", "type" ]
175 persistent_table = "treeview_nodes"
177 __gproperties__ = {
178 "norder": (int, "norder", "norder", 0, 1000, 0, gobject.PARAM_READWRITE),
181 def __init__(self):
182 GObject.__init__(self)
183 self.id = None
184 self.obj_id = None
185 self.norder = None
186 self.type = None
188 def do_get_property(self, property):
189 if property.name == "norder":
190 return self.norder
191 else:
192 raise AttributeError, "unknown property %s" % property.name
194 def do_set_property(self, property, value):
195 if property.name == "norder":
196 self.norder = value
197 else:
198 raise AttributeError, "unknown property %s" % property.name
200 def obj_changed(self, obj, property):
201 if property.name == "unread-count":
202 self.store.set(self.treeiter, 3, self.obj.unread_count)
203 elif property.name == "status":
204 if (self.obj.status & straw.FS_UPDATING) > 0:
205 title = self.store.get_value(self.treeiter, 1)
206 self.store.set(self.treeiter, 1, "<i>" + title + "</i>")
207 else:
208 title = self.obj.title
209 self.store.set(self.treeiter, 1, title)
211 @property
212 def title(self):
213 ''' The title of the node be it a category or a feed '''
214 return self.obj.title
216 @property
217 def unread_count(self):
218 ''' The title of the node be it a category or a feed '''
219 return self.obj.unread_count
221 @property
222 def pixbuf(self):
223 ''' gets the pixbuf to display according to the status of the feed '''
224 import gtk
225 widget = gtk.Label()
227 if isinstance(self.obj, Feed):
228 return widget.render_icon(gtk.STOCK_FILE, gtk.ICON_SIZE_MENU)
229 else:
230 return widget.render_icon(gtk.STOCK_DIRECTORY, gtk.ICON_SIZE_MENU)
232 # ignore why above is a gtk.Label. We just need
233 # gtk.Widget.render_icon to get a pixbuf out of a stock image.
234 # Fyi, gtk.Widget is abstract that is why we need a subclass to do
235 # this for us.
236 try:
237 if self.obj.process_status is not feeds.Feed.STATUS_IDLE:
238 return widget.render_icon(gtk.STOCK_EXECUTE, gtk.ICON_SIZE_MENU)
239 elif self.obj.error:
240 return widget.render_icon(gtk.STOCK_DIALOG_ERROR, gtk.ICON_SIZE_MENU)
241 except AttributeError, ex:
242 logging.exception(ex)
243 return widget.render_icon(gtk.STOCK_DIRECTORY, gtk.ICON_SIZE_MENU)
244 return self.default_pixbuf