mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Implement #7199 (Optional subscription)
This commit is contained in:
parent
7020ce507e
commit
ca4953f028
@ -39,7 +39,7 @@
|
|||||||
<item>
|
<item>
|
||||||
<widget class="QTabWidget" name="central_widget">
|
<widget class="QTabWidget" name="central_widget">
|
||||||
<property name="currentIndex">
|
<property name="currentIndex">
|
||||||
<number>2</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="tabWidgetPage1">
|
<widget class="QWidget" name="tabWidgetPage1">
|
||||||
<attribute name="title">
|
<attribute name="title">
|
||||||
|
@ -120,12 +120,15 @@ class SchedulerDialog(QDialog, Ui_Dialog):
|
|||||||
|
|
||||||
if self.account.isVisible():
|
if self.account.isVisible():
|
||||||
un, pw = map(unicode, (self.username.text(), self.password.text()))
|
un, pw = map(unicode, (self.username.text(), self.password.text()))
|
||||||
|
un, pw = un.strip(), pw.strip()
|
||||||
if not un and not pw and self.schedule.isChecked():
|
if not un and not pw and self.schedule.isChecked():
|
||||||
error_dialog(self, _('Need username and password'),
|
if not getattr(self, 'subscription_optional', False):
|
||||||
_('You must provide a username and/or password to '
|
error_dialog(self, _('Need username and password'),
|
||||||
'use this news source.'), show=True)
|
_('You must provide a username and/or password to '
|
||||||
return False
|
'use this news source.'), show=True)
|
||||||
self.recipe_model.set_account_info(urn, un.strip(), pw.strip())
|
return False
|
||||||
|
if un or pw:
|
||||||
|
self.recipe_model.set_account_info(urn, un, pw)
|
||||||
|
|
||||||
if self.schedule.isChecked():
|
if self.schedule.isChecked():
|
||||||
schedule_type = 'interval' if self.interval_button.isChecked() else 'day/time'
|
schedule_type = 'interval' if self.interval_button.isChecked() else 'day/time'
|
||||||
@ -157,7 +160,13 @@ class SchedulerDialog(QDialog, Ui_Dialog):
|
|||||||
account_info = self.recipe_model.account_info_from_urn(urn)
|
account_info = self.recipe_model.account_info_from_urn(urn)
|
||||||
customize_info = self.recipe_model.get_customize_info(urn)
|
customize_info = self.recipe_model.get_customize_info(urn)
|
||||||
|
|
||||||
self.account.setVisible(recipe.get('needs_subscription', '') == 'yes')
|
ns = recipe.get('needs_subscription', '')
|
||||||
|
self.account.setVisible(ns in ('yes', 'optional'))
|
||||||
|
self.subscription_optional = ns == 'optional'
|
||||||
|
act = _('Account')
|
||||||
|
act2 = _('(optional)') if self.subscription_optional else \
|
||||||
|
_('(required)')
|
||||||
|
self.account.setTitle(act+' '+act2)
|
||||||
un = pw = ''
|
un = pw = ''
|
||||||
if account_info is not None:
|
if account_info is not None:
|
||||||
un, pw = account_info[:2]
|
un, pw = account_info[:2]
|
||||||
|
@ -110,9 +110,11 @@ class BasicNewsRecipe(Recipe):
|
|||||||
|
|
||||||
#: If True the GUI will ask the user for a username and password
|
#: If True the GUI will ask the user for a username and password
|
||||||
#: to use while downloading
|
#: to use while downloading
|
||||||
#: @type: boolean
|
#: If set to "optional" the use of a username and password becomes optional
|
||||||
needs_subscription = False
|
needs_subscription = False
|
||||||
|
|
||||||
|
#:
|
||||||
|
|
||||||
#: If True the navigation bar is center aligned, otherwise it is left aligned
|
#: If True the navigation bar is center aligned, otherwise it is left aligned
|
||||||
center_navbar = True
|
center_navbar = True
|
||||||
|
|
||||||
@ -609,7 +611,8 @@ class BasicNewsRecipe(Recipe):
|
|||||||
if self.needs_subscription and (\
|
if self.needs_subscription and (\
|
||||||
self.username is None or self.password is None or \
|
self.username is None or self.password is None or \
|
||||||
(not self.username and not self.password)):
|
(not self.username and not self.password)):
|
||||||
raise ValueError(_('The "%s" recipe needs a username and password.')%self.title)
|
if self.needs_subscription != 'optional':
|
||||||
|
raise ValueError(_('The "%s" recipe needs a username and password.')%self.title)
|
||||||
|
|
||||||
self.browser = self.get_browser()
|
self.browser = self.get_browser()
|
||||||
self.image_map, self.image_counter = {}, 1
|
self.image_map, self.image_counter = {}, 1
|
||||||
|
@ -45,12 +45,17 @@ def serialize_recipe(urn, recipe_class):
|
|||||||
return ans
|
return ans
|
||||||
|
|
||||||
default_author = _('You') if urn.startswith('custom:') else _('Unknown')
|
default_author = _('You') if urn.startswith('custom:') else _('Unknown')
|
||||||
|
ns = attr('needs_subscription', False)
|
||||||
|
if not ns:
|
||||||
|
ns = 'no'
|
||||||
|
if ns is True:
|
||||||
|
ns = 'yes'
|
||||||
return E.recipe({
|
return E.recipe({
|
||||||
'id' : str(urn),
|
'id' : str(urn),
|
||||||
'title' : attr('title', _('Unknown')),
|
'title' : attr('title', _('Unknown')),
|
||||||
'author' : attr('__author__', default_author),
|
'author' : attr('__author__', default_author),
|
||||||
'language' : attr('language', 'und'),
|
'language' : attr('language', 'und'),
|
||||||
'needs_subscription' : 'yes' if attr('needs_subscription', False) else 'no',
|
'needs_subscription' : ns,
|
||||||
'description' : attr('description', '')
|
'description' : attr('description', '')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user