def updateFeedStatus(self): info("updateFeedStatus queue length: %d" % len(self.pendingFeedUpdates)) try: while not feedStatusQueue.empty(): # The idea: this function should never fail. # But, if we do, we keep our last attempted update in # memory, and we'll restart it the next try. data = feedStatusQueue.get() [action, id] = data[:2] debug("updateFeedStatus: %d %d" % (action, id)) # FIXME: make this more elegant # These are not really feed updates if action in [4, 5, 6]: if action == 4: # Add new feed self.addFeed(id) elif action == 5: # OPML to import # importOPML(id, root_feed) self.initTree() elif action == 6: # Just pop self.show() self.raise_() else: error("id %s not in the tree" % id) # We collapse all updates for a feed, and keep the last one else: self.pendingFeedUpdates[id] = data for id in self.pendingFeedUpdates: if not self.pendingFeedUpdates[id]: continue [action, id] = self.pendingFeedUpdates[id] feed = Feed.get_by(id=id) if not feed: # Maybe it got deleted while queued self.pendingFeedUpdates[id] = None continue if action == 0: # Mark as updating self.updateFeedItem(feed) else: # Mark as finished updating # Force recount after update feed.curUnread = -1 feed.unreadCount() self.updateFeedItem(feed) if feed.notify and len(data) > 2: # Systray notification self.notifiedFeed = feed self.tray.showMessage("New Articles", "%d new articles in %s" % (data[2], feed.text)) # We got this far, that means it's not pending anymore! self.pendingFeedUpdates[id] = None # We got this far, that means nothing is pending anymore! self.pendingFeedUpdates = {} except: # FIXME: handle errors better # traceback.print_exc(10) error("FIX error handling in updateFeedStatus already!") self.feedStatusTimer.start(2000)
def updateListedFeedItem(self): """This connects to the post list model's reset signal, so we can update the feed item when the model data changes""" feed = Feed.get_by(id=self.ui.posts.model().feed_id) self.queueFeedUpdate(feed)