mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Migrate choose library and cleanup fetch news connections
This commit is contained in:
parent
4635ae37d7
commit
c02272593e
@ -645,6 +645,10 @@ class ActionSimilarBooks(InterfaceActionBase):
|
||||
name = 'Similar Books'
|
||||
actual_plugin = 'calibre.gui2.actions.similar_books:SimilarBooksAction'
|
||||
|
||||
class ActionChooseLibrary(InterfaceActionBase):
|
||||
name = 'Choose Library'
|
||||
actual_plugin = 'calibre.gui2.actions.choose_library:ChooseLibraryAction'
|
||||
|
||||
|
||||
plugins += [ActionAdd, ActionFetchAnnotations, ActionGenerateCatalog,
|
||||
ActionConvert, ActionDelete, ActionEditMetadata, ActionView,
|
||||
|
39
src/calibre/gui2/actions/choose_library.py
Normal file
39
src/calibre/gui2/actions/choose_library.py
Normal file
@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env python
|
||||
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
from calibre.gui2.actions import InterfaceAction
|
||||
|
||||
class ChooseLibraryAction(InterfaceAction):
|
||||
|
||||
name = 'Choose Library'
|
||||
action_spec = (_('%d books')%0, 'lt.png',
|
||||
_('Choose calibre library to work with'), None)
|
||||
|
||||
def genesis(self):
|
||||
pass
|
||||
|
||||
def location_selected(self, loc):
|
||||
enabled = loc == 'library'
|
||||
self.qaction.setEnabled(enabled)
|
||||
self.qaction.triggered.connect(self.choose_library)
|
||||
|
||||
def count_changed(self, new_count):
|
||||
text = self.action_spec[0]%new_count
|
||||
a = self.qaction
|
||||
a.setText(text)
|
||||
tooltip = self.action_spec[2] + '\n\n' + text
|
||||
a.setToolTip(tooltip)
|
||||
a.setStatusTip(tooltip)
|
||||
a.setWhatsThis(tooltip)
|
||||
|
||||
def choose_library(self, *args):
|
||||
from calibre.gui2.dialogs.choose_library import ChooseLibrary
|
||||
db = self.gui.library_view.model().db
|
||||
c = ChooseLibrary(db, self.gui.library_moved, self.gui)
|
||||
c.exec_()
|
||||
|
||||
|
@ -5,6 +5,8 @@ __license__ = 'GPL v3'
|
||||
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
from PyQt4.Qt import Qt
|
||||
|
||||
from calibre.gui2 import Dispatcher
|
||||
from calibre.gui2.tools import fetch_scheduled_recipe
|
||||
from calibre.utils.config import dynamic
|
||||
@ -22,10 +24,19 @@ class FetchNewsAction(InterfaceAction):
|
||||
def genesis(self):
|
||||
self.conversion_jobs = {}
|
||||
|
||||
def connect_scheduler(self, scheduler):
|
||||
self.qaction.setMenu(scheduler.news_menu)
|
||||
def init_scheduler(self, db):
|
||||
from calibre.gui2.dialogs.scheduler import Scheduler
|
||||
self.scheduler = Scheduler(self.gui, db)
|
||||
self.scheduler.start_recipe_fetch.connect(self.download_scheduled_recipe, type=Qt.QueuedConnection)
|
||||
self.qaction.setMenu(self.scheduler.news_menu)
|
||||
self.qaction.triggered.connect(
|
||||
scheduler.show_dialog)
|
||||
self.scheduler.show_dialog)
|
||||
self.database_changed = self.scheduler.database_changed
|
||||
|
||||
def connect_scheduler(self):
|
||||
self.scheduler.delete_old_news.connect(
|
||||
self.gui.library_view.model().delete_books_by_id,
|
||||
type=Qt.QueuedConnection)
|
||||
|
||||
def download_scheduled_recipe(self, arg):
|
||||
func, args, desc, fmt, temp_files = \
|
||||
|
@ -19,7 +19,6 @@ from calibre.gui2.throbber import ThrobbingButton
|
||||
from calibre.gui2 import config, gprefs
|
||||
from calibre.gui2.widgets import ComboBoxWithHelp
|
||||
from calibre import human_readable
|
||||
from calibre.gui2.dialogs.scheduler import Scheduler
|
||||
|
||||
|
||||
|
||||
@ -279,11 +278,6 @@ class ToolBar(QToolBar): # {{{
|
||||
|
||||
self.choose_action.setVisible(not showing_device)
|
||||
|
||||
def count_changed(self, new_count):
|
||||
text = _('%d books')%new_count
|
||||
a = self.choose_action
|
||||
a.setText(text)
|
||||
a.setToolTip(_('Choose calibre library to work with') + '\n\n' + text)
|
||||
|
||||
def resizeEvent(self, ev):
|
||||
QToolBar.resizeEvent(self, ev)
|
||||
@ -322,61 +316,20 @@ class MainWindowMixin(object):
|
||||
self.donate_button = ThrobbingButton(self.centralwidget)
|
||||
self.location_manager = LocationManager(self)
|
||||
|
||||
self.init_scheduler(db)
|
||||
all_actions = self.setup_actions()
|
||||
self.iactions['Fetch News'].init_scheduler(db)
|
||||
|
||||
self.search_bar = SearchBar(self)
|
||||
self.tool_bar = ToolBar(all_actions, self.donate_button,
|
||||
self.location_manager, self)
|
||||
self.addToolBar(Qt.TopToolBarArea, self.tool_bar)
|
||||
self.tool_bar.choose_action.triggered.connect(self.choose_library)
|
||||
|
||||
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.iactions['Fetch News'].download_scheduled_recipe, type=Qt.QueuedConnection)
|
||||
self.iactions['Fetch News'].connect_scheduler(self.scheduler)
|
||||
|
||||
def read_toolbar_settings(self):
|
||||
pass
|
||||
|
||||
def choose_library(self, *args):
|
||||
from calibre.gui2.dialogs.choose_library import ChooseLibrary
|
||||
db = self.library_view.model().db
|
||||
c = ChooseLibrary(db, self.library_moved, self)
|
||||
c.exec_()
|
||||
|
||||
def setup_actions(self): # {{{
|
||||
all_actions = []
|
||||
|
||||
def ac(normal_order, device_order, separator_before,
|
||||
name, text, icon, shortcut=None, tooltip=None):
|
||||
action = Action(QIcon(I(icon)), text, self)
|
||||
action.normal_order = normal_order
|
||||
action.device_order = device_order
|
||||
action.separator_before = separator_before
|
||||
action.action_name = name
|
||||
text = tooltip if tooltip else text
|
||||
action.setToolTip(text)
|
||||
action.setStatusTip(text)
|
||||
action.setWhatsThis(text)
|
||||
action.setAutoRepeat(False)
|
||||
action.setObjectName('action_'+name)
|
||||
if shortcut:
|
||||
action.setShortcut(shortcut)
|
||||
setattr(self, 'action_'+name, action)
|
||||
all_actions.append(action)
|
||||
|
||||
ac(5, 5, 3, 'choose_library', _('%d books')%0, 'lt.png',
|
||||
tooltip=_('Choose calibre library to work with'))
|
||||
|
||||
|
||||
|
||||
return all_actions
|
||||
# }}}
|
||||
|
||||
|
||||
|
||||
|
@ -204,9 +204,8 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, # {{{
|
||||
|
||||
if self.system_tray_icon.isVisible() and opts.start_in_tray:
|
||||
self.hide_windows()
|
||||
for t in (self.tool_bar, ):
|
||||
self.library_view.model().count_changed_signal.connect \
|
||||
(t.count_changed)
|
||||
self.library_view.model().count_changed_signal.connect(
|
||||
self.iactions['Choose Library'].count_changed)
|
||||
if not gprefs.get('quick_start_guide_added', False):
|
||||
from calibre.ebooks.metadata import MetaInformation
|
||||
mi = MetaInformation(_('Calibre Quick Start Guide'), ['John Schember'])
|
||||
@ -250,9 +249,7 @@ 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)
|
||||
self.iactions['Fetch News'].connect_scheduler()
|
||||
|
||||
def start_content_server(self):
|
||||
from calibre.library.server.main import start_threaded_server
|
||||
@ -368,7 +365,7 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, # {{{
|
||||
self.saved_search.clear_to_help()
|
||||
self.book_details.reset_info()
|
||||
self.library_view.model().count_changed()
|
||||
self.scheduler.database_changed(db)
|
||||
self.iactions['Fetch News'].database_changed(db)
|
||||
prefs['library_path'] = self.library_path
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user