From 9b5768e2d1d70072e11f3dc060eac6136b59313f Mon Sep 17 00:00:00 2001 From: John Schember Date: Sat, 26 Feb 2011 15:42:51 -0500 Subject: [PATCH] Use StoreResult class for returning store results instead of a tuple. --- src/calibre/customize/__init__.py | 6 +++--- src/calibre/gui2/store/amazon_plugin.py | 16 +++++++++++++--- src/calibre/gui2/store/feedbooks_plugin.py | 15 ++++++++++++--- src/calibre/gui2/store/gutenberg_plugin.py | 15 ++++++++++++--- src/calibre/gui2/store/manybooks_plugin.py | 15 ++++++++++++--- src/calibre/gui2/store/search.py | 19 +------------------ 6 files changed, 53 insertions(+), 33 deletions(-) diff --git a/src/calibre/customize/__init__.py b/src/calibre/customize/__init__.py index 2c75b40494..c1e19bd543 100644 --- a/src/calibre/customize/__init__.py +++ b/src/calibre/customize/__init__.py @@ -588,7 +588,7 @@ class StorePlugin(Plugin): # {{{ author = 'John Schember' type = _('Stores') - def open(self, gui, parent=None, start_item=None): + def open(self, gui, parent=None, detail_item=None): ''' Open a dialog for displaying the store. start_item is a refernce unique to the store @@ -605,8 +605,8 @@ class StorePlugin(Plugin): # {{{ :param max_results: The maximum number of results to return. :param timeout: The maximum amount of time in seconds to spend download the search results. - :return: A tuple (cover_url, title, author, price, start_item). The start_item is plugin - specific and is used in :meth:`open` to open to a specifc place in the store. + :return: calibre.gui2.store.search_result.SearchResult object + item_data is plugin specific and is used in :meth:`open` to open to a specifc place in the store. ''' raise NotImplementedError() diff --git a/src/calibre/gui2/store/amazon_plugin.py b/src/calibre/gui2/store/amazon_plugin.py index 7a3ba90ccf..d3ab7c8911 100644 --- a/src/calibre/gui2/store/amazon_plugin.py +++ b/src/calibre/gui2/store/amazon_plugin.py @@ -12,6 +12,7 @@ from lxml import html from calibre import browser from calibre.customize import StorePlugin +from calibre.gui2.store.search_result import SearchResult class AmazonKindleStore(StorePlugin): @@ -20,9 +21,9 @@ class AmazonKindleStore(StorePlugin): ASTORE_URL = 'http://astore.amazon.com/josbl0e-20/' - def open(self, gui, parent=None, start_item=None): + def open(self, gui, parent=None, detail_item=None): from calibre.gui2.store.web_store_dialog import WebStoreDialog - d = WebStoreDialog(gui, self.ASTORE_URL, parent, start_item) + d = WebStoreDialog(gui, self.ASTORE_URL, parent, detail_item) d.setWindowTitle('Amazon Kindle Store') d = d.exec_() @@ -47,6 +48,7 @@ class AmazonKindleStore(StorePlugin): title = ''.join(data.xpath('div[@class="productTitle"]/a/text()')) author = ''.join(data.xpath('div[@class="productTitle"]/span[@class="ptBrand"]/text()')) + author = author.split('by')[-1] price = ''.join(data.xpath('div[@class="newPrice"]/span/text()')) # We must have an asin otherwise we can't easily reference the @@ -61,4 +63,12 @@ class AmazonKindleStore(StorePlugin): continue counter -= 1 - yield ('', title.strip(), author.strip(), price.strip(), '/detail/'+asin.strip()) + + s = SearchResult() + s.cover_url = '' + s.title = title.strip() + s.author = author.strip() + s.price = price.strip() + s.detail_item = '/detail/' + asin.strip() + + yield s diff --git a/src/calibre/gui2/store/feedbooks_plugin.py b/src/calibre/gui2/store/feedbooks_plugin.py index e1668a22a3..c9669b94a4 100644 --- a/src/calibre/gui2/store/feedbooks_plugin.py +++ b/src/calibre/gui2/store/feedbooks_plugin.py @@ -11,6 +11,7 @@ from lxml import html from calibre import browser from calibre.customize import StorePlugin +from calibre.gui2.store.search_result import SearchResult class FeedbooksStore(StorePlugin): @@ -18,9 +19,9 @@ class FeedbooksStore(StorePlugin): description = _('Read anywhere.') - def open(self, gui, parent=None, start_item=None): + def open(self, gui, parent=None, detail_item=None): from calibre.gui2.store.web_store_dialog import WebStoreDialog - d = WebStoreDialog(gui, 'http://m.feedbooks.com/', parent, start_item) + d = WebStoreDialog(gui, 'http://m.feedbooks.com/', parent, detail_item) d.setWindowTitle('Feedbooks') d = d.exec_() @@ -60,4 +61,12 @@ class FeedbooksStore(StorePlugin): price = '$0.00' counter -= 1 - yield ('', title.strip(), author.strip(), price.replace(' ', '').strip(), id.strip()) + + s = SearchResult() + s.cover_url = '' + s.title = title.strip() + s.author = author.strip() + s.price = price.replace(' ', '').strip() + s.detail_item = id.strip() + + yield s diff --git a/src/calibre/gui2/store/gutenberg_plugin.py b/src/calibre/gui2/store/gutenberg_plugin.py index 38b9af8012..5d55844180 100644 --- a/src/calibre/gui2/store/gutenberg_plugin.py +++ b/src/calibre/gui2/store/gutenberg_plugin.py @@ -11,6 +11,7 @@ from lxml import html from calibre import browser from calibre.customize import StorePlugin +from calibre.gui2.store.search_result import SearchResult class GutenbergStore(StorePlugin): @@ -18,9 +19,9 @@ class GutenbergStore(StorePlugin): description = _('The first producer of free ebooks.') - def open(self, gui, parent=None, start_item=None): + def open(self, gui, parent=None, detail_item=None): from calibre.gui2.store.web_store_dialog import WebStoreDialog - d = WebStoreDialog(gui, 'http://m.gutenberg.org/', parent, start_item) + d = WebStoreDialog(gui, 'http://m.gutenberg.org/', parent, detail_item) d.setWindowTitle('Project Gutenberg') d = d.exec_() @@ -55,4 +56,12 @@ class GutenbergStore(StorePlugin): price = '$0.00' counter -= 1 - yield ('', title.strip(), author.strip(), price.strip(), '/ebooks/' + id.strip()) + + s = SearchResult() + s.cover_url = '' + s.title = title.strip() + s.author = author.strip() + s.price = price.strip() + s.detail_item = '/ebooks/' + id.strip() + + yield s diff --git a/src/calibre/gui2/store/manybooks_plugin.py b/src/calibre/gui2/store/manybooks_plugin.py index 1ec6eeb500..abb27206a9 100644 --- a/src/calibre/gui2/store/manybooks_plugin.py +++ b/src/calibre/gui2/store/manybooks_plugin.py @@ -11,6 +11,7 @@ from lxml import html from calibre import browser from calibre.customize import StorePlugin +from calibre.gui2.store.search_result import SearchResult class ManyBooksStore(StorePlugin): @@ -18,9 +19,9 @@ class ManyBooksStore(StorePlugin): description = _('The best ebooks at the best price: free!.') - def open(self, gui, parent=None, start_item=None): + def open(self, gui, parent=None, detail_item=None): from calibre.gui2.store.web_store_dialog import WebStoreDialog - d = WebStoreDialog(gui, 'http://manybooks.net/', parent, start_item) + d = WebStoreDialog(gui, 'http://manybooks.net/', parent, detail_item) d.setWindowTitle('ManyBooks') d = d.exec_() @@ -57,4 +58,12 @@ class ManyBooksStore(StorePlugin): price = '$0.00' counter -= 1 - yield ('', title.strip(), author.strip(), price.strip(), '/titles/' + id.strip()) + + s = SearchResult() + s.cover_url = '' + s.title = title.strip() + s.author = author.strip() + s.price = price.strip() + s.detail_item = '/titles/' + id.strip() + + yield s diff --git a/src/calibre/gui2/store/search.py b/src/calibre/gui2/store/search.py index ac6981a25f..5c07984cda 100644 --- a/src/calibre/gui2/store/search.py +++ b/src/calibre/gui2/store/search.py @@ -86,14 +86,8 @@ class SearchDialog(QDialog, Ui_Dialog): while not self.results.empty(): res = self.results.get_nowait() if res: - result = SearchResult() + result = res[1] result.store = res[0] - result.cover_url = res[1][0] - result.title = res[1][1] - result.author = res[1][2] - result.price = res[1][3] - result.item_data = res[1][4] - self.results_view.model().add_result(result) def open_store(self, index): @@ -120,17 +114,6 @@ class SearchThread(Thread): self.results.put((self.store_name, res)) -class SearchResult(object): - - def __init__(self): - self.cover_url = '' - self.title = '' - self.author = '' - self.price = '' - self.store = '' - self.item_data = '' - - class Matches(QAbstractItemModel): HEADERS = [_('Cover'), _('Title'), _('Author(s)'), _('Price'), _('Store')]