mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-02 22:48:40 +00:00
[#3059|GTKUI] Fix starting and autoconnecting to daemon
* Fix start_daemon using callback for non-deferred method. * Ensure autostart checks daemon status before attempting to start it. * Remove initial delay with autoconnect, it will retry anyway. * Found method __connect that needed renaming to _connect. * Tweak the timing for refresh and retries. * Fix use of reason.trap instead of reason.check, causing code to silently error-out and not retry connecting. * Set the stop daemon button to insensitive when not connected. The client cannot stop a daemon with daemon.shutdown() if daemon is not instatiated. Perhaps in future use config and pidfile to allow shutdown without connecting to daemon.
This commit is contained in:
parent
dc27d873b3
commit
c169d8909f
2 changed files with 18 additions and 14 deletions
|
@ -237,6 +237,8 @@ class ConnectionManager(component.Component):
|
||||||
# Display a disconnect button if we're connected to this host
|
# Display a disconnect button if we're connected to this host
|
||||||
self.builder.get_object('button_connect').set_label(_('_Disconnect'))
|
self.builder.get_object('button_connect').set_label(_('_Disconnect'))
|
||||||
self.builder.get_object('button_removehost').set_sensitive(False)
|
self.builder.get_object('button_removehost').set_sensitive(False)
|
||||||
|
# Can only stop daemon when connected to it
|
||||||
|
self.builder.get_object('button_startdaemon').set_sensitive(False)
|
||||||
elif host in LOCALHOST:
|
elif host in LOCALHOST:
|
||||||
# If localhost we can start the dameon.
|
# If localhost we can start the dameon.
|
||||||
self.builder.get_object('button_startdaemon').set_sensitive(True)
|
self.builder.get_object('button_startdaemon').set_sensitive(True)
|
||||||
|
@ -254,7 +256,7 @@ class ConnectionManager(component.Component):
|
||||||
"""
|
"""
|
||||||
if client.start_daemon(port, config):
|
if client.start_daemon(port, config):
|
||||||
log.debug('Localhost daemon started')
|
log.debug('Localhost daemon started')
|
||||||
reactor.callLater(0.5, self._update_host_status)
|
reactor.callLater(1, self._update_host_status)
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
ErrorDialog(
|
ErrorDialog(
|
||||||
|
@ -304,15 +306,15 @@ class ConnectionManager(component.Component):
|
||||||
|
|
||||||
def dialog_finished(response_id):
|
def dialog_finished(response_id):
|
||||||
if response_id == gtk.RESPONSE_OK:
|
if response_id == gtk.RESPONSE_OK:
|
||||||
self.__connect(host_id, dialog.get_username(), dialog.get_password())
|
self._connect(host_id, dialog.get_username(), dialog.get_password())
|
||||||
return dialog.run().addCallback(dialog_finished)
|
return dialog.run().addCallback(dialog_finished)
|
||||||
|
|
||||||
elif reason.trap(IncompatibleClient):
|
elif reason.check(IncompatibleClient):
|
||||||
return ErrorDialog(_('Incompatible Client'), reason.value.message).run()
|
return ErrorDialog(_('Incompatible Client'), reason.value.message).run()
|
||||||
|
|
||||||
if try_counter:
|
if try_counter:
|
||||||
log.info('Retrying connection.. Retries left: %s', try_counter)
|
log.info('Retrying connection.. Retries left: %s', try_counter)
|
||||||
return reactor.callLater(0.8, self._connect, host_id, try_counter=try_counter - 1)
|
return reactor.callLater(0.5, self._connect, host_id, try_counter=try_counter - 1)
|
||||||
|
|
||||||
msg = str(reason.value)
|
msg = str(reason.value)
|
||||||
if not self.gtkui_config['autostart_localhost']:
|
if not self.gtkui_config['autostart_localhost']:
|
||||||
|
@ -338,7 +340,7 @@ class ConnectionManager(component.Component):
|
||||||
if auto_start and host in LOCALHOST and status == 'Offline':
|
if auto_start and host in LOCALHOST and status == 'Offline':
|
||||||
# Start the local daemon and then connect with retries set.
|
# Start the local daemon and then connect with retries set.
|
||||||
if self.start_daemon(port, get_config_dir()):
|
if self.start_daemon(port, get_config_dir()):
|
||||||
try_counter = 4
|
try_counter = 6
|
||||||
else:
|
else:
|
||||||
# Don't attempt to connect to offline daemon.
|
# Don't attempt to connect to offline daemon.
|
||||||
return
|
return
|
||||||
|
@ -459,7 +461,7 @@ class ConnectionManager(component.Component):
|
||||||
if host not in LOCALHOST:
|
if host not in LOCALHOST:
|
||||||
return
|
return
|
||||||
|
|
||||||
def on_daemon_status_change(d):
|
def on_daemon_status_change(result):
|
||||||
"""Daemon start/stop callback"""
|
"""Daemon start/stop callback"""
|
||||||
reactor.callLater(0.7, self._update_host_status)
|
reactor.callLater(0.7, self._update_host_status)
|
||||||
|
|
||||||
|
@ -476,7 +478,7 @@ class ConnectionManager(component.Component):
|
||||||
c.connect(host, port, user, password).addCallback(on_connect, c)
|
c.connect(host, port, user, password).addCallback(on_connect, c)
|
||||||
else:
|
else:
|
||||||
# Otherwise button will start the daemon.
|
# Otherwise button will start the daemon.
|
||||||
self.start_daemon(port, get_config_dir()).addCallback(on_daemon_status_change)
|
self.start_daemon(port, get_config_dir())
|
||||||
|
|
||||||
def on_button_refresh_clicked(self, widget):
|
def on_button_refresh_clicked(self, widget):
|
||||||
self._update_host_status()
|
self._update_host_status()
|
||||||
|
|
|
@ -339,14 +339,16 @@ class GtkUI(object):
|
||||||
|
|
||||||
# Check to see if we need to start the localhost daemon
|
# Check to see if we need to start the localhost daemon
|
||||||
if self.config['autostart_localhost']:
|
if self.config['autostart_localhost']:
|
||||||
port = 0
|
def on_localhost_status(status_info, port):
|
||||||
|
if status_info[1] == 'Offline':
|
||||||
|
log.debug('Autostarting localhost: %s', host_config[0:3])
|
||||||
|
self.connectionmanager.start_daemon(port, get_config_dir())
|
||||||
|
|
||||||
for host_config in self.connectionmanager.hostlist.config['hosts']:
|
for host_config in self.connectionmanager.hostlist.config['hosts']:
|
||||||
if host_config[1] in LOCALHOST:
|
if host_config[1] in LOCALHOST:
|
||||||
port = host_config[2]
|
d = self.connectionmanager.hostlist.get_host_status(host_config[0])
|
||||||
log.debug('Autostarting localhost: %s', host_config[0:3])
|
d.addCallback(on_localhost_status, host_config[2])
|
||||||
|
break
|
||||||
if port:
|
|
||||||
self.connectionmanager.start_daemon(port, get_config_dir())
|
|
||||||
|
|
||||||
# Autoconnect to a host
|
# Autoconnect to a host
|
||||||
if self.config['autoconnect']:
|
if self.config['autoconnect']:
|
||||||
|
@ -354,7 +356,7 @@ class GtkUI(object):
|
||||||
host_id, host, port, user, __ = host_config
|
host_id, host, port, user, __ = host_config
|
||||||
if host_id == self.config['autoconnect_host_id']:
|
if host_id == self.config['autoconnect_host_id']:
|
||||||
log.debug('Trying to connect to %s@%s:%s', user, host, port)
|
log.debug('Trying to connect to %s@%s:%s', user, host, port)
|
||||||
reactor.callLater(0.3, self.connectionmanager._connect, host_id, try_counter=6)
|
self.connectionmanager._connect(host_id, try_counter=6)
|
||||||
break
|
break
|
||||||
|
|
||||||
if self.config['show_connection_manager_on_start']:
|
if self.config['show_connection_manager_on_start']:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue