mirror of
https://github.com/codex-storage/deluge.git
synced 2025-02-26 10:05:19 +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
@ -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()
|
||||
|
||||
# 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):
|
||||
log.debug("__on_connected called")
|
||||
if self.gtkui_config["autoconnect"]:
|
||||
self.gtkui_config["autoconnect_host_id"] = host_id
|
||||
|
||||
self.connection_manager.response(gtk.RESPONSE_OK)
|
||||
|
||||
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):
|
||||
model, row = self.hostlist.get_selection().get_selected()
|
||||
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]
|
||||
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\
|
||||
host in ("127.0.0.1", "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)
|
||||
|
||||
|
||||
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)
|
||||
return self.__connect(host_id, host, port, user, password)
|
||||
|
||||
def on_button_close_clicked(self, widget):
|
||||
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):
|
||||
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(sw)
|
||||
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.ipcinterface = IPCInterface(args)
|
||||
|
||||
# Initialize gdk threading
|
||||
gtk.gdk.threads_init()
|
||||
|
||||
|
||||
# We make sure that the UI components start once we get a core URI
|
||||
client.set_disconnect_callback(self.__on_disconnect)
|
||||
|
||||
@ -234,8 +238,12 @@ class GtkUI(object):
|
||||
rpc_stats.start(10)
|
||||
|
||||
reactor.callWhenRunning(self._on_reactor_start)
|
||||
reactor.addSystemEventTrigger("before", "shutdown", self.shutdown)
|
||||
|
||||
# Initialize gdk threading
|
||||
gtk.gdk.threads_enter()
|
||||
reactor.run()
|
||||
self.shutdown()
|
||||
gtk.gdk.threads_leave()
|
||||
|
||||
def shutdown(self, *args, **kwargs):
|
||||
log.debug("gtkui shutting down..")
|
||||
|
Loading…
x
Reference in New Issue
Block a user