Show current library in title bar

This commit is contained in:
Kovid Goyal 2010-08-15 11:19:35 -06:00
parent e9c1aa873c
commit 45d20f7d7c
4 changed files with 44 additions and 8 deletions

View File

@ -26,8 +26,8 @@ class InterfaceAction(QObject):
If two :class:`InterfaceAction` objects have the same name, the one with higher
priority takes precedence.
Sub-classes should implement the :meth:`genesis` and
:meth:`location_selected` methods.
Sub-classes should implement the :meth:`genesis`, :meth:`library_moved`,
:meth:`location_selected` and :meth:`initialization_complete` methods.
Once initialized, this plugin has access to the main calibre GUI via the
:attr:`gui` member. You can access other plugins by name, for example::
@ -108,3 +108,17 @@ class InterfaceAction(QObject):
'''
pass
def library_changed(self, db):
'''
Called whenever the current library is changed.
:param db: The LibraryDatabase corresponding to the current library.
'''
pass
def initialization_complete(self):
'''
Called once per action when the initialization of the main GUI is
completed.
'''
pass

View File

@ -97,10 +97,21 @@ class ChooseLibraryAction(InterfaceAction):
ac.triggered.connect(partial(self.qs_requested, i))
self.choose_menu.addAction(ac)
def library_used(self, db):
def library_name(self):
db = self.gui.library_view.model().db
path = db.library_path
if isbytestring(path):
path = path.decode(filesystem_encoding)
path = path.replace(os.sep, '/')
return self.stats.pretty(path)
def library_changed(self, db):
self.stats.library_used(db)
self.build_menus()
def initialization_complete(self):
self.library_changed(self.gui.library_view.model().db)
def build_menus(self):
db = self.gui.library_view.model().db
locations = list(self.stats.locations(db))

View File

@ -31,7 +31,12 @@ class FetchNewsAction(InterfaceAction):
self.qaction.setMenu(self.scheduler.news_menu)
self.qaction.triggered.connect(
self.scheduler.show_dialog)
self.database_changed = self.scheduler.database_changed
def library_changed(self, db):
self.scheduler.database_changed(db)
def initialization_complete(self):
self.connect_scheduler()
def connect_scheduler(self):
self.scheduler.delete_old_news.connect(

View File

@ -249,9 +249,10 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, # {{{
self.read_settings()
self.finalize_layout()
self.donate_button.start_animation()
self.set_window_title()
self.iactions['Fetch News'].connect_scheduler()
self.iactions['Choose Library'].library_used(self.library_view.model().db)
for ac in self.iactions.values():
ac.initialization_complete()
def start_content_server(self):
from calibre.library.server.main import start_threaded_server
@ -367,9 +368,14 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, # {{{
self.saved_search.clear_to_help()
self.book_details.reset_info()
self.library_view.model().count_changed()
self.iactions['Fetch News'].database_changed(db)
prefs['library_path'] = self.library_path
self.iactions['Choose Library'].library_used(self.library_view.model().db)
db = self.library_view.model().db
for action in self.iactions.values():
action.library_changed(db)
self.set_window_title()
def set_window_title(self):
self.setWindowTitle(__appname__ + u' - ||%s||'%self.iactions['Choose Library'].library_name())
def location_selected(self, location):