Fixed bug #5477. Also fixed some oddities when searching while a device is connected.

This commit is contained in:
Charles Haley 2010-05-07 13:48:14 +01:00
parent f604ee58a4
commit 35e9d8d387
2 changed files with 16 additions and 8 deletions

View File

@ -74,6 +74,7 @@ class SearchBox2(QComboBox):
self.setMaxCount(self.MAX_COUNT) self.setMaxCount(self.MAX_COUNT)
self.setSizeAdjustPolicy(self.AdjustToMinimumContentsLengthWithIcon) self.setSizeAdjustPolicy(self.AdjustToMinimumContentsLengthWithIcon)
self.setMinimumContentsLength(25) self.setMinimumContentsLength(25)
self._in_a_search = False
def initialize(self, opt_name, colorize=False, def initialize(self, opt_name, colorize=False,
help_text=_('Search')): help_text=_('Search')):
@ -93,6 +94,7 @@ class SearchBox2(QComboBox):
self.help_state = False self.help_state = False
def clear_to_help(self): def clear_to_help(self):
self._in_a_search = False
self.setEditText(self.help_text) self.setEditText(self.help_text)
self.line_edit.home(False) self.line_edit.home(False)
self.help_state = True self.help_state = True
@ -111,6 +113,7 @@ class SearchBox2(QComboBox):
def search_done(self, ok): def search_done(self, ok):
if not unicode(self.currentText()).strip(): if not unicode(self.currentText()).strip():
return self.clear_to_help() return self.clear_to_help()
self._in_a_search = ok
col = 'rgba(0,255,0,20%)' if ok else 'rgb(255,0,0,20%)' col = 'rgba(0,255,0,20%)' if ok else 'rgb(255,0,0,20%)'
if not self.colorize: if not self.colorize:
col = self.normal_background col = self.normal_background
@ -184,6 +187,8 @@ class SearchBox2(QComboBox):
def search_as_you_type(self, enabled): def search_as_you_type(self, enabled):
self.as_you_type = enabled self.as_you_type = enabled
def in_a_search(self):
return self._in_a_search
class SavedSearchBox(QComboBox): class SavedSearchBox(QComboBox):

View File

@ -835,20 +835,20 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
self.restriction_count_of_books_in_view += c - self.restriction_count_of_books_in_library self.restriction_count_of_books_in_view += c - self.restriction_count_of_books_in_library
self.restriction_count_of_books_in_library = c self.restriction_count_of_books_in_library = c
if self.restriction_in_effect: if self.restriction_in_effect:
self.set_number_of_books_shown(all='not used', compute_count=False) self.set_number_of_books_shown(compute_count=False)
def mark_restriction_set(self, r): def mark_restriction_set(self, r):
self.restriction_in_effect = False if r is None or not r else True self.restriction_in_effect = False if r is None or not r else True
def set_number_of_books_shown(self, all, compute_count): def set_number_of_books_shown(self, compute_count):
if self.restriction_in_effect: if self.current_view() == self.library_view and self.restriction_in_effect:
if compute_count: if compute_count:
self.restriction_count_of_books_in_view = self.current_view().row_count() self.restriction_count_of_books_in_view = self.current_view().row_count()
t = _("({0} of {1})").format(self.current_view().row_count(), t = _("({0} of {1})").format(self.current_view().row_count(),
self.restriction_count_of_books_in_view) self.restriction_count_of_books_in_view)
self.search_count.setStyleSheet('QLabel { border-radius: 8px; background-color: yellow; }') self.search_count.setStyleSheet('QLabel { border-radius: 8px; background-color: yellow; }')
else: # No restriction else: # No restriction or not library view
if all == 'yes': if not self.search.in_a_search():
t = _("(all books)") t = _("(all books)")
else: else:
t = _("({0} of all)").format(self.current_view().row_count()) t = _("({0} of all)").format(self.current_view().row_count())
@ -857,18 +857,18 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
self.search_count.setText(t) self.search_count.setText(t)
def search_box_cleared(self): def search_box_cleared(self):
self.set_number_of_books_shown(all='yes', compute_count=True) self.set_number_of_books_shown(compute_count=True)
self.tags_view.clear() self.tags_view.clear()
self.saved_search.clear_to_help() self.saved_search.clear_to_help()
def search_clear(self): def search_clear(self):
self.set_number_of_books_shown(all='yes', compute_count=True) self.set_number_of_books_shown(compute_count=True)
self.search.clear() self.search.clear()
def search_done(self, view, ok): def search_done(self, view, ok):
if view is self.current_view(): if view is self.current_view():
self.set_number_of_books_shown(all='no', compute_count=False)
self.search.search_done(ok) self.search.search_done(ok)
self.set_number_of_books_shown(compute_count=False)
def sync_cf_to_listview(self, current, previous): def sync_cf_to_listview(self, current, previous):
if self.cover_flow_sync_flag and self.cover_flow.isVisible() and \ if self.cover_flow_sync_flag and self.cover_flow.isVisible() and \
@ -2297,6 +2297,7 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
self.view_menu.actions()[1].setEnabled(True) self.view_menu.actions()[1].setEnabled(True)
self.action_open_containing_folder.setEnabled(True) self.action_open_containing_folder.setEnabled(True)
self.action_sync.setEnabled(True) self.action_sync.setEnabled(True)
self.search_restriction.setEnabled(True)
for action in list(self.delete_menu.actions())[1:]: for action in list(self.delete_menu.actions())[1:]:
action.setEnabled(True) action.setEnabled(True)
else: else:
@ -2306,8 +2307,10 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
self.view_menu.actions()[1].setEnabled(False) self.view_menu.actions()[1].setEnabled(False)
self.action_open_containing_folder.setEnabled(False) self.action_open_containing_folder.setEnabled(False)
self.action_sync.setEnabled(False) self.action_sync.setEnabled(False)
self.search_restriction.setEnabled(False)
for action in list(self.delete_menu.actions())[1:]: for action in list(self.delete_menu.actions())[1:]:
action.setEnabled(False) action.setEnabled(False)
self.set_number_of_books_shown(compute_count=False)
def device_job_exception(self, job): def device_job_exception(self, job):