From a46954edf9675139ff26b5724e8c031be2eeed94 Mon Sep 17 00:00:00 2001 From: John Schember Date: Sat, 28 May 2011 16:55:57 -0400 Subject: [PATCH] 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