diff --git a/src/calibre/gui2/actions/store.py b/src/calibre/gui2/actions/store.py index 1989250bc8..db505cf590 100644 --- a/src/calibre/gui2/actions/store.py +++ b/src/calibre/gui2/actions/store.py @@ -26,16 +26,51 @@ 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() diff --git a/src/calibre/gui2/library/models.py b/src/calibre/gui2/library/models.py index dd5082c27f..fc1117167d 100644 --- a/src/calibre/gui2/library/models.py +++ b/src/calibre/gui2/library/models.py @@ -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) diff --git a/src/calibre/gui2/store/search/search.py b/src/calibre/gui2/store/search/search.py index 62e4e97f11..f7e8c88cd9 100644 --- a/src/calibre/gui2/store/search/search.py +++ b/src/calibre/gui2/store/search/search.py @@ -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() @@ -252,4 +255,9 @@ class SearchDialog(QDialog, Ui_Dialog): self.search_pool.abort() self.cache_pool.abort() self.save_state() + + def exec_(self): + if unicode(self.search_edit.text()).strip(): + self.do_search() + return QDialog.exec_(self)