From b04eed00121f98fee1316cc3bff761e4f993c438 Mon Sep 17 00:00:00 2001
From: Charles Haley <>
Date: Fri, 27 May 2011 13:00:31 +0100
Subject: [PATCH 01/21] New store: EBookShoppeUKStore. small correction to
FoylesUKStore. fix to threading problem in search causing range errors.
Disable waterstones.
---
src/calibre/customize/builtins.py | 13 ++-
.../gui2/store/ebookshoppe_uk_plugin.py | 97 +++++++++++++++++++
src/calibre/gui2/store/foyles_uk_plugin.py | 9 +-
src/calibre/gui2/store/search/models.py | 2 +
4 files changed, 118 insertions(+), 3 deletions(-)
create mode 100644 src/calibre/gui2/store/ebookshoppe_uk_plugin.py
diff --git a/src/calibre/customize/builtins.py b/src/calibre/customize/builtins.py
index 4a970b4661..150ad269bb 100644
--- a/src/calibre/customize/builtins.py
+++ b/src/calibre/customize/builtins.py
@@ -1393,6 +1393,16 @@ class StoreWoblinkStore(StoreBase):
headquarters = 'PL'
formats = ['EPUB']
+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'
+
+ drm_free_only = False
+ headquarters = 'UK'
+ formats = ['EPUB', 'PDF']
+
plugins += [
StoreArchiveOrgStore,
StoreAmazonKindleStore,
@@ -1404,6 +1414,7 @@ plugins += [
StoreBeWriteStore,
StoreDieselEbooksStore,
StoreEbookscomStore,
+ StoreEBookShoppeUKStore,
StoreEPubBuyDEStore,
StoreEHarlequinStore,
StoreFeedbooksStore,
@@ -1421,7 +1432,7 @@ plugins += [
StorePragmaticBookshelfStore,
StoreSmashwordsStore,
StoreVirtualoStore,
- StoreWaterstonesUKStore,
+ # StoreWaterstonesUKStore,
StoreWeightlessBooksStore,
StoreWizardsTowerBooksStore,
StoreWoblinkStore
diff --git a/src/calibre/gui2/store/ebookshoppe_uk_plugin.py b/src/calibre/gui2/store/ebookshoppe_uk_plugin.py
new file mode 100644
index 0000000000..de5304da86
--- /dev/null
+++ b/src/calibre/gui2/store/ebookshoppe_uk_plugin.py
@@ -0,0 +1,97 @@
+# -*- coding: utf-8 -*-
+
+from __future__ import (unicode_literals, division, absolute_import, print_function)
+
+__license__ = 'GPL 3'
+__copyright__ = '2011, John Schember '
+__docformat__ = 'restructuredtext en'
+
+import urllib2
+from contextlib import closing
+
+from lxml import html
+
+from PyQt4.Qt import QUrl
+
+from calibre import browser, url_slash_cleaner
+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_()
+
+ # reduce max_results because the filter will match everything. See the
+ # setting of 'author' below for more details
+
+ def search(self, query, max_results=5, 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()
+ # Set the author to the query terms to ensure that author
+ # queries match something when pruning searches. Of course, this
+ # means that all books will match. Sigh...
+ s.author = query
+ s.price = price
+ s.drm = SearchResult.DRM_UNLOCKED
+ s.detail_item = id
+ s.formats = ''
+
+ # Call this here instead of later. Reason: painting then
+ # removing matches looks very strange. There are also issues
+ # with threading. Yes, this makes things take longer, but we
+ # will do the work anyway.
+ self.my_get_details(s, timeout)
+
+ yield s
+
+ def my_get_details(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
\ No newline at end of file
diff --git a/src/calibre/gui2/store/foyles_uk_plugin.py b/src/calibre/gui2/store/foyles_uk_plugin.py
index 1a997cd671..fd670d2d85 100644
--- a/src/calibre/gui2/store/foyles_uk_plugin.py
+++ b/src/calibre/gui2/store/foyles_uk_plugin.py
@@ -23,12 +23,13 @@ from calibre.gui2.store.web_store_dialog import WebStoreDialog
class FoylesUKStore(BasicStoreConfig, StorePlugin):
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'
if external or self.config.get('open_external', False):
if detail_item:
- url = url + url_redirect + detail_item
+ url = detail_url + url_redirect + detail_item
open_url(QUrl(url_slash_cleaner(url)))
else:
detail_url = None
@@ -54,6 +55,10 @@ class FoylesUKStore(BasicStoreConfig, StorePlugin):
if not id:
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'))
if cover_url:
cover_url = 'http://www.foyles.co.uk' + cover_url
diff --git a/src/calibre/gui2/store/search/models.py b/src/calibre/gui2/store/search/models.py
index d7941480cc..64724be6aa 100644
--- a/src/calibre/gui2/store/search/models.py
+++ b/src/calibre/gui2/store/search/models.py
@@ -150,6 +150,8 @@ class Matches(QAbstractItemModel):
def data(self, index, role):
row, col = index.row(), index.column()
+ if row >= len(self.matches):
+ return NONE
result = self.matches[row]
if role == Qt.DisplayRole:
if col == 1:
From ca6e74f762c73e8d69a1f0d931172388108059c7 Mon Sep 17 00:00:00 2001
From: John Schember
Date: Fri, 27 May 2011 20:07:48 -0400
Subject: [PATCH 02/21] Store: Fix threading issue. Fix Manybooks cover
download.
---
src/calibre/gui2/store/manybooks_plugin.py | 3 ++-
src/calibre/gui2/store/search/models.py | 11 +++++++----
2 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/src/calibre/gui2/store/manybooks_plugin.py b/src/calibre/gui2/store/manybooks_plugin.py
index 1ae9d47d01..e990accc86 100644
--- a/src/calibre/gui2/store/manybooks_plugin.py
+++ b/src/calibre/gui2/store/manybooks_plugin.py
@@ -78,7 +78,8 @@ class ManyBooksStore(BasicStoreConfig, StorePlugin):
cover_name = mo.group()
cover_name = cover_name.replace('etext', '')
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
diff --git a/src/calibre/gui2/store/search/models.py b/src/calibre/gui2/store/search/models.py
index d7941480cc..3d1a5c2724 100644
--- a/src/calibre/gui2/store/search/models.py
+++ b/src/calibre/gui2/store/search/models.py
@@ -12,7 +12,7 @@ from operator import attrgetter
from PyQt4.Qt import (Qt, QAbstractItemModel, QVariant, QPixmap, QModelIndex, QSize,
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.download_thread import DetailsThreadPool, \
CoverThreadPool
@@ -56,6 +56,9 @@ class Matches(QAbstractItemModel):
self.search_filter = SearchFilter()
self.cover_pool = CoverThreadPool(cover_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_order = Qt.AscendingOrder
@@ -82,10 +85,10 @@ class Matches(QAbstractItemModel):
self.search_filter.add_search_result(result)
if result.cover_url:
result.cover_queued = True
- self.cover_pool.add_task(result, self.filter_results)
+ self.cover_pool.add_task(result, self.filter_results_dispatcher)
else:
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.layoutChanged.emit()
@@ -112,7 +115,7 @@ class Matches(QAbstractItemModel):
def got_result_details(self, result):
if not result.cover_queued and result.cover_url:
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:
row = self.matches.index(result)
self.dataChanged.emit(self.index(row, 0), self.index(row, self.columnCount() - 1))
From 5e3dd658dff6a640a7ef6756bea8d1ead9b2d557 Mon Sep 17 00:00:00 2001
From: John Schember
Date: Fri, 27 May 2011 20:10:15 -0400
Subject: [PATCH 03/21] Store: Fully remove Waterstones as its maintainer has
dropped it.
---
src/calibre/customize/builtins.py | 11 ---
.../gui2/store/waterstones_uk_plugin.py | 84 -------------------
2 files changed, 95 deletions(-)
delete mode 100644 src/calibre/gui2/store/waterstones_uk_plugin.py
diff --git a/src/calibre/customize/builtins.py b/src/calibre/customize/builtins.py
index 70ef1612ee..fb35fa14e9 100644
--- a/src/calibre/customize/builtins.py
+++ b/src/calibre/customize/builtins.py
@@ -1355,16 +1355,6 @@ class StoreVirtualoStore(StoreBase):
headquarters = 'PL'
formats = ['EPUB', 'PDF']
-class StoreWaterstonesUKStore(StoreBase):
- name = 'Waterstones UK'
- author = 'Charles Haley'
- 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'
-
- drm_free_only = False
- headquarters = 'UK'
- formats = ['EPUB', 'PDF']
-
class StoreWeightlessBooksStore(StoreBase):
name = 'Weightless Books'
description = u'An independent DRM-free ebooksite devoted to ebooks of all sorts.'
@@ -1421,7 +1411,6 @@ plugins += [
StorePragmaticBookshelfStore,
StoreSmashwordsStore,
StoreVirtualoStore,
- #StoreWaterstonesUKStore,
StoreWeightlessBooksStore,
StoreWizardsTowerBooksStore,
StoreWoblinkStore
diff --git a/src/calibre/gui2/store/waterstones_uk_plugin.py b/src/calibre/gui2/store/waterstones_uk_plugin.py
deleted file mode 100644
index a5065128ba..0000000000
--- a/src/calibre/gui2/store/waterstones_uk_plugin.py
+++ /dev/null
@@ -1,84 +0,0 @@
-# -*- coding: utf-8 -*-
-
-from __future__ import (unicode_literals, division, absolute_import, print_function)
-
-__license__ = 'GPL 3'
-__copyright__ = '2011, John Schember '
-__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 WaterstonesUKStore(BasicStoreConfig, StorePlugin):
-
- def open(self, parent=None, detail_item=None, external=False):
- url = 'http://clkuk.tradedoubler.com/click?p=51196&a=1951604&g=19333484'
- url_details = 'http://clkuk.tradedoubler.com/click?p(51196)a(1951604)g(16460516)url({0})'
-
- 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.waterstones.com/waterstonesweb/advancedSearch.do?buttonClicked=1&format=3757&bookkeywords=' + 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[contains(@class, "results-pane")]'):
- if counter <= 0:
- break
-
- id = ''.join(data.xpath('./div/div/h2/a/@href')).strip()
- if not id:
- continue
- cover_url = ''.join(data.xpath('.//div[@class="image"]/a/img/@src'))
- title = ''.join(data.xpath('./div/div/h2/a/text()'))
- author = ', '.join(data.xpath('.//p[@class="byAuthor"]/a/text()'))
- price = ''.join(data.xpath('.//p[@class="price"]/span[@class="priceStandard"]/text()'))
- drm = data.xpath('boolean(.//td[@headers="productFormat" and contains(., "DRM")])')
- pdf = data.xpath('boolean(.//td[@headers="productFormat" and contains(., "PDF")])')
- epub = data.xpath('boolean(.//td[@headers="productFormat" and contains(., "EPUB")])')
-
- counter -= 1
-
- s = SearchResult()
- s.cover_url = cover_url
- s.title = title.strip()
- s.author = author.strip()
- s.price = price
- if drm:
- s.drm = SearchResult.DRM_LOCKED
- else:
- s.drm = SearchResult.DRM_UNKNOWN
- s.detail_item = id
- formats = []
- if epub:
- formats.append('ePub')
- if pdf:
- formats.append('PDF')
- s.formats = ', '.join(formats)
-
- yield s
From 0192aa2da06889f4756af54dca4905d287344bc3 Mon Sep 17 00:00:00 2001
From: John Schember
Date: Fri, 27 May 2011 20:13:19 -0400
Subject: [PATCH 04/21] Store: chooser widget, add history.
---
.../gui2/store/config/chooser/chooser_widget.py | 2 ++
.../gui2/store/config/chooser/chooser_widget.ui | 14 +++++++++++++-
2 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/src/calibre/gui2/store/config/chooser/chooser_widget.py b/src/calibre/gui2/store/config/chooser/chooser_widget.py
index 93630d69a7..2f8c72d3d0 100644
--- a/src/calibre/gui2/store/config/chooser/chooser_widget.py
+++ b/src/calibre/gui2/store/config/chooser/chooser_widget.py
@@ -17,6 +17,8 @@ class StoreChooserWidget(QWidget, Ui_Form):
QWidget.__init__(self)
self.setupUi(self)
+ self.query.initialize('store_config_chooser_query')
+
self.adv_search_builder.setIcon(QIcon(I('search.png')))
self.search.clicked.connect(self.do_search)
diff --git a/src/calibre/gui2/store/config/chooser/chooser_widget.ui b/src/calibre/gui2/store/config/chooser/chooser_widget.ui
index 69117406b1..e833dbf4b9 100644
--- a/src/calibre/gui2/store/config/chooser/chooser_widget.ui
+++ b/src/calibre/gui2/store/config/chooser/chooser_widget.ui
@@ -31,7 +31,14 @@
-
-
+
+
+
+ 0
+ 0
+
+
+
-
@@ -81,6 +88,11 @@
QTreeView
+
+ HistoryLineEdit
+ QLineEdit
+
+
From 30743e1b9d4872e014f8a7b5d2528784eb5fb3f6 Mon Sep 17 00:00:00 2001
From: John Schember
Date: Sat, 28 May 2011 08:38:30 -0400
Subject: [PATCH 05/21] Store: Give MobileRead it's own advanced search dialog.
Fix MobileRead dialog class name.
---
.../store/mobileread/adv_search_builder.py | 119 ++++++
.../store/mobileread/adv_search_builder.ui | 350 ++++++++++++++++++
.../store/mobileread/mobileread_plugin.py | 4 +-
.../gui2/store/mobileread/store_dialog.py | 6 +-
4 files changed, 473 insertions(+), 6 deletions(-)
create mode 100644 src/calibre/gui2/store/mobileread/adv_search_builder.py
create mode 100644 src/calibre/gui2/store/mobileread/adv_search_builder.ui
diff --git a/src/calibre/gui2/store/mobileread/adv_search_builder.py b/src/calibre/gui2/store/mobileread/adv_search_builder.py
new file mode 100644
index 0000000000..8c41f1924b
--- /dev/null
+++ b/src/calibre/gui2/store/mobileread/adv_search_builder.py
@@ -0,0 +1,119 @@
+# -*- coding: utf-8 -*-
+
+from __future__ import (unicode_literals, division, absolute_import, print_function)
+
+__license__ = 'GPL 3'
+__copyright__ = '2011, John Schember '
+__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 ''
diff --git a/src/calibre/gui2/store/mobileread/adv_search_builder.ui b/src/calibre/gui2/store/mobileread/adv_search_builder.ui
new file mode 100644
index 0000000000..7742ccbd97
--- /dev/null
+++ b/src/calibre/gui2/store/mobileread/adv_search_builder.ui
@@ -0,0 +1,350 @@
+
+
+ Dialog
+
+
+
+ 0
+ 0
+ 752
+ 472
+
+
+
+ Advanced Search
+
+
+
+ :/images/search.png:/images/search.png
+
+
+
-
+
+
+ &What kind of match to use:
+
+
+ matchkind
+
+
+
+ -
+
+
-
+
+ Contains: the word or phrase matches anywhere in the metadata field
+
+
+ -
+
+ Equals: the word or phrase must match the entire metadata field
+
+
+ -
+
+ Regular expression: the expression must match anywhere in the metadata field
+
+
+
+
+ -
+
+
+ 0
+
+
+
+ A&dvanced Search
+
+
+
-
+
+
+ Find entries that have...
+
+
+
-
+
+
-
+
+
+ &All these words:
+
+
+ all
+
+
+
+ -
+
+
+
+
+ -
+
+
-
+
+
+ This exact &phrase:
+
+
+ all
+
+
+
+ -
+
+
+
+
+ -
+
+
-
+
+
+ &One or more of these words:
+
+
+ all
+
+
+
+ -
+
+
+
+
+
+
+
+ -
+
+
+ But dont show entries that have...
+
+
+
-
+
+
-
+
+
+ Any of these &unwanted words:
+
+
+ all
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+ 16777215
+ 30
+
+
+
+ See the <a href="http://calibre-ebook.com/user_manual/gui.html#the-search-interface">User Manual</a> for more help
+
+
+ true
+
+
+
+
+
+
+ -
+
+
+ Qt::Vertical
+
+
+
+ 20
+ 40
+
+
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+ QDialogButtonBox::Cancel|QDialogButtonBox::Ok
+
+
+
+
+
+
+
+ Titl&e/Author/Price ...
+
+
+ -
+
+
+ &Title:
+
+
+ title_box
+
+
+
+ -
+
+
+ Enter the title.
+
+
+
+ -
+
+
+ &Author:
+
+
+ author_box
+
+
+
+ -
+
+
-
+
+
+ &Clear
+
+
+
+ -
+
+
+ QDialogButtonBox::Cancel|QDialogButtonBox::Ok
+
+
+
+
+
+ -
+
+
+ Qt::Vertical
+
+
+
+ 20
+ 40
+
+
+
+
+ -
+
+
+ Search only in specific fields:
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ &Format:
+
+
+ format_box
+
+
+
+
+
+
+
+ -
+
+
+ Qt::Vertical
+
+
+
+ 20
+ 40
+
+
+
+
+
+
+
+
+ EnLineEdit
+ QLineEdit
+
+
+
+
+ all
+ phrase
+ any
+ none
+ buttonBox
+ title_box
+ author_box
+ format_box
+ clear_button
+ tab_2_button_box
+ tabWidget
+ matchkind
+
+
+
+
+
+
+ buttonBox
+ accepted()
+ Dialog
+ accept()
+
+
+ 248
+ 254
+
+
+ 157
+ 274
+
+
+
+
+ buttonBox
+ rejected()
+ Dialog
+ reject()
+
+
+ 316
+ 260
+
+
+ 286
+ 274
+
+
+
+
+
diff --git a/src/calibre/gui2/store/mobileread/mobileread_plugin.py b/src/calibre/gui2/store/mobileread/mobileread_plugin.py
index 271e34a619..4e11d62bbd 100644
--- a/src/calibre/gui2/store/mobileread/mobileread_plugin.py
+++ b/src/calibre/gui2/store/mobileread/mobileread_plugin.py
@@ -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.cache_progress_dialog import CacheProgressDialog
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):
@@ -38,7 +38,7 @@ class MobileReadStore(BasicStoreConfig, StorePlugin):
d.exec_()
else:
self.update_cache(parent, 30)
- d = MobeReadStoreDialog(self, parent)
+ d = MobileReadStoreDialog(self, parent)
d.setWindowTitle(self.name)
d.exec_()
diff --git a/src/calibre/gui2/store/mobileread/store_dialog.py b/src/calibre/gui2/store/mobileread/store_dialog.py
index 7a7b27837d..8908c9bb68 100644
--- a/src/calibre/gui2/store/mobileread/store_dialog.py
+++ b/src/calibre/gui2/store/mobileread/store_dialog.py
@@ -9,11 +9,11 @@ __docformat__ = 'restructuredtext en'
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.store_dialog_ui import Ui_Dialog
-class MobeReadStoreDialog(QDialog, Ui_Dialog):
+class MobileReadStoreDialog(QDialog, Ui_Dialog):
def __init__(self, plugin, *args):
QDialog.__init__(self, *args)
@@ -49,8 +49,6 @@ class MobeReadStoreDialog(QDialog, Ui_Dialog):
def build_adv_search(self):
adv = AdvSearchBuilderDialog(self)
- adv.price_label.hide()
- adv.price_box.hide()
if adv.exec_() == QDialog.Accepted:
self.search_query.setText(adv.search_string())
From 40b073c60cd7bea1063677f89c2feed310206d6a Mon Sep 17 00:00:00 2001
From: Charles Haley <>
Date: Sat, 28 May 2011 13:54:57 +0100
Subject: [PATCH 06/21] Add heart to search screen
---
src/calibre/customize/builtins.py | 8 +++++++-
src/calibre/gui2/store/search/models.py | 18 ++++++++++++++++--
src/calibre/gui2/store/search_result.py | 5 +++--
3 files changed, 26 insertions(+), 5 deletions(-)
diff --git a/src/calibre/customize/builtins.py b/src/calibre/customize/builtins.py
index ad587baf39..ba88d766dc 100644
--- a/src/calibre/customize/builtins.py
+++ b/src/calibre/customize/builtins.py
@@ -1111,6 +1111,7 @@ class StoreAmazonKindleStore(StoreBase):
drm_free_only = False
headquarters = 'US'
formats = ['KINDLE']
+ affiliate = True
class StoreAmazonDEKindleStore(StoreBase):
name = 'Amazon DE Kindle'
@@ -1121,6 +1122,7 @@ class StoreAmazonDEKindleStore(StoreBase):
drm_free_only = False
headquarters = 'DE'
formats = ['KINDLE']
+ affiliate = True
class StoreAmazonUKKindleStore(StoreBase):
name = 'Amazon UK Kindle'
@@ -1131,6 +1133,7 @@ class StoreAmazonUKKindleStore(StoreBase):
drm_free_only = False
headquarters = 'UK'
formats = ['KINDLE']
+ affiliate = True
class StoreArchiveOrgStore(StoreBase):
name = 'Archive.org'
@@ -1168,6 +1171,7 @@ class StoreBeamEBooksDEStore(StoreBase):
drm_free_only = True
headquarters = 'DE'
formats = ['EPUB', 'MOBI', 'PDF']
+ affiliate = True
class StoreBeWriteStore(StoreBase):
name = 'BeWrite Books'
@@ -1233,6 +1237,7 @@ class StoreFoylesUKStore(StoreBase):
drm_free_only = False
headquarters = 'UK'
formats = ['EPUB', 'PDF']
+ affiliate = True
class StoreGandalfStore(StoreBase):
name = 'Gandalf'
@@ -1402,6 +1407,7 @@ class StoreEBookShoppeUKStore(StoreBase):
drm_free_only = False
headquarters = 'UK'
formats = ['EPUB', 'PDF']
+ affiliate = True
plugins += [
StoreArchiveOrgStore,
@@ -1432,7 +1438,7 @@ plugins += [
StorePragmaticBookshelfStore,
StoreSmashwordsStore,
StoreVirtualoStore,
- #StoreWaterstonesUKStore,
+ StoreWaterstonesUKStore,
StoreWeightlessBooksStore,
StoreWizardsTowerBooksStore,
StoreWoblinkStore
diff --git a/src/calibre/gui2/store/search/models.py b/src/calibre/gui2/store/search/models.py
index 64724be6aa..797195e202 100644
--- a/src/calibre/gui2/store/search/models.py
+++ b/src/calibre/gui2/store/search/models.py
@@ -10,7 +10,7 @@ import re
from operator import attrgetter
from PyQt4.Qt import (Qt, QAbstractItemModel, QVariant, QPixmap, QModelIndex, QSize,
- pyqtSignal)
+ pyqtSignal, QIcon)
from calibre.gui2 import NONE
from calibre.gui2.store.search_result import SearchResult
@@ -33,7 +33,7 @@ class Matches(QAbstractItemModel):
total_changed = pyqtSignal(int)
- HEADERS = [_('Cover'), _('Title'), _('Price'), _('DRM'), _('Store')]
+ HEADERS = [_('Cover'), _('Title'), _('Price'), _('DRM'), _('Store'), _('')]
HTML_COLS = (1, 4)
def __init__(self, cover_thread_count=2, detail_thread_count=4):
@@ -76,6 +76,7 @@ class Matches(QAbstractItemModel):
self.reset()
def add_result(self, result, store_plugin):
+ result.plugin = store_plugin
if result not in self.all_matches:
self.layoutAboutToBeChanged.emit()
self.all_matches.append(result)
@@ -175,6 +176,12 @@ class Matches(QAbstractItemModel):
return QVariant(self.DRM_UNLOCKED_ICON)
elif result.drm == SearchResult.DRM_UNKNOWN:
return QVariant(self.DRM_UNKNOWN_ICON)
+ if col == 5:
+ if getattr(result.plugin.base_plugin, 'affiliate', False):
+ icon = QIcon()
+ icon.addFile(I('donate.png'), QSize(16, 16))
+ return QVariant(icon)
+ return NONE
elif role == Qt.ToolTipRole:
if col == 1:
return QVariant('%s
' % result.title)
@@ -189,6 +196,8 @@ class Matches(QAbstractItemModel):
return QVariant('' + _('The DRM status of this book could not be determined. There is a very high likelihood that this book is actually DRM restricted.') + '
')
elif col == 4:
return QVariant('%s
' % result.formats)
+ elif col == 5:
+ return QVariant(_('Buying from this store supports a calibre developer'))
elif role == Qt.SizeHintRole:
return QSize(64, 64)
return NONE
@@ -208,6 +217,11 @@ class Matches(QAbstractItemModel):
text = 'c'
elif col == 4:
text = result.store_name
+ elif col == 5:
+ if getattr(result.plugin.base_plugin, 'affiliate', False):
+ text = 'y'
+ else:
+ text = 'n'
return text
def sort(self, col, order, reset=True):
diff --git a/src/calibre/gui2/store/search_result.py b/src/calibre/gui2/store/search_result.py
index 7bf361157e..a3c6a5601e 100644
--- a/src/calibre/gui2/store/search_result.py
+++ b/src/calibre/gui2/store/search_result.py
@@ -7,11 +7,11 @@ __copyright__ = '2011, John Schember '
__docformat__ = 'restructuredtext en'
class SearchResult(object):
-
+
DRM_LOCKED = 1
DRM_UNLOCKED = 2
DRM_UNKNOWN = 3
-
+
def __init__(self):
self.store_name = ''
self.cover_url = ''
@@ -22,6 +22,7 @@ class SearchResult(object):
self.detail_item = ''
self.drm = None
self.formats = ''
+ self.plugin = None
def __eq__(self, other):
return self.title == other.title and self.author == other.author and self.store_name == other.store_name
From ddb7afffa9d846b2798e6c7a644d8dc052ebb7eb Mon Sep 17 00:00:00 2001
From: Charles Haley <>
Date: Sat, 28 May 2011 13:59:16 +0100
Subject: [PATCH 07/21] Improve handling of affiliate flag.
---
src/calibre/gui2/store/search/models.py | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/calibre/gui2/store/search/models.py b/src/calibre/gui2/store/search/models.py
index 797195e202..44a993ef12 100644
--- a/src/calibre/gui2/store/search/models.py
+++ b/src/calibre/gui2/store/search/models.py
@@ -76,7 +76,7 @@ class Matches(QAbstractItemModel):
self.reset()
def add_result(self, result, store_plugin):
- result.plugin = store_plugin
+ result.affiliate = getattr(store_plugin.base_plugin, 'affiliate', False)
if result not in self.all_matches:
self.layoutAboutToBeChanged.emit()
self.all_matches.append(result)
@@ -177,7 +177,7 @@ class Matches(QAbstractItemModel):
elif result.drm == SearchResult.DRM_UNKNOWN:
return QVariant(self.DRM_UNKNOWN_ICON)
if col == 5:
- if getattr(result.plugin.base_plugin, 'affiliate', False):
+ if result.affiliate:
icon = QIcon()
icon.addFile(I('donate.png'), QSize(16, 16))
return QVariant(icon)
@@ -218,7 +218,7 @@ class Matches(QAbstractItemModel):
elif col == 4:
text = result.store_name
elif col == 5:
- if getattr(result.plugin.base_plugin, 'affiliate', False):
+ if result.affiliate:
text = 'y'
else:
text = 'n'
From 07716ef80130943906d2e2bac4ba3d241d9bde8b Mon Sep 17 00:00:00 2001
From: Charles Haley <>
Date: Sat, 28 May 2011 14:56:53 +0100
Subject: [PATCH 08/21] Move setting affiliate in the results structure. Add
the heart to the list of stores. Initialize 'affiliate' in the thread.
---
src/calibre/customize/__init__.py | 4 +++-
src/calibre/gui2/actions/store.py | 9 +++++++--
src/calibre/gui2/store/search/download_thread.py | 7 ++++---
src/calibre/gui2/store/search/models.py | 6 ++++--
4 files changed, 18 insertions(+), 8 deletions(-)
diff --git a/src/calibre/customize/__init__.py b/src/calibre/customize/__init__.py
index 3d265aed1c..d087eb5351 100644
--- a/src/calibre/customize/__init__.py
+++ b/src/calibre/customize/__init__.py
@@ -615,7 +615,7 @@ class StoreBase(Plugin): # {{{
version = (1, 0, 1)
actual_plugin = None
-
+
# Does the store only distribute ebooks without DRM.
drm_free_only = False
# This is the 2 letter country code for the corporate
@@ -623,6 +623,8 @@ class StoreBase(Plugin): # {{{
headquarters = ''
# All formats the store distributes ebooks in.
formats = []
+ # Is this store on an affiliate program?
+ affiliate = False
def load_actual_plugin(self, gui):
'''
diff --git a/src/calibre/gui2/actions/store.py b/src/calibre/gui2/actions/store.py
index 6d9720548e..7f9b538bcf 100644
--- a/src/calibre/gui2/actions/store.py
+++ b/src/calibre/gui2/actions/store.py
@@ -8,7 +8,7 @@ __docformat__ = 'restructuredtext en'
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.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.addSeparator()
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()):
- 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.addAction(_('Choose stores'), self.choose)
self.qaction.setMenu(self.store_menu)
diff --git a/src/calibre/gui2/store/search/download_thread.py b/src/calibre/gui2/store/search/download_thread.py
index 1fc74a5748..67b4224981 100644
--- a/src/calibre/gui2/store/search/download_thread.py
+++ b/src/calibre/gui2/store/search/download_thread.py
@@ -38,7 +38,7 @@ class GenericDownloadThreadPool(object):
This must be implemented in a sub class and this function
must be called at the end of the add_task function in
the sub class.
-
+
The implementation of this function (in this base class)
starts any threads necessary to fill the pool if it is
not already full.
@@ -91,7 +91,7 @@ class SearchThreadPool(GenericDownloadThreadPool):
sp = SearchThreadPool(3)
sp.add_task(...)
'''
-
+
def __init__(self, thread_count):
GenericDownloadThreadPool.__init__(self, SearchThread, thread_count)
@@ -120,6 +120,7 @@ class SearchThread(Thread):
if not self._run:
return
res.store_name = store_name
+ res.affiliate = store_plugin.base_plugin.affiliate
self.results.put((res, store_plugin))
self.tasks.task_done()
except:
@@ -167,7 +168,7 @@ class CoverThread(Thread):
class DetailsThreadPool(GenericDownloadThreadPool):
-
+
def __init__(self, thread_count):
GenericDownloadThreadPool.__init__(self, DetailsThread, thread_count)
diff --git a/src/calibre/gui2/store/search/models.py b/src/calibre/gui2/store/search/models.py
index 44a993ef12..f5c24798f6 100644
--- a/src/calibre/gui2/store/search/models.py
+++ b/src/calibre/gui2/store/search/models.py
@@ -76,7 +76,6 @@ class Matches(QAbstractItemModel):
self.reset()
def add_result(self, result, store_plugin):
- result.affiliate = getattr(store_plugin.base_plugin, 'affiliate', False)
if result not in self.all_matches:
self.layoutAboutToBeChanged.emit()
self.all_matches.append(result)
@@ -178,6 +177,8 @@ class Matches(QAbstractItemModel):
return QVariant(self.DRM_UNKNOWN_ICON)
if col == 5:
if result.affiliate:
+ # For some reason the size(16, 16) is forgotten if the icon
+ # is a class attribute. Don't know why...
icon = QIcon()
icon.addFile(I('donate.png'), QSize(16, 16))
return QVariant(icon)
@@ -197,7 +198,8 @@ class Matches(QAbstractItemModel):
elif col == 4:
return QVariant('%s
' % result.formats)
elif col == 5:
- return QVariant(_('Buying from this store supports a calibre developer'))
+ if result.affiliate:
+ return QVariant(_('Buying from this store supports a calibre developer'))
elif role == Qt.SizeHintRole:
return QSize(64, 64)
return NONE
From 3bb508bb1fedbf61dccf54ebe974d3480b1c9d6a Mon Sep 17 00:00:00 2001
From: John Schember
Date: Sat, 28 May 2011 10:20:47 -0400
Subject: [PATCH 09/21] Store: Add Waterstones back.
---
.../gui2/store/waterstones_uk_plugin.py | 84 +++++++++++++++++++
1 file changed, 84 insertions(+)
create mode 100644 src/calibre/gui2/store/waterstones_uk_plugin.py
diff --git a/src/calibre/gui2/store/waterstones_uk_plugin.py b/src/calibre/gui2/store/waterstones_uk_plugin.py
new file mode 100644
index 0000000000..a5065128ba
--- /dev/null
+++ b/src/calibre/gui2/store/waterstones_uk_plugin.py
@@ -0,0 +1,84 @@
+# -*- coding: utf-8 -*-
+
+from __future__ import (unicode_literals, division, absolute_import, print_function)
+
+__license__ = 'GPL 3'
+__copyright__ = '2011, John Schember '
+__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 WaterstonesUKStore(BasicStoreConfig, StorePlugin):
+
+ def open(self, parent=None, detail_item=None, external=False):
+ url = 'http://clkuk.tradedoubler.com/click?p=51196&a=1951604&g=19333484'
+ url_details = 'http://clkuk.tradedoubler.com/click?p(51196)a(1951604)g(16460516)url({0})'
+
+ 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.waterstones.com/waterstonesweb/advancedSearch.do?buttonClicked=1&format=3757&bookkeywords=' + 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[contains(@class, "results-pane")]'):
+ if counter <= 0:
+ break
+
+ id = ''.join(data.xpath('./div/div/h2/a/@href')).strip()
+ if not id:
+ continue
+ cover_url = ''.join(data.xpath('.//div[@class="image"]/a/img/@src'))
+ title = ''.join(data.xpath('./div/div/h2/a/text()'))
+ author = ', '.join(data.xpath('.//p[@class="byAuthor"]/a/text()'))
+ price = ''.join(data.xpath('.//p[@class="price"]/span[@class="priceStandard"]/text()'))
+ drm = data.xpath('boolean(.//td[@headers="productFormat" and contains(., "DRM")])')
+ pdf = data.xpath('boolean(.//td[@headers="productFormat" and contains(., "PDF")])')
+ epub = data.xpath('boolean(.//td[@headers="productFormat" and contains(., "EPUB")])')
+
+ counter -= 1
+
+ s = SearchResult()
+ s.cover_url = cover_url
+ s.title = title.strip()
+ s.author = author.strip()
+ s.price = price
+ if drm:
+ s.drm = SearchResult.DRM_LOCKED
+ else:
+ s.drm = SearchResult.DRM_UNKNOWN
+ s.detail_item = id
+ formats = []
+ if epub:
+ formats.append('ePub')
+ if pdf:
+ formats.append('PDF')
+ s.formats = ', '.join(formats)
+
+ yield s
From 93128ab03fe15e2667dfe805dd7c0080a738731d Mon Sep 17 00:00:00 2001
From: John Schember
Date: Sat, 28 May 2011 10:23:10 -0400
Subject: [PATCH 10/21] Store: Change ebookshop to use get_details.
---
src/calibre/gui2/store/ebookshoppe_uk_plugin.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/calibre/gui2/store/ebookshoppe_uk_plugin.py b/src/calibre/gui2/store/ebookshoppe_uk_plugin.py
index 4ba2a1b5fd..b45b0e99d5 100644
--- a/src/calibre/gui2/store/ebookshoppe_uk_plugin.py
+++ b/src/calibre/gui2/store/ebookshoppe_uk_plugin.py
@@ -73,7 +73,7 @@ class EBookShoppeUKStore(BasicStoreConfig, StorePlugin):
yield s
- def my_get_details(self, search_result, timeout):
+ def get_details(self, search_result, timeout):
br = browser()
with closing(br.open(search_result.detail_item, timeout=timeout)) as nf:
idata = html.fromstring(nf.read())
From 9b245bdcf508964136244cf2ae0a3d9bfb25fb9a Mon Sep 17 00:00:00 2001
From: John Schember
Date: Sat, 28 May 2011 10:41:51 -0400
Subject: [PATCH 11/21] Store: ...
---
src/calibre/customize/builtins.py | 2 +-
src/calibre/gui2/store/ebookshoppe_uk_plugin.py | 11 +++++------
2 files changed, 6 insertions(+), 7 deletions(-)
diff --git a/src/calibre/customize/builtins.py b/src/calibre/customize/builtins.py
index 0b83d0f45b..c57c19fd0b 100644
--- a/src/calibre/customize/builtins.py
+++ b/src/calibre/customize/builtins.py
@@ -1420,7 +1420,7 @@ plugins += [
StoreBeWriteStore,
StoreDieselEbooksStore,
StoreEbookscomStore,
- #StoreEBookShoppeUKStore,
+ StoreEBookShoppeUKStore,
StoreEPubBuyDEStore,
StoreEHarlequinStore,
StoreFeedbooksStore,
diff --git a/src/calibre/gui2/store/ebookshoppe_uk_plugin.py b/src/calibre/gui2/store/ebookshoppe_uk_plugin.py
index b45b0e99d5..afe4d6ccc5 100644
--- a/src/calibre/gui2/store/ebookshoppe_uk_plugin.py
+++ b/src/calibre/gui2/store/ebookshoppe_uk_plugin.py
@@ -62,18 +62,17 @@ class EBookShoppeUKStore(BasicStoreConfig, StorePlugin):
s = SearchResult()
s.cover_url = cover_url
s.title = title.strip()
- # Set the author to the query terms to ensure that author
- # queries match something when pruning searches. Of course, this
- # means that all books will match. Sigh...
- s.author = query
s.price = price
s.drm = SearchResult.DRM_UNLOCKED
s.detail_item = id
- s.formats = ''
+
+ self.my_get_details(s, timeout)
+ if not s.author:
+ continue
yield s
- def get_details(self, search_result, timeout):
+ def my_get_details(self, search_result, timeout):
br = browser()
with closing(br.open(search_result.detail_item, timeout=timeout)) as nf:
idata = html.fromstring(nf.read())
From b244246fceffdc5781add6a58ee17c4e3d30ed56 Mon Sep 17 00:00:00 2001
From: Charles Haley <>
Date: Sat, 28 May 2011 16:21:45 +0100
Subject: [PATCH 12/21] Add WH Smith. Improve ebookshoppe_uk
---
src/calibre/customize/builtins.py | 60 +++++++++++---
.../gui2/store/ebookshoppe_uk_plugin.py | 8 +-
src/calibre/gui2/store/whsmith_uk_plugin.py | 83 +++++++++++++++++++
3 files changed, 134 insertions(+), 17 deletions(-)
create mode 100644 src/calibre/gui2/store/whsmith_uk_plugin.py
diff --git a/src/calibre/customize/builtins.py b/src/calibre/customize/builtins.py
index 0b83d0f45b..f1afb62cbc 100644
--- a/src/calibre/customize/builtins.py
+++ b/src/calibre/customize/builtins.py
@@ -1143,6 +1143,7 @@ class StoreArchiveOrgStore(StoreBase):
drm_free_only = True
headquarters = 'US'
formats = ['DAISY', 'DJVU', 'EPUB', 'MOBI', 'PDF', 'TXT']
+ affiliate = False
class StoreBaenWebScriptionStore(StoreBase):
name = 'Baen WebScription'
@@ -1152,6 +1153,7 @@ class StoreBaenWebScriptionStore(StoreBase):
drm_free_only = True
headquarters = 'US'
formats = ['EPUB', 'LIT', 'LRF', 'MOBI', 'RB', 'RTF', 'ZIP']
+ affiliate = False
class StoreBNStore(StoreBase):
name = 'Barnes and Noble'
@@ -1161,6 +1163,7 @@ class StoreBNStore(StoreBase):
drm_free_only = False
headquarters = 'US'
formats = ['NOOK']
+ affiliate = True
class StoreBeamEBooksDEStore(StoreBase):
name = 'Beam EBooks DE'
@@ -1181,6 +1184,7 @@ class StoreBeWriteStore(StoreBase):
drm_free_only = True
headquarters = 'US'
formats = ['EPUB', 'MOBI', 'PDF']
+ affiliate = False
class StoreDieselEbooksStore(StoreBase):
name = 'Diesel eBooks'
@@ -1190,6 +1194,7 @@ class StoreDieselEbooksStore(StoreBase):
drm_free_only = False
headquarters = 'US'
formats = ['EPUB', 'PDF']
+ affiliate = True
class StoreEbookscomStore(StoreBase):
name = 'eBooks.com'
@@ -1199,6 +1204,18 @@ class StoreEbookscomStore(StoreBase):
drm_free_only = False
headquarters = 'US'
formats = ['EPUB', 'LIT', 'MOBI', 'PDF']
+ affiliate = True
+
+class StoreEPubBuyDEStore(StoreBase):
+ name = 'EPUBBuy DE'
+ author = 'Charles Haley'
+ description = u'Bei EPUBBuy.com finden Sie ausschliesslich eBooks im weitverbreiteten EPUB-Format und ohne DRM. So haben Sie die freie Wahl, wo Sie Ihr eBook lesen: Tablet, eBook-Reader, Smartphone oder einfach auf Ihrem PC. So macht eBook-Lesen Spaß!'
+ actual_plugin = 'calibre.gui2.store.epubbuy_de_plugin:EPubBuyDEStore'
+
+ drm_free_only = True
+ headquarters = 'DE'
+ formats = ['EPUB']
+ affiliate = True
class StoreEBookShoppeUKStore(StoreBase):
name = 'ebookShoppe UK'
@@ -1211,16 +1228,6 @@ class StoreEBookShoppeUKStore(StoreBase):
formats = ['EPUB', 'PDF']
affiliate = True
-class StoreEPubBuyDEStore(StoreBase):
- name = 'EPUBBuy DE'
- author = 'Charles Haley'
- description = u'Bei EPUBBuy.com finden Sie ausschliesslich eBooks im weitverbreiteten EPUB-Format und ohne DRM. So haben Sie die freie Wahl, wo Sie Ihr eBook lesen: Tablet, eBook-Reader, Smartphone oder einfach auf Ihrem PC. So macht eBook-Lesen Spaß!'
- actual_plugin = 'calibre.gui2.store.epubbuy_de_plugin:EPubBuyDEStore'
-
- drm_free_only = True
- headquarters = 'DE'
- formats = ['EPUB']
-
class StoreEHarlequinStore(StoreBase):
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.'
@@ -1229,6 +1236,7 @@ class StoreEHarlequinStore(StoreBase):
drm_free_only = False
headquarters = 'CA'
formats = ['EPUB', 'PDF']
+ affiliate = True
class StoreFeedbooksStore(StoreBase):
name = 'Feedbooks'
@@ -1238,6 +1246,7 @@ class StoreFeedbooksStore(StoreBase):
drm_free_only = False
headquarters = 'FR'
formats = ['EPUB', 'MOBI', 'PDF']
+ affiliate = False
class StoreFoylesUKStore(StoreBase):
name = 'Foyles UK'
@@ -1259,6 +1268,7 @@ class StoreGandalfStore(StoreBase):
drm_free_only = False
headquarters = 'PL'
formats = ['EPUB', 'PDF']
+ affiliate = False
class StoreGoogleBooksStore(StoreBase):
name = 'Google Books'
@@ -1268,6 +1278,7 @@ class StoreGoogleBooksStore(StoreBase):
drm_free_only = False
headquarters = 'US'
formats = ['EPUB', 'PDF', 'TXT']
+ affiliate = False
class StoreGutenbergStore(StoreBase):
name = 'Project Gutenberg'
@@ -1277,6 +1288,7 @@ class StoreGutenbergStore(StoreBase):
drm_free_only = True
headquarters = 'US'
formats = ['EPUB', 'HTML', 'MOBI', 'PDB', 'TXT']
+ affiliate = False
class StoreKoboStore(StoreBase):
name = 'Kobo'
@@ -1286,6 +1298,7 @@ class StoreKoboStore(StoreBase):
drm_free_only = False
headquarters = 'CA'
formats = ['EPUB']
+ affiliate = True
class StoreLegimiStore(StoreBase):
name = 'Legimi'
@@ -1296,6 +1309,7 @@ class StoreLegimiStore(StoreBase):
drm_free_only = False
headquarters = 'PL'
formats = ['EPUB']
+ affiliate = False
class StoreManyBooksStore(StoreBase):
name = 'ManyBooks'
@@ -1305,6 +1319,7 @@ class StoreManyBooksStore(StoreBase):
drm_free_only = True
headquarters = 'US'
formats = ['EPUB', 'FB2', 'JAR', 'LIT', 'LRF', 'MOBI', 'PDB', 'PDF', 'RB', 'RTF', 'TCR', 'TXT', 'ZIP']
+ affiliate = False
class StoreMobileReadStore(StoreBase):
name = 'MobileRead'
@@ -1314,6 +1329,7 @@ class StoreMobileReadStore(StoreBase):
drm_free_only = True
headquarters = 'CH'
formats = ['EPUB', 'IMP', 'LRF', 'LIT', 'MOBI', 'PDF']
+ affiliate = False
class StoreNextoStore(StoreBase):
name = 'Nexto'
@@ -1324,6 +1340,7 @@ class StoreNextoStore(StoreBase):
drm_free_only = False
headquarters = 'PL'
formats = ['EPUB', 'PDF']
+ affiliate = True
class StoreOpenLibraryStore(StoreBase):
name = 'Open Library'
@@ -1333,6 +1350,7 @@ class StoreOpenLibraryStore(StoreBase):
drm_free_only = True
headquarters = 'US'
formats = ['DAISY', 'DJVU', 'EPUB', 'MOBI', 'PDF', 'TXT']
+ affiliate = False
class StoreOReillyStore(StoreBase):
name = 'OReilly'
@@ -1342,6 +1360,7 @@ class StoreOReillyStore(StoreBase):
drm_free_only = True
headquarters = 'US'
formats = ['APK', 'DAISY', 'EPUB', 'MOBI', 'PDF']
+ affiliate = False
class StorePragmaticBookshelfStore(StoreBase):
name = 'Pragmatic Bookshelf'
@@ -1351,6 +1370,7 @@ class StorePragmaticBookshelfStore(StoreBase):
drm_free_only = True
headquarters = 'US'
formats = ['EPUB', 'MOBI', 'PDF']
+ affiliate = False
class StoreSmashwordsStore(StoreBase):
name = 'Smashwords'
@@ -1360,6 +1380,7 @@ class StoreSmashwordsStore(StoreBase):
drm_free_only = True
headquarters = 'US'
formats = ['EPUB', 'HTML', 'LRF', 'MOBI', 'PDB', 'RTF', 'TXT']
+ affiliate = True
class StoreVirtualoStore(StoreBase):
name = 'Virtualo'
@@ -1370,6 +1391,7 @@ class StoreVirtualoStore(StoreBase):
drm_free_only = False
headquarters = 'PL'
formats = ['EPUB', 'PDF']
+ affiliate = False
class StoreWaterstonesUKStore(StoreBase):
name = 'Waterstones UK'
@@ -1380,6 +1402,7 @@ class StoreWaterstonesUKStore(StoreBase):
drm_free_only = False
headquarters = 'UK'
formats = ['EPUB', 'PDF']
+ affiliate = False
class StoreWeightlessBooksStore(StoreBase):
name = 'Weightless Books'
@@ -1389,6 +1412,18 @@ class StoreWeightlessBooksStore(StoreBase):
drm_free_only = True
headquarters = 'US'
formats = ['EPUB', 'HTML', 'LIT', 'MOBI', 'PDF']
+ affiliate = False
+
+class StoreWHSmithUKStore(StoreBase):
+ name = 'WH Smith UK'
+ author = 'Charles Haley'
+ description = u"With over 550 stores on the high street and 490 stores at airports, train stations, hospitals and motorway services, WHSmith is one of the UK's leading retail groups and a household name."
+ actual_plugin = 'calibre.gui2.store.whsmith_uk_plugin:WHSmithUKStore'
+
+ drm_free_only = False
+ headquarters = 'UK'
+ formats = ['EPUB', 'PDF']
+ affiliate = False
class StoreWizardsTowerBooksStore(StoreBase):
name = 'Wizards Tower Books'
@@ -1398,6 +1433,7 @@ class StoreWizardsTowerBooksStore(StoreBase):
drm_free_only = True
headquarters = 'UK'
formats = ['EPUB', 'MOBI']
+ affiliate = False
class StoreWoblinkStore(StoreBase):
name = 'Woblink'
@@ -1408,6 +1444,7 @@ class StoreWoblinkStore(StoreBase):
drm_free_only = False
headquarters = 'PL'
formats = ['EPUB']
+ affiliate = False
plugins += [
StoreArchiveOrgStore,
@@ -1420,7 +1457,7 @@ plugins += [
StoreBeWriteStore,
StoreDieselEbooksStore,
StoreEbookscomStore,
- #StoreEBookShoppeUKStore,
+ StoreEBookShoppeUKStore,
StoreEPubBuyDEStore,
StoreEHarlequinStore,
StoreFeedbooksStore,
@@ -1440,6 +1477,7 @@ plugins += [
StoreVirtualoStore,
StoreWaterstonesUKStore,
StoreWeightlessBooksStore,
+ StoreWHSmithUKStore,
StoreWizardsTowerBooksStore,
StoreWoblinkStore
]
diff --git a/src/calibre/gui2/store/ebookshoppe_uk_plugin.py b/src/calibre/gui2/store/ebookshoppe_uk_plugin.py
index b45b0e99d5..21bef85db9 100644
--- a/src/calibre/gui2/store/ebookshoppe_uk_plugin.py
+++ b/src/calibre/gui2/store/ebookshoppe_uk_plugin.py
@@ -62,18 +62,14 @@ class EBookShoppeUKStore(BasicStoreConfig, StorePlugin):
s = SearchResult()
s.cover_url = cover_url
s.title = title.strip()
- # Set the author to the query terms to ensure that author
- # queries match something when pruning searches. Of course, this
- # means that all books will match. Sigh...
- s.author = query
s.price = price
s.drm = SearchResult.DRM_UNLOCKED
s.detail_item = id
- s.formats = ''
+ self.get_author_and_formats(s, timeout)
yield s
- def get_details(self, search_result, timeout):
+ 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())
diff --git a/src/calibre/gui2/store/whsmith_uk_plugin.py b/src/calibre/gui2/store/whsmith_uk_plugin.py
new file mode 100644
index 0000000000..66d81258f7
--- /dev/null
+++ b/src/calibre/gui2/store/whsmith_uk_plugin.py
@@ -0,0 +1,83 @@
+# -*- coding: utf-8 -*-
+
+from __future__ import (unicode_literals, division, absolute_import, print_function)
+
+__license__ = 'GPL 3'
+__copyright__ = '2011, John Schember '
+__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
From 66571550e9181a39debcbdad8ded2c80d89886d7 Mon Sep 17 00:00:00 2001
From: Charles Haley <>
Date: Sat, 28 May 2011 16:57:37 +0100
Subject: [PATCH 13/21] Add the heart to the search store chooser
---
src/calibre/customize/builtins.py | 2 +-
src/calibre/gui2/store/search/search.py | 28 ++++++++++++++++---------
2 files changed, 19 insertions(+), 11 deletions(-)
diff --git a/src/calibre/customize/builtins.py b/src/calibre/customize/builtins.py
index f1afb62cbc..cd5f81067f 100644
--- a/src/calibre/customize/builtins.py
+++ b/src/calibre/customize/builtins.py
@@ -1417,7 +1417,7 @@ class StoreWeightlessBooksStore(StoreBase):
class StoreWHSmithUKStore(StoreBase):
name = 'WH Smith UK'
author = 'Charles Haley'
- description = u"With over 550 stores on the high street and 490 stores at airports, train stations, hospitals and motorway services, WHSmith is one of the UK's leading retail groups and a household name."
+ 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'
drm_free_only = False
diff --git a/src/calibre/gui2/store/search/search.py b/src/calibre/gui2/store/search/search.py
index faeaf507c9..7ce6c93c68 100644
--- a/src/calibre/gui2/store/search/search.py
+++ b/src/calibre/gui2/store/search/search.py
@@ -9,8 +9,8 @@ __docformat__ = 'restructuredtext en'
import re
from random import shuffle
-from PyQt4.Qt import (Qt, QDialog, QDialogButtonBox, QTimer, QCheckBox,
- QVBoxLayout, QIcon, QWidget, QTabWidget)
+from PyQt4.Qt import (Qt, QDialog, QDialogButtonBox, QTimer, QCheckBox, QLabel,
+ QVBoxLayout, QIcon, QWidget, QTabWidget, QGridLayout)
from calibre.gui2 import JSONConfig, info_dialog
from calibre.gui2.progress_indicator import ProgressIndicator
@@ -80,7 +80,7 @@ class SearchDialog(QDialog, Ui_Dialog):
self.progress_checker.start(100)
self.restore_state()
-
+
def setup_store_checks(self):
# Add check boxes for each store so the user
# can disable searching specific stores on a
@@ -88,18 +88,26 @@ class SearchDialog(QDialog, Ui_Dialog):
existing = {}
for n in self.store_checks:
existing[n] = self.store_checks[n].isChecked()
-
+
self.store_checks = {}
stores_check_widget = QWidget()
- store_list_layout = QVBoxLayout()
+ store_list_layout = QGridLayout()
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'))
+ i = 0 # just in case the list of stores is empty
+ for i, x in enumerate(sorted(self.gui.istores.keys(), key=lambda x: x.lower())):
cbox = QCheckBox(x)
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.setPixmap(icon.pixmap(16, 16))
+ store_list_layout.addWidget(iw, i, 1, 1, 1)
self.store_checks[x] = cbox
- store_list_layout.addStretch()
+ i += 1
+ store_list_layout.setRowStretch(i, 10)
self.store_list.setWidget(stores_check_widget)
def build_adv_search(self):
@@ -250,14 +258,14 @@ class SearchDialog(QDialog, Ui_Dialog):
button_box.accepted.connect(d.accept)
button_box.rejected.connect(d.reject)
d.setWindowTitle(_('Customize get books search'))
-
+
tab_widget = QTabWidget(d)
v.addWidget(tab_widget)
v.addWidget(button_box)
chooser_config_widget = StoreChooserWidget()
search_config_widget = StoreConfigWidget(self.config)
-
+
tab_widget.addTab(chooser_config_widget, _('Choose stores'))
tab_widget.addTab(search_config_widget, _('Configure search'))
From 3a93e4561ce20dd76bfb1f6af3593b9989818f2b Mon Sep 17 00:00:00 2001
From: Charles Haley <>
Date: Sat, 28 May 2011 18:59:30 +0100
Subject: [PATCH 14/21] Fix amazon UK grid. Add tooltip to heart on menu.
---
src/calibre/gui2/store/amazon_uk_plugin.py | 84 ++++++++++++++++++++++
src/calibre/gui2/store/search/search.py | 1 +
2 files changed, 85 insertions(+)
diff --git a/src/calibre/gui2/store/amazon_uk_plugin.py b/src/calibre/gui2/store/amazon_uk_plugin.py
index 9544add17c..1448e1548a 100644
--- a/src/calibre/gui2/store/amazon_uk_plugin.py
+++ b/src/calibre/gui2/store/amazon_uk_plugin.py
@@ -6,11 +6,17 @@ __license__ = 'GPL 3'
__copyright__ = '2011, John Schember '
__docformat__ = 'restructuredtext en'
+import urllib
+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.amazon_plugin import AmazonKindleStore
+from calibre.gui2.store.search_result import SearchResult
class AmazonUKKindleStore(AmazonKindleStore):
'''
@@ -28,3 +34,81 @@ class AmazonUKKindleStore(AmazonKindleStore):
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
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
+
+
diff --git a/src/calibre/gui2/store/search/search.py b/src/calibre/gui2/store/search/search.py
index 7ce6c93c68..9e60223a3d 100644
--- a/src/calibre/gui2/store/search/search.py
+++ b/src/calibre/gui2/store/search/search.py
@@ -103,6 +103,7 @@ class SearchDialog(QDialog, Ui_Dialog):
store_list_layout.addWidget(cbox, i, 0, 1, 1)
if self.gui.istores[x].base_plugin.affiliate:
iw = QLabel(self)
+ iw.setToolTip(_('Buying from this store supports a calibre developer'))
iw.setPixmap(icon.pixmap(16, 16))
store_list_layout.addWidget(iw, i, 1, 1, 1)
self.store_checks[x] = cbox
From 542d65bdc000f54e5d4c5a53430640a707d8ae40 Mon Sep 17 00:00:00 2001
From: John Schember
Date: Sat, 28 May 2011 15:42:31 -0400
Subject: [PATCH 15/21] Store: Remove redundant setting of variables.
---
src/calibre/customize/builtins.py | 38 -------------------------------
1 file changed, 38 deletions(-)
diff --git a/src/calibre/customize/builtins.py b/src/calibre/customize/builtins.py
index cd5f81067f..5cde30f72e 100644
--- a/src/calibre/customize/builtins.py
+++ b/src/calibre/customize/builtins.py
@@ -1108,7 +1108,6 @@ class StoreAmazonKindleStore(StoreBase):
description = u'Kindle books from Amazon.'
actual_plugin = 'calibre.gui2.store.amazon_plugin:AmazonKindleStore'
- drm_free_only = False
headquarters = 'US'
formats = ['KINDLE']
affiliate = True
@@ -1119,7 +1118,6 @@ class StoreAmazonDEKindleStore(StoreBase):
description = u'Kindle Bücher von Amazon.'
actual_plugin = 'calibre.gui2.store.amazon_de_plugin:AmazonDEKindleStore'
- drm_free_only = False
headquarters = 'DE'
formats = ['KINDLE']
affiliate = True
@@ -1130,7 +1128,6 @@ class StoreAmazonUKKindleStore(StoreBase):
description = u'Kindle books from Amazon\'s UK web site. Also, includes French language ebooks.'
actual_plugin = 'calibre.gui2.store.amazon_uk_plugin:AmazonUKKindleStore'
- drm_free_only = False
headquarters = 'UK'
formats = ['KINDLE']
affiliate = True
@@ -1143,7 +1140,6 @@ class StoreArchiveOrgStore(StoreBase):
drm_free_only = True
headquarters = 'US'
formats = ['DAISY', 'DJVU', 'EPUB', 'MOBI', 'PDF', 'TXT']
- affiliate = False
class StoreBaenWebScriptionStore(StoreBase):
name = 'Baen WebScription'
@@ -1153,14 +1149,12 @@ class StoreBaenWebScriptionStore(StoreBase):
drm_free_only = True
headquarters = 'US'
formats = ['EPUB', 'LIT', 'LRF', 'MOBI', 'RB', 'RTF', 'ZIP']
- affiliate = False
class StoreBNStore(StoreBase):
name = 'Barnes and Noble'
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'
- drm_free_only = False
headquarters = 'US'
formats = ['NOOK']
affiliate = True
@@ -1184,14 +1178,12 @@ class StoreBeWriteStore(StoreBase):
drm_free_only = True
headquarters = 'US'
formats = ['EPUB', 'MOBI', 'PDF']
- affiliate = False
class StoreDieselEbooksStore(StoreBase):
name = 'Diesel eBooks'
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'
- drm_free_only = False
headquarters = 'US'
formats = ['EPUB', 'PDF']
affiliate = True
@@ -1201,7 +1193,6 @@ class StoreEbookscomStore(StoreBase):
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'
- drm_free_only = False
headquarters = 'US'
formats = ['EPUB', 'LIT', 'MOBI', 'PDF']
affiliate = True
@@ -1223,7 +1214,6 @@ class StoreEBookShoppeUKStore(StoreBase):
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'
- drm_free_only = False
headquarters = 'UK'
formats = ['EPUB', 'PDF']
affiliate = True
@@ -1233,7 +1223,6 @@ class StoreEHarlequinStore(StoreBase):
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'
- drm_free_only = False
headquarters = 'CA'
formats = ['EPUB', 'PDF']
affiliate = True
@@ -1243,10 +1232,8 @@ class StoreFeedbooksStore(StoreBase):
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'
- drm_free_only = False
headquarters = 'FR'
formats = ['EPUB', 'MOBI', 'PDF']
- affiliate = False
class StoreFoylesUKStore(StoreBase):
name = 'Foyles UK'
@@ -1254,7 +1241,6 @@ class StoreFoylesUKStore(StoreBase):
description = u'Foyles of London\'s ebook store. Provides extensive range covering all subjects.'
actual_plugin = 'calibre.gui2.store.foyles_uk_plugin:FoylesUKStore'
- drm_free_only = False
headquarters = 'UK'
formats = ['EPUB', 'PDF']
affiliate = True
@@ -1265,20 +1251,16 @@ class StoreGandalfStore(StoreBase):
description = u'Księgarnia internetowa Gandalf.'
actual_plugin = 'calibre.gui2.store.gandalf_plugin:GandalfStore'
- drm_free_only = False
headquarters = 'PL'
formats = ['EPUB', 'PDF']
- affiliate = False
class StoreGoogleBooksStore(StoreBase):
name = 'Google Books'
description = u'Google Books'
actual_plugin = 'calibre.gui2.store.google_books_plugin:GoogleBooksStore'
- drm_free_only = False
headquarters = 'US'
formats = ['EPUB', 'PDF', 'TXT']
- affiliate = False
class StoreGutenbergStore(StoreBase):
name = 'Project Gutenberg'
@@ -1288,14 +1270,12 @@ class StoreGutenbergStore(StoreBase):
drm_free_only = True
headquarters = 'US'
formats = ['EPUB', 'HTML', 'MOBI', 'PDB', 'TXT']
- affiliate = False
class StoreKoboStore(StoreBase):
name = 'Kobo'
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'
- drm_free_only = False
headquarters = 'CA'
formats = ['EPUB']
affiliate = True
@@ -1306,10 +1286,8 @@ 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'
actual_plugin = 'calibre.gui2.store.legimi_plugin:LegimiStore'
- drm_free_only = False
headquarters = 'PL'
formats = ['EPUB']
- affiliate = False
class StoreManyBooksStore(StoreBase):
name = 'ManyBooks'
@@ -1319,7 +1297,6 @@ class StoreManyBooksStore(StoreBase):
drm_free_only = True
headquarters = 'US'
formats = ['EPUB', 'FB2', 'JAR', 'LIT', 'LRF', 'MOBI', 'PDB', 'PDF', 'RB', 'RTF', 'TCR', 'TXT', 'ZIP']
- affiliate = False
class StoreMobileReadStore(StoreBase):
name = 'MobileRead'
@@ -1329,7 +1306,6 @@ class StoreMobileReadStore(StoreBase):
drm_free_only = True
headquarters = 'CH'
formats = ['EPUB', 'IMP', 'LRF', 'LIT', 'MOBI', 'PDF']
- affiliate = False
class StoreNextoStore(StoreBase):
name = 'Nexto'
@@ -1337,7 +1313,6 @@ class StoreNextoStore(StoreBase):
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'
- drm_free_only = False
headquarters = 'PL'
formats = ['EPUB', 'PDF']
affiliate = True
@@ -1350,7 +1325,6 @@ class StoreOpenLibraryStore(StoreBase):
drm_free_only = True
headquarters = 'US'
formats = ['DAISY', 'DJVU', 'EPUB', 'MOBI', 'PDF', 'TXT']
- affiliate = False
class StoreOReillyStore(StoreBase):
name = 'OReilly'
@@ -1360,7 +1334,6 @@ class StoreOReillyStore(StoreBase):
drm_free_only = True
headquarters = 'US'
formats = ['APK', 'DAISY', 'EPUB', 'MOBI', 'PDF']
- affiliate = False
class StorePragmaticBookshelfStore(StoreBase):
name = 'Pragmatic Bookshelf'
@@ -1370,7 +1343,6 @@ class StorePragmaticBookshelfStore(StoreBase):
drm_free_only = True
headquarters = 'US'
formats = ['EPUB', 'MOBI', 'PDF']
- affiliate = False
class StoreSmashwordsStore(StoreBase):
name = 'Smashwords'
@@ -1388,10 +1360,8 @@ class StoreVirtualoStore(StoreBase):
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'
- drm_free_only = False
headquarters = 'PL'
formats = ['EPUB', 'PDF']
- affiliate = False
class StoreWaterstonesUKStore(StoreBase):
name = 'Waterstones UK'
@@ -1399,10 +1369,8 @@ 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.'
actual_plugin = 'calibre.gui2.store.waterstones_uk_plugin:WaterstonesUKStore'
- drm_free_only = False
headquarters = 'UK'
formats = ['EPUB', 'PDF']
- affiliate = False
class StoreWeightlessBooksStore(StoreBase):
name = 'Weightless Books'
@@ -1412,7 +1380,6 @@ class StoreWeightlessBooksStore(StoreBase):
drm_free_only = True
headquarters = 'US'
formats = ['EPUB', 'HTML', 'LIT', 'MOBI', 'PDF']
- affiliate = False
class StoreWHSmithUKStore(StoreBase):
name = 'WH Smith UK'
@@ -1420,10 +1387,8 @@ class StoreWHSmithUKStore(StoreBase):
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'
- drm_free_only = False
headquarters = 'UK'
formats = ['EPUB', 'PDF']
- affiliate = False
class StoreWizardsTowerBooksStore(StoreBase):
name = 'Wizards Tower Books'
@@ -1433,7 +1398,6 @@ class StoreWizardsTowerBooksStore(StoreBase):
drm_free_only = True
headquarters = 'UK'
formats = ['EPUB', 'MOBI']
- affiliate = False
class StoreWoblinkStore(StoreBase):
name = 'Woblink'
@@ -1441,10 +1405,8 @@ class StoreWoblinkStore(StoreBase):
description = u'Czytanie zdarza się wszędzie!'
actual_plugin = 'calibre.gui2.store.woblink_plugin:WoblinkStore'
- drm_free_only = False
headquarters = 'PL'
formats = ['EPUB']
- affiliate = False
plugins += [
StoreArchiveOrgStore,
From 66315cead2b6f2ff0e0c60d890387b05867fb933 Mon Sep 17 00:00:00 2001
From: John Schember
Date: Sat, 28 May 2011 16:14:57 -0400
Subject: [PATCH 16/21] Store: Make use of donate.png consistant with other
images.
---
.../store/config/chooser/chooser_widget.ui | 45 +++++++++++++++++++
src/calibre/gui2/store/search/models.py | 8 ++--
2 files changed, 48 insertions(+), 5 deletions(-)
diff --git a/src/calibre/gui2/store/config/chooser/chooser_widget.ui b/src/calibre/gui2/store/config/chooser/chooser_widget.ui
index e833dbf4b9..4c2f136b62 100644
--- a/src/calibre/gui2/store/config/chooser/chooser_widget.ui
+++ b/src/calibre/gui2/store/config/chooser/chooser_widget.ui
@@ -80,6 +80,51 @@
+ -
+
+
-
+
+
+ Select:
+
+
+
+ -
+
+
+ All
+
+
+
+ -
+
+
+ None
+
+
+
+ -
+
+
+ Invert
+
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+
+ 40
+ 20
+
+
+
+
+
+
diff --git a/src/calibre/gui2/store/search/models.py b/src/calibre/gui2/store/search/models.py
index 25d30e3385..9b2966d0eb 100644
--- a/src/calibre/gui2/store/search/models.py
+++ b/src/calibre/gui2/store/search/models.py
@@ -45,6 +45,8 @@ class Matches(QAbstractItemModel):
Qt.SmoothTransformation)
self.DRM_UNKNOWN_ICON = QPixmap(I('dialog_question.png')).scaledToHeight(64,
Qt.SmoothTransformation)
+ self.DONATE_ICON = QPixmap(I('donate.png')).scaledToHeight(16,
+ Qt.SmoothTransformation)
# All matches. Used to determine the order to display
# self.matches because the SearchFilter returns
@@ -180,11 +182,7 @@ class Matches(QAbstractItemModel):
return QVariant(self.DRM_UNKNOWN_ICON)
if col == 5:
if result.affiliate:
- # For some reason the size(16, 16) is forgotten if the icon
- # is a class attribute. Don't know why...
- icon = QIcon()
- icon.addFile(I('donate.png'), QSize(16, 16))
- return QVariant(icon)
+ return QVariant(self.DONATE_ICON)
return NONE
elif role == Qt.ToolTipRole:
if col == 1:
From a46954edf9675139ff26b5724e8c031be2eeed94 Mon Sep 17 00:00:00 2001
From: John Schember
Date: Sat, 28 May 2011 16:55:57 -0400
Subject: [PATCH 17/21] Store: Advance search for affiliate. Clean up tool
tips. Add quick enable buttons in chooser. Add affiliate status in chooser.
---
.../config/chooser/adv_search_builder.py | 8 ++-
.../config/chooser/adv_search_builder.ui | 30 ++++++++++-
.../store/config/chooser/chooser_widget.py | 3 ++
.../store/config/chooser/chooser_widget.ui | 8 +--
.../gui2/store/config/chooser/models.py | 52 ++++++++++++++-----
.../gui2/store/search/adv_search_builder.py | 6 ++-
.../gui2/store/search/adv_search_builder.ui | 30 ++++++++++-
.../gui2/store/search/download_thread.py | 1 +
src/calibre/gui2/store/search/models.py | 2 +-
src/calibre/gui2/store/search/search.py | 2 +-
src/calibre/gui2/store/search_result.py | 1 +
11 files changed, 118 insertions(+), 25 deletions(-)
diff --git a/src/calibre/gui2/store/config/chooser/adv_search_builder.py b/src/calibre/gui2/store/config/chooser/adv_search_builder.py
index 7b519abcd1..d22554b111 100644
--- a/src/calibre/gui2/store/config/chooser/adv_search_builder.py
+++ b/src/calibre/gui2/store/config/chooser/adv_search_builder.py
@@ -45,8 +45,9 @@ class AdvSearchBuilderDialog(QDialog, Ui_Dialog):
self.description_box.setText('')
self.headquarters_box.setText('')
self.format_box.setText('')
- self.enabled_combo.setIndex(0)
- self.drm_combo.setIndex(0)
+ self.enabled_combo.setCurrentIndex(0)
+ self.drm_combo.setCurrentIndex(0)
+ self.affiliate_combo.setCurrentIndex(0)
def tokens(self, raw):
phrases = re.findall(r'\s*".*?"\s*', raw)
@@ -126,6 +127,9 @@ class AdvSearchBuilderDialog(QDialog, Ui_Dialog):
drm = unicode(self.drm_combo.currentText()).strip()
if drm:
ans.append('drm:' + drm)
+ affiliate = unicode(self.affiliate_combo.currentText()).strip()
+ if affiliate:
+ ans.append('affiliate:' + affiliate)
if ans:
return ' and '.join(ans)
return ''
diff --git a/src/calibre/gui2/store/config/chooser/adv_search_builder.ui b/src/calibre/gui2/store/config/chooser/adv_search_builder.ui
index 7d57321c72..3ace8ef04e 100644
--- a/src/calibre/gui2/store/config/chooser/adv_search_builder.ui
+++ b/src/calibre/gui2/store/config/chooser/adv_search_builder.ui
@@ -226,7 +226,7 @@
- -
+
-
-
@@ -244,7 +244,7 @@
- -
+
-
Qt::Vertical
@@ -335,6 +335,32 @@
+ -
+
+
+ Affiliate:
+
+
+
+ -
+
+
-
+
+
+
+
+ -
+
+ true
+
+
+ -
+
+ false
+
+
+
+
diff --git a/src/calibre/gui2/store/config/chooser/chooser_widget.py b/src/calibre/gui2/store/config/chooser/chooser_widget.py
index 2f8c72d3d0..cc1db488f1 100644
--- a/src/calibre/gui2/store/config/chooser/chooser_widget.py
+++ b/src/calibre/gui2/store/config/chooser/chooser_widget.py
@@ -23,6 +23,9 @@ class StoreChooserWidget(QWidget, Ui_Form):
self.search.clicked.connect(self.do_search)
self.adv_search_builder.clicked.connect(self.build_adv_search)
+ 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.toggle_plugin)
def do_search(self):
diff --git a/src/calibre/gui2/store/config/chooser/chooser_widget.ui b/src/calibre/gui2/store/config/chooser/chooser_widget.ui
index 4c2f136b62..7513cdd752 100644
--- a/src/calibre/gui2/store/config/chooser/chooser_widget.ui
+++ b/src/calibre/gui2/store/config/chooser/chooser_widget.ui
@@ -85,26 +85,26 @@
-
- Select:
+ Enable
-
-
+
All
-
-
+
None
-
-
+
Invert
diff --git a/src/calibre/gui2/store/config/chooser/models.py b/src/calibre/gui2/store/config/chooser/models.py
index 6c95d74ffc..dbda367fae 100644
--- a/src/calibre/gui2/store/config/chooser/models.py
+++ b/src/calibre/gui2/store/config/chooser/models.py
@@ -6,7 +6,7 @@ __license__ = 'GPL 3'
__copyright__ = '2011, John Schember '
__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.customize.ui import is_disabled, disable_plugin, enable_plugin
@@ -18,13 +18,15 @@ from calibre.utils.search_query_parser import SearchQueryParser
class Matches(QAbstractItemModel):
- HEADERS = [_('Enabled'), _('Name'), _('No DRM'), _('Headquarters'), _('Formats')]
+ HEADERS = [_('Enabled'), _('Name'), _('No DRM'), _('Headquarters'), _('Affiliate'), _('Formats')]
HTML_COLS = [1]
def __init__(self, plugins):
QAbstractItemModel.__init__(self)
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.matches = plugins
@@ -53,6 +55,22 @@ class Matches(QAbstractItemModel):
self.layoutChanged.emit()
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):
new_index = self.createIndex(index.row(), 0)
data = QVariant(is_disabled(self.get_plugin(index)))
@@ -91,12 +109,15 @@ class Matches(QAbstractItemModel):
return QVariant('%s
%s' % (result.name, result.description))
elif col == 3:
return QVariant(result.headquarters)
- elif col == 4:
+ elif col == 5:
return QVariant(', '.join(result.formats).upper())
elif role == Qt.DecorationRole:
if col == 2:
if result.drm_free_only:
return QVariant(self.NO_DRM_ICON)
+ if col == 4:
+ if result.affiliate:
+ return QVariant(self.DONATE_ICON)
elif role == Qt.CheckStateRole:
if col == 0:
if is_disabled(result):
@@ -105,20 +126,23 @@ class Matches(QAbstractItemModel):
elif role == Qt.ToolTipRole:
if col == 0:
if is_disabled(result):
- return QVariant(_('This store is currently diabled and cannot be used in other parts of calibre.
'))
+ return QVariant('' + _('This store is currently diabled and cannot be used in other parts of calibre.') + '
')
else:
- return QVariant(_('This store is currently enabled and can be used in other parts of calibre.
'))
+ return QVariant('' + _('This store is currently enabled and can be used in other parts of calibre.') + '
')
elif col == 1:
return QVariant('%s
' % result.description)
elif col == 2:
if result.drm_free_only:
- return QVariant(_('This store only distributes ebooks with DRM.
'))
+ return QVariant('' + _('This store only distributes ebooks with DRM.') + '
')
else:
- return QVariant(_('This store distributes ebooks with DRM. It may have some titles without DRM, but you will need to check on a per title basis.
'))
+ return QVariant('' + _('This store distributes ebooks with DRM. It may have some titles without DRM, but you will need to check on a per title basis.') + '
')
elif col == 3:
- return QVariant(_('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)
+ return QVariant('' + _('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 + '
')
elif col == 4:
- return QVariant(_('This store distributes ebooks in the following formats: %s
') % ', '.join(result.formats))
+ if result.affiliate:
+ return QVariant('' + _('Buying from this store supports the calibre developer: %s.') % result.author + '
')
+ elif col == 5:
+ return QVariant('' + _('This store distributes ebooks in the following formats: %s') % ', '.join(result.formats) + '
')
return NONE
def setData(self, index, data, role):
@@ -148,6 +172,8 @@ class Matches(QAbstractItemModel):
text = 'a' if getattr(match, 'drm_free_only', True) else 'b'
elif col == 3:
text = getattr(match, 'headquarters', '')
+ elif col == 4:
+ text = 'a' if getattr(match, 'affiliate', False) else 'b'
return text
def sort(self, col, order, reset=True):
@@ -167,6 +193,7 @@ class SearchFilter(SearchQueryParser):
USABLE_LOCATIONS = [
'all',
+ 'affiliate',
'description',
'drm',
'enabled',
@@ -207,6 +234,7 @@ class SearchFilter(SearchQueryParser):
all_locs = set(self.USABLE_LOCATIONS) - set(['all'])
locations = all_locs if location == 'all' else [location]
q = {
+ 'affiliate': lambda x: x.affiliate,
'description': lambda x: x.description.lower(),
'drm': lambda x: not x.drm_free_only,
'enabled': lambda x: not is_disabled(x),
@@ -219,21 +247,21 @@ class SearchFilter(SearchQueryParser):
for locvalue in locations:
accessor = q[locvalue]
if query == 'true':
- if locvalue in ('drm', 'enabled'):
+ if locvalue in ('affiliate', 'drm', 'enabled'):
if accessor(sr) == True:
matches.add(sr)
elif accessor(sr) is not None:
matches.add(sr)
continue
if query == 'false':
- if locvalue in ('drm', 'enabled'):
+ if locvalue in ('affiliate', 'drm', 'enabled'):
if accessor(sr) == False:
matches.add(sr)
elif accessor(sr) is None:
matches.add(sr)
continue
# this is bool, so can't match below
- if locvalue in ('drm', 'enabled'):
+ if locvalue in ('affiliate', 'drm', 'enabled'):
continue
try:
### Can't separate authors because comma is used for name sep and author sep
diff --git a/src/calibre/gui2/store/search/adv_search_builder.py b/src/calibre/gui2/store/search/adv_search_builder.py
index 745e709f90..cc89ca4eb7 100644
--- a/src/calibre/gui2/store/search/adv_search_builder.py
+++ b/src/calibre/gui2/store/search/adv_search_builder.py
@@ -45,6 +45,7 @@ class AdvSearchBuilderDialog(QDialog, Ui_Dialog):
self.author_box.setText('')
self.price_box.setText('')
self.format_box.setText('')
+ self.affiliate_combo.setCurrentIndex(0)
def tokens(self, raw):
phrases = re.findall(r'\s*".*?"\s*', raw)
@@ -117,7 +118,10 @@ class AdvSearchBuilderDialog(QDialog, Ui_Dialog):
ans.append('price:"' + self.mc + price + '"')
format = unicode(self.format_box.text()).strip()
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:
return ' and '.join(ans)
return ''
diff --git a/src/calibre/gui2/store/search/adv_search_builder.ui b/src/calibre/gui2/store/search/adv_search_builder.ui
index a758057311..e07c3d7d48 100644
--- a/src/calibre/gui2/store/search/adv_search_builder.ui
+++ b/src/calibre/gui2/store/search/adv_search_builder.ui
@@ -226,7 +226,7 @@
- -
+
-
-
@@ -244,7 +244,7 @@
- -
+
-
Qt::Vertical
@@ -283,6 +283,32 @@
-
+ -
+
+
+ Affiliate:
+
+
+
+ -
+
+
-
+
+
+
+
+ -
+
+ true
+
+
+ -
+
+ false
+
+
+
+
diff --git a/src/calibre/gui2/store/search/download_thread.py b/src/calibre/gui2/store/search/download_thread.py
index 67b4224981..c55c487b5f 100644
--- a/src/calibre/gui2/store/search/download_thread.py
+++ b/src/calibre/gui2/store/search/download_thread.py
@@ -121,6 +121,7 @@ class SearchThread(Thread):
return
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.tasks.task_done()
except:
diff --git a/src/calibre/gui2/store/search/models.py b/src/calibre/gui2/store/search/models.py
index 9b2966d0eb..c922bb31d7 100644
--- a/src/calibre/gui2/store/search/models.py
+++ b/src/calibre/gui2/store/search/models.py
@@ -200,7 +200,7 @@ class Matches(QAbstractItemModel):
return QVariant('%s
' % result.formats)
elif col == 5:
if result.affiliate:
- return QVariant(_('Buying from this store supports a calibre developer'))
+ return QVariant('' + _('Buying from this store supports the calibre developer: %s.') % result.plugin_author + '
')
elif role == Qt.SizeHintRole:
return QSize(64, 64)
return NONE
diff --git a/src/calibre/gui2/store/search/search.py b/src/calibre/gui2/store/search/search.py
index 7e69c61524..aa9aef6c3e 100644
--- a/src/calibre/gui2/store/search/search.py
+++ b/src/calibre/gui2/store/search/search.py
@@ -102,7 +102,7 @@ class SearchDialog(QDialog, Ui_Dialog):
store_list_layout.addWidget(cbox, i, 0, 1, 1)
if self.gui.istores[x].base_plugin.affiliate:
iw = QLabel(self)
- iw.setToolTip(_('Buying from this store supports a calibre developer'))
+ iw.setToolTip('' + _('Buying from this store supports the calibre developer: %s
') % self.gui.istores[x].base_plugin.author + '
')
iw.setPixmap(icon.pixmap(16, 16))
store_list_layout.addWidget(iw, i, 1, 1, 1)
self.store_checks[x] = cbox
diff --git a/src/calibre/gui2/store/search_result.py b/src/calibre/gui2/store/search_result.py
index 83a2c8601d..7d6ac5acad 100644
--- a/src/calibre/gui2/store/search_result.py
+++ b/src/calibre/gui2/store/search_result.py
@@ -23,6 +23,7 @@ class SearchResult(object):
self.drm = None
self.formats = ''
self.affiliate = False
+ self.plugin_author = ''
def __eq__(self, other):
return self.title == other.title and self.author == other.author and self.store_name == other.store_name
From 97774c0f932f1c4d59512e2f1cdbf5ff8ef5d999 Mon Sep 17 00:00:00 2001
From: John Schember
Date: Sat, 28 May 2011 16:56:58 -0400
Subject: [PATCH 18/21] ...
---
src/calibre/gui2/store/search/models.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/calibre/gui2/store/search/models.py b/src/calibre/gui2/store/search/models.py
index c922bb31d7..89c11445b3 100644
--- a/src/calibre/gui2/store/search/models.py
+++ b/src/calibre/gui2/store/search/models.py
@@ -10,7 +10,7 @@ import re
from operator import attrgetter
from PyQt4.Qt import (Qt, QAbstractItemModel, QVariant, QPixmap, QModelIndex, QSize,
- pyqtSignal, QIcon)
+ pyqtSignal)
from calibre.gui2 import NONE, FunctionDispatcher
from calibre.gui2.store.search_result import SearchResult
From b19ebf917aca06a87f8d85689a7d47f4e9214b0a Mon Sep 17 00:00:00 2001
From: John Schember
Date: Sat, 28 May 2011 20:29:40 -0400
Subject: [PATCH 19/21] Store: Chooser allow user to configure plugins via
right clicking.
---
.../gui2/store/config/chooser/results_view.py | 21 ++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/src/calibre/gui2/store/config/chooser/results_view.py b/src/calibre/gui2/store/config/chooser/results_view.py
index 1c18a18d7b..10dff4bcdb 100644
--- a/src/calibre/gui2/store/config/chooser/results_view.py
+++ b/src/calibre/gui2/store/config/chooser/results_view.py
@@ -6,7 +6,9 @@ __license__ = 'GPL 3'
__copyright__ = '2011, John Schember '
__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.gui2.metadata.single_download import RichTextDelegate
@@ -32,3 +34,20 @@ class ResultsView(QTreeView):
self.model().sort(1, Qt.AscendingOrder)
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)
From 8135b12f2d05435b6bb19d671267569f7dd55e41 Mon Sep 17 00:00:00 2001
From: John Schember
Date: Sat, 28 May 2011 20:38:41 -0400
Subject: [PATCH 20/21] Store: search, config dialog save size and current tab.
Set better default size.
---
src/calibre/gui2/store/search/search.py | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/src/calibre/gui2/store/search/search.py b/src/calibre/gui2/store/search/search.py
index aa9aef6c3e..cda89f278e 100644
--- a/src/calibre/gui2/store/search/search.py
+++ b/src/calibre/gui2/store/search/search.py
@@ -268,7 +268,22 @@ class SearchDialog(QDialog, Ui_Dialog):
tab_widget.addTab(chooser_config_widget, _('Choose stores'))
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_()
+
+ # 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()
self.config_changed()
self.gui.load_store_plugins()
From 45e2298080b2b0ddb3a516b111467b09641ebe49 Mon Sep 17 00:00:00 2001
From: John Schember
Date: Sat, 28 May 2011 20:43:34 -0400
Subject: [PATCH 21/21] Store: Remove unnecessary code.
---
src/calibre/gui2/store/config/chooser/chooser_widget.py | 5 +----
src/calibre/gui2/store/search/search.py | 2 ++
2 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/src/calibre/gui2/store/config/chooser/chooser_widget.py b/src/calibre/gui2/store/config/chooser/chooser_widget.py
index cc1db488f1..a9399028f8 100644
--- a/src/calibre/gui2/store/config/chooser/chooser_widget.py
+++ b/src/calibre/gui2/store/config/chooser/chooser_widget.py
@@ -26,14 +26,11 @@ class StoreChooserWidget(QWidget, Ui_Form):
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.toggle_plugin)
+ self.results_view.activated.connect(self.results_view.model().toggle_plugin)
def do_search(self):
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):
adv = AdvSearchBuilderDialog(self)
if adv.exec_() == QDialog.Accepted:
diff --git a/src/calibre/gui2/store/search/search.py b/src/calibre/gui2/store/search/search.py
index cda89f278e..e1ad24943d 100644
--- a/src/calibre/gui2/store/search/search.py
+++ b/src/calibre/gui2/store/search/search.py
@@ -251,6 +251,8 @@ class SearchDialog(QDialog, Ui_Dialog):
# search widget.
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)
button_box = QDialogButtonBox(QDialogButtonBox.Close)
v = QVBoxLayout(d)