Store: Search selected book's title and author. Put stores into sub menu.

This commit is contained in:
John Schember 2011-05-11 20:10:00 -04:00
parent dd38b80fbc
commit 587a5dfde5
3 changed files with 52 additions and 6 deletions

View File

@ -26,17 +26,52 @@ class StoreAction(InterfaceAction):
def load_menu(self):
self.store_menu.clear()
self.store_menu.addAction(_('Search'), self.search)
self.store_menu.addAction(_('Search Author'), self.search_author)
self.store_menu.addAction(_('Search Title'), self.search_title)
self.store_menu.addSeparator()
self.store_list_menu = self.store_menu.addMenu(_('Stores'))
for n, p in sorted(self.gui.istores.items(), key=lambda x: x[0].lower()):
self.store_menu.addAction(n, partial(self.open_store, p))
self.store_list_menu.addAction(n, partial(self.open_store, p))
self.qaction.setMenu(self.store_menu)
def search(self):
def search(self, query=''):
self.show_disclaimer()
from calibre.gui2.store.search.search import SearchDialog
sd = SearchDialog(self.gui.istores, self.gui)
sd = SearchDialog(self.gui.istores, self.gui, query)
sd.exec_()
def search_author(self):
rows = self.gui.current_view().selectionModel().selectedRows()
if not rows or len(rows) == 0:
return
row = rows[0].row()
author = ''
if self.gui.current_view() is self.gui.library_view:
author = self.gui.library_view.model().authors(row)
else:
mi = self.gui.current_view().model().get_book_display_info(row)
author = ' & '.join(mi.authors)
query = 'author:"%s"' % author
self.search(query)
def search_title(self):
rows = self.gui.current_view().selectionModel().selectedRows()
if not rows or len(rows) == 0:
return
row = rows[0].row()
title = ''
if self.gui.current_view() is self.gui.library_view:
title = self.gui.library_view.model().title(row)
else:
mi = self.gui.current_view().model().get_book_display_info(row)
title = mi.title
query = 'title:"%s"' % title
self.search(query)
def open_store(self, store_plugin):
self.show_disclaimer()
store_plugin.open(self.gui)

View File

@ -506,6 +506,9 @@ class BooksModel(QAbstractTableModel): # {{{
def id(self, row):
return self.db.id(getattr(row, 'row', lambda:row)())
def authors(self, row_number):
return self.db.authors(row_number)
def title(self, row_number):
return self.db.title(row_number)

View File

@ -23,8 +23,8 @@ TIMEOUT = 75 # seconds
class SearchDialog(QDialog, Ui_Dialog):
def __init__(self, istores, *args):
QDialog.__init__(self, *args)
def __init__(self, istores, parent=None, query=''):
QDialog.__init__(self, parent)
self.setupUi(self)
self.config = JSONConfig('store/search')
@ -54,6 +54,9 @@ class SearchDialog(QDialog, Ui_Dialog):
setattr(self, 'store_check_' + x, cbox)
stores_group_layout.addStretch()
# Set the search query
self.search_edit.setText(query)
# Create and add the progress indicator
self.pi = ProgressIndicator(self, 24)
self.top_layout.addWidget(self.pi)
@ -93,7 +96,7 @@ class SearchDialog(QDialog, Ui_Dialog):
# Store / Formats
self.results_view.setColumnWidth(4, int(total*.25))
def do_search(self, checked=False):
def do_search(self):
# Stop all running threads.
self.checker.stop()
self.search_pool.abort()
@ -253,3 +256,8 @@ class SearchDialog(QDialog, Ui_Dialog):
self.cache_pool.abort()
self.save_state()
def exec_(self):
if unicode(self.search_edit.text()).strip():
self.do_search()
return QDialog.exec_(self)