Move setting affiliate in the results structure. Add the heart to the list of stores. Initialize 'affiliate' in the thread.

This commit is contained in:
Charles Haley 2011-05-28 14:56:53 +01:00
parent ddb7afffa9
commit 07716ef801
4 changed files with 18 additions and 8 deletions

View File

@ -623,6 +623,8 @@ class StoreBase(Plugin): # {{{
headquarters = '' headquarters = ''
# All formats the store distributes ebooks in. # All formats the store distributes ebooks in.
formats = [] formats = []
# Is this store on an affiliate program?
affiliate = False
def load_actual_plugin(self, gui): def load_actual_plugin(self, gui):
''' '''

View File

@ -8,7 +8,7 @@ __docformat__ = 'restructuredtext en'
from functools import partial from functools import partial
from PyQt4.Qt import QMenu from PyQt4.Qt import QMenu, QIcon, QSize
from calibre.gui2 import error_dialog from calibre.gui2 import error_dialog
from calibre.gui2.actions import InterfaceAction from calibre.gui2.actions import InterfaceAction
@ -32,7 +32,12 @@ class StoreAction(InterfaceAction):
self.store_menu.addAction(_('Search for this book'), self.search_author_title) self.store_menu.addAction(_('Search for this book'), self.search_author_title)
self.store_menu.addSeparator() self.store_menu.addSeparator()
self.store_list_menu = self.store_menu.addMenu(_('Stores')) self.store_list_menu = self.store_menu.addMenu(_('Stores'))
icon = QIcon()
icon.addFile(I('donate.png'), QSize(16, 16))
for n, p in sorted(self.gui.istores.items(), key=lambda x: x[0].lower()): for n, p in sorted(self.gui.istores.items(), key=lambda x: x[0].lower()):
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_list_menu.addAction(n, partial(self.open_store, p))
self.store_menu.addSeparator() self.store_menu.addSeparator()
self.store_menu.addAction(_('Choose stores'), self.choose) self.store_menu.addAction(_('Choose stores'), self.choose)

View File

@ -120,6 +120,7 @@ class SearchThread(Thread):
if not self._run: if not self._run:
return return
res.store_name = store_name res.store_name = store_name
res.affiliate = store_plugin.base_plugin.affiliate
self.results.put((res, store_plugin)) self.results.put((res, store_plugin))
self.tasks.task_done() self.tasks.task_done()
except: except:

View File

@ -76,7 +76,6 @@ class Matches(QAbstractItemModel):
self.reset() self.reset()
def add_result(self, result, store_plugin): def add_result(self, result, store_plugin):
result.affiliate = getattr(store_plugin.base_plugin, 'affiliate', False)
if result not in self.all_matches: if result not in self.all_matches:
self.layoutAboutToBeChanged.emit() self.layoutAboutToBeChanged.emit()
self.all_matches.append(result) self.all_matches.append(result)
@ -178,6 +177,8 @@ class Matches(QAbstractItemModel):
return QVariant(self.DRM_UNKNOWN_ICON) return QVariant(self.DRM_UNKNOWN_ICON)
if col == 5: if col == 5:
if result.affiliate: 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 = QIcon()
icon.addFile(I('donate.png'), QSize(16, 16)) icon.addFile(I('donate.png'), QSize(16, 16))
return QVariant(icon) return QVariant(icon)
@ -197,6 +198,7 @@ class Matches(QAbstractItemModel):
elif col == 4: elif col == 4:
return QVariant('<p>%s</p>' % result.formats) return QVariant('<p>%s</p>' % result.formats)
elif col == 5: elif col == 5:
if result.affiliate:
return QVariant(_('Buying from this store supports a calibre developer')) return QVariant(_('Buying from this store supports a calibre developer'))
elif role == Qt.SizeHintRole: elif role == Qt.SizeHintRole:
return QSize(64, 64) return QSize(64, 64)