Commit f3fae530 authored by Ilja's avatar Ilja
Browse files

Allow to change the port in the webremote plug-in

This changes the portlabel to an entry where you can specify the port you want to use. There is error-handling for setting a wrong value (non-int or int that's out of range).
When a port is given that is already in use, it will set an unused port. This was behaviour that was already present and I have no idea how to change it to be more consistent to the other error-handlings (i'm pretty new to all this). I hope this is ok, if not, tips to how I can make it better are more than welcome.

I don't know how to build Rhythmbox from source, so I changed the plugin in my Rhythmbox 3.4.4 installation on Kubuntu 20.04.2 and added the relevant changes here.
parent cd8c0aaa
Pipeline #271846 passed with stage
in 8 minutes and 40 seconds
......@@ -62,6 +62,18 @@
<property name="width">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="error-message">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_markup">True</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">4</property>
<property name="width">2</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="accesskey">
<property name="visible">True</property>
......@@ -73,10 +85,9 @@
</packing>
</child>
<child>
<object class="GtkLabel" id="portnumber">
<object class="GtkEntry" id="portnumber">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">0</property>
<property name="can_focus">True</property>
<property name="xalign">0</property>
</object>
<packing>
......
......@@ -59,7 +59,6 @@ def get_host_name():
class ClientSession(object):
def __init__(self, plugin, connection, client, connid):
print("new connection attached")
self.connid = connid
......@@ -531,7 +530,6 @@ class WebRemotePlugin(GObject.Object, Peas.Activatable):
self.listen_reset = False
def do_activate(self):
shell = self.object
self.db = shell.props.db
......@@ -567,6 +565,26 @@ class WebRemotePlugin(GObject.Object, Peas.Activatable):
class WebRemoteConfig(GObject.Object, PeasGtk.Configurable):
__gtype_name__ = 'WebRemoteConfig'
object = GObject.property(type=GObject.Object)
def portnumber_focus_out_cb(self, widget, event):
try:
p = int(widget.get_text())
except Exception as e:
self.update_port()
self.set_error_message(e)
sys.excepthook(*sys.exc_info())
current_port = self.settings['listen-port']
if p != current_port:
print("changing portnumber to %s" % p)
try:
self.settings['listen-port'] = p
except Exception as e:
print("keeping portnumber %s" % current_port)
self.update_port()
self.set_error_message(e)
sys.excepthook(*sys.exc_info())
return False
def accesskey_focus_out_cb(self, widget, event):
k = widget.get_text()
......@@ -587,9 +605,17 @@ class WebRemoteConfig(GObject.Object, PeasGtk.Configurable):
self.portnumber.set_text("%d" % port)
def settings_changed_cb(self, settings, key):
self.clear_error_message()
if key == 'listen-port':
self.update_port()
def set_error_message(self, message):
print('ERROR:', message)
self.error_message.set_markup('<i><b>ERROR:</b> %s</i>' % (message))
def clear_error_message(self):
self.error_message.set_markup('')
def do_create_configure_widget(self):
self.settings = Gio.Settings.new("org.gnome.rhythmbox.plugins.webremote")
self.settings.connect("changed", self.settings_changed_cb)
......@@ -603,12 +629,15 @@ class WebRemoteConfig(GObject.Object, PeasGtk.Configurable):
self.portnumber = self.builder.get_object("portnumber")
self.launch_link = self.builder.get_object("launch-link")
self.update_port()
self.portnumber.connect("focus-out-event", self.portnumber_focus_out_cb)
self.key_entry = self.builder.get_object("accesskey")
self.access_key = self.settings['access-key']
if self.access_key:
self.key_entry.set_text(self.access_key)
self.key_entry.connect("focus-out-event", self.accesskey_focus_out_cb)
self.error_message = self.builder.get_object("error-message")
return content
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment