mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-02 22:48:40 +00:00
GTK UI Connection Manager (#1824)
Warn the user if he's trying to connect to a local daemon that's not running and "start local daemon if necessary" is not enabled. Extend and reuse the connection callbacks on the connection manager to re-use code.
This commit is contained in:
parent
8922717ff2
commit
a7bd953169
1 changed files with 30 additions and 29 deletions
|
@ -471,6 +471,7 @@ class ConnectionManager(component.Component):
|
||||||
_("Deluge cannot find the 'deluged' executable, it is "
|
_("Deluge cannot find the 'deluged' executable, it is "
|
||||||
"likely that you forgot to install the deluged package "
|
"likely that you forgot to install the deluged package "
|
||||||
"or it's not in your PATH.")).run()
|
"or it's not in your PATH.")).run()
|
||||||
|
return False
|
||||||
else:
|
else:
|
||||||
raise e
|
raise e
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
|
@ -483,11 +484,13 @@ class ConnectionManager(component.Component):
|
||||||
details=traceback.format_exc(tb[2])).run()
|
details=traceback.format_exc(tb[2])).run()
|
||||||
|
|
||||||
# Signal handlers
|
# Signal handlers
|
||||||
def __connect(self, host_id, host, port, username, password, skip_authentication=False):
|
def __connect(self, host_id, host, port, username, password,
|
||||||
|
skip_authentication=False, try_counter=0):
|
||||||
def do_connect(*args):
|
def do_connect(*args):
|
||||||
d = client.connect(host, port, username, password, skip_authentication)
|
d = client.connect(host, port, username, password, skip_authentication)
|
||||||
d.addCallback(self.__on_connected, host_id)
|
d.addCallback(self.__on_connected, host_id)
|
||||||
d.addErrback(self.__on_connected_failed, host_id, host, port, username)
|
d.addErrback(self.__on_connected_failed, host_id, host, port,
|
||||||
|
username, password, try_counter)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
if client.connected():
|
if client.connected():
|
||||||
|
@ -506,8 +509,11 @@ class ConnectionManager(component.Component):
|
||||||
self.connection_manager.response(gtk.RESPONSE_OK)
|
self.connection_manager.response(gtk.RESPONSE_OK)
|
||||||
component.start()
|
component.start()
|
||||||
|
|
||||||
def __on_connected_failed(self, reason, host_id, host, port, user):
|
def __on_connected_failed(self, reason, host_id, host, port, user, passwd,
|
||||||
log.debug("Failed to connect: %s", reason)
|
try_counter):
|
||||||
|
log.debug("Failed to connect: %s", reason.value)
|
||||||
|
print reason, host_id, host, port, user, passwd, try_counter
|
||||||
|
|
||||||
if reason.check(AuthenticationRequired, BadLoginError):
|
if reason.check(AuthenticationRequired, BadLoginError):
|
||||||
log.debug("PasswordRequired exception")
|
log.debug("PasswordRequired exception")
|
||||||
dialog = dialogs.AuthenticationDialog(
|
dialog = dialogs.AuthenticationDialog(
|
||||||
|
@ -520,9 +526,19 @@ class ConnectionManager(component.Component):
|
||||||
dialog.get_password())
|
dialog.get_password())
|
||||||
d = dialog.run().addCallback(dialog_finished, host, port, user)
|
d = dialog.run().addCallback(dialog_finished, host, port, user)
|
||||||
return d
|
return d
|
||||||
dialogs.ErrorDialog(
|
|
||||||
_("Failed To Authenticate"), reason.value.message
|
if try_counter:
|
||||||
).run()
|
log.info("Retrying connection.. Retries left: %s", try_counter)
|
||||||
|
return reactor.callLater(
|
||||||
|
0.5, self.__connect, host_id, host, port, user, passwd,
|
||||||
|
try_counter=try_counter-1
|
||||||
|
)
|
||||||
|
|
||||||
|
msg = str(reason.value)
|
||||||
|
if not self.glade.get_widget("chk_autostart").get_active():
|
||||||
|
msg += '\n' + _("Auto-starting the daemon localy is not enabled. "
|
||||||
|
"See \"Options\" on the \"Connection Manager\".")
|
||||||
|
dialogs.ErrorDialog(_("Failed To Connect"), msg).run()
|
||||||
|
|
||||||
def on_button_connect_clicked(self, widget=None):
|
def on_button_connect_clicked(self, widget=None):
|
||||||
model, row = self.hostlist.get_selection().get_selected()
|
model, row = self.hostlist.get_selection().get_selected()
|
||||||
|
@ -544,28 +560,13 @@ class ConnectionManager(component.Component):
|
||||||
if status == _("Offline") and \
|
if status == _("Offline") and \
|
||||||
self.glade.get_widget("chk_autostart").get_active() and \
|
self.glade.get_widget("chk_autostart").get_active() and \
|
||||||
host in ("127.0.0.1", "localhost"):
|
host in ("127.0.0.1", "localhost"):
|
||||||
# We need to start this localhost
|
if not self.start_daemon(port, deluge.configmanager.get_config_dir()):
|
||||||
self.start_daemon(port, deluge.configmanager.get_config_dir())
|
log.debug("Failed to auto-start daemon")
|
||||||
|
return
|
||||||
def on_connect_fail(result, try_counter):
|
return self.__connect(
|
||||||
log.error("Connection to host failed..")
|
host_id, host, port, user, password, try_counter=6
|
||||||
# We failed connecting to the daemon, but lets try again
|
)
|
||||||
if try_counter:
|
return self.__connect(host_id, host, port, user, password)
|
||||||
log.info("Retrying connection.. Retries left: %s", try_counter)
|
|
||||||
try_counter -= 1
|
|
||||||
import time
|
|
||||||
time.sleep(0.5)
|
|
||||||
do_retry_connect(try_counter)
|
|
||||||
return result
|
|
||||||
|
|
||||||
def do_retry_connect(try_counter):
|
|
||||||
d = client.connect(host, port, user, password)
|
|
||||||
d.addCallback(self.__on_connected, host_id)
|
|
||||||
d.addErrback(on_connect_fail, try_counter)
|
|
||||||
|
|
||||||
do_retry_connect(6)
|
|
||||||
|
|
||||||
return self.__connect(host_id, host, port, user, password, skip_authentication=False)
|
|
||||||
|
|
||||||
def on_button_close_clicked(self, widget):
|
def on_button_close_clicked(self, widget):
|
||||||
self.connection_manager.response(gtk.RESPONSE_CLOSE)
|
self.connection_manager.response(gtk.RESPONSE_CLOSE)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue