Fix Fetch news action

This commit is contained in:
Kovid Goyal 2010-07-17 11:19:55 -06:00
parent a54e1d1938
commit 161a61f6fd
3 changed files with 24 additions and 18 deletions

View File

@ -10,7 +10,7 @@ Scheduler for automated recipe downloads
from datetime import timedelta from datetime import timedelta
from PyQt4.Qt import QDialog, SIGNAL, Qt, QTime, QObject, QMenu, \ 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.dialogs.scheduler_ui import Ui_Dialog
from calibre.gui2.search_box import SearchBox2 from calibre.gui2.search_box import SearchBox2
@ -203,6 +203,9 @@ class Scheduler(QObject):
INTERVAL = 1 # minutes INTERVAL = 1 # minutes
delete_old_news = pyqtSignal(object)
start_recipe_fetch = pyqtSignal(object)
def __init__(self, parent, db): def __init__(self, parent, db):
QObject.__init__(self, parent) QObject.__init__(self, parent)
self.internet_connection_failed = False self.internet_connection_failed = False
@ -238,7 +241,7 @@ class Scheduler(QObject):
delta = timedelta(days=self.oldest) delta = timedelta(days=self.oldest)
ids = self.recipe_model.db.tags_older_than(_('News'), delta) ids = self.recipe_model.db.tags_older_than(_('News'), delta)
if ids: if ids:
self.emit(SIGNAL('delete_old_news(PyQt_PyObject)'), ids) self.delete_old_news.emit(ids)
def show_dialog(self, *args): def show_dialog(self, *args):
self.lock.lock() self.lock.lock()
@ -282,7 +285,7 @@ class Scheduler(QObject):
'urn':urn, 'urn':urn,
} }
self.download_queue.add(urn) self.download_queue.add(urn)
self.emit(SIGNAL('start_recipe_fetch(PyQt_PyObject)'), arg) self.start_recipe_fetch.emit(arg)
finally: finally:
self.lock.unlock() self.lock.unlock()

View File

@ -21,6 +21,7 @@ from calibre.gui2.widgets import ComboBoxWithHelp
from calibre import human_readable from calibre import human_readable
from calibre.utils.config import prefs from calibre.utils.config import prefs
from calibre.ebooks import BOOK_EXTENSIONS from calibre.ebooks import BOOK_EXTENSIONS
from calibre.gui2.dialogs.scheduler import Scheduler
ICON_SIZE = 48 ICON_SIZE = 48
@ -307,7 +308,7 @@ class Action(QAction):
class MainWindowMixin(object): class MainWindowMixin(object):
def __init__(self): def __init__(self, db):
self.device_connected = None self.device_connected = None
self.setObjectName('MainWindow') self.setObjectName('MainWindow')
self.setWindowIcon(QIcon(I('library.png'))) 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.donate_button.set_normal_icon_size(ICON_SIZE, ICON_SIZE)
self.location_manager = LocationManager(self) self.location_manager = LocationManager(self)
self.init_scheduler(db)
all_actions = self.setup_actions() all_actions = self.setup_actions()
self.search_bar = SearchBar(self) self.search_bar = SearchBar(self)
@ -334,6 +336,11 @@ class MainWindowMixin(object):
l = self.centralwidget.layout() l = self.centralwidget.layout()
l.addWidget(self.search_bar) 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): def read_toolbar_settings(self):
pass pass
@ -392,6 +399,10 @@ class MainWindowMixin(object):
ac(-1, -1, 0, 'books_with_the_same_tags', _('Books with the same tags'), ac(-1, -1, 0, 'books_with_the_same_tags', _('Books with the same tags'),
'tags.svg') '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) self.action_help.triggered.connect(self.show_help)
md = QMenu() md = QMenu()
md.addAction(_('Edit metadata individually'), md.addAction(_('Edit metadata individually'),

View File

@ -27,7 +27,6 @@ from calibre.gui2 import error_dialog, GetMetadata, open_local_file, \
gprefs, max_available_height, config, info_dialog gprefs, max_available_height, config, info_dialog
from calibre.gui2.cover_flow import CoverFlowMixin from calibre.gui2.cover_flow import CoverFlowMixin
from calibre.gui2.widgets import ProgressIndicator from calibre.gui2.widgets import ProgressIndicator
from calibre.gui2.dialogs.scheduler import Scheduler
from calibre.gui2.update import UpdateMixin from calibre.gui2.update import UpdateMixin
from calibre.gui2.main_window import MainWindow from calibre.gui2.main_window import MainWindow
from calibre.gui2.layout import MainWindowMixin from calibre.gui2.layout import MainWindowMixin
@ -119,7 +118,7 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, # {{{
self.another_instance_wants_to_talk) self.another_instance_wants_to_talk)
self.check_messages_timer.start(1000) self.check_messages_timer.start(1000)
MainWindowMixin.__init__(self) MainWindowMixin.__init__(self, db)
# Jobs Button {{{ # Jobs Button {{{
self.job_manager = JobManager() self.job_manager = JobManager()
@ -253,18 +252,6 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, # {{{
db, server_config().parse()) db, server_config().parse())
self.test_server_timer = QTimer.singleShot(10000, self.test_server) 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) self.keyboard_interrupt.connect(self.quit, type=Qt.QueuedConnection)
AddAction.__init__(self) AddAction.__init__(self)
@ -272,6 +259,11 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, # {{{
self.finalize_layout() self.finalize_layout()
self.donate_button.start_animation() 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): def resizeEvent(self, ev):
MainWindow.resizeEvent(self, ev) MainWindow.resizeEvent(self, ev)
self.search.setMaximumWidth(self.width()-150) self.search.setMaximumWidth(self.width()-150)