From f4e76ca2c8e6e605e7a95eb8bc2553298e297e19 Mon Sep 17 00:00:00 2001 From: DrFrasierCrane Date: Sun, 23 Dec 2007 13:12:38 +0100 Subject: [PATCH] Improved "Update All" button - now it also a "Stop Update All" button. --- TODO | 3 +++ straw/Application.py | 25 +++++++++++++++++++++---- straw/FeedManager.py | 15 ++++++++++++--- straw/JobManager.py | 16 +++++++++++----- 4 files changed, 47 insertions(+), 12 deletions(-) diff --git a/TODO b/TODO index 17ae263..e99fe1c 100644 --- a/TODO +++ b/TODO @@ -1,6 +1,9 @@ * High priority - JobManager: stopping a job = allow for graceful shutdown +- JobManager: consider using stack instead of FIFO queue to allow adding priority tasks + when job is already running + - Feed error display - Fix and migrate tray icon - Downloading/displaying feed icons (check if there are user interaction and usability issues) diff --git a/straw/Application.py b/straw/Application.py index 73901d1..d942fa6 100644 --- a/straw/Application.py +++ b/straw/Application.py @@ -3,6 +3,7 @@ This is the main module that binds everything together. """ + __copyright__ = "Copyright (c) 2002-2005 Free Software Foundation, Inc." __license__ = """ GNU General Public License @@ -28,6 +29,7 @@ from xml.sax import saxutils import Config import FeedManager import ImageCache +import JobManager import MVP import error import gnome, gconf @@ -147,6 +149,8 @@ class ToolbarPresenter(MVP.BasicPresenter): class ApplicationPresenter(MVP.BasicPresenter): def _initialize(self): + FeedManager._get_instance().connect("update-all-done", self._on_update_all_done) + self._curr_category = None self._curr_feed = None self._curr_item = None @@ -156,12 +160,15 @@ class ApplicationPresenter(MVP.BasicPresenter): def _init_widgets(self): widget_tree = self._view.get_widget_tree() + self._itemlist_view_notebook = widget_tree.get_widget('mode_view_notebook') self._feedlist_view_notebook = widget_tree.get_widget('left_mode_view_notebook') item_view_container = widget_tree.get_widget('item_view_container') item_list_container = widget_tree.get_widget('item_list_container') + self.update_all_button = widget_tree.get_widget("toolbar_refresh_all_button") + parent_paned = item_view_container.get_parent() parent_parent_widget = parent_paned.get_parent() @@ -251,16 +258,28 @@ class ApplicationPresenter(MVP.BasicPresenter): return helpers.credits() def poll_all(self): - if self._warn_if_offline(): + if not self._warn_if_offline(): + return + + if not FeedManager.is_update_all_running(): FeedManager.update_all_feeds({ "task-start": [ self._on_feed_poll_started ], "task-done": [ self._on_feed_poll_done ] }) + self.update_all_button.set_sensitive(True) + self.update_all_button.set_stock_id(gtk.STOCK_STOP) + else: + self.update_all_button.set_sensitive(False) + JobManager.stop_jobs() def _on_feed_poll_started(self, handler, feed): - pass#print feed.id + pass def _on_feed_poll_done(self, handler, data): pass + def _on_update_all_done(self, obj): + self.update_all_button.set_sensitive(True) + self.update_all_button.set_stock_id(gtk.STOCK_REFRESH) + def poll_current_category(self): if self._warn_if_offline(): self._poll_categories([self._curr_category]) @@ -297,11 +316,9 @@ class ApplicationPresenter(MVP.BasicPresenter): # self._find_presenter.item_list.signal_disconnect(Event.ItemSelectionChangedSignal, # self._item_view.item_selection_changed) - def _poll_categories(self, fclist): pm = PollManager.get_instance() pm.poll_categories(fclist) - return def _warn_if_offline(self): config = Config.get_instance() diff --git a/straw/FeedManager.py b/straw/FeedManager.py index c3865cd..162498b 100644 --- a/straw/FeedManager.py +++ b/straw/FeedManager.py @@ -53,6 +53,10 @@ def update_all_feeds(observers, feeds = None): fm = _get_instance() return fm.update_all_feeds(observers, feeds) +def is_update_all_running(): + fm = _get_instance() + return fm.update_all_running + def save_category(category): fm = _get_instance() return fm.save_category(category) @@ -96,12 +100,14 @@ class FeedManager(GObject): "item-added" : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,)), "feed-added" : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,)), "category-added" : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,)), + "update-all-done" : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()) } def __init__(self): GObject.__init__(self) self.storage = None + self.update_all_running = False def init_storage(self, path): self.storage = Storage(path) @@ -235,14 +241,17 @@ class FeedManager(GObject): if not feeds: feeds = [node for node in self.nodes.values() if node.type == "F"] + self.update_all_running = True + FeedUpdater.update_feeds(feeds, [{ - "job-done": [ self.update_all_feeds_done ], + "job-done": [ self._on_update_all_done ], "task-start": [ self._on_update_feed_start ], "task-done": [ self._on_update_feed_done ] }, observers]) - def update_all_feeds_done(self, handler, data): - pass + def _on_update_all_done(self, handler, data): + self.update_all_running = False + self.emit("update-all-done") def _on_update_feed_start(self, handler, feed): feed.props.status = straw.FS_UPDATING diff --git a/straw/JobManager.py b/straw/JobManager.py index f434486..ec87e4a 100644 --- a/straw/JobManager.py +++ b/straw/JobManager.py @@ -74,10 +74,10 @@ class JobHandler(GObject): """ __gsignals__ = { - 'job-done' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,)), - 'task-done' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,)), - 'task-start' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,)) - } + 'job-done' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,)), + 'task-done' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,)), + 'task-start' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,)) + } def __init__(self, job): gobject.GObject.__init__(self) @@ -119,6 +119,7 @@ class HandlerThread(Thread): self.handler = handler self.control_queue = Queue() + self.stopped = False def run(self): worker = HandlerWorkerThread(self) @@ -140,7 +141,12 @@ class HandlerThread(Thread): self.handler.task_queue.task_done() def stop(self): - self.control_queue.task_done() + error.debug("CONTROL -- STOP") + + if not self.stopped: + self.control_queue.task_done() + + self.stopped = True class HandlerWorkerThread(Thread): def __init__(self, handler_thread): -- 2.11.4.GIT