mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-04 15:38:43 +00:00
Cleaned up previous commit regarding threads and the GTK2Reactor.
Now a dialog apears if the daemon complains about a missing password in order to authenticate. Asks the password from the user and retries to connect.
This commit is contained in:
parent
249398489e
commit
e17c035521
3 changed files with 61 additions and 24 deletions
|
@ -435,13 +435,40 @@ that you forgot to install the deluged package or it's not in your PATH.")).run(
|
||||||
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, user, password):
|
||||||
|
def do_connect(*args):
|
||||||
|
d = client.connect(host, port, user, password)
|
||||||
|
d.addCallback(self.__on_connected, host_id)
|
||||||
|
d.addErrback(self.__on_connected_failed, host_id, host, port, user)
|
||||||
|
return d
|
||||||
|
|
||||||
|
if client.connected():
|
||||||
|
return client.disconnect().addCallback(do_connect)
|
||||||
|
else:
|
||||||
|
return do_connect()
|
||||||
|
|
||||||
def __on_connected(self, connector, host_id):
|
def __on_connected(self, connector, host_id):
|
||||||
log.debug("__on_connected called")
|
log.debug("__on_connected called")
|
||||||
if self.gtkui_config["autoconnect"]:
|
if self.gtkui_config["autoconnect"]:
|
||||||
self.gtkui_config["autoconnect_host_id"] = host_id
|
self.gtkui_config["autoconnect_host_id"] = host_id
|
||||||
|
|
||||||
|
self.connection_manager.response(gtk.RESPONSE_OK)
|
||||||
|
|
||||||
component.start()
|
component.start()
|
||||||
|
|
||||||
|
def __on_connected_failed(self, reason, host_id, host, port, user):
|
||||||
|
if reason.value.exception_type == "PasswordRequired":
|
||||||
|
log.debug("PasswordRequired exception")
|
||||||
|
dialog = dialogs.AuthenticationDialog(reason.value.exception_msg)
|
||||||
|
def dialog_finished(response_id, host, port, user):
|
||||||
|
if response_id == gtk.RESPONSE_OK:
|
||||||
|
self.__connect(host_id, host, port, user,
|
||||||
|
dialog.password.get_text())
|
||||||
|
d = dialog.run().addCallback(dialog_finished, host, port, user)
|
||||||
|
return d
|
||||||
|
dialogs.ErrorDialog(_("Failed To Authenticate"),
|
||||||
|
reason.value.exception_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()
|
||||||
if not row:
|
if not row:
|
||||||
|
@ -459,10 +486,6 @@ that you forgot to install the deluged package or it's not in your PATH.")).run(
|
||||||
user = model[row][HOSTLIST_COL_USER]
|
user = model[row][HOSTLIST_COL_USER]
|
||||||
password = model[row][HOSTLIST_COL_PASS]
|
password = model[row][HOSTLIST_COL_PASS]
|
||||||
|
|
||||||
if not password:
|
|
||||||
self.askpassword_dialog.run()
|
|
||||||
password = self.askpassword_dialog_entry.get_text()
|
|
||||||
|
|
||||||
if status == _("Offline") and self.glade.get_widget("chk_autostart").get_active() and\
|
if status == _("Offline") 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
|
# We need to start this localhost
|
||||||
|
@ -486,18 +509,7 @@ that you forgot to install the deluged package or it's not in your PATH.")).run(
|
||||||
|
|
||||||
do_retry_connect(6)
|
do_retry_connect(6)
|
||||||
|
|
||||||
|
return self.__connect(host_id, host, port, user, password)
|
||||||
def do_connect(*args):
|
|
||||||
d = client.connect(host, port, user, password)
|
|
||||||
d.addCallback(self.__on_connected, host_id)
|
|
||||||
d.addErrback(self.__on_connected_failed, host_id, host, port, user)
|
|
||||||
|
|
||||||
if client.connected():
|
|
||||||
client.disconnect().addCallback(do_connect)
|
|
||||||
else:
|
|
||||||
do_connect()
|
|
||||||
|
|
||||||
self.connection_manager.response(gtk.RESPONSE_OK)
|
|
||||||
|
|
||||||
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)
|
||||||
|
@ -653,10 +665,3 @@ that you forgot to install the deluged package or it's not in your PATH.")).run(
|
||||||
|
|
||||||
def on_askpassword_dialog_entry_activate(self, entry):
|
def on_askpassword_dialog_entry_activate(self, entry):
|
||||||
self.askpassword_dialog.response(gtk.RESPONSE_OK)
|
self.askpassword_dialog.response(gtk.RESPONSE_OK)
|
||||||
|
|
||||||
def __on_connected_failed(self, reason, host_id, host, port, user):
|
|
||||||
log.exception(reason)
|
|
||||||
log.debug(reason.value)
|
|
||||||
log.debug(reason.value.__dict__)
|
|
||||||
dialogs.ErrorDialog(_("Failed To Authenticate"),
|
|
||||||
reason.value.exception_msg).run()
|
|
||||||
|
|
|
@ -189,3 +189,27 @@ class ErrorDialog(BaseDialog):
|
||||||
self.vbox.pack_start(label, False, False)
|
self.vbox.pack_start(label, False, False)
|
||||||
self.vbox.pack_start(sw)
|
self.vbox.pack_start(sw)
|
||||||
self.vbox.show_all()
|
self.vbox.show_all()
|
||||||
|
|
||||||
|
class AuthenticationDialog(BaseDialog):
|
||||||
|
"""
|
||||||
|
Displays a dialog with an entry field asking for a password.
|
||||||
|
|
||||||
|
When run(), it will return either a gtk.RESPONSE_CANCEL or a
|
||||||
|
gtk.RESPONSE_OK.
|
||||||
|
"""
|
||||||
|
def __init__(self, err_msg="", parent=None):
|
||||||
|
"""
|
||||||
|
:param err_msg: the error message we got back from the server
|
||||||
|
:type err_msg: string
|
||||||
|
"""
|
||||||
|
super(AuthenticationDialog, self).__init__(
|
||||||
|
_("Authenticate"), err_msg,
|
||||||
|
gtk.STOCK_DIALOG_AUTHENTICATION,
|
||||||
|
(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_CONNECT, gtk.RESPONSE_OK),
|
||||||
|
parent)
|
||||||
|
|
||||||
|
self.password = gtk.Entry()
|
||||||
|
self.password.set_visibility(False)
|
||||||
|
self.vbox.pack_start(self.password, False, False)
|
||||||
|
self.set_focus(self.password)
|
||||||
|
self.show_all()
|
||||||
|
|
|
@ -205,6 +205,10 @@ class GtkUI(object):
|
||||||
self.queuedtorrents = QueuedTorrents()
|
self.queuedtorrents = QueuedTorrents()
|
||||||
self.ipcinterface = IPCInterface(args)
|
self.ipcinterface = IPCInterface(args)
|
||||||
|
|
||||||
|
# Initialize gdk threading
|
||||||
|
gtk.gdk.threads_init()
|
||||||
|
|
||||||
|
|
||||||
# We make sure that the UI components start once we get a core URI
|
# We make sure that the UI components start once we get a core URI
|
||||||
client.set_disconnect_callback(self.__on_disconnect)
|
client.set_disconnect_callback(self.__on_disconnect)
|
||||||
|
|
||||||
|
@ -234,8 +238,12 @@ class GtkUI(object):
|
||||||
rpc_stats.start(10)
|
rpc_stats.start(10)
|
||||||
|
|
||||||
reactor.callWhenRunning(self._on_reactor_start)
|
reactor.callWhenRunning(self._on_reactor_start)
|
||||||
reactor.addSystemEventTrigger("before", "shutdown", self.shutdown)
|
|
||||||
|
# Initialize gdk threading
|
||||||
|
gtk.gdk.threads_enter()
|
||||||
reactor.run()
|
reactor.run()
|
||||||
|
self.shutdown()
|
||||||
|
gtk.gdk.threads_leave()
|
||||||
|
|
||||||
def shutdown(self, *args, **kwargs):
|
def shutdown(self, *args, **kwargs):
|
||||||
log.debug("gtkui shutting down..")
|
log.debug("gtkui shutting down..")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue