mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Add WH Smiths and E-book Shoppe stores to Get Books. Various other minor tweaks to Get Books.
This commit is contained in:
commit
6f4ce0c0bc
@ -623,6 +623,8 @@ class StoreBase(Plugin): # {{{
|
|||||||
headquarters = ''
|
headquarters = ''
|
||||||
# All formats the store distributes ebooks in.
|
# All formats the store distributes ebooks in.
|
||||||
formats = []
|
formats = []
|
||||||
|
# Is this store on an affiliate program?
|
||||||
|
affiliate = False
|
||||||
|
|
||||||
def load_actual_plugin(self, gui):
|
def load_actual_plugin(self, gui):
|
||||||
'''
|
'''
|
||||||
|
@ -1108,9 +1108,9 @@ class StoreAmazonKindleStore(StoreBase):
|
|||||||
description = u'Kindle books from Amazon.'
|
description = u'Kindle books from Amazon.'
|
||||||
actual_plugin = 'calibre.gui2.store.amazon_plugin:AmazonKindleStore'
|
actual_plugin = 'calibre.gui2.store.amazon_plugin:AmazonKindleStore'
|
||||||
|
|
||||||
drm_free_only = False
|
|
||||||
headquarters = 'US'
|
headquarters = 'US'
|
||||||
formats = ['KINDLE']
|
formats = ['KINDLE']
|
||||||
|
affiliate = True
|
||||||
|
|
||||||
class StoreAmazonDEKindleStore(StoreBase):
|
class StoreAmazonDEKindleStore(StoreBase):
|
||||||
name = 'Amazon DE Kindle'
|
name = 'Amazon DE Kindle'
|
||||||
@ -1118,9 +1118,9 @@ class StoreAmazonDEKindleStore(StoreBase):
|
|||||||
description = u'Kindle Bücher von Amazon.'
|
description = u'Kindle Bücher von Amazon.'
|
||||||
actual_plugin = 'calibre.gui2.store.amazon_de_plugin:AmazonDEKindleStore'
|
actual_plugin = 'calibre.gui2.store.amazon_de_plugin:AmazonDEKindleStore'
|
||||||
|
|
||||||
drm_free_only = False
|
|
||||||
headquarters = 'DE'
|
headquarters = 'DE'
|
||||||
formats = ['KINDLE']
|
formats = ['KINDLE']
|
||||||
|
affiliate = True
|
||||||
|
|
||||||
class StoreAmazonUKKindleStore(StoreBase):
|
class StoreAmazonUKKindleStore(StoreBase):
|
||||||
name = 'Amazon UK Kindle'
|
name = 'Amazon UK Kindle'
|
||||||
@ -1128,9 +1128,9 @@ class StoreAmazonUKKindleStore(StoreBase):
|
|||||||
description = u'Kindle books from Amazon\'s UK web site. Also, includes French language ebooks.'
|
description = u'Kindle books from Amazon\'s UK web site. Also, includes French language ebooks.'
|
||||||
actual_plugin = 'calibre.gui2.store.amazon_uk_plugin:AmazonUKKindleStore'
|
actual_plugin = 'calibre.gui2.store.amazon_uk_plugin:AmazonUKKindleStore'
|
||||||
|
|
||||||
drm_free_only = False
|
|
||||||
headquarters = 'UK'
|
headquarters = 'UK'
|
||||||
formats = ['KINDLE']
|
formats = ['KINDLE']
|
||||||
|
affiliate = True
|
||||||
|
|
||||||
class StoreArchiveOrgStore(StoreBase):
|
class StoreArchiveOrgStore(StoreBase):
|
||||||
name = 'Archive.org'
|
name = 'Archive.org'
|
||||||
@ -1155,9 +1155,9 @@ class StoreBNStore(StoreBase):
|
|||||||
description = u'The world\'s largest book seller. As the ultimate destination for book lovers, Barnes & Noble.com offers an incredible array of content.'
|
description = u'The world\'s largest book seller. As the ultimate destination for book lovers, Barnes & Noble.com offers an incredible array of content.'
|
||||||
actual_plugin = 'calibre.gui2.store.bn_plugin:BNStore'
|
actual_plugin = 'calibre.gui2.store.bn_plugin:BNStore'
|
||||||
|
|
||||||
drm_free_only = False
|
|
||||||
headquarters = 'US'
|
headquarters = 'US'
|
||||||
formats = ['NOOK']
|
formats = ['NOOK']
|
||||||
|
affiliate = True
|
||||||
|
|
||||||
class StoreBeamEBooksDEStore(StoreBase):
|
class StoreBeamEBooksDEStore(StoreBase):
|
||||||
name = 'Beam EBooks DE'
|
name = 'Beam EBooks DE'
|
||||||
@ -1168,6 +1168,7 @@ class StoreBeamEBooksDEStore(StoreBase):
|
|||||||
drm_free_only = True
|
drm_free_only = True
|
||||||
headquarters = 'DE'
|
headquarters = 'DE'
|
||||||
formats = ['EPUB', 'MOBI', 'PDF']
|
formats = ['EPUB', 'MOBI', 'PDF']
|
||||||
|
affiliate = True
|
||||||
|
|
||||||
class StoreBeWriteStore(StoreBase):
|
class StoreBeWriteStore(StoreBase):
|
||||||
name = 'BeWrite Books'
|
name = 'BeWrite Books'
|
||||||
@ -1183,18 +1184,18 @@ class StoreDieselEbooksStore(StoreBase):
|
|||||||
description = u'Instant access to over 2.4 million titles from hundreds of publishers including Harlequin, HarperCollins, John Wiley & Sons, McGraw-Hill, Simon & Schuster and Random House.'
|
description = u'Instant access to over 2.4 million titles from hundreds of publishers including Harlequin, HarperCollins, John Wiley & Sons, McGraw-Hill, Simon & Schuster and Random House.'
|
||||||
actual_plugin = 'calibre.gui2.store.diesel_ebooks_plugin:DieselEbooksStore'
|
actual_plugin = 'calibre.gui2.store.diesel_ebooks_plugin:DieselEbooksStore'
|
||||||
|
|
||||||
drm_free_only = False
|
|
||||||
headquarters = 'US'
|
headquarters = 'US'
|
||||||
formats = ['EPUB', 'PDF']
|
formats = ['EPUB', 'PDF']
|
||||||
|
affiliate = True
|
||||||
|
|
||||||
class StoreEbookscomStore(StoreBase):
|
class StoreEbookscomStore(StoreBase):
|
||||||
name = 'eBooks.com'
|
name = 'eBooks.com'
|
||||||
description = u'Sells books in multiple electronic formats in all categories. Technical infrastructure is cutting edge, robust and scalable, with servers in the US and Europe.'
|
description = u'Sells books in multiple electronic formats in all categories. Technical infrastructure is cutting edge, robust and scalable, with servers in the US and Europe.'
|
||||||
actual_plugin = 'calibre.gui2.store.ebooks_com_plugin:EbookscomStore'
|
actual_plugin = 'calibre.gui2.store.ebooks_com_plugin:EbookscomStore'
|
||||||
|
|
||||||
drm_free_only = False
|
|
||||||
headquarters = 'US'
|
headquarters = 'US'
|
||||||
formats = ['EPUB', 'LIT', 'MOBI', 'PDF']
|
formats = ['EPUB', 'LIT', 'MOBI', 'PDF']
|
||||||
|
affiliate = True
|
||||||
|
|
||||||
class StoreEPubBuyDEStore(StoreBase):
|
class StoreEPubBuyDEStore(StoreBase):
|
||||||
name = 'EPUBBuy DE'
|
name = 'EPUBBuy DE'
|
||||||
@ -1205,22 +1206,32 @@ class StoreEPubBuyDEStore(StoreBase):
|
|||||||
drm_free_only = True
|
drm_free_only = True
|
||||||
headquarters = 'DE'
|
headquarters = 'DE'
|
||||||
formats = ['EPUB']
|
formats = ['EPUB']
|
||||||
|
affiliate = True
|
||||||
|
|
||||||
|
class StoreEBookShoppeUKStore(StoreBase):
|
||||||
|
name = 'ebookShoppe UK'
|
||||||
|
author = u'Charles Haley'
|
||||||
|
description = u'We made this website in an attempt to offer the widest range of UK eBooks possible across and as many formats as we could manage.'
|
||||||
|
actual_plugin = 'calibre.gui2.store.ebookshoppe_uk_plugin:EBookShoppeUKStore'
|
||||||
|
|
||||||
|
headquarters = 'UK'
|
||||||
|
formats = ['EPUB', 'PDF']
|
||||||
|
affiliate = True
|
||||||
|
|
||||||
class StoreEHarlequinStore(StoreBase):
|
class StoreEHarlequinStore(StoreBase):
|
||||||
name = 'eHarlequin'
|
name = 'eHarlequin'
|
||||||
description = u'A global leader in series romance and one of the world\'s leading publishers of books for women. Offers women a broad range of reading from romance to bestseller fiction, from young adult novels to erotic literature, from nonfiction to fantasy, from African-American novels to inspirational romance, and more.'
|
description = u'A global leader in series romance and one of the world\'s leading publishers of books for women. Offers women a broad range of reading from romance to bestseller fiction, from young adult novels to erotic literature, from nonfiction to fantasy, from African-American novels to inspirational romance, and more.'
|
||||||
actual_plugin = 'calibre.gui2.store.eharlequin_plugin:EHarlequinStore'
|
actual_plugin = 'calibre.gui2.store.eharlequin_plugin:EHarlequinStore'
|
||||||
|
|
||||||
drm_free_only = False
|
|
||||||
headquarters = 'CA'
|
headquarters = 'CA'
|
||||||
formats = ['EPUB', 'PDF']
|
formats = ['EPUB', 'PDF']
|
||||||
|
affiliate = True
|
||||||
|
|
||||||
class StoreFeedbooksStore(StoreBase):
|
class StoreFeedbooksStore(StoreBase):
|
||||||
name = 'Feedbooks'
|
name = 'Feedbooks'
|
||||||
description = u'Feedbooks is a cloud publishing and distribution service, connected to a large ecosystem of reading systems and social networks. Provides a variety of genres from independent and classic books.'
|
description = u'Feedbooks is a cloud publishing and distribution service, connected to a large ecosystem of reading systems and social networks. Provides a variety of genres from independent and classic books.'
|
||||||
actual_plugin = 'calibre.gui2.store.feedbooks_plugin:FeedbooksStore'
|
actual_plugin = 'calibre.gui2.store.feedbooks_plugin:FeedbooksStore'
|
||||||
|
|
||||||
drm_free_only = False
|
|
||||||
headquarters = 'FR'
|
headquarters = 'FR'
|
||||||
formats = ['EPUB', 'MOBI', 'PDF']
|
formats = ['EPUB', 'MOBI', 'PDF']
|
||||||
|
|
||||||
@ -1230,9 +1241,9 @@ class StoreFoylesUKStore(StoreBase):
|
|||||||
description = u'Foyles of London\'s ebook store. Provides extensive range covering all subjects.'
|
description = u'Foyles of London\'s ebook store. Provides extensive range covering all subjects.'
|
||||||
actual_plugin = 'calibre.gui2.store.foyles_uk_plugin:FoylesUKStore'
|
actual_plugin = 'calibre.gui2.store.foyles_uk_plugin:FoylesUKStore'
|
||||||
|
|
||||||
drm_free_only = False
|
|
||||||
headquarters = 'UK'
|
headquarters = 'UK'
|
||||||
formats = ['EPUB', 'PDF']
|
formats = ['EPUB', 'PDF']
|
||||||
|
affiliate = True
|
||||||
|
|
||||||
class StoreGandalfStore(StoreBase):
|
class StoreGandalfStore(StoreBase):
|
||||||
name = 'Gandalf'
|
name = 'Gandalf'
|
||||||
@ -1240,7 +1251,6 @@ class StoreGandalfStore(StoreBase):
|
|||||||
description = u'Księgarnia internetowa Gandalf.'
|
description = u'Księgarnia internetowa Gandalf.'
|
||||||
actual_plugin = 'calibre.gui2.store.gandalf_plugin:GandalfStore'
|
actual_plugin = 'calibre.gui2.store.gandalf_plugin:GandalfStore'
|
||||||
|
|
||||||
drm_free_only = False
|
|
||||||
headquarters = 'PL'
|
headquarters = 'PL'
|
||||||
formats = ['EPUB', 'PDF']
|
formats = ['EPUB', 'PDF']
|
||||||
|
|
||||||
@ -1249,7 +1259,6 @@ class StoreGoogleBooksStore(StoreBase):
|
|||||||
description = u'Google Books'
|
description = u'Google Books'
|
||||||
actual_plugin = 'calibre.gui2.store.google_books_plugin:GoogleBooksStore'
|
actual_plugin = 'calibre.gui2.store.google_books_plugin:GoogleBooksStore'
|
||||||
|
|
||||||
drm_free_only = False
|
|
||||||
headquarters = 'US'
|
headquarters = 'US'
|
||||||
formats = ['EPUB', 'PDF', 'TXT']
|
formats = ['EPUB', 'PDF', 'TXT']
|
||||||
|
|
||||||
@ -1267,9 +1276,9 @@ class StoreKoboStore(StoreBase):
|
|||||||
description = u'With over 2.3 million eBooks to browse we have engaged readers in over 200 countries in Kobo eReading. Our eBook listings include New York Times Bestsellers, award winners, classics and more!'
|
description = u'With over 2.3 million eBooks to browse we have engaged readers in over 200 countries in Kobo eReading. Our eBook listings include New York Times Bestsellers, award winners, classics and more!'
|
||||||
actual_plugin = 'calibre.gui2.store.kobo_plugin:KoboStore'
|
actual_plugin = 'calibre.gui2.store.kobo_plugin:KoboStore'
|
||||||
|
|
||||||
drm_free_only = False
|
|
||||||
headquarters = 'CA'
|
headquarters = 'CA'
|
||||||
formats = ['EPUB']
|
formats = ['EPUB']
|
||||||
|
affiliate = True
|
||||||
|
|
||||||
class StoreLegimiStore(StoreBase):
|
class StoreLegimiStore(StoreBase):
|
||||||
name = 'Legimi'
|
name = 'Legimi'
|
||||||
@ -1277,7 +1286,6 @@ class StoreLegimiStore(StoreBase):
|
|||||||
description = u'Tanie oraz darmowe ebooki, egazety i blogi w formacie EPUB, wprost na Twój e-czytnik, iPhone, iPad, Android i komputer'
|
description = u'Tanie oraz darmowe ebooki, egazety i blogi w formacie EPUB, wprost na Twój e-czytnik, iPhone, iPad, Android i komputer'
|
||||||
actual_plugin = 'calibre.gui2.store.legimi_plugin:LegimiStore'
|
actual_plugin = 'calibre.gui2.store.legimi_plugin:LegimiStore'
|
||||||
|
|
||||||
drm_free_only = False
|
|
||||||
headquarters = 'PL'
|
headquarters = 'PL'
|
||||||
formats = ['EPUB']
|
formats = ['EPUB']
|
||||||
|
|
||||||
@ -1305,9 +1313,9 @@ class StoreNextoStore(StoreBase):
|
|||||||
description = u'Największy w Polsce sklep internetowy z audiobookami mp3, ebookami pdf oraz prasą do pobrania on-line.'
|
description = u'Największy w Polsce sklep internetowy z audiobookami mp3, ebookami pdf oraz prasą do pobrania on-line.'
|
||||||
actual_plugin = 'calibre.gui2.store.nexto_plugin:NextoStore'
|
actual_plugin = 'calibre.gui2.store.nexto_plugin:NextoStore'
|
||||||
|
|
||||||
drm_free_only = False
|
|
||||||
headquarters = 'PL'
|
headquarters = 'PL'
|
||||||
formats = ['EPUB', 'PDF']
|
formats = ['EPUB', 'PDF']
|
||||||
|
affiliate = True
|
||||||
|
|
||||||
class StoreOpenLibraryStore(StoreBase):
|
class StoreOpenLibraryStore(StoreBase):
|
||||||
name = 'Open Library'
|
name = 'Open Library'
|
||||||
@ -1344,6 +1352,7 @@ class StoreSmashwordsStore(StoreBase):
|
|||||||
drm_free_only = True
|
drm_free_only = True
|
||||||
headquarters = 'US'
|
headquarters = 'US'
|
||||||
formats = ['EPUB', 'HTML', 'LRF', 'MOBI', 'PDB', 'RTF', 'TXT']
|
formats = ['EPUB', 'HTML', 'LRF', 'MOBI', 'PDB', 'RTF', 'TXT']
|
||||||
|
affiliate = True
|
||||||
|
|
||||||
class StoreVirtualoStore(StoreBase):
|
class StoreVirtualoStore(StoreBase):
|
||||||
name = 'Virtualo'
|
name = 'Virtualo'
|
||||||
@ -1351,7 +1360,6 @@ class StoreVirtualoStore(StoreBase):
|
|||||||
description = u'Księgarnia internetowa, która oferuje bezpieczny i szeroki dostęp do książek w formie cyfrowej.'
|
description = u'Księgarnia internetowa, która oferuje bezpieczny i szeroki dostęp do książek w formie cyfrowej.'
|
||||||
actual_plugin = 'calibre.gui2.store.virtualo_plugin:VirtualoStore'
|
actual_plugin = 'calibre.gui2.store.virtualo_plugin:VirtualoStore'
|
||||||
|
|
||||||
drm_free_only = False
|
|
||||||
headquarters = 'PL'
|
headquarters = 'PL'
|
||||||
formats = ['EPUB', 'PDF']
|
formats = ['EPUB', 'PDF']
|
||||||
|
|
||||||
@ -1361,7 +1369,6 @@ class StoreWaterstonesUKStore(StoreBase):
|
|||||||
description = u'Waterstone\'s mission is to be the leading Bookseller on the High Street and online providing customers the widest choice, great value and expert advice from a team passionate about Bookselling.'
|
description = u'Waterstone\'s mission is to be the leading Bookseller on the High Street and online providing customers the widest choice, great value and expert advice from a team passionate about Bookselling.'
|
||||||
actual_plugin = 'calibre.gui2.store.waterstones_uk_plugin:WaterstonesUKStore'
|
actual_plugin = 'calibre.gui2.store.waterstones_uk_plugin:WaterstonesUKStore'
|
||||||
|
|
||||||
drm_free_only = False
|
|
||||||
headquarters = 'UK'
|
headquarters = 'UK'
|
||||||
formats = ['EPUB', 'PDF']
|
formats = ['EPUB', 'PDF']
|
||||||
|
|
||||||
@ -1374,6 +1381,15 @@ class StoreWeightlessBooksStore(StoreBase):
|
|||||||
headquarters = 'US'
|
headquarters = 'US'
|
||||||
formats = ['EPUB', 'HTML', 'LIT', 'MOBI', 'PDF']
|
formats = ['EPUB', 'HTML', 'LIT', 'MOBI', 'PDF']
|
||||||
|
|
||||||
|
class StoreWHSmithUKStore(StoreBase):
|
||||||
|
name = 'WH Smith UK'
|
||||||
|
author = 'Charles Haley'
|
||||||
|
description = u"Shop for savings on Books, discounted Magazine subscriptions and great prices on Stationery, Toys & Games"
|
||||||
|
actual_plugin = 'calibre.gui2.store.whsmith_uk_plugin:WHSmithUKStore'
|
||||||
|
|
||||||
|
headquarters = 'UK'
|
||||||
|
formats = ['EPUB', 'PDF']
|
||||||
|
|
||||||
class StoreWizardsTowerBooksStore(StoreBase):
|
class StoreWizardsTowerBooksStore(StoreBase):
|
||||||
name = 'Wizards Tower Books'
|
name = 'Wizards Tower Books'
|
||||||
description = u'A science fiction and fantasy publisher. Concentrates mainly on making out-of-print works available once more as e-books, and helping other small presses exploit the e-book market. Also publishes a small number of limited-print-run anthologies with a view to encouraging diversity in the science fiction and fantasy field.'
|
description = u'A science fiction and fantasy publisher. Concentrates mainly on making out-of-print works available once more as e-books, and helping other small presses exploit the e-book market. Also publishes a small number of limited-print-run anthologies with a view to encouraging diversity in the science fiction and fantasy field.'
|
||||||
@ -1389,7 +1405,6 @@ class StoreWoblinkStore(StoreBase):
|
|||||||
description = u'Czytanie zdarza się wszędzie!'
|
description = u'Czytanie zdarza się wszędzie!'
|
||||||
actual_plugin = 'calibre.gui2.store.woblink_plugin:WoblinkStore'
|
actual_plugin = 'calibre.gui2.store.woblink_plugin:WoblinkStore'
|
||||||
|
|
||||||
drm_free_only = False
|
|
||||||
headquarters = 'PL'
|
headquarters = 'PL'
|
||||||
formats = ['EPUB']
|
formats = ['EPUB']
|
||||||
|
|
||||||
@ -1404,6 +1419,7 @@ plugins += [
|
|||||||
StoreBeWriteStore,
|
StoreBeWriteStore,
|
||||||
StoreDieselEbooksStore,
|
StoreDieselEbooksStore,
|
||||||
StoreEbookscomStore,
|
StoreEbookscomStore,
|
||||||
|
StoreEBookShoppeUKStore,
|
||||||
StoreEPubBuyDEStore,
|
StoreEPubBuyDEStore,
|
||||||
StoreEHarlequinStore,
|
StoreEHarlequinStore,
|
||||||
StoreFeedbooksStore,
|
StoreFeedbooksStore,
|
||||||
@ -1421,8 +1437,9 @@ plugins += [
|
|||||||
StorePragmaticBookshelfStore,
|
StorePragmaticBookshelfStore,
|
||||||
StoreSmashwordsStore,
|
StoreSmashwordsStore,
|
||||||
StoreVirtualoStore,
|
StoreVirtualoStore,
|
||||||
#StoreWaterstonesUKStore,
|
StoreWaterstonesUKStore,
|
||||||
StoreWeightlessBooksStore,
|
StoreWeightlessBooksStore,
|
||||||
|
StoreWHSmithUKStore,
|
||||||
StoreWizardsTowerBooksStore,
|
StoreWizardsTowerBooksStore,
|
||||||
StoreWoblinkStore
|
StoreWoblinkStore
|
||||||
]
|
]
|
||||||
|
@ -8,7 +8,7 @@ __docformat__ = 'restructuredtext en'
|
|||||||
|
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
from PyQt4.Qt import QMenu
|
from PyQt4.Qt import QMenu, QIcon, QSize
|
||||||
|
|
||||||
from calibre.gui2 import error_dialog
|
from calibre.gui2 import error_dialog
|
||||||
from calibre.gui2.actions import InterfaceAction
|
from calibre.gui2.actions import InterfaceAction
|
||||||
@ -32,8 +32,13 @@ class StoreAction(InterfaceAction):
|
|||||||
self.store_menu.addAction(_('Search for this book'), self.search_author_title)
|
self.store_menu.addAction(_('Search for this book'), self.search_author_title)
|
||||||
self.store_menu.addSeparator()
|
self.store_menu.addSeparator()
|
||||||
self.store_list_menu = self.store_menu.addMenu(_('Stores'))
|
self.store_list_menu = self.store_menu.addMenu(_('Stores'))
|
||||||
|
icon = QIcon()
|
||||||
|
icon.addFile(I('donate.png'), QSize(16, 16))
|
||||||
for n, p in sorted(self.gui.istores.items(), key=lambda x: x[0].lower()):
|
for n, p in sorted(self.gui.istores.items(), key=lambda x: x[0].lower()):
|
||||||
self.store_list_menu.addAction(n, partial(self.open_store, p))
|
if p.base_plugin.affiliate:
|
||||||
|
self.store_list_menu.addAction(icon, n, partial(self.open_store, p))
|
||||||
|
else:
|
||||||
|
self.store_list_menu.addAction(n, partial(self.open_store, p))
|
||||||
self.store_menu.addSeparator()
|
self.store_menu.addSeparator()
|
||||||
self.store_menu.addAction(_('Choose stores'), self.choose)
|
self.store_menu.addAction(_('Choose stores'), self.choose)
|
||||||
self.qaction.setMenu(self.store_menu)
|
self.qaction.setMenu(self.store_menu)
|
||||||
|
@ -6,11 +6,17 @@ __license__ = 'GPL 3'
|
|||||||
__copyright__ = '2011, John Schember <john@nachtimwald.com>'
|
__copyright__ = '2011, John Schember <john@nachtimwald.com>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
|
import urllib
|
||||||
|
from contextlib import closing
|
||||||
|
|
||||||
|
from lxml import html
|
||||||
|
|
||||||
from PyQt4.Qt import QUrl
|
from PyQt4.Qt import QUrl
|
||||||
|
|
||||||
|
from calibre import browser
|
||||||
from calibre.gui2 import open_url
|
from calibre.gui2 import open_url
|
||||||
from calibre.gui2.store.amazon_plugin import AmazonKindleStore
|
from calibre.gui2.store.amazon_plugin import AmazonKindleStore
|
||||||
|
from calibre.gui2.store.search_result import SearchResult
|
||||||
|
|
||||||
class AmazonUKKindleStore(AmazonKindleStore):
|
class AmazonUKKindleStore(AmazonKindleStore):
|
||||||
'''
|
'''
|
||||||
@ -28,3 +34,81 @@ class AmazonUKKindleStore(AmazonKindleStore):
|
|||||||
aff_id['asin'] = detail_item
|
aff_id['asin'] = detail_item
|
||||||
store_link = 'http://www.amazon.co.uk/gp/redirect.html?ie=UTF8&location=http://www.amazon.co.uk/dp/%(asin)s&tag=%(tag)s&linkCode=ur2&camp=1634&creative=6738' % aff_id
|
store_link = 'http://www.amazon.co.uk/gp/redirect.html?ie=UTF8&location=http://www.amazon.co.uk/dp/%(asin)s&tag=%(tag)s&linkCode=ur2&camp=1634&creative=6738' % aff_id
|
||||||
open_url(QUrl(store_link))
|
open_url(QUrl(store_link))
|
||||||
|
|
||||||
|
def search(self, query, max_results=10, timeout=60):
|
||||||
|
url = self.search_url + urllib.quote_plus(query)
|
||||||
|
br = browser()
|
||||||
|
|
||||||
|
counter = max_results
|
||||||
|
with closing(br.open(url, timeout=timeout)) as f:
|
||||||
|
doc = html.fromstring(f.read())
|
||||||
|
|
||||||
|
# Amazon has two results pages.
|
||||||
|
is_shot = doc.xpath('boolean(//div[@id="shotgunMainResults"])')
|
||||||
|
# Horizontal grid of books.
|
||||||
|
if is_shot:
|
||||||
|
data_xpath = '//div[contains(@class, "result")]'
|
||||||
|
cover_xpath = './/div[@class="productTitle"]//img/@src'
|
||||||
|
# Vertical list of books.
|
||||||
|
else:
|
||||||
|
data_xpath = '//div[contains(@class, "product")]'
|
||||||
|
cover_xpath = './div[@class="productImage"]/a/img/@src'
|
||||||
|
|
||||||
|
for data in doc.xpath(data_xpath):
|
||||||
|
if counter <= 0:
|
||||||
|
break
|
||||||
|
|
||||||
|
# We must have an asin otherwise we can't easily reference the
|
||||||
|
# book later.
|
||||||
|
asin = ''.join(data.xpath('./@name'))
|
||||||
|
if not asin:
|
||||||
|
continue
|
||||||
|
cover_url = ''.join(data.xpath(cover_xpath))
|
||||||
|
|
||||||
|
title = ''.join(data.xpath('.//div[@class="productTitle"]/a/text()'))
|
||||||
|
price = ''.join(data.xpath('.//div[@class="newPrice"]/span/text()'))
|
||||||
|
|
||||||
|
counter -= 1
|
||||||
|
|
||||||
|
s = SearchResult()
|
||||||
|
s.cover_url = cover_url.strip()
|
||||||
|
s.title = title.strip()
|
||||||
|
s.price = price.strip()
|
||||||
|
s.detail_item = asin.strip()
|
||||||
|
s.formats = 'Kindle'
|
||||||
|
|
||||||
|
if is_shot:
|
||||||
|
# Amazon UK does not include the author on the grid layout
|
||||||
|
s.author = ''
|
||||||
|
self.get_details(s, timeout)
|
||||||
|
else:
|
||||||
|
author = ''.join(data.xpath('.//div[@class="productTitle"]/span[@class="ptBrand"]/text()'))
|
||||||
|
s.author = author.split(' by ')[-1].strip()
|
||||||
|
|
||||||
|
yield s
|
||||||
|
|
||||||
|
def get_details(self, search_result, timeout):
|
||||||
|
# We might already have been called.
|
||||||
|
if search_result.drm:
|
||||||
|
return
|
||||||
|
|
||||||
|
url = self.details_url
|
||||||
|
|
||||||
|
br = browser()
|
||||||
|
with closing(br.open(url + search_result.detail_item, timeout=timeout)) as nf:
|
||||||
|
idata = html.fromstring(nf.read())
|
||||||
|
if not search_result.author:
|
||||||
|
search_result.author = ''.join(idata.xpath('//div[@class="buying" and contains(., "Author")]/a/text()'))
|
||||||
|
if idata.xpath('boolean(//div[@class="content"]//li/b[contains(text(), "' +
|
||||||
|
self.drm_search_text + '")])'):
|
||||||
|
if idata.xpath('boolean(//div[@class="content"]//li[contains(., "' +
|
||||||
|
self.drm_free_text + '") and contains(b, "' +
|
||||||
|
self.drm_search_text + '")])'):
|
||||||
|
search_result.drm = SearchResult.DRM_UNLOCKED
|
||||||
|
else:
|
||||||
|
search_result.drm = SearchResult.DRM_UNKNOWN
|
||||||
|
else:
|
||||||
|
search_result.drm = SearchResult.DRM_LOCKED
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
@ -45,8 +45,9 @@ class AdvSearchBuilderDialog(QDialog, Ui_Dialog):
|
|||||||
self.description_box.setText('')
|
self.description_box.setText('')
|
||||||
self.headquarters_box.setText('')
|
self.headquarters_box.setText('')
|
||||||
self.format_box.setText('')
|
self.format_box.setText('')
|
||||||
self.enabled_combo.setIndex(0)
|
self.enabled_combo.setCurrentIndex(0)
|
||||||
self.drm_combo.setIndex(0)
|
self.drm_combo.setCurrentIndex(0)
|
||||||
|
self.affiliate_combo.setCurrentIndex(0)
|
||||||
|
|
||||||
def tokens(self, raw):
|
def tokens(self, raw):
|
||||||
phrases = re.findall(r'\s*".*?"\s*', raw)
|
phrases = re.findall(r'\s*".*?"\s*', raw)
|
||||||
@ -126,6 +127,9 @@ class AdvSearchBuilderDialog(QDialog, Ui_Dialog):
|
|||||||
drm = unicode(self.drm_combo.currentText()).strip()
|
drm = unicode(self.drm_combo.currentText()).strip()
|
||||||
if drm:
|
if drm:
|
||||||
ans.append('drm:' + drm)
|
ans.append('drm:' + drm)
|
||||||
|
affiliate = unicode(self.affiliate_combo.currentText()).strip()
|
||||||
|
if affiliate:
|
||||||
|
ans.append('affiliate:' + affiliate)
|
||||||
if ans:
|
if ans:
|
||||||
return ' and '.join(ans)
|
return ' and '.join(ans)
|
||||||
return ''
|
return ''
|
||||||
|
@ -226,7 +226,7 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="8" column="0" colspan="2">
|
<item row="9" column="0" colspan="2">
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_6">
|
<layout class="QHBoxLayout" name="horizontalLayout_6">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="clear_button">
|
<widget class="QPushButton" name="clear_button">
|
||||||
@ -244,7 +244,7 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item row="7" column="1">
|
<item row="8" column="1">
|
||||||
<spacer name="verticalSpacer">
|
<spacer name="verticalSpacer">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Vertical</enum>
|
<enum>Qt::Vertical</enum>
|
||||||
@ -335,6 +335,32 @@
|
|||||||
</item>
|
</item>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="7" column="0">
|
||||||
|
<widget class="QLabel" name="label_13">
|
||||||
|
<property name="text">
|
||||||
|
<string>Affiliate:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="7" column="1">
|
||||||
|
<widget class="QComboBox" name="affiliate_combo">
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>true</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>false</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
|
@ -17,18 +17,20 @@ class StoreChooserWidget(QWidget, Ui_Form):
|
|||||||
QWidget.__init__(self)
|
QWidget.__init__(self)
|
||||||
self.setupUi(self)
|
self.setupUi(self)
|
||||||
|
|
||||||
|
self.query.initialize('store_config_chooser_query')
|
||||||
|
|
||||||
self.adv_search_builder.setIcon(QIcon(I('search.png')))
|
self.adv_search_builder.setIcon(QIcon(I('search.png')))
|
||||||
|
|
||||||
self.search.clicked.connect(self.do_search)
|
self.search.clicked.connect(self.do_search)
|
||||||
self.adv_search_builder.clicked.connect(self.build_adv_search)
|
self.adv_search_builder.clicked.connect(self.build_adv_search)
|
||||||
self.results_view.activated.connect(self.toggle_plugin)
|
self.enable_all.clicked.connect(self.results_view.model().enable_all)
|
||||||
|
self.enable_none.clicked.connect(self.results_view.model().enable_none)
|
||||||
|
self.enable_invert.clicked.connect(self.results_view.model().enable_invert)
|
||||||
|
self.results_view.activated.connect(self.results_view.model().toggle_plugin)
|
||||||
|
|
||||||
def do_search(self):
|
def do_search(self):
|
||||||
self.results_view.model().search(unicode(self.query.text()))
|
self.results_view.model().search(unicode(self.query.text()))
|
||||||
|
|
||||||
def toggle_plugin(self, index):
|
|
||||||
self.results_view.model().toggle_plugin(index)
|
|
||||||
|
|
||||||
def build_adv_search(self):
|
def build_adv_search(self):
|
||||||
adv = AdvSearchBuilderDialog(self)
|
adv = AdvSearchBuilderDialog(self)
|
||||||
if adv.exec_() == QDialog.Accepted:
|
if adv.exec_() == QDialog.Accepted:
|
||||||
|
@ -31,7 +31,14 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLineEdit" name="query"/>
|
<widget class="HistoryLineEdit" name="query">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="search">
|
<widget class="QPushButton" name="search">
|
||||||
@ -73,6 +80,51 @@
|
|||||||
</attribute>
|
</attribute>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_2">
|
||||||
|
<property name="text">
|
||||||
|
<string>Enable</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="enable_all">
|
||||||
|
<property name="text">
|
||||||
|
<string>All</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="enable_none">
|
||||||
|
<property name="text">
|
||||||
|
<string>None</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="enable_invert">
|
||||||
|
<property name="text">
|
||||||
|
<string>Invert</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
@ -81,6 +133,11 @@
|
|||||||
<extends>QTreeView</extends>
|
<extends>QTreeView</extends>
|
||||||
<header>results_view.h</header>
|
<header>results_view.h</header>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
|
<customwidget>
|
||||||
|
<class>HistoryLineEdit</class>
|
||||||
|
<extends>QLineEdit</extends>
|
||||||
|
<header>widgets.h</header>
|
||||||
|
</customwidget>
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
|
@ -6,7 +6,7 @@ __license__ = 'GPL 3'
|
|||||||
__copyright__ = '2011, John Schember <john@nachtimwald.com>'
|
__copyright__ = '2011, John Schember <john@nachtimwald.com>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
from PyQt4.Qt import (Qt, QAbstractItemModel, QIcon, QVariant, QModelIndex)
|
from PyQt4.Qt import (Qt, QAbstractItemModel, QIcon, QVariant, QModelIndex, QSize)
|
||||||
|
|
||||||
from calibre.gui2 import NONE
|
from calibre.gui2 import NONE
|
||||||
from calibre.customize.ui import is_disabled, disable_plugin, enable_plugin
|
from calibre.customize.ui import is_disabled, disable_plugin, enable_plugin
|
||||||
@ -18,13 +18,15 @@ from calibre.utils.search_query_parser import SearchQueryParser
|
|||||||
|
|
||||||
class Matches(QAbstractItemModel):
|
class Matches(QAbstractItemModel):
|
||||||
|
|
||||||
HEADERS = [_('Enabled'), _('Name'), _('No DRM'), _('Headquarters'), _('Formats')]
|
HEADERS = [_('Enabled'), _('Name'), _('No DRM'), _('Headquarters'), _('Affiliate'), _('Formats')]
|
||||||
HTML_COLS = [1]
|
HTML_COLS = [1]
|
||||||
|
|
||||||
def __init__(self, plugins):
|
def __init__(self, plugins):
|
||||||
QAbstractItemModel.__init__(self)
|
QAbstractItemModel.__init__(self)
|
||||||
|
|
||||||
self.NO_DRM_ICON = QIcon(I('ok.png'))
|
self.NO_DRM_ICON = QIcon(I('ok.png'))
|
||||||
|
self.DONATE_ICON = QIcon()
|
||||||
|
self.DONATE_ICON.addFile(I('donate.png'), QSize(16, 16))
|
||||||
|
|
||||||
self.all_matches = plugins
|
self.all_matches = plugins
|
||||||
self.matches = plugins
|
self.matches = plugins
|
||||||
@ -53,6 +55,22 @@ class Matches(QAbstractItemModel):
|
|||||||
self.layoutChanged.emit()
|
self.layoutChanged.emit()
|
||||||
self.sort(self.sort_col, self.sort_order)
|
self.sort(self.sort_col, self.sort_order)
|
||||||
|
|
||||||
|
def enable_all(self):
|
||||||
|
for i in xrange(len(self.matches)):
|
||||||
|
index = self.createIndex(i, 0)
|
||||||
|
data = QVariant(True)
|
||||||
|
self.setData(index, data, Qt.CheckStateRole)
|
||||||
|
|
||||||
|
def enable_none(self):
|
||||||
|
for i in xrange(len(self.matches)):
|
||||||
|
index = self.createIndex(i, 0)
|
||||||
|
data = QVariant(False)
|
||||||
|
self.setData(index, data, Qt.CheckStateRole)
|
||||||
|
|
||||||
|
def enable_invert(self):
|
||||||
|
for i in xrange(len(self.matches)):
|
||||||
|
self.toggle_plugin(self.createIndex(i, 0))
|
||||||
|
|
||||||
def toggle_plugin(self, index):
|
def toggle_plugin(self, index):
|
||||||
new_index = self.createIndex(index.row(), 0)
|
new_index = self.createIndex(index.row(), 0)
|
||||||
data = QVariant(is_disabled(self.get_plugin(index)))
|
data = QVariant(is_disabled(self.get_plugin(index)))
|
||||||
@ -91,12 +109,15 @@ class Matches(QAbstractItemModel):
|
|||||||
return QVariant('<b>%s</b><br><i>%s</i>' % (result.name, result.description))
|
return QVariant('<b>%s</b><br><i>%s</i>' % (result.name, result.description))
|
||||||
elif col == 3:
|
elif col == 3:
|
||||||
return QVariant(result.headquarters)
|
return QVariant(result.headquarters)
|
||||||
elif col == 4:
|
elif col == 5:
|
||||||
return QVariant(', '.join(result.formats).upper())
|
return QVariant(', '.join(result.formats).upper())
|
||||||
elif role == Qt.DecorationRole:
|
elif role == Qt.DecorationRole:
|
||||||
if col == 2:
|
if col == 2:
|
||||||
if result.drm_free_only:
|
if result.drm_free_only:
|
||||||
return QVariant(self.NO_DRM_ICON)
|
return QVariant(self.NO_DRM_ICON)
|
||||||
|
if col == 4:
|
||||||
|
if result.affiliate:
|
||||||
|
return QVariant(self.DONATE_ICON)
|
||||||
elif role == Qt.CheckStateRole:
|
elif role == Qt.CheckStateRole:
|
||||||
if col == 0:
|
if col == 0:
|
||||||
if is_disabled(result):
|
if is_disabled(result):
|
||||||
@ -105,20 +126,23 @@ class Matches(QAbstractItemModel):
|
|||||||
elif role == Qt.ToolTipRole:
|
elif role == Qt.ToolTipRole:
|
||||||
if col == 0:
|
if col == 0:
|
||||||
if is_disabled(result):
|
if is_disabled(result):
|
||||||
return QVariant(_('<p>This store is currently diabled and cannot be used in other parts of calibre.</p>'))
|
return QVariant('<p>' + _('This store is currently diabled and cannot be used in other parts of calibre.') + '</p>')
|
||||||
else:
|
else:
|
||||||
return QVariant(_('<p>This store is currently enabled and can be used in other parts of calibre.</p>'))
|
return QVariant('<p>' + _('This store is currently enabled and can be used in other parts of calibre.') + '</p>')
|
||||||
elif col == 1:
|
elif col == 1:
|
||||||
return QVariant('<p>%s</p>' % result.description)
|
return QVariant('<p>%s</p>' % result.description)
|
||||||
elif col == 2:
|
elif col == 2:
|
||||||
if result.drm_free_only:
|
if result.drm_free_only:
|
||||||
return QVariant(_('<p>This store only distributes ebooks with DRM.</p>'))
|
return QVariant('<p>' + _('This store only distributes ebooks with DRM.') + '</p>')
|
||||||
else:
|
else:
|
||||||
return QVariant(_('<p>This store distributes ebooks with DRM. It may have some titles without DRM, but you will need to check on a per title basis.</p>'))
|
return QVariant('<p>' + _('This store distributes ebooks with DRM. It may have some titles without DRM, but you will need to check on a per title basis.') + '</p>')
|
||||||
elif col == 3:
|
elif col == 3:
|
||||||
return QVariant(_('<p>This store is headquartered in %s. This is a good indication of what market the store caters to. However, this does not necessarily mean that the store is limited to that market only.</p>') % result.headquarters)
|
return QVariant('<p>' + _('This store is headquartered in %s. This is a good indication of what market the store caters to. However, this does not necessarily mean that the store is limited to that market only.') % result.headquarters + '</p>')
|
||||||
elif col == 4:
|
elif col == 4:
|
||||||
return QVariant(_('<p>This store distributes ebooks in the following formats: %s</p>') % ', '.join(result.formats))
|
if result.affiliate:
|
||||||
|
return QVariant('<p>' + _('Buying from this store supports the calibre developer: %s.') % result.author + '</p>')
|
||||||
|
elif col == 5:
|
||||||
|
return QVariant('<p>' + _('This store distributes ebooks in the following formats: %s') % ', '.join(result.formats) + '</p>')
|
||||||
return NONE
|
return NONE
|
||||||
|
|
||||||
def setData(self, index, data, role):
|
def setData(self, index, data, role):
|
||||||
@ -148,6 +172,8 @@ class Matches(QAbstractItemModel):
|
|||||||
text = 'a' if getattr(match, 'drm_free_only', True) else 'b'
|
text = 'a' if getattr(match, 'drm_free_only', True) else 'b'
|
||||||
elif col == 3:
|
elif col == 3:
|
||||||
text = getattr(match, 'headquarters', '')
|
text = getattr(match, 'headquarters', '')
|
||||||
|
elif col == 4:
|
||||||
|
text = 'a' if getattr(match, 'affiliate', False) else 'b'
|
||||||
return text
|
return text
|
||||||
|
|
||||||
def sort(self, col, order, reset=True):
|
def sort(self, col, order, reset=True):
|
||||||
@ -167,6 +193,7 @@ class SearchFilter(SearchQueryParser):
|
|||||||
|
|
||||||
USABLE_LOCATIONS = [
|
USABLE_LOCATIONS = [
|
||||||
'all',
|
'all',
|
||||||
|
'affiliate',
|
||||||
'description',
|
'description',
|
||||||
'drm',
|
'drm',
|
||||||
'enabled',
|
'enabled',
|
||||||
@ -207,6 +234,7 @@ class SearchFilter(SearchQueryParser):
|
|||||||
all_locs = set(self.USABLE_LOCATIONS) - set(['all'])
|
all_locs = set(self.USABLE_LOCATIONS) - set(['all'])
|
||||||
locations = all_locs if location == 'all' else [location]
|
locations = all_locs if location == 'all' else [location]
|
||||||
q = {
|
q = {
|
||||||
|
'affiliate': lambda x: x.affiliate,
|
||||||
'description': lambda x: x.description.lower(),
|
'description': lambda x: x.description.lower(),
|
||||||
'drm': lambda x: not x.drm_free_only,
|
'drm': lambda x: not x.drm_free_only,
|
||||||
'enabled': lambda x: not is_disabled(x),
|
'enabled': lambda x: not is_disabled(x),
|
||||||
@ -219,21 +247,21 @@ class SearchFilter(SearchQueryParser):
|
|||||||
for locvalue in locations:
|
for locvalue in locations:
|
||||||
accessor = q[locvalue]
|
accessor = q[locvalue]
|
||||||
if query == 'true':
|
if query == 'true':
|
||||||
if locvalue in ('drm', 'enabled'):
|
if locvalue in ('affiliate', 'drm', 'enabled'):
|
||||||
if accessor(sr) == True:
|
if accessor(sr) == True:
|
||||||
matches.add(sr)
|
matches.add(sr)
|
||||||
elif accessor(sr) is not None:
|
elif accessor(sr) is not None:
|
||||||
matches.add(sr)
|
matches.add(sr)
|
||||||
continue
|
continue
|
||||||
if query == 'false':
|
if query == 'false':
|
||||||
if locvalue in ('drm', 'enabled'):
|
if locvalue in ('affiliate', 'drm', 'enabled'):
|
||||||
if accessor(sr) == False:
|
if accessor(sr) == False:
|
||||||
matches.add(sr)
|
matches.add(sr)
|
||||||
elif accessor(sr) is None:
|
elif accessor(sr) is None:
|
||||||
matches.add(sr)
|
matches.add(sr)
|
||||||
continue
|
continue
|
||||||
# this is bool, so can't match below
|
# this is bool, so can't match below
|
||||||
if locvalue in ('drm', 'enabled'):
|
if locvalue in ('affiliate', 'drm', 'enabled'):
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
### Can't separate authors because comma is used for name sep and author sep
|
### Can't separate authors because comma is used for name sep and author sep
|
||||||
|
@ -6,7 +6,9 @@ __license__ = 'GPL 3'
|
|||||||
__copyright__ = '2011, John Schember <john@nachtimwald.com>'
|
__copyright__ = '2011, John Schember <john@nachtimwald.com>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
from PyQt4.Qt import (Qt, QTreeView, QSize)
|
from functools import partial
|
||||||
|
|
||||||
|
from PyQt4.Qt import (Qt, QTreeView, QSize, QMenu)
|
||||||
|
|
||||||
from calibre.customize.ui import store_plugins
|
from calibre.customize.ui import store_plugins
|
||||||
from calibre.gui2.metadata.single_download import RichTextDelegate
|
from calibre.gui2.metadata.single_download import RichTextDelegate
|
||||||
@ -32,3 +34,20 @@ class ResultsView(QTreeView):
|
|||||||
|
|
||||||
self.model().sort(1, Qt.AscendingOrder)
|
self.model().sort(1, Qt.AscendingOrder)
|
||||||
self.header().setSortIndicator(self.model().sort_col, self.model().sort_order)
|
self.header().setSortIndicator(self.model().sort_col, self.model().sort_order)
|
||||||
|
|
||||||
|
def contextMenuEvent(self, event):
|
||||||
|
index = self.indexAt(event.pos())
|
||||||
|
|
||||||
|
if not index.isValid():
|
||||||
|
return
|
||||||
|
|
||||||
|
plugin = self.model().get_plugin(index)
|
||||||
|
|
||||||
|
menu = QMenu()
|
||||||
|
ca = menu.addAction(_('Configure...'), partial(self.configure_plugin, plugin))
|
||||||
|
if not plugin.is_customizable():
|
||||||
|
ca.setEnabled(False)
|
||||||
|
menu.exec_(event.globalPos())
|
||||||
|
|
||||||
|
def configure_plugin(self, plugin):
|
||||||
|
plugin.do_user_config(self)
|
||||||
|
87
src/calibre/gui2/store/ebookshoppe_uk_plugin.py
Normal file
87
src/calibre/gui2/store/ebookshoppe_uk_plugin.py
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from __future__ import (unicode_literals, division, absolute_import, print_function)
|
||||||
|
|
||||||
|
__license__ = 'GPL 3'
|
||||||
|
__copyright__ = '2011, John Schember <john@nachtimwald.com>'
|
||||||
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
|
import urllib2
|
||||||
|
from contextlib import closing
|
||||||
|
|
||||||
|
from lxml import html
|
||||||
|
|
||||||
|
from PyQt4.Qt import QUrl
|
||||||
|
|
||||||
|
from calibre import browser
|
||||||
|
from calibre.gui2 import open_url
|
||||||
|
from calibre.gui2.store import StorePlugin
|
||||||
|
from calibre.gui2.store.basic_config import BasicStoreConfig
|
||||||
|
from calibre.gui2.store.search_result import SearchResult
|
||||||
|
from calibre.gui2.store.web_store_dialog import WebStoreDialog
|
||||||
|
|
||||||
|
class EBookShoppeUKStore(BasicStoreConfig, StorePlugin):
|
||||||
|
|
||||||
|
def open(self, parent=None, detail_item=None, external=False):
|
||||||
|
url_details = 'http://www.awin1.com/cread.php?awinmid=1414&awinaffid=120917&clickref=&p={0}'
|
||||||
|
url = 'http://www.awin1.com/awclick.php?mid=2666&id=120917'
|
||||||
|
|
||||||
|
if external or self.config.get('open_external', False):
|
||||||
|
if detail_item:
|
||||||
|
url = url_details.format(detail_item)
|
||||||
|
open_url(QUrl(url))
|
||||||
|
else:
|
||||||
|
detail_url = None
|
||||||
|
if detail_item:
|
||||||
|
detail_url = url_details.format(detail_item)
|
||||||
|
d = WebStoreDialog(self.gui, url, parent, detail_url)
|
||||||
|
d.setWindowTitle(self.name)
|
||||||
|
d.set_tags(self.config.get('tags', ''))
|
||||||
|
d.exec_()
|
||||||
|
|
||||||
|
def search(self, query, max_results=10, timeout=60):
|
||||||
|
url = 'http://www.ebookshoppe.com/search.php?search_query=' + urllib2.quote(query)
|
||||||
|
br = browser()
|
||||||
|
|
||||||
|
counter = max_results
|
||||||
|
with closing(br.open(url, timeout=timeout)) as f:
|
||||||
|
doc = html.fromstring(f.read())
|
||||||
|
for data in doc.xpath('//ul[@class="ProductList"]/li'):
|
||||||
|
if counter <= 0:
|
||||||
|
break
|
||||||
|
|
||||||
|
id = ''.join(data.xpath('./div[@class="ProductDetails"]/'
|
||||||
|
'strong/a/@href')).strip()
|
||||||
|
if not id:
|
||||||
|
continue
|
||||||
|
cover_url = ''.join(data.xpath('./div[@class="ProductImage"]/a/img/@src'))
|
||||||
|
title = ''.join(data.xpath('./div[@class="ProductDetails"]/strong/a/text()'))
|
||||||
|
price = ''.join(data.xpath('./div[@class="ProductPriceRating"]/em/text()'))
|
||||||
|
counter -= 1
|
||||||
|
|
||||||
|
s = SearchResult()
|
||||||
|
s.cover_url = cover_url
|
||||||
|
s.title = title.strip()
|
||||||
|
s.price = price
|
||||||
|
s.drm = SearchResult.DRM_UNLOCKED
|
||||||
|
s.detail_item = id
|
||||||
|
|
||||||
|
self.get_author_and_formats(s, timeout)
|
||||||
|
if not s.author:
|
||||||
|
continue
|
||||||
|
|
||||||
|
yield s
|
||||||
|
|
||||||
|
def get_author_and_formats(self, search_result, timeout):
|
||||||
|
br = browser()
|
||||||
|
with closing(br.open(search_result.detail_item, timeout=timeout)) as nf:
|
||||||
|
idata = html.fromstring(nf.read())
|
||||||
|
author = ''.join(idata.xpath('//div[@id="ProductOtherDetails"]/dl/dd[1]/text()'))
|
||||||
|
if author:
|
||||||
|
search_result.author = author
|
||||||
|
formats = idata.xpath('//dl[@class="ProductAddToCart"]/dd/'
|
||||||
|
'ul[@class="ProductOptionList"]/li/label/text()')
|
||||||
|
if formats:
|
||||||
|
search_result.formats = ', '.join(formats)
|
||||||
|
search_result.drm = SearchResult.DRM_UNKNOWN
|
||||||
|
return True
|
@ -23,12 +23,13 @@ from calibre.gui2.store.web_store_dialog import WebStoreDialog
|
|||||||
class FoylesUKStore(BasicStoreConfig, StorePlugin):
|
class FoylesUKStore(BasicStoreConfig, StorePlugin):
|
||||||
|
|
||||||
def open(self, parent=None, detail_item=None, external=False):
|
def open(self, parent=None, detail_item=None, external=False):
|
||||||
url = 'http://www.awin1.com/cread.php?awinmid=1414&awinaffid=120917&clickref=&p='
|
url = 'http://www.awin1.com/awclick.php?mid=1414&id=120917'
|
||||||
|
detail_url = 'http://www.awin1.com/cread.php?awinmid=1414&awinaffid=120917&clickref=&p='
|
||||||
url_redirect = 'http://www.foyles.co.uk'
|
url_redirect = 'http://www.foyles.co.uk'
|
||||||
|
|
||||||
if external or self.config.get('open_external', False):
|
if external or self.config.get('open_external', False):
|
||||||
if detail_item:
|
if detail_item:
|
||||||
url = url + url_redirect + detail_item
|
url = detail_url + url_redirect + detail_item
|
||||||
open_url(QUrl(url_slash_cleaner(url)))
|
open_url(QUrl(url_slash_cleaner(url)))
|
||||||
else:
|
else:
|
||||||
detail_url = None
|
detail_url = None
|
||||||
@ -54,6 +55,10 @@ class FoylesUKStore(BasicStoreConfig, StorePlugin):
|
|||||||
if not id:
|
if not id:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
# filter out the audio books
|
||||||
|
if not data.xpath('boolean(.//div[@class="Relative"]/ul/li[contains(text(), "ePub")])'):
|
||||||
|
continue
|
||||||
|
|
||||||
cover_url = ''.join(data.xpath('.//a[@class="Jacket"]/img/@src'))
|
cover_url = ''.join(data.xpath('.//a[@class="Jacket"]/img/@src'))
|
||||||
if cover_url:
|
if cover_url:
|
||||||
cover_url = 'http://www.foyles.co.uk' + cover_url
|
cover_url = 'http://www.foyles.co.uk' + cover_url
|
||||||
|
@ -78,7 +78,8 @@ class ManyBooksStore(BasicStoreConfig, StorePlugin):
|
|||||||
cover_name = mo.group()
|
cover_name = mo.group()
|
||||||
cover_name = cover_name.replace('etext', '')
|
cover_name = cover_name.replace('etext', '')
|
||||||
cover_id = id.split('.')[0]
|
cover_id = id.split('.')[0]
|
||||||
cover_url = 'http://manybooks_images.s3.amazonaws.com/original_covers/' + id[0] + '/' + cover_name + '/' + cover_id + '-thumb.jpg'
|
cover_url = 'http://www.manybooks.net/images/' + id[0] + '/' + cover_name + '/' + cover_id + '-thumb.jpg'
|
||||||
|
print(cover_url)
|
||||||
|
|
||||||
counter -= 1
|
counter -= 1
|
||||||
|
|
||||||
|
119
src/calibre/gui2/store/mobileread/adv_search_builder.py
Normal file
119
src/calibre/gui2/store/mobileread/adv_search_builder.py
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from __future__ import (unicode_literals, division, absolute_import, print_function)
|
||||||
|
|
||||||
|
__license__ = 'GPL 3'
|
||||||
|
__copyright__ = '2011, John Schember <john@nachtimwald.com>'
|
||||||
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
|
import re
|
||||||
|
|
||||||
|
from PyQt4.Qt import (QDialog, QDialogButtonBox)
|
||||||
|
|
||||||
|
from calibre.gui2.store.mobileread.adv_search_builder_ui import Ui_Dialog
|
||||||
|
from calibre.library.caches import CONTAINS_MATCH, EQUALS_MATCH
|
||||||
|
|
||||||
|
class AdvSearchBuilderDialog(QDialog, Ui_Dialog):
|
||||||
|
|
||||||
|
def __init__(self, parent):
|
||||||
|
QDialog.__init__(self, parent)
|
||||||
|
self.setupUi(self)
|
||||||
|
|
||||||
|
self.buttonBox.accepted.connect(self.advanced_search_button_pushed)
|
||||||
|
self.tab_2_button_box.accepted.connect(self.accept)
|
||||||
|
self.tab_2_button_box.rejected.connect(self.reject)
|
||||||
|
self.clear_button.clicked.connect(self.clear_button_pushed)
|
||||||
|
self.adv_search_used = False
|
||||||
|
self.mc = ''
|
||||||
|
|
||||||
|
self.tabWidget.setCurrentIndex(0)
|
||||||
|
self.tabWidget.currentChanged[int].connect(self.tab_changed)
|
||||||
|
self.tab_changed(0)
|
||||||
|
|
||||||
|
def tab_changed(self, idx):
|
||||||
|
if idx == 1:
|
||||||
|
self.tab_2_button_box.button(QDialogButtonBox.Ok).setDefault(True)
|
||||||
|
else:
|
||||||
|
self.buttonBox.button(QDialogButtonBox.Ok).setDefault(True)
|
||||||
|
|
||||||
|
def advanced_search_button_pushed(self):
|
||||||
|
self.adv_search_used = True
|
||||||
|
self.accept()
|
||||||
|
|
||||||
|
def clear_button_pushed(self):
|
||||||
|
self.title_box.setText('')
|
||||||
|
self.author_box.setText('')
|
||||||
|
self.format_box.setText('')
|
||||||
|
|
||||||
|
def tokens(self, raw):
|
||||||
|
phrases = re.findall(r'\s*".*?"\s*', raw)
|
||||||
|
for f in phrases:
|
||||||
|
raw = raw.replace(f, ' ')
|
||||||
|
phrases = [t.strip('" ') for t in phrases]
|
||||||
|
return ['"' + self.mc + t + '"' for t in phrases + [r.strip() for r in raw.split()]]
|
||||||
|
|
||||||
|
def search_string(self):
|
||||||
|
if self.adv_search_used:
|
||||||
|
return self.adv_search_string()
|
||||||
|
else:
|
||||||
|
return self.box_search_string()
|
||||||
|
|
||||||
|
def adv_search_string(self):
|
||||||
|
mk = self.matchkind.currentIndex()
|
||||||
|
if mk == CONTAINS_MATCH:
|
||||||
|
self.mc = ''
|
||||||
|
elif mk == EQUALS_MATCH:
|
||||||
|
self.mc = '='
|
||||||
|
else:
|
||||||
|
self.mc = '~'
|
||||||
|
all, any, phrase, none = map(lambda x: unicode(x.text()),
|
||||||
|
(self.all, self.any, self.phrase, self.none))
|
||||||
|
all, any, none = map(self.tokens, (all, any, none))
|
||||||
|
phrase = phrase.strip()
|
||||||
|
all = ' and '.join(all)
|
||||||
|
any = ' or '.join(any)
|
||||||
|
none = ' and not '.join(none)
|
||||||
|
ans = ''
|
||||||
|
if phrase:
|
||||||
|
ans += '"%s"'%phrase
|
||||||
|
if all:
|
||||||
|
ans += (' and ' if ans else '') + all
|
||||||
|
if none:
|
||||||
|
ans += (' and not ' if ans else 'not ') + none
|
||||||
|
if any:
|
||||||
|
ans += (' or ' if ans else '') + any
|
||||||
|
return ans
|
||||||
|
|
||||||
|
def token(self):
|
||||||
|
txt = unicode(self.text.text()).strip()
|
||||||
|
if txt:
|
||||||
|
if self.negate.isChecked():
|
||||||
|
txt = '!'+txt
|
||||||
|
tok = self.FIELDS[unicode(self.field.currentText())]+txt
|
||||||
|
if re.search(r'\s', tok):
|
||||||
|
tok = '"%s"'%tok
|
||||||
|
return tok
|
||||||
|
|
||||||
|
def box_search_string(self):
|
||||||
|
mk = self.matchkind.currentIndex()
|
||||||
|
if mk == CONTAINS_MATCH:
|
||||||
|
self.mc = ''
|
||||||
|
elif mk == EQUALS_MATCH:
|
||||||
|
self.mc = '='
|
||||||
|
else:
|
||||||
|
self.mc = '~'
|
||||||
|
|
||||||
|
ans = []
|
||||||
|
self.box_last_values = {}
|
||||||
|
title = unicode(self.title_box.text()).strip()
|
||||||
|
if title:
|
||||||
|
ans.append('title:"' + self.mc + title + '"')
|
||||||
|
author = unicode(self.author_box.text()).strip()
|
||||||
|
if author:
|
||||||
|
ans.append('author:"' + self.mc + author + '"')
|
||||||
|
format = unicode(self.format_box.text()).strip()
|
||||||
|
if format:
|
||||||
|
ans.append('format:"' + self.mc + format + '"')
|
||||||
|
if ans:
|
||||||
|
return ' and '.join(ans)
|
||||||
|
return ''
|
350
src/calibre/gui2/store/mobileread/adv_search_builder.ui
Normal file
350
src/calibre/gui2/store/mobileread/adv_search_builder.ui
Normal file
@ -0,0 +1,350 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>Dialog</class>
|
||||||
|
<widget class="QDialog" name="Dialog">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>752</width>
|
||||||
|
<height>472</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Advanced Search</string>
|
||||||
|
</property>
|
||||||
|
<property name="windowIcon">
|
||||||
|
<iconset>
|
||||||
|
<normaloff>:/images/search.png</normaloff>:/images/search.png</iconset>
|
||||||
|
</property>
|
||||||
|
<layout class="QGridLayout" name="gridLayout_2">
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QLabel" name="label_5">
|
||||||
|
<property name="text">
|
||||||
|
<string>&What kind of match to use:</string>
|
||||||
|
</property>
|
||||||
|
<property name="buddy">
|
||||||
|
<cstring>matchkind</cstring>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="1">
|
||||||
|
<widget class="QComboBox" name="matchkind">
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>Contains: the word or phrase matches anywhere in the metadata field</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>Equals: the word or phrase must match the entire metadata field</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>Regular expression: the expression must match anywhere in the metadata field</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="0" colspan="2">
|
||||||
|
<widget class="QTabWidget" name="tabWidget">
|
||||||
|
<property name="currentIndex">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<widget class="QWidget" name="tab">
|
||||||
|
<attribute name="title">
|
||||||
|
<string>A&dvanced Search</string>
|
||||||
|
</attribute>
|
||||||
|
<layout class="QGridLayout" name="gridLayout_3">
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QGroupBox" name="groupBox">
|
||||||
|
<property name="title">
|
||||||
|
<string>Find entries that have...</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label">
|
||||||
|
<property name="text">
|
||||||
|
<string>&All these words:</string>
|
||||||
|
</property>
|
||||||
|
<property name="buddy">
|
||||||
|
<cstring>all</cstring>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="all"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_2">
|
||||||
|
<property name="text">
|
||||||
|
<string>This exact &phrase:</string>
|
||||||
|
</property>
|
||||||
|
<property name="buddy">
|
||||||
|
<cstring>all</cstring>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="phrase"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_3">
|
||||||
|
<property name="text">
|
||||||
|
<string>&One or more of these words:</string>
|
||||||
|
</property>
|
||||||
|
<property name="buddy">
|
||||||
|
<cstring>all</cstring>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="any"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QGroupBox" name="groupBox_2">
|
||||||
|
<property name="title">
|
||||||
|
<string>But dont show entries that have...</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_4">
|
||||||
|
<property name="text">
|
||||||
|
<string>Any of these &unwanted words:</string>
|
||||||
|
</property>
|
||||||
|
<property name="buddy">
|
||||||
|
<cstring>all</cstring>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="none"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_6">
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>16777215</width>
|
||||||
|
<height>30</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>See the <a href="http://calibre-ebook.com/user_manual/gui.html#the-search-interface">User Manual</a> for more help</string>
|
||||||
|
</property>
|
||||||
|
<property name="openExternalLinks">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="0">
|
||||||
|
<spacer name="verticalSpacer_2">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>20</width>
|
||||||
|
<height>40</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item row="3" column="0">
|
||||||
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="standardButtons">
|
||||||
|
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<widget class="QWidget" name="tab_2">
|
||||||
|
<attribute name="title">
|
||||||
|
<string>Titl&e/Author/Price ...</string>
|
||||||
|
</attribute>
|
||||||
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QLabel" name="label_7">
|
||||||
|
<property name="text">
|
||||||
|
<string>&Title:</string>
|
||||||
|
</property>
|
||||||
|
<property name="buddy">
|
||||||
|
<cstring>title_box</cstring>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="1">
|
||||||
|
<widget class="EnLineEdit" name="title_box">
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Enter the title.</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="0">
|
||||||
|
<widget class="QLabel" name="label_8">
|
||||||
|
<property name="text">
|
||||||
|
<string>&Author:</string>
|
||||||
|
</property>
|
||||||
|
<property name="buddy">
|
||||||
|
<cstring>author_box</cstring>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="5" column="0" colspan="2">
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_6">
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="clear_button">
|
||||||
|
<property name="text">
|
||||||
|
<string>&Clear</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QDialogButtonBox" name="tab_2_button_box">
|
||||||
|
<property name="standardButtons">
|
||||||
|
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item row="4" column="1">
|
||||||
|
<spacer name="verticalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>20</width>
|
||||||
|
<height>40</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="0" colspan="2">
|
||||||
|
<widget class="QLabel" name="label_11">
|
||||||
|
<property name="text">
|
||||||
|
<string>Search only in specific fields:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="1">
|
||||||
|
<widget class="EnLineEdit" name="author_box"/>
|
||||||
|
</item>
|
||||||
|
<item row="3" column="1">
|
||||||
|
<widget class="QLineEdit" name="format_box"/>
|
||||||
|
</item>
|
||||||
|
<item row="3" column="0">
|
||||||
|
<widget class="QLabel" name="label_10">
|
||||||
|
<property name="text">
|
||||||
|
<string>&Format:</string>
|
||||||
|
</property>
|
||||||
|
<property name="buddy">
|
||||||
|
<cstring>format_box</cstring>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="1">
|
||||||
|
<spacer name="verticalSpacer_3">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>20</width>
|
||||||
|
<height>40</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<customwidgets>
|
||||||
|
<customwidget>
|
||||||
|
<class>EnLineEdit</class>
|
||||||
|
<extends>QLineEdit</extends>
|
||||||
|
<header>widgets.h</header>
|
||||||
|
</customwidget>
|
||||||
|
</customwidgets>
|
||||||
|
<tabstops>
|
||||||
|
<tabstop>all</tabstop>
|
||||||
|
<tabstop>phrase</tabstop>
|
||||||
|
<tabstop>any</tabstop>
|
||||||
|
<tabstop>none</tabstop>
|
||||||
|
<tabstop>buttonBox</tabstop>
|
||||||
|
<tabstop>title_box</tabstop>
|
||||||
|
<tabstop>author_box</tabstop>
|
||||||
|
<tabstop>format_box</tabstop>
|
||||||
|
<tabstop>clear_button</tabstop>
|
||||||
|
<tabstop>tab_2_button_box</tabstop>
|
||||||
|
<tabstop>tabWidget</tabstop>
|
||||||
|
<tabstop>matchkind</tabstop>
|
||||||
|
</tabstops>
|
||||||
|
<resources>
|
||||||
|
<include location="../../../../resources/images.qrc"/>
|
||||||
|
</resources>
|
||||||
|
<connections>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>accepted()</signal>
|
||||||
|
<receiver>Dialog</receiver>
|
||||||
|
<slot>accept()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>248</x>
|
||||||
|
<y>254</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>157</x>
|
||||||
|
<y>274</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>rejected()</signal>
|
||||||
|
<receiver>Dialog</receiver>
|
||||||
|
<slot>reject()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>316</x>
|
||||||
|
<y>260</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>286</x>
|
||||||
|
<y>274</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
</connections>
|
||||||
|
</ui>
|
@ -18,7 +18,7 @@ from calibre.gui2.store.web_store_dialog import WebStoreDialog
|
|||||||
from calibre.gui2.store.mobileread.models import SearchFilter
|
from calibre.gui2.store.mobileread.models import SearchFilter
|
||||||
from calibre.gui2.store.mobileread.cache_progress_dialog import CacheProgressDialog
|
from calibre.gui2.store.mobileread.cache_progress_dialog import CacheProgressDialog
|
||||||
from calibre.gui2.store.mobileread.cache_update_thread import CacheUpdateThread
|
from calibre.gui2.store.mobileread.cache_update_thread import CacheUpdateThread
|
||||||
from calibre.gui2.store.mobileread.store_dialog import MobeReadStoreDialog
|
from calibre.gui2.store.mobileread.store_dialog import MobileReadStoreDialog
|
||||||
|
|
||||||
class MobileReadStore(BasicStoreConfig, StorePlugin):
|
class MobileReadStore(BasicStoreConfig, StorePlugin):
|
||||||
|
|
||||||
@ -38,7 +38,7 @@ class MobileReadStore(BasicStoreConfig, StorePlugin):
|
|||||||
d.exec_()
|
d.exec_()
|
||||||
else:
|
else:
|
||||||
self.update_cache(parent, 30)
|
self.update_cache(parent, 30)
|
||||||
d = MobeReadStoreDialog(self, parent)
|
d = MobileReadStoreDialog(self, parent)
|
||||||
d.setWindowTitle(self.name)
|
d.setWindowTitle(self.name)
|
||||||
d.exec_()
|
d.exec_()
|
||||||
|
|
||||||
|
@ -9,11 +9,11 @@ __docformat__ = 'restructuredtext en'
|
|||||||
|
|
||||||
from PyQt4.Qt import (Qt, QDialog, QIcon)
|
from PyQt4.Qt import (Qt, QDialog, QIcon)
|
||||||
|
|
||||||
from calibre.gui2.store.search.adv_search_builder import AdvSearchBuilderDialog
|
from calibre.gui2.store.mobileread.adv_search_builder import AdvSearchBuilderDialog
|
||||||
from calibre.gui2.store.mobileread.models import BooksModel
|
from calibre.gui2.store.mobileread.models import BooksModel
|
||||||
from calibre.gui2.store.mobileread.store_dialog_ui import Ui_Dialog
|
from calibre.gui2.store.mobileread.store_dialog_ui import Ui_Dialog
|
||||||
|
|
||||||
class MobeReadStoreDialog(QDialog, Ui_Dialog):
|
class MobileReadStoreDialog(QDialog, Ui_Dialog):
|
||||||
|
|
||||||
def __init__(self, plugin, *args):
|
def __init__(self, plugin, *args):
|
||||||
QDialog.__init__(self, *args)
|
QDialog.__init__(self, *args)
|
||||||
@ -49,8 +49,6 @@ class MobeReadStoreDialog(QDialog, Ui_Dialog):
|
|||||||
|
|
||||||
def build_adv_search(self):
|
def build_adv_search(self):
|
||||||
adv = AdvSearchBuilderDialog(self)
|
adv = AdvSearchBuilderDialog(self)
|
||||||
adv.price_label.hide()
|
|
||||||
adv.price_box.hide()
|
|
||||||
if adv.exec_() == QDialog.Accepted:
|
if adv.exec_() == QDialog.Accepted:
|
||||||
self.search_query.setText(adv.search_string())
|
self.search_query.setText(adv.search_string())
|
||||||
|
|
||||||
|
@ -45,6 +45,7 @@ class AdvSearchBuilderDialog(QDialog, Ui_Dialog):
|
|||||||
self.author_box.setText('')
|
self.author_box.setText('')
|
||||||
self.price_box.setText('')
|
self.price_box.setText('')
|
||||||
self.format_box.setText('')
|
self.format_box.setText('')
|
||||||
|
self.affiliate_combo.setCurrentIndex(0)
|
||||||
|
|
||||||
def tokens(self, raw):
|
def tokens(self, raw):
|
||||||
phrases = re.findall(r'\s*".*?"\s*', raw)
|
phrases = re.findall(r'\s*".*?"\s*', raw)
|
||||||
@ -118,6 +119,9 @@ class AdvSearchBuilderDialog(QDialog, Ui_Dialog):
|
|||||||
format = unicode(self.format_box.text()).strip()
|
format = unicode(self.format_box.text()).strip()
|
||||||
if format:
|
if format:
|
||||||
ans.append('format:"' + self.mc + format + '"')
|
ans.append('format:"' + self.mc + format + '"')
|
||||||
|
affiliate = unicode(self.affiliate_combo.currentText()).strip()
|
||||||
|
if affiliate:
|
||||||
|
ans.append('affiliate:' + affiliate)
|
||||||
if ans:
|
if ans:
|
||||||
return ' and '.join(ans)
|
return ' and '.join(ans)
|
||||||
return ''
|
return ''
|
||||||
|
@ -226,7 +226,7 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="6" column="0" colspan="2">
|
<item row="7" column="0" colspan="2">
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_6">
|
<layout class="QHBoxLayout" name="horizontalLayout_6">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="clear_button">
|
<widget class="QPushButton" name="clear_button">
|
||||||
@ -244,7 +244,7 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item row="5" column="1">
|
<item row="6" column="1">
|
||||||
<spacer name="verticalSpacer">
|
<spacer name="verticalSpacer">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Vertical</enum>
|
<enum>Qt::Vertical</enum>
|
||||||
@ -283,6 +283,32 @@
|
|||||||
<item row="3" column="1">
|
<item row="3" column="1">
|
||||||
<widget class="EnLineEdit" name="price_box"/>
|
<widget class="EnLineEdit" name="price_box"/>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="5" column="0">
|
||||||
|
<widget class="QLabel" name="label_9">
|
||||||
|
<property name="text">
|
||||||
|
<string>Affiliate:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="5" column="1">
|
||||||
|
<widget class="QComboBox" name="affiliate_combo">
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>true</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>false</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
|
@ -120,6 +120,8 @@ class SearchThread(Thread):
|
|||||||
if not self._run:
|
if not self._run:
|
||||||
return
|
return
|
||||||
res.store_name = store_name
|
res.store_name = store_name
|
||||||
|
res.affiliate = store_plugin.base_plugin.affiliate
|
||||||
|
res.plugin_author = store_plugin.base_plugin.author
|
||||||
self.results.put((res, store_plugin))
|
self.results.put((res, store_plugin))
|
||||||
self.tasks.task_done()
|
self.tasks.task_done()
|
||||||
except:
|
except:
|
||||||
|
@ -12,7 +12,7 @@ from operator import attrgetter
|
|||||||
from PyQt4.Qt import (Qt, QAbstractItemModel, QVariant, QPixmap, QModelIndex, QSize,
|
from PyQt4.Qt import (Qt, QAbstractItemModel, QVariant, QPixmap, QModelIndex, QSize,
|
||||||
pyqtSignal)
|
pyqtSignal)
|
||||||
|
|
||||||
from calibre.gui2 import NONE
|
from calibre.gui2 import NONE, FunctionDispatcher
|
||||||
from calibre.gui2.store.search_result import SearchResult
|
from calibre.gui2.store.search_result import SearchResult
|
||||||
from calibre.gui2.store.search.download_thread import DetailsThreadPool, \
|
from calibre.gui2.store.search.download_thread import DetailsThreadPool, \
|
||||||
CoverThreadPool
|
CoverThreadPool
|
||||||
@ -33,7 +33,7 @@ class Matches(QAbstractItemModel):
|
|||||||
|
|
||||||
total_changed = pyqtSignal(int)
|
total_changed = pyqtSignal(int)
|
||||||
|
|
||||||
HEADERS = [_('Cover'), _('Title'), _('Price'), _('DRM'), _('Store')]
|
HEADERS = [_('Cover'), _('Title'), _('Price'), _('DRM'), _('Store'), _('')]
|
||||||
HTML_COLS = (1, 4)
|
HTML_COLS = (1, 4)
|
||||||
|
|
||||||
def __init__(self, cover_thread_count=2, detail_thread_count=4):
|
def __init__(self, cover_thread_count=2, detail_thread_count=4):
|
||||||
@ -45,6 +45,8 @@ class Matches(QAbstractItemModel):
|
|||||||
Qt.SmoothTransformation)
|
Qt.SmoothTransformation)
|
||||||
self.DRM_UNKNOWN_ICON = QPixmap(I('dialog_question.png')).scaledToHeight(64,
|
self.DRM_UNKNOWN_ICON = QPixmap(I('dialog_question.png')).scaledToHeight(64,
|
||||||
Qt.SmoothTransformation)
|
Qt.SmoothTransformation)
|
||||||
|
self.DONATE_ICON = QPixmap(I('donate.png')).scaledToHeight(16,
|
||||||
|
Qt.SmoothTransformation)
|
||||||
|
|
||||||
# All matches. Used to determine the order to display
|
# All matches. Used to determine the order to display
|
||||||
# self.matches because the SearchFilter returns
|
# self.matches because the SearchFilter returns
|
||||||
@ -57,6 +59,9 @@ class Matches(QAbstractItemModel):
|
|||||||
self.cover_pool = CoverThreadPool(cover_thread_count)
|
self.cover_pool = CoverThreadPool(cover_thread_count)
|
||||||
self.details_pool = DetailsThreadPool(detail_thread_count)
|
self.details_pool = DetailsThreadPool(detail_thread_count)
|
||||||
|
|
||||||
|
self.filter_results_dispatcher = FunctionDispatcher(self.filter_results)
|
||||||
|
self.got_result_details_dispatcher = FunctionDispatcher(self.got_result_details)
|
||||||
|
|
||||||
self.sort_col = 2
|
self.sort_col = 2
|
||||||
self.sort_order = Qt.AscendingOrder
|
self.sort_order = Qt.AscendingOrder
|
||||||
|
|
||||||
@ -82,10 +87,10 @@ class Matches(QAbstractItemModel):
|
|||||||
self.search_filter.add_search_result(result)
|
self.search_filter.add_search_result(result)
|
||||||
if result.cover_url:
|
if result.cover_url:
|
||||||
result.cover_queued = True
|
result.cover_queued = True
|
||||||
self.cover_pool.add_task(result, self.filter_results)
|
self.cover_pool.add_task(result, self.filter_results_dispatcher)
|
||||||
else:
|
else:
|
||||||
result.cover_queued = False
|
result.cover_queued = False
|
||||||
self.details_pool.add_task(result, store_plugin, self.got_result_details)
|
self.details_pool.add_task(result, store_plugin, self.got_result_details_dispatcher)
|
||||||
self.filter_results()
|
self.filter_results()
|
||||||
self.layoutChanged.emit()
|
self.layoutChanged.emit()
|
||||||
|
|
||||||
@ -112,7 +117,7 @@ class Matches(QAbstractItemModel):
|
|||||||
def got_result_details(self, result):
|
def got_result_details(self, result):
|
||||||
if not result.cover_queued and result.cover_url:
|
if not result.cover_queued and result.cover_url:
|
||||||
result.cover_queued = True
|
result.cover_queued = True
|
||||||
self.cover_pool.add_task(result, self.filter_results)
|
self.cover_pool.add_task(result, self.filter_results_dispatcher)
|
||||||
if result in self.matches:
|
if result in self.matches:
|
||||||
row = self.matches.index(result)
|
row = self.matches.index(result)
|
||||||
self.dataChanged.emit(self.index(row, 0), self.index(row, self.columnCount() - 1))
|
self.dataChanged.emit(self.index(row, 0), self.index(row, self.columnCount() - 1))
|
||||||
@ -150,6 +155,8 @@ class Matches(QAbstractItemModel):
|
|||||||
|
|
||||||
def data(self, index, role):
|
def data(self, index, role):
|
||||||
row, col = index.row(), index.column()
|
row, col = index.row(), index.column()
|
||||||
|
if row >= len(self.matches):
|
||||||
|
return NONE
|
||||||
result = self.matches[row]
|
result = self.matches[row]
|
||||||
if role == Qt.DisplayRole:
|
if role == Qt.DisplayRole:
|
||||||
if col == 1:
|
if col == 1:
|
||||||
@ -173,6 +180,10 @@ class Matches(QAbstractItemModel):
|
|||||||
return QVariant(self.DRM_UNLOCKED_ICON)
|
return QVariant(self.DRM_UNLOCKED_ICON)
|
||||||
elif result.drm == SearchResult.DRM_UNKNOWN:
|
elif result.drm == SearchResult.DRM_UNKNOWN:
|
||||||
return QVariant(self.DRM_UNKNOWN_ICON)
|
return QVariant(self.DRM_UNKNOWN_ICON)
|
||||||
|
if col == 5:
|
||||||
|
if result.affiliate:
|
||||||
|
return QVariant(self.DONATE_ICON)
|
||||||
|
return NONE
|
||||||
elif role == Qt.ToolTipRole:
|
elif role == Qt.ToolTipRole:
|
||||||
if col == 1:
|
if col == 1:
|
||||||
return QVariant('<p>%s</p>' % result.title)
|
return QVariant('<p>%s</p>' % result.title)
|
||||||
@ -187,6 +198,9 @@ class Matches(QAbstractItemModel):
|
|||||||
return QVariant('<p>' + _('The DRM status of this book could not be determined. There is a very high likelihood that this book is actually DRM restricted.') + '</p>')
|
return QVariant('<p>' + _('The DRM status of this book could not be determined. There is a very high likelihood that this book is actually DRM restricted.') + '</p>')
|
||||||
elif col == 4:
|
elif col == 4:
|
||||||
return QVariant('<p>%s</p>' % result.formats)
|
return QVariant('<p>%s</p>' % result.formats)
|
||||||
|
elif col == 5:
|
||||||
|
if result.affiliate:
|
||||||
|
return QVariant('<p>' + _('Buying from this store supports the calibre developer: %s.') % result.plugin_author + '</p>')
|
||||||
elif role == Qt.SizeHintRole:
|
elif role == Qt.SizeHintRole:
|
||||||
return QSize(64, 64)
|
return QSize(64, 64)
|
||||||
return NONE
|
return NONE
|
||||||
@ -206,6 +220,11 @@ class Matches(QAbstractItemModel):
|
|||||||
text = 'c'
|
text = 'c'
|
||||||
elif col == 4:
|
elif col == 4:
|
||||||
text = result.store_name
|
text = result.store_name
|
||||||
|
elif col == 5:
|
||||||
|
if result.affiliate:
|
||||||
|
text = 'a'
|
||||||
|
else:
|
||||||
|
text = 'b'
|
||||||
return text
|
return text
|
||||||
|
|
||||||
def sort(self, col, order, reset=True):
|
def sort(self, col, order, reset=True):
|
||||||
@ -234,6 +253,7 @@ class SearchFilter(SearchQueryParser):
|
|||||||
|
|
||||||
USABLE_LOCATIONS = [
|
USABLE_LOCATIONS = [
|
||||||
'all',
|
'all',
|
||||||
|
'affiliate',
|
||||||
'author',
|
'author',
|
||||||
'authors',
|
'authors',
|
||||||
'cover',
|
'cover',
|
||||||
@ -284,6 +304,7 @@ class SearchFilter(SearchQueryParser):
|
|||||||
all_locs = set(self.USABLE_LOCATIONS) - set(['all'])
|
all_locs = set(self.USABLE_LOCATIONS) - set(['all'])
|
||||||
locations = all_locs if location == 'all' else [location]
|
locations = all_locs if location == 'all' else [location]
|
||||||
q = {
|
q = {
|
||||||
|
'affiliate': attrgetter('affiliate'),
|
||||||
'author': lambda x: x.author.lower(),
|
'author': lambda x: x.author.lower(),
|
||||||
'cover': attrgetter('cover_url'),
|
'cover': attrgetter('cover_url'),
|
||||||
'drm': attrgetter('drm'),
|
'drm': attrgetter('drm'),
|
||||||
@ -298,23 +319,35 @@ class SearchFilter(SearchQueryParser):
|
|||||||
for locvalue in locations:
|
for locvalue in locations:
|
||||||
accessor = q[locvalue]
|
accessor = q[locvalue]
|
||||||
if query == 'true':
|
if query == 'true':
|
||||||
if locvalue == 'drm':
|
# True/False.
|
||||||
|
if locvalue == 'affiliate':
|
||||||
|
if accessor(sr):
|
||||||
|
matches.add(sr)
|
||||||
|
# Special that are treated as True/False.
|
||||||
|
elif locvalue == 'drm':
|
||||||
if accessor(sr) == SearchResult.DRM_LOCKED:
|
if accessor(sr) == SearchResult.DRM_LOCKED:
|
||||||
matches.add(sr)
|
matches.add(sr)
|
||||||
|
# Testing for something or nothing.
|
||||||
else:
|
else:
|
||||||
if accessor(sr) is not None:
|
if accessor(sr) is not None:
|
||||||
matches.add(sr)
|
matches.add(sr)
|
||||||
continue
|
continue
|
||||||
if query == 'false':
|
if query == 'false':
|
||||||
if locvalue == 'drm':
|
# True/False.
|
||||||
|
if locvalue == 'affiliate':
|
||||||
|
if not accessor(sr):
|
||||||
|
matches.add(sr)
|
||||||
|
# Special that are treated as True/False.
|
||||||
|
elif locvalue == 'drm':
|
||||||
if accessor(sr) == SearchResult.DRM_UNLOCKED:
|
if accessor(sr) == SearchResult.DRM_UNLOCKED:
|
||||||
matches.add(sr)
|
matches.add(sr)
|
||||||
|
# Testing for something or nothing.
|
||||||
else:
|
else:
|
||||||
if accessor(sr) is None:
|
if accessor(sr) is None:
|
||||||
matches.add(sr)
|
matches.add(sr)
|
||||||
continue
|
continue
|
||||||
# this is bool, so can't match below
|
# this is bool or treated as bool, so can't match below.
|
||||||
if locvalue == 'drm':
|
if locvalue in ('affiliate', 'drm'):
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
### Can't separate authors because comma is used for name sep and author sep
|
### Can't separate authors because comma is used for name sep and author sep
|
||||||
|
@ -9,8 +9,8 @@ __docformat__ = 'restructuredtext en'
|
|||||||
import re
|
import re
|
||||||
from random import shuffle
|
from random import shuffle
|
||||||
|
|
||||||
from PyQt4.Qt import (Qt, QDialog, QDialogButtonBox, QTimer, QCheckBox,
|
from PyQt4.Qt import (Qt, QDialog, QDialogButtonBox, QTimer, QCheckBox, QLabel,
|
||||||
QVBoxLayout, QIcon, QWidget, QTabWidget)
|
QVBoxLayout, QIcon, QWidget, QTabWidget, QGridLayout)
|
||||||
|
|
||||||
from calibre.gui2 import JSONConfig, info_dialog
|
from calibre.gui2 import JSONConfig, info_dialog
|
||||||
from calibre.gui2.progress_indicator import ProgressIndicator
|
from calibre.gui2.progress_indicator import ProgressIndicator
|
||||||
@ -92,14 +92,21 @@ class SearchDialog(QDialog, Ui_Dialog):
|
|||||||
self.store_checks = {}
|
self.store_checks = {}
|
||||||
|
|
||||||
stores_check_widget = QWidget()
|
stores_check_widget = QWidget()
|
||||||
store_list_layout = QVBoxLayout()
|
store_list_layout = QGridLayout()
|
||||||
stores_check_widget.setLayout(store_list_layout)
|
stores_check_widget.setLayout(store_list_layout)
|
||||||
for x in sorted(self.gui.istores.keys(), key=lambda x: x.lower()):
|
|
||||||
|
icon = QIcon(I('donate.png'))
|
||||||
|
for i, x in enumerate(sorted(self.gui.istores.keys(), key=lambda x: x.lower())):
|
||||||
cbox = QCheckBox(x)
|
cbox = QCheckBox(x)
|
||||||
cbox.setChecked(existing.get(x, False))
|
cbox.setChecked(existing.get(x, False))
|
||||||
store_list_layout.addWidget(cbox)
|
store_list_layout.addWidget(cbox, i, 0, 1, 1)
|
||||||
|
if self.gui.istores[x].base_plugin.affiliate:
|
||||||
|
iw = QLabel(self)
|
||||||
|
iw.setToolTip('<p>' + _('Buying from this store supports the calibre developer: %s</p>') % self.gui.istores[x].base_plugin.author + '</p>')
|
||||||
|
iw.setPixmap(icon.pixmap(16, 16))
|
||||||
|
store_list_layout.addWidget(iw, i, 1, 1, 1)
|
||||||
self.store_checks[x] = cbox
|
self.store_checks[x] = cbox
|
||||||
store_list_layout.addStretch()
|
store_list_layout.setRowStretch(store_list_layout.rowCount(), 10)
|
||||||
self.store_list.setWidget(stores_check_widget)
|
self.store_list.setWidget(stores_check_widget)
|
||||||
|
|
||||||
def build_adv_search(self):
|
def build_adv_search(self):
|
||||||
@ -244,6 +251,8 @@ class SearchDialog(QDialog, Ui_Dialog):
|
|||||||
# search widget.
|
# search widget.
|
||||||
self.config['open_external'] = self.open_external.isChecked()
|
self.config['open_external'] = self.open_external.isChecked()
|
||||||
|
|
||||||
|
# Create the config dialog. It's going to put two config widgets
|
||||||
|
# into a QTabWidget for displaying all of the settings.
|
||||||
d = QDialog(self)
|
d = QDialog(self)
|
||||||
button_box = QDialogButtonBox(QDialogButtonBox.Close)
|
button_box = QDialogButtonBox(QDialogButtonBox.Close)
|
||||||
v = QVBoxLayout(d)
|
v = QVBoxLayout(d)
|
||||||
@ -261,7 +270,22 @@ class SearchDialog(QDialog, Ui_Dialog):
|
|||||||
tab_widget.addTab(chooser_config_widget, _('Choose stores'))
|
tab_widget.addTab(chooser_config_widget, _('Choose stores'))
|
||||||
tab_widget.addTab(search_config_widget, _('Configure search'))
|
tab_widget.addTab(search_config_widget, _('Configure search'))
|
||||||
|
|
||||||
|
# Restore dialog state.
|
||||||
|
geometry = self.config.get('config_dialog_geometry', None)
|
||||||
|
if geometry:
|
||||||
|
d.restoreGeometry(geometry)
|
||||||
|
else:
|
||||||
|
d.resize(800, 600)
|
||||||
|
tab_index = self.config.get('config_dialog_tab_index', 0)
|
||||||
|
tab_index = min(tab_index, tab_widget.count() - 1)
|
||||||
|
tab_widget.setCurrentIndex(tab_index)
|
||||||
|
|
||||||
d.exec_()
|
d.exec_()
|
||||||
|
|
||||||
|
# Save dialog state.
|
||||||
|
self.config['config_dialog_geometry'] = bytearray(d.saveGeometry())
|
||||||
|
self.config['config_dialog_tab_index'] = tab_widget.currentIndex()
|
||||||
|
|
||||||
search_config_widget.save_settings()
|
search_config_widget.save_settings()
|
||||||
self.config_changed()
|
self.config_changed()
|
||||||
self.gui.load_store_plugins()
|
self.gui.load_store_plugins()
|
||||||
|
@ -22,6 +22,8 @@ class SearchResult(object):
|
|||||||
self.detail_item = ''
|
self.detail_item = ''
|
||||||
self.drm = None
|
self.drm = None
|
||||||
self.formats = ''
|
self.formats = ''
|
||||||
|
self.affiliate = False
|
||||||
|
self.plugin_author = ''
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
return self.title == other.title and self.author == other.author and self.store_name == other.store_name
|
return self.title == other.title and self.author == other.author and self.store_name == other.store_name
|
||||||
|
83
src/calibre/gui2/store/whsmith_uk_plugin.py
Normal file
83
src/calibre/gui2/store/whsmith_uk_plugin.py
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from __future__ import (unicode_literals, division, absolute_import, print_function)
|
||||||
|
|
||||||
|
__license__ = 'GPL 3'
|
||||||
|
__copyright__ = '2011, John Schember <john@nachtimwald.com>'
|
||||||
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
|
import urllib2
|
||||||
|
from contextlib import closing
|
||||||
|
|
||||||
|
from lxml import html
|
||||||
|
|
||||||
|
from PyQt4.Qt import QUrl
|
||||||
|
|
||||||
|
from calibre import browser
|
||||||
|
from calibre.gui2 import open_url
|
||||||
|
from calibre.gui2.store import StorePlugin
|
||||||
|
from calibre.gui2.store.basic_config import BasicStoreConfig
|
||||||
|
from calibre.gui2.store.search_result import SearchResult
|
||||||
|
from calibre.gui2.store.web_store_dialog import WebStoreDialog
|
||||||
|
|
||||||
|
class WHSmithUKStore(BasicStoreConfig, StorePlugin):
|
||||||
|
|
||||||
|
def open(self, parent=None, detail_item=None, external=False):
|
||||||
|
url = 'http://www.whsmith.co.uk/'
|
||||||
|
url_details = ''
|
||||||
|
|
||||||
|
if external or self.config.get('open_external', False):
|
||||||
|
if detail_item:
|
||||||
|
url = url_details + detail_item
|
||||||
|
open_url(QUrl(url))
|
||||||
|
else:
|
||||||
|
detail_url = None
|
||||||
|
if detail_item:
|
||||||
|
detail_url = url_details + detail_item
|
||||||
|
d = WebStoreDialog(self.gui, url, parent, detail_url)
|
||||||
|
d.setWindowTitle(self.name)
|
||||||
|
d.set_tags(self.config.get('tags', ''))
|
||||||
|
d.exec_()
|
||||||
|
|
||||||
|
def search(self, query, max_results=10, timeout=60):
|
||||||
|
url = ('http://www.whsmith.co.uk/CatalogAndSearch/SearchWithinCategory.aspx'
|
||||||
|
'?cat=\Books\eb_eBooks&gq=' + urllib2.quote(query))
|
||||||
|
|
||||||
|
br = browser()
|
||||||
|
|
||||||
|
counter = max_results
|
||||||
|
with closing(br.open(url, timeout=timeout)) as f:
|
||||||
|
doc = html.fromstring(f.read())
|
||||||
|
for data in doc.xpath('//div[@class="product-search"]/'
|
||||||
|
'div[contains(@id, "whsSearchResultItem")]'):
|
||||||
|
if counter <= 0:
|
||||||
|
break
|
||||||
|
|
||||||
|
id = ''.join(data.xpath('.//a[contains(@id, "labelProductTitle")]/@href'))
|
||||||
|
if not id:
|
||||||
|
continue
|
||||||
|
cover_url = ''.join(data.xpath('.//a[contains(@id, "hlinkProductImage")]/img/@src'))
|
||||||
|
title = ''.join(data.xpath('.//a[contains(@id, "labelProductTitle")]/text()'))
|
||||||
|
author = ', '.join(data.xpath('.//div[@class="author"]/h3/span/text()'))
|
||||||
|
price = ''.join(data.xpath('.//span[contains(@id, "labelProductPrice")]/text()'))
|
||||||
|
pdf = data.xpath('boolean(.//span[contains(@id, "labelFormatText") and '
|
||||||
|
'contains(., "PDF")])')
|
||||||
|
epub = data.xpath('boolean(.//span[contains(@id, "labelFormatText") and '
|
||||||
|
'contains(., "ePub")])')
|
||||||
|
counter -= 1
|
||||||
|
|
||||||
|
s = SearchResult()
|
||||||
|
s.cover_url = cover_url
|
||||||
|
s.title = title.strip()
|
||||||
|
s.author = author.strip()
|
||||||
|
s.price = price
|
||||||
|
s.drm = SearchResult.DRM_LOCKED
|
||||||
|
s.detail_item = id
|
||||||
|
formats = []
|
||||||
|
if epub:
|
||||||
|
formats.append('ePub')
|
||||||
|
if pdf:
|
||||||
|
formats.append('PDF')
|
||||||
|
s.formats = ', '.join(formats)
|
||||||
|
|
||||||
|
yield s
|
Loading…
x
Reference in New Issue
Block a user