From 161a61f6fdcf71d0cd05c191c819f2e45e4ea4fe Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 17 Jul 2010 11:19:55 -0600 Subject: [PATCH] Fix Fetch news action --- src/calibre/gui2/dialogs/scheduler.py | 9 ++++++--- src/calibre/gui2/layout.py | 13 ++++++++++++- src/calibre/gui2/ui.py | 20 ++++++-------------- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/calibre/gui2/dialogs/scheduler.py b/src/calibre/gui2/dialogs/scheduler.py index 7e2d75e9e7..e3381049dd 100644 --- a/src/calibre/gui2/dialogs/scheduler.py +++ b/src/calibre/gui2/dialogs/scheduler.py @@ -10,7 +10,7 @@ Scheduler for automated recipe downloads from datetime import timedelta from PyQt4.Qt import QDialog, SIGNAL, Qt, QTime, QObject, QMenu, \ - QAction, QIcon, QMutex, QTimer + QAction, QIcon, QMutex, QTimer, pyqtSignal from calibre.gui2.dialogs.scheduler_ui import Ui_Dialog from calibre.gui2.search_box import SearchBox2 @@ -203,6 +203,9 @@ class Scheduler(QObject): INTERVAL = 1 # minutes + delete_old_news = pyqtSignal(object) + start_recipe_fetch = pyqtSignal(object) + def __init__(self, parent, db): QObject.__init__(self, parent) self.internet_connection_failed = False @@ -238,7 +241,7 @@ class Scheduler(QObject): delta = timedelta(days=self.oldest) ids = self.recipe_model.db.tags_older_than(_('News'), delta) if ids: - self.emit(SIGNAL('delete_old_news(PyQt_PyObject)'), ids) + self.delete_old_news.emit(ids) def show_dialog(self, *args): self.lock.lock() @@ -282,7 +285,7 @@ class Scheduler(QObject): 'urn':urn, } self.download_queue.add(urn) - self.emit(SIGNAL('start_recipe_fetch(PyQt_PyObject)'), arg) + self.start_recipe_fetch.emit(arg) finally: self.lock.unlock() diff --git a/src/calibre/gui2/layout.py b/src/calibre/gui2/layout.py index c6885058c0..8604587649 100644 --- a/src/calibre/gui2/layout.py +++ b/src/calibre/gui2/layout.py @@ -21,6 +21,7 @@ from calibre.gui2.widgets import ComboBoxWithHelp from calibre import human_readable from calibre.utils.config import prefs from calibre.ebooks import BOOK_EXTENSIONS +from calibre.gui2.dialogs.scheduler import Scheduler ICON_SIZE = 48 @@ -307,7 +308,7 @@ class Action(QAction): class MainWindowMixin(object): - def __init__(self): + def __init__(self, db): self.device_connected = None self.setObjectName('MainWindow') self.setWindowIcon(QIcon(I('library.png'))) @@ -323,6 +324,7 @@ class MainWindowMixin(object): self.donate_button.set_normal_icon_size(ICON_SIZE, ICON_SIZE) self.location_manager = LocationManager(self) + self.init_scheduler(db) all_actions = self.setup_actions() self.search_bar = SearchBar(self) @@ -334,6 +336,11 @@ class MainWindowMixin(object): l = self.centralwidget.layout() l.addWidget(self.search_bar) + def init_scheduler(self, db): + self.scheduler = Scheduler(self, db) + self.scheduler.start_recipe_fetch.connect( + self.download_scheduled_recipe, type=Qt.QueuedConnection) + def read_toolbar_settings(self): pass @@ -392,6 +399,10 @@ class MainWindowMixin(object): ac(-1, -1, 0, 'books_with_the_same_tags', _('Books with the same tags'), 'tags.svg') + self.action_news.setMenu(self.scheduler.news_menu) + self.action_news.triggered.connect( + self.scheduler.show_dialog) + self.action_help.triggered.connect(self.show_help) md = QMenu() md.addAction(_('Edit metadata individually'), diff --git a/src/calibre/gui2/ui.py b/src/calibre/gui2/ui.py index eec03876e9..dd87514a13 100644 --- a/src/calibre/gui2/ui.py +++ b/src/calibre/gui2/ui.py @@ -27,7 +27,6 @@ from calibre.gui2 import error_dialog, GetMetadata, open_local_file, \ gprefs, max_available_height, config, info_dialog from calibre.gui2.cover_flow import CoverFlowMixin from calibre.gui2.widgets import ProgressIndicator -from calibre.gui2.dialogs.scheduler import Scheduler from calibre.gui2.update import UpdateMixin from calibre.gui2.main_window import MainWindow from calibre.gui2.layout import MainWindowMixin @@ -119,7 +118,7 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, # {{{ self.another_instance_wants_to_talk) self.check_messages_timer.start(1000) - MainWindowMixin.__init__(self) + MainWindowMixin.__init__(self, db) # Jobs Button {{{ self.job_manager = JobManager() @@ -253,18 +252,6 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, # {{{ db, server_config().parse()) self.test_server_timer = QTimer.singleShot(10000, self.test_server) - - self.scheduler = Scheduler(self, self.library_view.model().db) - self.action_news.setMenu(self.scheduler.news_menu) - self.connect(self.action_news, SIGNAL('triggered(bool)'), - self.scheduler.show_dialog) - self.connect(self.scheduler, SIGNAL('delete_old_news(PyQt_PyObject)'), - self.library_view.model().delete_books_by_id, - Qt.QueuedConnection) - self.connect(self.scheduler, - SIGNAL('start_recipe_fetch(PyQt_PyObject)'), - self.download_scheduled_recipe, Qt.QueuedConnection) - self.keyboard_interrupt.connect(self.quit, type=Qt.QueuedConnection) AddAction.__init__(self) @@ -272,6 +259,11 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, # {{{ self.finalize_layout() self.donate_button.start_animation() + self.scheduler.delete_old_news.connect( + self.library_view.model().delete_books_by_id, + type=Qt.QueuedConnection) + + def resizeEvent(self, ev): MainWindow.resizeEvent(self, ev) self.search.setMaximumWidth(self.width()-150)