Fix problems with restrictions when changing libraries:

- restrictions box is not reloaded
- counts are not correct

Add tweak to set restriction at calibre startup
This commit is contained in:
Charles Haley 2010-08-17 10:30:32 +01:00
parent c917f95c2c
commit 83fc6c54f6
4 changed files with 26 additions and 15 deletions

View File

@ -80,3 +80,8 @@ title_series_sorting = 'library_order'
# strictly_alphabetic, it would remain "The Client". # strictly_alphabetic, it would remain "The Client".
save_template_title_series_sorting = 'library_order' save_template_title_series_sorting = 'library_order'
# Specify a restriction to apply when calibre starts or when change library is
# used. Provide the name of a saved search. It is ignored if the saved search
# does not exist in the library being opened. The value '' means no restriction.
restrict_at_startup = ''

View File

@ -382,8 +382,7 @@ class SearchBoxMixin(object):
class SavedSearchBoxMixin(object): class SavedSearchBoxMixin(object):
def __init__(self, db): def __init__(self):
self.db = db
self.connect(self.saved_search, SIGNAL('changed()'), self.saved_searches_changed) self.connect(self.saved_search, SIGNAL('changed()'), self.saved_searches_changed)
self.saved_searches_changed() self.saved_searches_changed()
self.connect(self.clear_button, SIGNAL('clicked()'), self.saved_search.clear_to_help) self.connect(self.clear_button, SIGNAL('clicked()'), self.saved_search.clear_to_help)
@ -402,10 +401,6 @@ class SavedSearchBoxMixin(object):
b = getattr(self, x+'_search_button') b = getattr(self, x+'_search_button')
b.setStatusTip(b.toolTip()) b.setStatusTip(b.toolTip())
def set_database(self, db):
self.db = db
self.saved_searches_changed()
def saved_searches_changed(self): def saved_searches_changed(self):
p = saved_searches().names() p = saved_searches().names()
p.sort() p.sort()
@ -415,13 +410,8 @@ class SavedSearchBoxMixin(object):
self.tags_view.recount() self.tags_view.recount()
for s in p: for s in p:
self.search_restriction.addItem(s) self.search_restriction.addItem(s)
if t: if t: # redo the search restriction if there was one
if t in p: # redo the current restriction, if there was one self.apply_named_search_restriction(t)
self.search_restriction.setCurrentIndex(self.search_restriction.findText(t))
# self.tags_view.set_search_restriction(t)
else:
self.search_restriction.setCurrentIndex(0)
self.apply_search_restriction('')
def do_saved_search_edit(self, search): def do_saved_search_edit(self, search):
d = SavedSearchEditor(self, search) d = SavedSearchEditor(self, search)

View File

@ -29,6 +29,16 @@ class SearchRestrictionMixin(object):
if self.restriction_in_effect: if self.restriction_in_effect:
self.set_number_of_books_shown() self.set_number_of_books_shown()
def apply_named_search_restriction(self, name):
if not name:
r = 0
else:
r = self.search_restriction.findText(name)
if r < 0:
r = 0
self.search_restriction.setCurrentIndex(r)
self.apply_search_restriction(r)
def apply_search_restriction(self, i): def apply_search_restriction(self, i):
r = unicode(self.search_restriction.currentText()) r = unicode(self.search_restriction.currentText())
if r is not None and r != '': if r is not None and r != '':

View File

@ -21,7 +21,7 @@ from PyQt4.Qt import Qt, SIGNAL, QTimer, \
from calibre import prints from calibre import prints
from calibre.constants import __appname__, isosx from calibre.constants import __appname__, isosx
from calibre.ptempfile import PersistentTemporaryFile from calibre.ptempfile import PersistentTemporaryFile
from calibre.utils.config import prefs, dynamic from calibre.utils.config import prefs, dynamic, tweaks
from calibre.utils.ipc.server import Server from calibre.utils.ipc.server import Server
from calibre.library.database2 import LibraryDatabase2 from calibre.library.database2 import LibraryDatabase2
from calibre.customize.ui import interface_actions from calibre.customize.ui import interface_actions
@ -195,7 +195,7 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, # {{{
UpdateMixin.__init__(self, opts) UpdateMixin.__init__(self, opts)
####################### Search boxes ######################## ####################### Search boxes ########################
SavedSearchBoxMixin.__init__(self, db) SavedSearchBoxMixin.__init__(self)
SearchBoxMixin.__init__(self) SearchBoxMixin.__init__(self)
####################### Library view ######################## ####################### Library view ########################
@ -230,6 +230,8 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, # {{{
######################### Search Restriction ########################## ######################### Search Restriction ##########################
SearchRestrictionMixin.__init__(self) SearchRestrictionMixin.__init__(self)
if tweaks['restrict_at_startup']:
self.apply_named_search_restriction(tweaks['restrict_at_startup'])
########################### Cover Flow ################################ ########################### Cover Flow ################################
@ -371,6 +373,10 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, # {{{
for action in self.iactions.values(): for action in self.iactions.values():
action.library_changed(db) action.library_changed(db)
self.set_window_title() self.set_window_title()
self.apply_named_search_restriction('') # reset restriction to null
self.saved_searches_changed() # reload the search restrictions combo box
if tweaks['restrict_at_startup']:
self.apply_named_search_restriction(tweaks['restrict_at_startup'])
def set_window_title(self): def set_window_title(self):
self.setWindowTitle(__appname__ + u' - ||%s||'%self.iactions['Choose Library'].library_name()) self.setWindowTitle(__appname__ + u' - ||%s||'%self.iactions['Choose Library'].library_name())