mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 18:24:30 -04:00
Enhancement #1929322: Move setting for Virtual library to apply when the current library is opened
This commit is contained in:
parent
259f1c2471
commit
479e9a46ec
@ -200,6 +200,17 @@ class BackupStatus(QDialog): # {{{
|
|||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
current_change_library_action_pi = None
|
||||||
|
|
||||||
|
|
||||||
|
def set_change_library_action_plugin(pi):
|
||||||
|
global current_change_library_action_pi
|
||||||
|
current_change_library_action_pi = pi
|
||||||
|
|
||||||
|
|
||||||
|
def get_change_library_action_plugin():
|
||||||
|
return current_change_library_action_pi
|
||||||
|
|
||||||
|
|
||||||
class ChooseLibraryAction(InterfaceAction):
|
class ChooseLibraryAction(InterfaceAction):
|
||||||
|
|
||||||
@ -210,6 +221,7 @@ class ChooseLibraryAction(InterfaceAction):
|
|||||||
action_add_menu = True
|
action_add_menu = True
|
||||||
action_menu_clone_qaction = _('Switch/create library')
|
action_menu_clone_qaction = _('Switch/create library')
|
||||||
restore_view_state = pyqtSignal(object)
|
restore_view_state = pyqtSignal(object)
|
||||||
|
rebuild_change_library_menus = pyqtSignal()
|
||||||
|
|
||||||
def genesis(self):
|
def genesis(self):
|
||||||
self.prev_lname = self.last_lname = ''
|
self.prev_lname = self.last_lname = ''
|
||||||
@ -242,6 +254,10 @@ class ChooseLibraryAction(InterfaceAction):
|
|||||||
self.choose_menu.addAction(ac)
|
self.choose_menu.addAction(ac)
|
||||||
self.delete_menu = QMenu(_('Remove library'))
|
self.delete_menu = QMenu(_('Remove library'))
|
||||||
self.delete_menu_action = self.choose_menu.addMenu(self.delete_menu)
|
self.delete_menu_action = self.choose_menu.addMenu(self.delete_menu)
|
||||||
|
self.vl_to_apply_menu = QMenu('waiting ...')
|
||||||
|
self.vl_to_apply_action = self.choose_menu.addMenu(self.vl_to_apply_menu)
|
||||||
|
self.rebuild_change_library_menus.connect(self.build_menus,
|
||||||
|
type=Qt.ConnectionType.QueuedConnection)
|
||||||
self.choose_menu.addAction(self.action_exim)
|
self.choose_menu.addAction(self.action_exim)
|
||||||
else:
|
else:
|
||||||
self.choose_menu.addAction(ac)
|
self.choose_menu.addAction(ac)
|
||||||
@ -352,6 +368,7 @@ class ChooseLibraryAction(InterfaceAction):
|
|||||||
|
|
||||||
def initialization_complete(self):
|
def initialization_complete(self):
|
||||||
self.library_changed(self.gui.library_view.model().db)
|
self.library_changed(self.gui.library_view.model().db)
|
||||||
|
set_change_library_action_plugin(self)
|
||||||
|
|
||||||
def switch_to_previous_library(self):
|
def switch_to_previous_library(self):
|
||||||
db = self.gui.library_view.model().db
|
db = self.gui.library_view.model().db
|
||||||
@ -366,6 +383,8 @@ class ChooseLibraryAction(InterfaceAction):
|
|||||||
if os.environ.get('CALIBRE_OVERRIDE_DATABASE_PATH', None):
|
if os.environ.get('CALIBRE_OVERRIDE_DATABASE_PATH', None):
|
||||||
return
|
return
|
||||||
db = self.gui.library_view.model().db
|
db = self.gui.library_view.model().db
|
||||||
|
lname = self.stats.library_used(db)
|
||||||
|
self.vl_to_apply_action.setText(_('Apply virtual library when %s is opened') % lname)
|
||||||
locations = list(self.stats.locations(db))
|
locations = list(self.stats.locations(db))
|
||||||
|
|
||||||
for ac in self.switch_actions:
|
for ac in self.switch_actions:
|
||||||
@ -416,10 +435,29 @@ class ChooseLibraryAction(InterfaceAction):
|
|||||||
self.gui.location_manager.set_switch_actions(quick_actions,
|
self.gui.location_manager.set_switch_actions(quick_actions,
|
||||||
rename_actions, delete_actions, qs_actions,
|
rename_actions, delete_actions, qs_actions,
|
||||||
self.action_choose)
|
self.action_choose)
|
||||||
|
# VL at startup
|
||||||
|
self.vl_to_apply_menu.clear()
|
||||||
|
restrictions = sorted(db.prefs['virtual_libraries'], key=sort_key)
|
||||||
|
# check that the virtual library choice still exists
|
||||||
|
vl_at_startup = db.prefs['virtual_lib_on_startup']
|
||||||
|
if vl_at_startup and vl_at_startup not in restrictions:
|
||||||
|
vl_at_startup = db.prefs['virtual_lib_on_startup'] = ''
|
||||||
|
restrictions.insert(0, '')
|
||||||
|
for vl in restrictions:
|
||||||
|
if vl == vl_at_startup:
|
||||||
|
self.vl_to_apply_menu.addAction(QIcon(I('ok.png')), vl if vl else _('No virtual library'),
|
||||||
|
Dispatcher(partial(self.change_vl_at_startup_requested, vl)))
|
||||||
|
else:
|
||||||
|
self.vl_to_apply_menu.addAction(vl if vl else _('No virtual library'),
|
||||||
|
Dispatcher(partial(self.change_vl_at_startup_requested, vl)))
|
||||||
# Allow the cloned actions in the OS X global menubar to update
|
# Allow the cloned actions in the OS X global menubar to update
|
||||||
for a in (self.qaction, self.menuless_qaction):
|
for a in (self.qaction, self.menuless_qaction):
|
||||||
a.changed.emit()
|
a.changed.emit()
|
||||||
|
|
||||||
|
def change_vl_at_startup_requested(self, vl):
|
||||||
|
self.gui.library_view.model().db.prefs['virtual_lib_on_startup'] = vl
|
||||||
|
self.build_menus()
|
||||||
|
|
||||||
def location_selected(self, loc):
|
def location_selected(self, loc):
|
||||||
enabled = loc == 'library'
|
enabled = loc == 'library'
|
||||||
self.qaction.setEnabled(enabled)
|
self.qaction.setEnabled(enabled)
|
||||||
|
@ -11,6 +11,7 @@ from functools import partial
|
|||||||
|
|
||||||
from qt.core import Qt, QListWidgetItem
|
from qt.core import Qt, QListWidgetItem
|
||||||
|
|
||||||
|
from calibre.gui2.actions.choose_library import get_change_library_action_plugin
|
||||||
from calibre.gui2.preferences import ConfigWidgetBase, test_widget, Setting
|
from calibre.gui2.preferences import ConfigWidgetBase, test_widget, Setting
|
||||||
from calibre.gui2.preferences.behavior_ui import Ui_Form
|
from calibre.gui2.preferences.behavior_ui import Ui_Form
|
||||||
from calibre.gui2 import config, info_dialog, dynamic, gprefs
|
from calibre.gui2 import config, info_dialog, dynamic, gprefs
|
||||||
@ -102,7 +103,10 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
|||||||
old = config['internally_viewed_formats']
|
old = config['internally_viewed_formats']
|
||||||
if fmts != old:
|
if fmts != old:
|
||||||
config['internally_viewed_formats'] = fmts
|
config['internally_viewed_formats'] = fmts
|
||||||
return ConfigWidgetBase.commit(self)
|
ret = ConfigWidgetBase.commit(self)
|
||||||
|
# Signal a possible change of the VL at startup opt
|
||||||
|
get_change_library_action_plugin().rebuild_change_library_menus.emit()
|
||||||
|
return ret
|
||||||
|
|
||||||
# Internally viewed formats {{{
|
# Internally viewed formats {{{
|
||||||
def internally_viewed_formats_changed(self, *args):
|
def internally_viewed_formats_changed(self, *args):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user