From 07716ef80130943906d2e2bac4ba3d241d9bde8b Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Sat, 28 May 2011 14:56:53 +0100 Subject: [PATCH] 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