Add heart to search screen

This commit is contained in:
Charles Haley 2011-05-28 13:54:57 +01:00
parent bd115b5561
commit 40b073c60c
3 changed files with 26 additions and 5 deletions

View File

@ -1111,6 +1111,7 @@ class StoreAmazonKindleStore(StoreBase):
drm_free_only = False drm_free_only = False
headquarters = 'US' headquarters = 'US'
formats = ['KINDLE'] formats = ['KINDLE']
affiliate = True
class StoreAmazonDEKindleStore(StoreBase): class StoreAmazonDEKindleStore(StoreBase):
name = 'Amazon DE Kindle' name = 'Amazon DE Kindle'
@ -1121,6 +1122,7 @@ class StoreAmazonDEKindleStore(StoreBase):
drm_free_only = False drm_free_only = False
headquarters = 'DE' headquarters = 'DE'
formats = ['KINDLE'] formats = ['KINDLE']
affiliate = True
class StoreAmazonUKKindleStore(StoreBase): class StoreAmazonUKKindleStore(StoreBase):
name = 'Amazon UK Kindle' name = 'Amazon UK Kindle'
@ -1131,6 +1133,7 @@ class StoreAmazonUKKindleStore(StoreBase):
drm_free_only = False drm_free_only = False
headquarters = 'UK' headquarters = 'UK'
formats = ['KINDLE'] formats = ['KINDLE']
affiliate = True
class StoreArchiveOrgStore(StoreBase): class StoreArchiveOrgStore(StoreBase):
name = 'Archive.org' name = 'Archive.org'
@ -1168,6 +1171,7 @@ class StoreBeamEBooksDEStore(StoreBase):
drm_free_only = True drm_free_only = True
headquarters = 'DE' headquarters = 'DE'
formats = ['EPUB', 'MOBI', 'PDF'] formats = ['EPUB', 'MOBI', 'PDF']
affiliate = True
class StoreBeWriteStore(StoreBase): class StoreBeWriteStore(StoreBase):
name = 'BeWrite Books' name = 'BeWrite Books'
@ -1233,6 +1237,7 @@ class StoreFoylesUKStore(StoreBase):
drm_free_only = False drm_free_only = False
headquarters = 'UK' headquarters = 'UK'
formats = ['EPUB', 'PDF'] formats = ['EPUB', 'PDF']
affiliate = True
class StoreGandalfStore(StoreBase): class StoreGandalfStore(StoreBase):
name = 'Gandalf' name = 'Gandalf'
@ -1402,6 +1407,7 @@ class StoreEBookShoppeUKStore(StoreBase):
drm_free_only = False drm_free_only = False
headquarters = 'UK' headquarters = 'UK'
formats = ['EPUB', 'PDF'] formats = ['EPUB', 'PDF']
affiliate = True
plugins += [ plugins += [
StoreArchiveOrgStore, StoreArchiveOrgStore,
@ -1432,7 +1438,7 @@ plugins += [
StorePragmaticBookshelfStore, StorePragmaticBookshelfStore,
StoreSmashwordsStore, StoreSmashwordsStore,
StoreVirtualoStore, StoreVirtualoStore,
#StoreWaterstonesUKStore, StoreWaterstonesUKStore,
StoreWeightlessBooksStore, StoreWeightlessBooksStore,
StoreWizardsTowerBooksStore, StoreWizardsTowerBooksStore,
StoreWoblinkStore StoreWoblinkStore

View File

@ -10,7 +10,7 @@ import re
from operator import attrgetter from operator import attrgetter
from PyQt4.Qt import (Qt, QAbstractItemModel, QVariant, QPixmap, QModelIndex, QSize, from PyQt4.Qt import (Qt, QAbstractItemModel, QVariant, QPixmap, QModelIndex, QSize,
pyqtSignal) pyqtSignal, QIcon)
from calibre.gui2 import NONE from calibre.gui2 import NONE
from calibre.gui2.store.search_result import SearchResult from calibre.gui2.store.search_result import SearchResult
@ -33,7 +33,7 @@ class Matches(QAbstractItemModel):
total_changed = pyqtSignal(int) total_changed = pyqtSignal(int)
HEADERS = [_('Cover'), _('Title'), _('Price'), _('DRM'), _('Store')] HEADERS = [_('Cover'), _('Title'), _('Price'), _('DRM'), _('Store'), _('')]
HTML_COLS = (1, 4) HTML_COLS = (1, 4)
def __init__(self, cover_thread_count=2, detail_thread_count=4): def __init__(self, cover_thread_count=2, detail_thread_count=4):
@ -76,6 +76,7 @@ class Matches(QAbstractItemModel):
self.reset() self.reset()
def add_result(self, result, store_plugin): def add_result(self, result, store_plugin):
result.plugin = store_plugin
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)
@ -175,6 +176,12 @@ class Matches(QAbstractItemModel):
return QVariant(self.DRM_UNLOCKED_ICON) return QVariant(self.DRM_UNLOCKED_ICON)
elif result.drm == SearchResult.DRM_UNKNOWN: elif result.drm == SearchResult.DRM_UNKNOWN:
return QVariant(self.DRM_UNKNOWN_ICON) return QVariant(self.DRM_UNKNOWN_ICON)
if col == 5:
if 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: elif role == Qt.ToolTipRole:
if col == 1: if col == 1:
return QVariant('<p>%s</p>' % result.title) return QVariant('<p>%s</p>' % result.title)
@ -189,6 +196,8 @@ class Matches(QAbstractItemModel):
return QVariant('<p>' + _('The DRM status of this book could not be determined. There is a very high likelihood that this book is actually DRM restricted.') + '</p>') return QVariant('<p>' + _('The DRM status of this book could not be determined. There is a very high likelihood that this book is actually DRM restricted.') + '</p>')
elif col == 4: elif col == 4:
return QVariant('<p>%s</p>' % result.formats) return QVariant('<p>%s</p>' % result.formats)
elif col == 5:
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)
return NONE return NONE
@ -208,6 +217,11 @@ class Matches(QAbstractItemModel):
text = 'c' text = 'c'
elif col == 4: elif col == 4:
text = result.store_name text = result.store_name
elif col == 5:
if getattr(result.plugin.base_plugin, 'affiliate', False):
text = 'y'
else:
text = 'n'
return text return text
def sort(self, col, order, reset=True): def sort(self, col, order, reset=True):

View File

@ -7,11 +7,11 @@ __copyright__ = '2011, John Schember <john@nachtimwald.com>'
__docformat__ = 'restructuredtext en' __docformat__ = 'restructuredtext en'
class SearchResult(object): class SearchResult(object):
DRM_LOCKED = 1 DRM_LOCKED = 1
DRM_UNLOCKED = 2 DRM_UNLOCKED = 2
DRM_UNKNOWN = 3 DRM_UNKNOWN = 3
def __init__(self): def __init__(self):
self.store_name = '' self.store_name = ''
self.cover_url = '' self.cover_url = ''
@ -22,6 +22,7 @@ class SearchResult(object):
self.detail_item = '' self.detail_item = ''
self.drm = None self.drm = None
self.formats = '' self.formats = ''
self.plugin = None
def __eq__(self, other): def __eq__(self, other):
return self.title == other.title and self.author == other.author and self.store_name == other.store_name return self.title == other.title and self.author == other.author and self.store_name == other.store_name