Module: deluge
Branch: multiuser
Commit: aa8ddb64af85d0a4b0c28add6c019d746ab7cf9e

Author: Pedro Algarvio <[email protected]>
Date:   Thu Dec 16 01:18:40 2010 +0000

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.

---

 deluge/ui/gtkui/connectionmanager.py |   51 ++++++++++++++++++---------------
 deluge/ui/gtkui/dialogs.py           |   24 ++++++++++++++++
 deluge/ui/gtkui/gtkui.py             |   10 ++++++-
 3 files changed, 61 insertions(+), 24 deletions(-)

diff --git a/deluge/ui/gtkui/connectionmanager.py 
b/deluge/ui/gtkui/connectionmanager.py
index 43ebf09..c48db53 100644
--- a/deluge/ui/gtkui/connectionmanager.py
+++ b/deluge/ui/gtkui/connectionmanager.py
@@ -434,13 +434,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:
@@ -458,10 +485,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
@@ -485,18 +508,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)
@@ -652,10 +664,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()
diff --git a/deluge/ui/gtkui/dialogs.py b/deluge/ui/gtkui/dialogs.py
index 9409513..d4be76e 100644
--- a/deluge/ui/gtkui/dialogs.py
+++ b/deluge/ui/gtkui/dialogs.py
@@ -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()
diff --git a/deluge/ui/gtkui/gtkui.py b/deluge/ui/gtkui/gtkui.py
index ab2acf1..70e14a3 100644
--- a/deluge/ui/gtkui/gtkui.py
+++ b/deluge/ui/gtkui/gtkui.py
@@ -201,6 +201,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)
 
@@ -230,8 +234,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..")

-- 
You received this message because you are subscribed to the Google Groups 
"deluge-commit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/deluge-commit?hl=en.

Reply via email to