Migrated Fetch News

This commit is contained in:
Kovid Goyal 2010-08-12 20:04:27 -06:00
parent d9ac3a0e0a
commit 5c9ec13a29
4 changed files with 25 additions and 13 deletions

View File

@ -605,5 +605,10 @@ class ActionView(InterfaceActionBase):
name = 'View' name = 'View'
actual_plugin = 'calibre.gui2.actions.view:ViewAction' actual_plugin = 'calibre.gui2.actions.view:ViewAction'
class ActionFetchNews(InterfaceActionBase):
name = 'Fetch News'
actual_plugin = 'calibre.gui2.actions.fetch_news:FetchNewsAction'
plugins += [ActionAdd, ActionFetchAnnotations, ActionGenerateCatalog, plugins += [ActionAdd, ActionFetchAnnotations, ActionGenerateCatalog,
ActionConvert, ActionDelete, ActionEditMetadata, ActionView] ActionConvert, ActionDelete, ActionEditMetadata, ActionView,
ActionFetchNews]

View File

@ -8,8 +8,12 @@ __docformat__ = 'restructuredtext en'
from calibre.gui2 import Dispatcher from calibre.gui2 import Dispatcher
from calibre.gui2.tools import fetch_scheduled_recipe from calibre.gui2.tools import fetch_scheduled_recipe
from calibre.utils.config import dynamic from calibre.utils.config import dynamic
from calibre.gui2.actions import InterfaceAction
class FetchNewsAction(object): class FetchNewsAction(InterfaceAction):
name = 'Fetch News'
action_spec = (_('Fetch news'), 'news.svg', None, _('F'))
def location_selected(self, loc): def location_selected(self, loc):
enabled = loc == 'library' enabled = loc == 'library'
@ -18,10 +22,15 @@ class FetchNewsAction(object):
def genesis(self): def genesis(self):
self.conversion_jobs = {} self.conversion_jobs = {}
def connect_scheduler(self, scheduler):
self.qaction.setMenu(scheduler.news_menu)
self.qaction.triggered.connect(
scheduler.show_dialog)
def download_scheduled_recipe(self, arg): def download_scheduled_recipe(self, arg):
func, args, desc, fmt, temp_files = \ func, args, desc, fmt, temp_files = \
fetch_scheduled_recipe(arg) fetch_scheduled_recipe(arg)
job = self.job_manager.run_job( job = self.gui.job_manager.run_job(
Dispatcher(self.scheduled_recipe_fetched), func, args=args, Dispatcher(self.scheduled_recipe_fetched), func, args=args,
description=desc) description=desc)
self.conversion_jobs[job] = (temp_files, fmt, arg) self.conversion_jobs[job] = (temp_files, fmt, arg)
@ -31,16 +40,16 @@ class FetchNewsAction(object):
temp_files, fmt, arg = self.conversion_jobs.pop(job) temp_files, fmt, arg = self.conversion_jobs.pop(job)
pt = temp_files[0] pt = temp_files[0]
if job.failed: if job.failed:
self.scheduler.recipe_download_failed(arg) self.gui.scheduler.recipe_download_failed(arg)
return self.job_exception(job) return self.gui.job_exception(job)
id = self.gui.library_view.model().add_news(pt.name, arg) id = self.gui.library_view.model().add_news(pt.name, arg)
self.gui.library_view.model().reset() self.gui.library_view.model().reset()
sync = dynamic.get('news_to_be_synced', set([])) sync = dynamic.get('news_to_be_synced', set([]))
sync.add(id) sync.add(id)
dynamic.set('news_to_be_synced', sync) dynamic.set('news_to_be_synced', sync)
self.scheduler.recipe_downloaded(arg) self.gui.scheduler.recipe_downloaded(arg)
self.gui.status_bar.show_message(arg['title'] + _(' fetched.'), 3000) self.gui.status_bar.show_message(arg['title'] + _(' fetched.'), 3000)
self.email_news(id) self.gui.email_news(id)
self.sync_news() self.gui.sync_news()

View File

@ -427,7 +427,8 @@ class MainWindowMixin(object):
def init_scheduler(self, db): def init_scheduler(self, db):
self.scheduler = Scheduler(self, db) self.scheduler = Scheduler(self, db)
self.scheduler.start_recipe_fetch.connect( self.scheduler.start_recipe_fetch.connect(
self.download_scheduled_recipe, type=Qt.QueuedConnection) self.iactions['Fetch News'].download_scheduled_recipe, type=Qt.QueuedConnection)
self.iactions['Fetch News'].connect_scheduler(self.scheduler)
def read_toolbar_settings(self): def read_toolbar_settings(self):
pass pass
@ -462,7 +463,6 @@ class MainWindowMixin(object):
ac(-1, 4, 0, 'sync', _('Send to device'), 'sync.svg') ac(-1, 4, 0, 'sync', _('Send to device'), 'sync.svg')
ac(5, 5, 3, 'choose_library', _('%d books')%0, 'lt.png', ac(5, 5, 3, 'choose_library', _('%d books')%0, 'lt.png',
tooltip=_('Choose calibre library to work with')) tooltip=_('Choose calibre library to work with'))
ac(6, 6, 3, 'news', _('Fetch news'), 'news.svg', _('F'))
ac(7, 7, 0, 'save', _('Save to disk'), 'save.svg', _('S')) ac(7, 7, 0, 'save', _('Save to disk'), 'save.svg', _('S'))
ac(8, 8, 0, 'conn_share', _('Connect/share'), 'connect_share.svg') ac(8, 8, 0, 'conn_share', _('Connect/share'), 'connect_share.svg')
ac(9, 9, 3, 'del', _('Remove books'), 'trash.svg', _('Del')) ac(9, 9, 3, 'del', _('Remove books'), 'trash.svg', _('Del'))
@ -482,9 +482,6 @@ 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.share_conn_menu = ShareConnMenu(self) self.share_conn_menu = ShareConnMenu(self)
self.share_conn_menu.toggle_server.connect(self.toggle_content_server) self.share_conn_menu.toggle_server.connect(self.toggle_content_server)
self.share_conn_menu.config_email.connect(partial(self.do_config, self.share_conn_menu.config_email.connect(partial(self.do_config,

View File

@ -256,6 +256,7 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, # {{{
self.keyboard_interrupt.connect(self.quit, type=Qt.QueuedConnection) self.keyboard_interrupt.connect(self.quit, type=Qt.QueuedConnection)
self.read_settings() self.read_settings()
self.finalize_layout() self.finalize_layout()
self.donate_button.start_animation() self.donate_button.start_animation()