Merge pull request #264 from elelay/self-hosting

Easier self-hosting support
This commit is contained in:
Adam Voss 2017-04-11 17:08:41 -05:00 committed by GitHub
commit 1fa31c39c2
5 changed files with 96 additions and 38 deletions

View File

@ -351,8 +351,8 @@
</packing>
</child>
<child>
<object class="GtkLabel" id="label_username">
<property name="label" translatable="yes">Username:</property>
<object class="GtkLabel" id="label_server">
<property name="label" translatable="yes">Server:</property>
<property name="visible">True</property>
<property name="xalign">1.0</property>
</object>
@ -363,6 +363,19 @@
<property name="y_options"></property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label_username">
<property name="label" translatable="yes">Username:</property>
<property name="visible">True</property>
<property name="xalign">1.0</property>
</object>
<packing>
<property name="bottom_attach">4</property>
<property name="top_attach">3</property>
<property name="x_options">fill</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label_password">
<property name="label" translatable="yes">Password:</property>
@ -370,8 +383,8 @@
<property name="xalign">1.0</property>
</object>
<packing>
<property name="bottom_attach">4</property>
<property name="top_attach">3</property>
<property name="bottom_attach">5</property>
<property name="top_attach">4</property>
<property name="x_options">fill</property>
<property name="y_options"></property>
</packing>
@ -383,9 +396,9 @@
<signal handler="on_button_overwrite_clicked" name="clicked"/>
</object>
<packing>
<property name="bottom_attach">6</property>
<property name="bottom_attach">7</property>
<property name="right_attach">3</property>
<property name="top_attach">5</property>
<property name="top_attach">6</property>
<property name="y_options"></property>
</packing>
</child>
@ -396,22 +409,35 @@
<property name="xalign">1.0</property>
</object>
<packing>
<property name="bottom_attach">5</property>
<property name="top_attach">4</property>
<property name="bottom_attach">6</property>
<property name="top_attach">5</property>
<property name="x_options">fill</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<object class="GtkEntry" id="entry_server">
<property name="visible">True</property>
<signal handler="on_server_changed" name="changed"/>
</object>
<packing>
<property name="bottom_attach">3</property>
<property name="left_attach">1</property>
<property name="right_attach">3</property>
<property name="top_attach">2</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<object class="GtkEntry" id="entry_username">
<property name="visible">True</property>
<signal handler="on_username_changed" name="changed"/>
</object>
<packing>
<property name="bottom_attach">3</property>
<property name="bottom_attach">4</property>
<property name="left_attach">1</property>
<property name="right_attach">3</property>
<property name="top_attach">2</property>
<property name="top_attach">3</property>
<property name="y_options"></property>
</packing>
</child>
@ -423,10 +449,10 @@
<signal handler="on_password_changed" name="changed"/>
</object>
<packing>
<property name="bottom_attach">4</property>
<property name="bottom_attach">5</property>
<property name="left_attach">1</property>
<property name="right_attach">3</property>
<property name="top_attach">3</property>
<property name="top_attach">4</property>
<property name="y_options"></property>
</packing>
</child>
@ -436,10 +462,10 @@
<signal handler="on_device_caption_changed" name="changed"/>
</object>
<packing>
<property name="bottom_attach">5</property>
<property name="bottom_attach">6</property>
<property name="left_attach">1</property>
<property name="right_attach">3</property>
<property name="top_attach">4</property>
<property name="top_attach">5</property>
<property name="y_options"></property>
</packing>
</child>

View File

@ -281,6 +281,7 @@ class gPodderPreferences(BuilderWidget):
# Initialize the UI state with configuration settings
self.checkbutton_enable.set_active(self._config.mygpo.enabled)
self.entry_server.set_text(self._config.mygpo.server)
self.entry_username.set_text(self._config.mygpo.username)
self.entry_password.set_text(self._config.mygpo.password)
self.entry_caption.set_text(self._config.mygpo.device.caption)
@ -528,6 +529,9 @@ class gPodderPreferences(BuilderWidget):
def on_button_youtube_api_key_clicked(self, widget):
util.open_website('http://wiki.gpodder.org/wiki/Youtube')
def on_server_changed(self, widget):
self._config.mygpo.server = widget.get_text()
def on_username_changed(self, widget):
self._config.mygpo.username = widget.get_text()

View File

@ -154,8 +154,8 @@ class BuilderWidget(GtkBuilderWidget):
else:
return None
def show_login_dialog(self, title, message, username=None, password=None,
username_prompt=None, register_callback=None, register_text=None):
def show_login_dialog(self, title, message, root_url=None, username=None, password=None,
username_prompt=None, register_callback=None, register_text=None, ask_server=False):
if username_prompt is None:
username_prompt = _('Username')
@ -177,36 +177,50 @@ class BuilderWidget(GtkBuilderWidget):
if register_callback is not None:
dialog.add_button(register_text, gtk.RESPONSE_HELP)
server_entry = gtk.Entry()
server_entry.set_tooltip_text(_('hostname or root URL (e.g. https://gpodder.net)'))
username_entry = gtk.Entry()
password_entry = gtk.Entry()
server_entry.connect('activate', lambda w: username_entry.grab_focus())
username_entry.connect('activate', lambda w: password_entry.grab_focus())
password_entry.set_visibility(False)
password_entry.set_activates_default(True)
if root_url is not None:
server_entry.set_text(root_url)
if username is not None:
username_entry.set_text(username)
if password is not None:
password_entry.set_text(password)
table = gtk.Table(2, 2)
table = gtk.Table(3, 2)
table.set_row_spacings(6)
table.set_col_spacings(6)
server_label = gtk.Label()
server_label.set_markup('<b>' + _('Server') + ':</b>')
username_label = gtk.Label()
username_label.set_markup('<b>' + username_prompt + ':</b>')
username_label.set_alignment(0.0, 0.5)
table.attach(username_label, 0, 1, 0, 1, gtk.FILL, 0)
table.attach(username_entry, 1, 2, 0, 1)
password_label = gtk.Label()
password_label.set_markup('<b>' + _('Password') + ':</b>')
password_label.set_alignment(0.0, 0.5)
table.attach(password_label, 0, 1, 1, 2, gtk.FILL, 0)
table.attach(password_entry, 1, 2, 1, 2)
label_entries = [(username_label, username_entry),
(password_label, password_entry)]
if ask_server:
label_entries.insert(0, (server_label, server_entry))
for i, (label, entry) in enumerate(label_entries):
label.set_alignment(0.0, 0.5)
table.attach(label, 0, 1, i, i + 1, gtk.FILL, 0)
table.attach(entry, 1, 2, i, i + 1)
dialog.vbox.pack_end(table, True, True, 0)
dialog.show_all()
username_entry.grab_focus()
response = dialog.run()
while response == gtk.RESPONSE_HELP:
@ -214,13 +228,17 @@ class BuilderWidget(GtkBuilderWidget):
response = dialog.run()
password_entry.set_visibility(True)
root_url = server_entry.get_text()
username = username_entry.get_text()
password = password_entry.get_text()
success = (response == gtk.RESPONSE_OK)
dialog.destroy()
return (success, (username, password))
if ask_server:
return (success, (root_url, username, password))
else:
return (success, (username, password))
def show_copy_dialog(self, src_filename, dst_filename=None, dst_directory=None, title=_('Select destination')):
if dst_filename is None:

View File

@ -2921,33 +2921,37 @@ class gPodder(BuilderWidget, dbus.service.Object):
self.mygpo_client.open_website()
def on_download_subscriptions_from_mygpo(self, action=None):
def after_login():
title = _('Subscriptions on %(server)s') \
% {'server': self.config.mygpo.server}
dir = gPodderPodcastDirectory(self.gPodder,
_config=self.config,
custom_title=title,
add_podcast_list=self.add_podcast_list,
hide_url_entry=True)
url = self.mygpo_client.get_download_user_subscriptions_url()
dir.download_opml_file(url)
title = _('Login to gpodder.net')
message = _('Please login to download your subscriptions.')
def on_register_button_clicked():
util.open_website('http://gpodder.net/register/')
success, (username, password) = self.show_login_dialog(title, message,
success, (root_url, username, password) = self.show_login_dialog(title, message,
self.config.mygpo.server,
self.config.mygpo.username, self.config.mygpo.password,
register_callback=on_register_button_clicked)
register_callback=on_register_button_clicked,
ask_server=True)
if not success:
return
self.config.mygpo.server = root_url
self.config.mygpo.username = username
self.config.mygpo.password = password
dir = gPodderPodcastDirectory(self.gPodder, _config=self.config, \
custom_title=_('Subscriptions on gpodder.net'), \
add_podcast_list=self.add_podcast_list,
hide_url_entry=True)
# TODO: Refactor this into "gpodder.my" or mygpoclient, so that
# we do not have to hardcode the URL here
OPML_URL = 'http://gpodder.net/subscriptions/%s.opml' % self.config.mygpo.username
url = util.url_add_authentication(OPML_URL, \
self.config.mygpo.username, \
self.config.mygpo.password)
dir.download_opml_file(url)
util.idle_add(after_login)
def on_itemAddChannel_activate(self, widget=None):
self._add_podcast_dialog = gPodderAddPodcast(self.gPodder, \

View File

@ -638,6 +638,12 @@ class MygPoClient(object):
def open_website(self):
util.open_website('http://' + self._config.mygpo.server)
def get_download_user_subscriptions_url(self):
OPML_URL = self._client.locator.subscriptions_uri()
url = util.url_add_authentication(OPML_URL, \
self._config.mygpo.username, \
self._config.mygpo.password)
return url
class Directory(object):
def __init__(self):