my.gpodder.org device browser + push sync
This commit is contained in:
parent
a9bae2b720
commit
293205ab19
|
@ -38,7 +38,7 @@
|
|||
</object>
|
||||
<packing>
|
||||
<property name="bottom_attach">2</property>
|
||||
<property name="right_attach">3</property>
|
||||
<property name="right_attach">2</property>
|
||||
<property name="top_attach">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
|
@ -67,8 +67,10 @@
|
|||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkHSeparator" id="hseparator">
|
||||
<object class="GtkButton" id="button_overwrite">
|
||||
<property name="label" translatable="yes">Upload subscription list now (overwrite on server)</property>
|
||||
<property name="visible">True</property>
|
||||
<signal handler="on_button_overwrite_clicked" name="clicked"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="bottom_attach">5</property>
|
||||
|
@ -153,6 +155,7 @@
|
|||
<child>
|
||||
<object class="GtkEntry" id="entry_uid">
|
||||
<property name="visible">True</property>
|
||||
<signal handler="on_device_settings_changed" name="changed"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="bottom_attach">7</property>
|
||||
|
@ -164,6 +167,7 @@
|
|||
<child>
|
||||
<object class="GtkEntry" id="entry_caption">
|
||||
<property name="visible">True</property>
|
||||
<signal handler="on_device_settings_changed" name="changed"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="bottom_attach">8</property>
|
||||
|
@ -175,6 +179,7 @@
|
|||
<child>
|
||||
<object class="GtkComboBox" id="combo_type">
|
||||
<property name="visible">True</property>
|
||||
<signal handler="on_device_settings_changed" name="changed"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="bottom_attach">9</property>
|
||||
|
@ -186,9 +191,8 @@
|
|||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="button_list_uids">
|
||||
<property context="yes" name="label" translatable="yes">List UIDs</property>
|
||||
<property context="yes" name="label" translatable="yes">Select device</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="sensitive">False</property>
|
||||
<signal handler="on_button_list_uids_clicked" name="clicked"/>
|
||||
</object>
|
||||
<packing>
|
||||
|
|
|
@ -21,13 +21,78 @@
|
|||
# Thomas Perl <thpinfo.com>; 2010-01-19
|
||||
|
||||
import gtk
|
||||
import threading
|
||||
|
||||
import gpodder
|
||||
|
||||
_ = gpodder.gettext
|
||||
|
||||
from gpodder import util
|
||||
|
||||
from gpodder.gtkui.interface.progress import ProgressIndicator
|
||||
from gpodder.gtkui.interface.common import BuilderWidget
|
||||
|
||||
|
||||
class DeviceList(gtk.ListStore):
|
||||
C_UID, C_CAPTION, C_DEVICE_TYPE, C_ICON_NAME = range(4)
|
||||
|
||||
def __init__(self, devices):
|
||||
gtk.ListStore.__init__(self, str, str, str, str)
|
||||
for uid, caption, device_type in devices:
|
||||
if device_type == 'desktop':
|
||||
icon_name = 'computer'
|
||||
elif device_type == 'mobile':
|
||||
icon_name = 'phone'
|
||||
elif device_type == 'server':
|
||||
icon_name = 'server'
|
||||
elif device_type == 'laptop':
|
||||
icon_name = 'stock_notebook'
|
||||
else:
|
||||
icon_name = 'audio-x-generic'
|
||||
self.append((uid, caption, device_type, icon_name))
|
||||
|
||||
class DeviceBrowser(gtk.Dialog):
|
||||
def __init__(self, model, parent=None):
|
||||
gtk.Dialog.__init__(self, _('Select a device'), parent)
|
||||
|
||||
self._model = model
|
||||
|
||||
hbox = gtk.HBox()
|
||||
hbox.set_border_width(6)
|
||||
hbox.set_spacing(6)
|
||||
self.vbox.add(hbox)
|
||||
hbox.pack_start(gtk.Label(_('Device:')), expand=False)
|
||||
|
||||
combobox = gtk.ComboBox()
|
||||
hbox.add(combobox)
|
||||
cell = gtk.CellRendererPixbuf()
|
||||
combobox.pack_start(cell, expand=False)
|
||||
combobox.add_attribute(cell, 'icon-name', DeviceList.C_ICON_NAME)
|
||||
cell = gtk.CellRendererText()
|
||||
combobox.pack_start(cell)
|
||||
combobox.add_attribute(cell, 'text', DeviceList.C_CAPTION)
|
||||
|
||||
combobox.set_model(self._model)
|
||||
combobox.set_active(0)
|
||||
self._combobox = combobox
|
||||
|
||||
self.add_button(_('Cancel'), gtk.RESPONSE_CANCEL)
|
||||
self.add_button(_('Use device'), gtk.RESPONSE_OK)
|
||||
|
||||
def get_selected(self):
|
||||
result = None
|
||||
|
||||
self.show_all()
|
||||
if self.run() == gtk.RESPONSE_OK:
|
||||
active = self._combobox.get_active()
|
||||
result = (self._model[active][DeviceList.C_UID],
|
||||
self._model[active][DeviceList.C_CAPTION],
|
||||
self._model[active][DeviceList.C_DEVICE_TYPE])
|
||||
self.destroy()
|
||||
|
||||
return result
|
||||
|
||||
|
||||
class MygPodderSettings(BuilderWidget):
|
||||
# Valid types defined in mygpoclient.api.PodcastDevice
|
||||
VALID_TYPES = (
|
||||
|
@ -42,6 +107,9 @@ class MygPodderSettings(BuilderWidget):
|
|||
C_ID, C_CAPTION = range(2)
|
||||
|
||||
def new(self):
|
||||
# We need to have a MygPoClient instance available
|
||||
assert getattr(self, 'mygpo_client', None) is not None
|
||||
|
||||
active_index = 0
|
||||
self._model = gtk.ListStore(str, str)
|
||||
for index, data in enumerate(self.VALID_TYPES):
|
||||
|
@ -63,9 +131,38 @@ class MygPodderSettings(BuilderWidget):
|
|||
self.entry_caption.set_text(self.config.mygpo_device_caption)
|
||||
self.combo_type.set_active(active_index)
|
||||
|
||||
self.button_overwrite.set_sensitive(True)
|
||||
|
||||
def on_device_settings_changed(self, widget):
|
||||
self.button_overwrite.set_sensitive(False)
|
||||
|
||||
def on_button_overwrite_clicked(self, button):
|
||||
threading.Thread(target=self.mygpo_client.force_fresh_upload).start()
|
||||
|
||||
def on_button_list_uids_clicked(self, button):
|
||||
# FIXME: Not implemented yet
|
||||
pass
|
||||
indicator = ProgressIndicator(_('Downloading device list'),
|
||||
_('Getting the list of devices from your account.'),
|
||||
False, self.main_window)
|
||||
|
||||
def thread_proc():
|
||||
devices = self.mygpo_client.get_devices()
|
||||
indicator.on_finished()
|
||||
def ui_callback(devices):
|
||||
model = DeviceList(devices)
|
||||
dialog = DeviceBrowser(model, self.main_window)
|
||||
result = dialog.get_selected()
|
||||
if result is not None:
|
||||
uid, caption, device_type = result
|
||||
self.entry_uid.set_text(uid)
|
||||
self.entry_caption.set_text(caption)
|
||||
for index, data in enumerate(self.VALID_TYPES):
|
||||
d_type, d_name = data
|
||||
if device_type == d_type:
|
||||
self.combo_type.set_active(index)
|
||||
break
|
||||
util.idle_add(ui_callback, devices)
|
||||
|
||||
threading.Thread(target=thread_proc).start()
|
||||
|
||||
def on_button_cancel_clicked(self, button):
|
||||
# Ignore changed settings and close
|
||||
|
@ -86,4 +183,3 @@ class MygPodderSettings(BuilderWidget):
|
|||
|
||||
self.main_window.destroy()
|
||||
|
||||
|
||||
|
|
|
@ -550,7 +550,19 @@ class gPodder(BuilderWidget, dbus.service.Object):
|
|||
|
||||
def on_send_full_subscriptions(self):
|
||||
# Send the full subscription list to the my.gpodder.org client
|
||||
self.mygpo_client.on_subscribe([c.url for c in self.channels])
|
||||
# (this will overwrite the subscription list on the server)
|
||||
indicator = ProgressIndicator(_('Uploading subscriptions'), \
|
||||
_('Your subscriptions are being uploaded to the server.'), \
|
||||
False, self.main_window)
|
||||
|
||||
try:
|
||||
self.mygpo_client.set_subscriptions([c.url for c in self.channels])
|
||||
util.idle_add(self.show_message, _('List uploaded successfully.'))
|
||||
except Exception, e:
|
||||
util.idle_add(self.show_message, str(e), \
|
||||
_('Error while uploading'), important=True)
|
||||
|
||||
util.idle_add(indicator.on_finished)
|
||||
|
||||
def on_podcast_selected(self, treeview, path, column):
|
||||
# for Maemo 5's UI
|
||||
|
@ -2940,7 +2952,9 @@ class gPodder(BuilderWidget, dbus.service.Object):
|
|||
self.mygpo_client.open_website()
|
||||
|
||||
def on_mygpo_settings_activate(self, action=None):
|
||||
settings = MygPodderSettings(self.main_window, config=self.config)
|
||||
settings = MygPodderSettings(self.main_window, \
|
||||
config=self.config, \
|
||||
mygpo_client=self.mygpo_client)
|
||||
|
||||
def on_itemAddChannel_activate(self, widget=None):
|
||||
gPodderAddPodcast(self.gPodder, \
|
||||
|
|
|
@ -69,7 +69,7 @@ class Actions(object):
|
|||
|
||||
class MygPoClient(object):
|
||||
CACHE_FILE = 'mygpo.queue.json'
|
||||
FLUSH_TIMEOUT = 10
|
||||
FLUSH_TIMEOUT = 60
|
||||
FLUSH_RETRIES = 3
|
||||
|
||||
def __init__(self, config,
|
||||
|
@ -120,6 +120,14 @@ class MygPoClient(object):
|
|||
if 'remove_podcasts' not in self._cache:
|
||||
self._cache['remove_podcasts'] = []
|
||||
|
||||
def force_fresh_upload(self):
|
||||
self._on_send_full_subscriptions()
|
||||
|
||||
def set_subscriptions(self, urls):
|
||||
log('Uploading (overwriting) subscriptions...')
|
||||
self._client.put_subscriptions(self._config.mygpo_device_uid, urls)
|
||||
log('Subscription upload done.')
|
||||
|
||||
def on_subscribe(self, urls):
|
||||
self.request_podcast_lists_in_cache()
|
||||
self._cache['add_podcasts'].extend(urls)
|
||||
|
@ -223,7 +231,7 @@ class MygPoClient(object):
|
|||
self.schedule(Actions.UPDATE_DEVICE)
|
||||
if name == 'mygpo_device_uid':
|
||||
# Reset everything because we have a new device ID
|
||||
self._on_send_full_subscriptions()
|
||||
threading.Thread(target=self.force_fresh_upload).start()
|
||||
self._cache['podcasts_since'] = 0
|
||||
|
||||
def synchronize_subscriptions(self):
|
||||
|
@ -274,6 +282,12 @@ class MygPoClient(object):
|
|||
log('Cannot update device %s: %s', uid, str(e), sender=self, traceback=True)
|
||||
return False
|
||||
|
||||
def get_devices(self):
|
||||
result = []
|
||||
for d in self._client.get_devices():
|
||||
result.append((d.device_id, d.caption, d.type))
|
||||
return result
|
||||
|
||||
def open_website(self):
|
||||
util.open_website('http://' + self._config.mygpo_server)
|
||||
|
||||
|
|
Loading…
Reference in New Issue