%s
' % result.description) + if col == 0: + if is_disabled(result): + 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.
')) + 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.
')) + 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.
')) + 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) + elif col == 4: + return QVariant(_('This store distributes ebooks in the following formats: %s
') % ', '.join(result.formats)) return NONE def setData(self, index, data, role): @@ -130,7 +145,7 @@ class Matches(QAbstractItemModel): elif col == 1: text = match.name elif col == 2: - text = 'b' if getattr(match, 'drm', True) else 'a' + text = 'a' if getattr(match, 'drm_free_only', True) else 'b' elif col == 3: text = getattr(match, 'headquarters', '') return text @@ -240,5 +255,3 @@ class SearchFilter(SearchQueryParser): import traceback traceback.print_exc() return matches - - diff --git a/src/calibre/gui2/store/search/search.py b/src/calibre/gui2/store/search/search.py index 3be39e3e87..faeaf507c9 100644 --- a/src/calibre/gui2/store/search/search.py +++ b/src/calibre/gui2/store/search/search.py @@ -10,10 +10,11 @@ import re from random import shuffle from PyQt4.Qt import (Qt, QDialog, QDialogButtonBox, QTimer, QCheckBox, - QVBoxLayout, QIcon, QWidget) + QVBoxLayout, QIcon, QWidget, QTabWidget) from calibre.gui2 import JSONConfig, info_dialog from calibre.gui2.progress_indicator import ProgressIndicator +from calibre.gui2.store.config.chooser.chooser_widget import StoreChooserWidget from calibre.gui2.store.config.search.search_widget import StoreConfigWidget from calibre.gui2.store.search.adv_search_builder import AdvSearchBuilderDialog from calibre.gui2.store.search.download_thread import SearchThreadPool, \ @@ -22,7 +23,7 @@ from calibre.gui2.store.search.search_ui import Ui_Dialog class SearchDialog(QDialog, Ui_Dialog): - def __init__(self, istores, parent=None, query=''): + def __init__(self, gui, parent=None, query=''): QDialog.__init__(self, parent) self.setupUi(self) @@ -34,8 +35,7 @@ class SearchDialog(QDialog, Ui_Dialog): # the variables it sets up are used later. self.load_settings() - # We keep a cache of store plugins and reference them by name. - self.store_plugins = istores + self.gui = gui # Setup our worker threads. self.search_pool = SearchThreadPool(self.search_thread_count) @@ -49,22 +49,11 @@ class SearchDialog(QDialog, Ui_Dialog): self.hang_check = 0 # Update store caches silently. - for p in self.store_plugins.values(): + for p in self.gui.istores.values(): self.cache_pool.add_task(p, self.timeout) - # Add check boxes for each store so the user - # can disable searching specific stores on a - # per search basis. - stores_check_widget = QWidget() - store_list_layout = QVBoxLayout() - stores_check_widget.setLayout(store_list_layout) - for x in sorted(self.store_plugins.keys(), key=lambda x: x.lower()): - cbox = QCheckBox(x) - cbox.setChecked(False) - store_list_layout.addWidget(cbox) - setattr(self, 'store_check_' + x, cbox) - store_list_layout.addStretch() - self.store_list.setWidget(stores_check_widget) + self.store_checks = {} + self.setup_store_checks() # Set the search query self.search_edit.setText(query) @@ -91,6 +80,27 @@ 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 + # per search basis. + 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() + stores_check_widget.setLayout(store_list_layout) + for x in sorted(self.gui.istores.keys(), key=lambda x: x.lower()): + cbox = QCheckBox(x) + cbox.setChecked(existing.get(x, False)) + store_list_layout.addWidget(cbox) + self.store_checks[x] = cbox + store_list_layout.addStretch() + self.store_list.setWidget(stores_check_widget) def build_adv_search(self): adv = AdvSearchBuilderDialog(self) @@ -126,11 +136,12 @@ class SearchDialog(QDialog, Ui_Dialog): # futher filtering. self.results_view.model().set_query(query) - # Plugins are in alphebetic order. Randomize the - # order of plugin names. This way plugins closer + # Plugins are in random order that does not change. + # Randomize the ord of the plugin names every time + # there is a search. This way plugins closer # to a don't have an unfair advantage over # plugins further from a. - store_names = self.store_plugins.keys() + store_names = self.store_checks.keys() if not store_names: return # Remove all of our internal filtering logic from the query. @@ -138,8 +149,8 @@ class SearchDialog(QDialog, Ui_Dialog): shuffle(store_names) # Add plugins that the user has checked to the search pool's work queue. for n in store_names: - if getattr(self, 'store_check_' + n).isChecked(): - self.search_pool.add_task(query, n, self.store_plugins[n], self.max_results, self.timeout) + if self.store_checks[n].isChecked(): + self.search_pool.add_task(query, n, self.gui.istores[n], self.max_results, self.timeout) self.hang_check = 0 self.checker.start(100) self.pi.startAnimation() @@ -179,8 +190,8 @@ class SearchDialog(QDialog, Ui_Dialog): self.config['open_external'] = self.open_external.isChecked() store_check = {} - for n in self.store_plugins: - store_check[n] = getattr(self, 'store_check_' + n).isChecked() + for k, v in self.store_checks.items(): + store_check[k] = v.isChecked() self.config['store_checked'] = store_check def restore_state(self): @@ -206,8 +217,8 @@ class SearchDialog(QDialog, Ui_Dialog): store_check = self.config.get('store_checked', None) if store_check: for n in store_check: - if hasattr(self, 'store_check_' + n): - getattr(self, 'store_check_' + n).setChecked(store_check[n]) + if n in self.store_checks: + self.store_checks[n].setChecked(store_check[n]) self.results_view.model().sort_col = self.config.get('sort_col', 2) self.results_view.model().sort_order = self.config.get('sort_order', Qt.AscendingOrder) @@ -234,20 +245,27 @@ class SearchDialog(QDialog, Ui_Dialog): self.config['open_external'] = self.open_external.isChecked() d = QDialog(self) - button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) + button_box = QDialogButtonBox(QDialogButtonBox.Close) v = QVBoxLayout(d) button_box.accepted.connect(d.accept) button_box.rejected.connect(d.reject) d.setWindowTitle(_('Customize get books search')) - config_widget = StoreConfigWidget(self.config) - v.addWidget(config_widget) + + tab_widget = QTabWidget(d) + v.addWidget(tab_widget) v.addWidget(button_box) - d.exec_() + 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')) - if d.result() == QDialog.Accepted: - config_widget.save_settings() - self.config_changed() + d.exec_() + search_config_widget.save_settings() + self.config_changed() + self.gui.load_store_plugins() + self.setup_store_checks() def config_changed(self): self.load_settings() @@ -283,7 +301,7 @@ class SearchDialog(QDialog, Ui_Dialog): def open_store(self, index): result = self.results_view.model().get_result(index) - self.store_plugins[result.store_name].open(self, result.detail_item, self.open_external.isChecked()) + self.gui.istores[result.store_name].open(self, result.detail_item, self.open_external.isChecked()) def check_progress(self): if not self.search_pool.threads_running() and not self.results_view.model().cover_pool.threads_running() and not self.results_view.model().details_pool.threads_running(): @@ -292,27 +310,16 @@ class SearchDialog(QDialog, Ui_Dialog): if not self.pi.isAnimated(): self.pi.startAnimation() - def get_store_checks(self): - ''' - Returns a list of QCheckBox's for each store. - ''' - checks = [] - for x in self.store_plugins: - check = getattr(self, 'store_check_' + x, None) - if check: - checks.append(check) - return checks - def stores_select_all(self): - for check in self.get_store_checks(): + for check in self.store_checks.values(): check.setChecked(True) def stores_select_invert(self): - for check in self.get_store_checks(): + for check in self.store_checks.values(): check.setChecked(not check.isChecked()) def stores_select_none(self): - for check in self.get_store_checks(): + for check in self.store_checks.values(): check.setChecked(False) def dialog_closed(self, result): diff --git a/src/calibre/gui2/store/virtualo_plugin.py b/src/calibre/gui2/store/virtualo_plugin.py new file mode 100644 index 0000000000..d86aa3e0e5 --- /dev/null +++ b/src/calibre/gui2/store/virtualo_plugin.py @@ -0,0 +1,72 @@ +# -*- coding: utf-8 -*- + +from __future__ import (unicode_literals, division, absolute_import, print_function) + +__license__ = 'GPL 3' +__copyright__ = '2011, Tomasz Długosz'+_('Setup sending email using') + + ' {name}
' + + _('If you don\'t have an account, you can sign up for a free {name} email ' + 'account at http://{url}. {extra}')).format( + **service)) + l.addWidget(self.tl, 0, 0, 3, 0) + self.tl.setWordWrap(True) + self.tl.setOpenExternalLinks(True) + for name, label in ( + ['from_', _('Your %s &email address:')], + ['username', _('Your %s &username:')], + ['password', _('Your %s &password:')], + ): + la = QLabel(label%service['name']) + le = QLineEdit(self) + setattr(self, name, le) + setattr(self, name+'_label', la) + r = l.rowCount() + l.addWidget(la, r, 0) + l.addWidget(le, r, 1) + la.setBuddy(le) + if name == 'password': + self.ptoggle = QCheckBox(_('&Show password'), self) + l.addWidget(self.ptoggle, r, 2) + self.ptoggle.stateChanged.connect( + lambda s: self.password.setEchoMode(self.password.Normal if s + == Qt.Checked else self.password.Password)) + self.username.setText(service['username']) + self.password.setEchoMode(self.password.Password) + self.bl = QLabel('
' + _( + 'If you plan to use email to send books to your Kindle, remember to' + ' add the your %s email address to the allowed email addresses in your ' + 'Amazon.com Kindle management page.')%service['name']) + self.bl.setWordWrap(True) + l.addWidget(self.bl, l.rowCount(), 0, 3, 0) + l.addWidget(bb, l.rowCount(), 0, 3, 0) + self.setWindowTitle(_('Setup') + ' ' + service['name']) + self.resize(self.sizeHint()) + self.service = service + + def accept(self): + un = unicode(self.username.text()) + if self.service.get('at_in_username', False) and '@' not in un: + return error_dialog(self, _('Incorrect username'), + _('%s needs the full email address as your username') % + self.service['name'], show=True) + QDialog.accept(self) + class SendEmail(QWidget, Ui_Form): @@ -129,7 +187,8 @@ class SendEmail(QWidget, Ui_Form): 'port': 587, 'username': '@gmail.com', 'url': 'www.gmail.com', - 'extra': '' + 'extra': '', + 'at_in_username': True, }, 'hotmail': { 'name': 'Hotmail', @@ -143,53 +202,10 @@ class SendEmail(QWidget, Ui_Form): ' will let calibre send email. In this case, I' ' strongly suggest you setup a free gmail account' ' instead.'), + 'at_in_username': True, } }[service] - d = QDialog(self) - l = QGridLayout() - d.setLayout(l) - bb = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel) - bb.accepted.connect(d.accept) - bb.rejected.connect(d.reject) - d.tl = QLabel(('
'+_('Setup sending email using') + - ' {name}
' + - _('If you don\'t have an account, you can sign up for a free {name} email ' - 'account at http://{url}. {extra}')).format( - **service)) - l.addWidget(d.tl, 0, 0, 3, 0) - d.tl.setWordWrap(True) - d.tl.setOpenExternalLinks(True) - for name, label in ( - ['from_', _('Your %s &email address:')], - ['username', _('Your %s &username:')], - ['password', _('Your %s &password:')], - ): - la = QLabel(label%service['name']) - le = QLineEdit(d) - setattr(d, name, le) - setattr(d, name+'_label', la) - r = l.rowCount() - l.addWidget(la, r, 0) - l.addWidget(le, r, 1) - la.setBuddy(le) - if name == 'password': - d.ptoggle = QCheckBox(_('&Show password'), d) - l.addWidget(d.ptoggle, r, 2) - d.ptoggle.stateChanged.connect( - lambda s: d.password.setEchoMode(d.password.Normal if s - == Qt.Checked else d.password.Password)) - d.username.setText(service['username']) - d.password.setEchoMode(d.password.Password) - d.bl = QLabel('
' + _( - 'If you plan to use email to send books to your Kindle, remember to' - ' add the your %s email address to the allowed email addresses in your ' - 'Amazon.com Kindle management page.')%service['name']) - d.bl.setWordWrap(True) - l.addWidget(d.bl, l.rowCount(), 0, 3, 0) - l.addWidget(bb, l.rowCount(), 0, 3, 0) - d.setWindowTitle(_('Setup') + ' ' + service['name']) - d.resize(d.sizeHint()) - bb.setVisible(True) + d = RelaySetup(service, self) if d.exec_() != d.Accepted: return self.relay_username.setText(d.username.text()) diff --git a/src/calibre/manual/faq.rst b/src/calibre/manual/faq.rst index b120fd4a1b..1c0b49f30b 100644 --- a/src/calibre/manual/faq.rst +++ b/src/calibre/manual/faq.rst @@ -587,7 +587,7 @@ You can download news and convert it into an ebook with the command:: /opt/calibre/ebook-convert "Title of news source.recipe" outputfile.epub -If you want to generate MOBI, use outputfile.mobi instead. +If you want to generate MOBI, use outputfile.mobi instead and use ``--output-profile kindle``. You can email downloaded news with the command::