Fix restriction count display on main UI.

This commit is contained in:
Charles Haley 2010-06-06 09:59:15 +01:00
parent fa6aa4be3c
commit eb599d569f
4 changed files with 27 additions and 9 deletions

View File

@ -214,19 +214,20 @@ class BooksModel(QAbstractTableModel): # {{{
self.count_changed()
def search(self, text, refinement, reset=True):
initial_rowcount = self.rowCount(None)
try:
self.db.search(text)
except ParseException:
self.searched.emit(False)
return
self.last_search = text
final_rowcount = self.rowCount(None)
if reset:
self.clear_caches()
self.reset()
if self.last_search:
if self.last_search or initial_rowcount != final_rowcount:
self.searched.emit(True)
def sort(self, col, order, reset=True):
if not self.db:
return

View File

@ -99,6 +99,9 @@ class SearchBox2(QComboBox):
def clear_to_help(self):
self._in_a_search = False
self.setEditText(self.help_text)
if self.timer is not None: # Turn off any timers that got started in setEditText
self.killTimer(self.timer)
self.timer = None
self.line_edit.home(False)
self.help_state = True
self.line_edit.setStyleSheet(

View File

@ -76,8 +76,6 @@ class TagsView(QTreeView): # {{{
self.search_restriction = 'search:"%s"' % unicode(s).strip()
self.model().set_search_restriction(self.search_restriction)
self.restriction_set.emit(self.search_restriction)
self.recount() # Must happen after the emission of the restriction_set signal
self.tags_marked.emit(self._model.tokens(), self.match_all)
def mouseReleaseEvent(self, event):
# Swallow everything except leftButton so context menus work correctly

View File

@ -547,8 +547,7 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
self.connect(self.edit_categories, SIGNAL('clicked()'), self.do_user_categories_edit)
self.tags_view.set_database(db, self.tag_match, self.popularity, self.search_restriction)
self.tags_view.tags_marked.connect(self.search.search_from_tags)
for x in (self.saved_search.clear_to_help, self.mark_restriction_set):
self.tags_view.restriction_set.connect(x)
self.tags_view.restriction_set.connect(self.mark_restriction_set)
self.tags_view.tags_marked.connect(self.saved_search.clear_to_help)
self.tags_view.tag_list_edit.connect(self.do_tags_list_edit)
self.tags_view.user_category_edit.connect(self.do_user_categories_edit)
@ -866,15 +865,29 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
def mark_restriction_set(self, r):
self.restriction_in_effect = False if r is None or not r else True
# Set the count of books to -1 so that the next search knows to capture
# the count
self.restriction_count_of_books_in_view = -1
self.saved_search.clear_to_help()
# Force a null search so that the restriction change is taken into
# account. As a side effect, this will clear the search box to empty
self.search.set_search_string('')
def set_number_of_books_shown(self, compute_count):
if self.current_view() == self.library_view and self.restriction_in_effect:
if compute_count:
self.restriction_count_of_books_in_view = self.current_view().row_count()
# tell the tag browser that counts might have changed
self.tags_view.recount()
t = _("({0} of {1})").format(self.current_view().row_count(),
self.restriction_count_of_books_in_view)
self.search_count.setStyleSheet('QLabel { border-radius: 8px; background-color: yellow; }')
else: # No restriction or not library view
if self.current_view() == self.library_view and compute_count:
# set the count to turn off future recounts
self.restriction_count_of_books_in_view = self.current_view().row_count()
# tell the tag browser that counts might have changed
self.tags_view.recount()
if not self.search.in_a_search():
t = _("(all books)")
else:
@ -884,18 +897,21 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
self.search_count.setText(t)
def search_box_cleared(self):
self.set_number_of_books_shown(compute_count=True)
self.set_number_of_books_shown(compute_count=False)
self.tags_view.clear()
self.saved_search.clear_to_help()
def search_clear(self):
self.set_number_of_books_shown(compute_count=True)
self.set_number_of_books_shown(compute_count=False)
self.search.clear()
def search_done(self, view, ok):
if view is self.current_view():
self.search.search_done(ok)
self.set_number_of_books_shown(compute_count=False)
if self.restriction_count_of_books_in_view < 0:
self.set_number_of_books_shown(compute_count=True)
else:
self.set_number_of_books_shown(compute_count=False)
def sync_cf_to_listview(self, current, previous):
if self.cover_flow_sync_flag and self.cover_flow.isVisible() and \