mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix #9011: Incorrect book total next to restricted view drop-down - seems random
This commit is contained in:
parent
46a5105fb4
commit
0c01e48d09
@ -867,11 +867,6 @@ class BooksModel(QAbstractTableModel): # {{{
|
|||||||
self.dataChanged.emit(index, index)
|
self.dataChanged.emit(index, index)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def set_search_restriction(self, s):
|
|
||||||
self.db.data.set_search_restriction(s)
|
|
||||||
self.search('')
|
|
||||||
return self.rowCount(None)
|
|
||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
class OnDeviceSearch(SearchQueryParser): # {{{
|
class OnDeviceSearch(SearchQueryParser): # {{{
|
||||||
@ -1341,8 +1336,5 @@ class DeviceBooksModel(BooksModel): # {{{
|
|||||||
if prefs['manage_device_metadata']=='on_connect':
|
if prefs['manage_device_metadata']=='on_connect':
|
||||||
self.editable = []
|
self.editable = []
|
||||||
|
|
||||||
def set_search_restriction(self, s):
|
|
||||||
pass
|
|
||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
@ -11,26 +11,13 @@ class SearchRestrictionMixin(object):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.search_restriction.initialize(help_text=_('Restrict to'))
|
self.search_restriction.initialize(help_text=_('Restrict to'))
|
||||||
self.search_restriction.activated[int].connect(self.apply_search_restriction)
|
self.search_restriction.activated[int].connect(self.apply_search_restriction)
|
||||||
self.library_view.model().count_changed_signal.connect(self.restriction_count_changed)
|
self.library_view.model().count_changed_signal.connect(self.set_number_of_books_shown)
|
||||||
self.search_restriction.setSizeAdjustPolicy(self.search_restriction.AdjustToMinimumContentsLengthWithIcon)
|
self.search_restriction.setSizeAdjustPolicy(
|
||||||
|
self.search_restriction.AdjustToMinimumContentsLengthWithIcon)
|
||||||
self.search_restriction.setMinimumContentsLength(10)
|
self.search_restriction.setMinimumContentsLength(10)
|
||||||
self.search_restriction.setStatusTip(self.search_restriction.toolTip())
|
self.search_restriction.setStatusTip(self.search_restriction.toolTip())
|
||||||
self.search_count.setText(_("(all books)"))
|
self.search_count.setText(_("(all books)"))
|
||||||
|
|
||||||
'''
|
|
||||||
Adding and deleting books while restricted creates a complexity. When added,
|
|
||||||
they are displayed regardless of whether they match a search restriction.
|
|
||||||
However, if they do not, they are removed at the next search. The counts
|
|
||||||
must take this behavior into effect.
|
|
||||||
'''
|
|
||||||
|
|
||||||
def restriction_count_changed(self, c):
|
|
||||||
self.restriction_count_of_books_in_view += \
|
|
||||||
c - self.restriction_count_of_books_in_library
|
|
||||||
self.restriction_count_of_books_in_library = c
|
|
||||||
if self.restriction_in_effect:
|
|
||||||
self.set_number_of_books_shown()
|
|
||||||
|
|
||||||
def apply_named_search_restriction(self, name):
|
def apply_named_search_restriction(self, name):
|
||||||
if not name:
|
if not name:
|
||||||
r = 0
|
r = 0
|
||||||
@ -44,13 +31,10 @@ class SearchRestrictionMixin(object):
|
|||||||
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 != '':
|
||||||
self.restriction_in_effect = True
|
|
||||||
restriction = 'search:"%s"'%(r)
|
restriction = 'search:"%s"'%(r)
|
||||||
else:
|
else:
|
||||||
self.restriction_in_effect = False
|
|
||||||
restriction = ''
|
restriction = ''
|
||||||
self.restriction_count_of_books_in_view = \
|
self.library_view.model().db.data.set_search_restriction(restriction)
|
||||||
self.library_view.model().set_search_restriction(restriction)
|
|
||||||
self.search.clear()
|
self.search.clear()
|
||||||
self.saved_search.clear()
|
self.saved_search.clear()
|
||||||
self.tags_view.set_search_restriction(restriction)
|
self.tags_view.set_search_restriction(restriction)
|
||||||
@ -58,9 +42,12 @@ class SearchRestrictionMixin(object):
|
|||||||
self.current_view().setFocus(Qt.OtherFocusReason)
|
self.current_view().setFocus(Qt.OtherFocusReason)
|
||||||
|
|
||||||
def set_number_of_books_shown(self):
|
def set_number_of_books_shown(self):
|
||||||
if self.current_view() == self.library_view and self.restriction_in_effect:
|
db = self.library_view.model().db
|
||||||
t = _("({0} of {1})").format(self.current_view().row_count(),
|
if self.current_view() == self.library_view and db is not None and \
|
||||||
self.restriction_count_of_books_in_view)
|
db.data.search_restriction_applied():
|
||||||
|
rows = self.current_view().row_count()
|
||||||
|
rbc = max(rows, db.data.get_search_restriction_book_count())
|
||||||
|
t = _("({0} of {1})").format(rows, rbc)
|
||||||
self.search_count.setStyleSheet \
|
self.search_count.setStyleSheet \
|
||||||
('QLabel { border-radius: 8px; background-color: yellow; }')
|
('QLabel { border-radius: 8px; background-color: yellow; }')
|
||||||
else: # No restriction or not library view
|
else: # No restriction or not library view
|
||||||
|
@ -166,10 +166,6 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, EmailMixin, # {{{
|
|||||||
EmailMixin.__init__(self)
|
EmailMixin.__init__(self)
|
||||||
DeviceMixin.__init__(self)
|
DeviceMixin.__init__(self)
|
||||||
|
|
||||||
self.restriction_count_of_books_in_view = 0
|
|
||||||
self.restriction_count_of_books_in_library = 0
|
|
||||||
self.restriction_in_effect = False
|
|
||||||
|
|
||||||
self.progress_indicator = ProgressIndicator(self)
|
self.progress_indicator = ProgressIndicator(self)
|
||||||
self.progress_indicator.pos = (0, 20)
|
self.progress_indicator.pos = (0, 20)
|
||||||
self.verbose = opts.verbose
|
self.verbose = opts.verbose
|
||||||
|
@ -181,6 +181,7 @@ class ResultCache(SearchQueryParser): # {{{
|
|||||||
self._map = self._map_filtered = []
|
self._map = self._map_filtered = []
|
||||||
self.first_sort = True
|
self.first_sort = True
|
||||||
self.search_restriction = ''
|
self.search_restriction = ''
|
||||||
|
self.search_restriction_book_count = 0
|
||||||
self.field_metadata = field_metadata
|
self.field_metadata = field_metadata
|
||||||
self.all_search_locations = field_metadata.get_search_terms()
|
self.all_search_locations = field_metadata.get_search_terms()
|
||||||
SearchQueryParser.__init__(self, self.all_search_locations, optimize=True)
|
SearchQueryParser.__init__(self, self.all_search_locations, optimize=True)
|
||||||
@ -618,12 +619,14 @@ class ResultCache(SearchQueryParser): # {{{
|
|||||||
return matches
|
return matches
|
||||||
|
|
||||||
def search(self, query, return_matches=False):
|
def search(self, query, return_matches=False):
|
||||||
ans = self.search_getting_ids(query, self.search_restriction)
|
ans = self.search_getting_ids(query, self.search_restriction,
|
||||||
|
set_restriction_count=True)
|
||||||
if return_matches:
|
if return_matches:
|
||||||
return ans
|
return ans
|
||||||
self._map_filtered = ans
|
self._map_filtered = ans
|
||||||
|
|
||||||
def search_getting_ids(self, query, search_restriction):
|
def search_getting_ids(self, query, search_restriction,
|
||||||
|
set_restriction_count=False):
|
||||||
q = ''
|
q = ''
|
||||||
if not query or not query.strip():
|
if not query or not query.strip():
|
||||||
q = search_restriction
|
q = search_restriction
|
||||||
@ -632,16 +635,27 @@ class ResultCache(SearchQueryParser): # {{{
|
|||||||
if search_restriction:
|
if search_restriction:
|
||||||
q = u'%s (%s)' % (search_restriction, query)
|
q = u'%s (%s)' % (search_restriction, query)
|
||||||
if not q:
|
if not q:
|
||||||
|
if set_restriction_count:
|
||||||
|
self.search_restriction_book_count = len(self._map)
|
||||||
return list(self._map)
|
return list(self._map)
|
||||||
matches = self.parse(q)
|
matches = self.parse(q)
|
||||||
tmap = list(itertools.repeat(False, len(self._data)))
|
tmap = list(itertools.repeat(False, len(self._data)))
|
||||||
for x in matches:
|
for x in matches:
|
||||||
tmap[x] = True
|
tmap[x] = True
|
||||||
return [x for x in self._map if tmap[x]]
|
rv = [x for x in self._map if tmap[x]]
|
||||||
|
if set_restriction_count and q == search_restriction:
|
||||||
|
self.search_restriction_book_count = len(rv)
|
||||||
|
return rv
|
||||||
|
|
||||||
def set_search_restriction(self, s):
|
def set_search_restriction(self, s):
|
||||||
self.search_restriction = s
|
self.search_restriction = s
|
||||||
|
|
||||||
|
def search_restriction_applied(self):
|
||||||
|
return bool(self.search_restriction)
|
||||||
|
|
||||||
|
def get_search_restriction_book_count(self):
|
||||||
|
return self.search_restriction_book_count
|
||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
def remove(self, id):
|
def remove(self, id):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user