mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Use StoreResult class for returning store results instead of a tuple.
This commit is contained in:
parent
93c2231f26
commit
9b5768e2d1
@ -588,7 +588,7 @@ class StorePlugin(Plugin): # {{{
|
|||||||
author = 'John Schember'
|
author = 'John Schember'
|
||||||
type = _('Stores')
|
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.
|
Open a dialog for displaying the store.
|
||||||
start_item is a refernce unique to 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 max_results: The maximum number of results to return.
|
||||||
:param timeout: The maximum amount of time in seconds to spend download the search results.
|
: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
|
:return: calibre.gui2.store.search_result.SearchResult object
|
||||||
specific and is used in :meth:`open` to open to a specifc place in the store.
|
item_data is plugin specific and is used in :meth:`open` to open to a specifc place in the store.
|
||||||
'''
|
'''
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ from lxml import html
|
|||||||
|
|
||||||
from calibre import browser
|
from calibre import browser
|
||||||
from calibre.customize import StorePlugin
|
from calibre.customize import StorePlugin
|
||||||
|
from calibre.gui2.store.search_result import SearchResult
|
||||||
|
|
||||||
class AmazonKindleStore(StorePlugin):
|
class AmazonKindleStore(StorePlugin):
|
||||||
|
|
||||||
@ -20,9 +21,9 @@ class AmazonKindleStore(StorePlugin):
|
|||||||
|
|
||||||
ASTORE_URL = 'http://astore.amazon.com/josbl0e-20/'
|
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
|
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.setWindowTitle('Amazon Kindle Store')
|
||||||
d = d.exec_()
|
d = d.exec_()
|
||||||
|
|
||||||
@ -47,6 +48,7 @@ class AmazonKindleStore(StorePlugin):
|
|||||||
|
|
||||||
title = ''.join(data.xpath('div[@class="productTitle"]/a/text()'))
|
title = ''.join(data.xpath('div[@class="productTitle"]/a/text()'))
|
||||||
author = ''.join(data.xpath('div[@class="productTitle"]/span[@class="ptBrand"]/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()'))
|
price = ''.join(data.xpath('div[@class="newPrice"]/span/text()'))
|
||||||
|
|
||||||
# We must have an asin otherwise we can't easily reference the
|
# We must have an asin otherwise we can't easily reference the
|
||||||
@ -61,4 +63,12 @@ class AmazonKindleStore(StorePlugin):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
counter -= 1
|
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
|
||||||
|
@ -11,6 +11,7 @@ from lxml import html
|
|||||||
|
|
||||||
from calibre import browser
|
from calibre import browser
|
||||||
from calibre.customize import StorePlugin
|
from calibre.customize import StorePlugin
|
||||||
|
from calibre.gui2.store.search_result import SearchResult
|
||||||
|
|
||||||
class FeedbooksStore(StorePlugin):
|
class FeedbooksStore(StorePlugin):
|
||||||
|
|
||||||
@ -18,9 +19,9 @@ class FeedbooksStore(StorePlugin):
|
|||||||
description = _('Read anywhere.')
|
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
|
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.setWindowTitle('Feedbooks')
|
||||||
d = d.exec_()
|
d = d.exec_()
|
||||||
|
|
||||||
@ -60,4 +61,12 @@ class FeedbooksStore(StorePlugin):
|
|||||||
price = '$0.00'
|
price = '$0.00'
|
||||||
|
|
||||||
counter -= 1
|
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
|
||||||
|
@ -11,6 +11,7 @@ from lxml import html
|
|||||||
|
|
||||||
from calibre import browser
|
from calibre import browser
|
||||||
from calibre.customize import StorePlugin
|
from calibre.customize import StorePlugin
|
||||||
|
from calibre.gui2.store.search_result import SearchResult
|
||||||
|
|
||||||
class GutenbergStore(StorePlugin):
|
class GutenbergStore(StorePlugin):
|
||||||
|
|
||||||
@ -18,9 +19,9 @@ class GutenbergStore(StorePlugin):
|
|||||||
description = _('The first producer of free ebooks.')
|
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
|
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.setWindowTitle('Project Gutenberg')
|
||||||
d = d.exec_()
|
d = d.exec_()
|
||||||
|
|
||||||
@ -55,4 +56,12 @@ class GutenbergStore(StorePlugin):
|
|||||||
price = '$0.00'
|
price = '$0.00'
|
||||||
|
|
||||||
counter -= 1
|
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
|
||||||
|
@ -11,6 +11,7 @@ from lxml import html
|
|||||||
|
|
||||||
from calibre import browser
|
from calibre import browser
|
||||||
from calibre.customize import StorePlugin
|
from calibre.customize import StorePlugin
|
||||||
|
from calibre.gui2.store.search_result import SearchResult
|
||||||
|
|
||||||
class ManyBooksStore(StorePlugin):
|
class ManyBooksStore(StorePlugin):
|
||||||
|
|
||||||
@ -18,9 +19,9 @@ class ManyBooksStore(StorePlugin):
|
|||||||
description = _('The best ebooks at the best price: free!.')
|
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
|
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.setWindowTitle('ManyBooks')
|
||||||
d = d.exec_()
|
d = d.exec_()
|
||||||
|
|
||||||
@ -57,4 +58,12 @@ class ManyBooksStore(StorePlugin):
|
|||||||
price = '$0.00'
|
price = '$0.00'
|
||||||
|
|
||||||
counter -= 1
|
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
|
||||||
|
@ -86,14 +86,8 @@ class SearchDialog(QDialog, Ui_Dialog):
|
|||||||
while not self.results.empty():
|
while not self.results.empty():
|
||||||
res = self.results.get_nowait()
|
res = self.results.get_nowait()
|
||||||
if res:
|
if res:
|
||||||
result = SearchResult()
|
result = res[1]
|
||||||
result.store = res[0]
|
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)
|
self.results_view.model().add_result(result)
|
||||||
|
|
||||||
def open_store(self, index):
|
def open_store(self, index):
|
||||||
@ -120,17 +114,6 @@ class SearchThread(Thread):
|
|||||||
self.results.put((self.store_name, res))
|
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):
|
class Matches(QAbstractItemModel):
|
||||||
|
|
||||||
HEADERS = [_('Cover'), _('Title'), _('Author(s)'), _('Price'), _('Store')]
|
HEADERS = [_('Cover'), _('Title'), _('Author(s)'), _('Price'), _('Store')]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user