Module: deluge
Branch: glade-to-gtkbuilder
Commit: e3831877965570dd0e808ac6bd462dcaa4171643

Author: Pedro Algarvio <[email protected]>
Date:   Tue May 17 22:50:05 2011 +0100

Fix #1281. Show a nice dialog stating that the client is incompatible on the 
GTK UI.

---

 deluge/core/rpcserver.py             |   19 +++++++++----------
 deluge/error.py                      |    7 ++++++-
 deluge/ui/client.py                  |    4 ++--
 deluge/ui/gtkui/connectionmanager.py |   10 ++++++++--
 4 files changed, 25 insertions(+), 15 deletions(-)

diff --git a/deluge/core/rpcserver.py b/deluge/core/rpcserver.py
index 5536d28..7069ec6 100644
--- a/deluge/core/rpcserver.py
+++ b/deluge/core/rpcserver.py
@@ -55,14 +55,15 @@ except ImportError:
 
 import deluge.component as component
 import deluge.configmanager
-from deluge.core.authmanager import AUTH_LEVEL_NONE, AUTH_LEVEL_DEFAULT, 
AUTH_LEVEL_ADMIN
+from deluge.core.authmanager import (AUTH_LEVEL_NONE, AUTH_LEVEL_DEFAULT,
+                                     AUTH_LEVEL_ADMIN)
 from deluge.error import (DelugeError, NotAuthorizedError, _PassthroughError,
                           IncompatibleClient)
 
 RPC_RESPONSE = 1
 RPC_ERROR = 2
 RPC_EVENT = 3
-RPC_EVENT_AUTH = 4
+RPC_EVENT_EXCEPTION = 4
 
 log = logging.getLogger(__name__)
 
@@ -177,7 +178,8 @@ class DelugeRPCProtocol(Protocol):
 
             for call in request:
                 if len(call) != 4:
-                    log.debug("Received invalid rpc request: number of items 
in request is %s", len(call))
+                    log.debug("Received invalid rpc request: number of items "
+                              "in request is %s", len(call))
                     continue
                 #log.debug("RPCRequest: %s", format_request(call))
                 reactor.callLater(0, self.dispatch, *call)
@@ -198,7 +200,8 @@ class DelugeRPCProtocol(Protocol):
         This method is called when a new client connects.
         """
         peer = self.transport.getPeer()
-        log.info("Deluge Client connection made from: %s:%s", peer.host, 
peer.port)
+        log.info("Deluge Client connection made from: %s:%s",
+                 peer.host, peer.port)
         # Set the initial auth level of this session to AUTH_LEVEL_NONE
         self.factory.authorized_sessions[self.transport.sessionno] = 
AUTH_LEVEL_NONE
 
@@ -264,11 +267,7 @@ class DelugeRPCProtocol(Protocol):
             try:
                 client_version = kwargs.pop('client_version', None)
                 if client_version is None:
-                    raise IncompatibleClient(
-                        "Your deluge client is not compatible with the daemon. 
"
-                        "Please upgrade your client to %s" %
-                        deluge.common.get_version()
-                    )
+                    raise IncompatibleClient(deluge.common.get_version())
                 ret = component.get("AuthManager").authorize(*args, **kwargs)
                 if ret:
                     self.factory.authorized_sessions[self.transport.sessionno] 
= (ret, args[0])
@@ -276,7 +275,7 @@ class DelugeRPCProtocol(Protocol):
             except Exception, e:
                 if isinstance(e, _PassthroughError):
                     self.sendData(
-                        (RPC_EVENT_AUTH, request_id,
+                        (RPC_EVENT_EXCEPTION, request_id,
                          e.__class__.__name__,
                          e._args, e._kwargs, args[0])
                     )
diff --git a/deluge/error.py b/deluge/error.py
index 2e3c783..14579d8 100644
--- a/deluge/error.py
+++ b/deluge/error.py
@@ -66,7 +66,12 @@ class _PassthroughError(DelugeError):
         return inst
 
 class IncompatibleClient(_PassthroughError):
-    pass
+    def __init__(self, daemon_version):
+        self.daemon_version = daemon_version
+        self.message = _(
+            "Your deluge client is not compatible with the daemon. "
+            "Please upgrade your client to %(daemon_version)s"
+        ) % {'daemon_version': self.daemon_version}
 
 class NotAuthorizedError(_PassthroughError):
 
diff --git a/deluge/ui/client.py b/deluge/ui/client.py
index e2105f2..794f3ed 100644
--- a/deluge/ui/client.py
+++ b/deluge/ui/client.py
@@ -56,7 +56,7 @@ else:
 RPC_RESPONSE = 1
 RPC_ERROR = 2
 RPC_EVENT = 3
-RPC_EVENT_AUTH = 4
+RPC_EVENT_EXCEPTION = 4
 
 log = logging.getLogger(__name__)
 
@@ -204,7 +204,7 @@ class DelugeRPCProtocol(Protocol):
             if message_type == RPC_RESPONSE:
                 # Run the callbacks registered with this Deferred object
                 d.callback(request[2])
-            elif message_type == RPC_EVENT_AUTH:
+            elif message_type == RPC_EVENT_EXCEPTION:
                 # Recreate exception and errback'it
                 d.errback(getattr(error, request[2])(*request[3], 
**request[4]))
             elif message_type == RPC_ERROR:
diff --git a/deluge/ui/gtkui/connectionmanager.py 
b/deluge/ui/gtkui/connectionmanager.py
index fdddacd..c76c80c 100644
--- a/deluge/ui/gtkui/connectionmanager.py
+++ b/deluge/ui/gtkui/connectionmanager.py
@@ -48,7 +48,7 @@ from deluge.ui.common import get_localhost_auth
 from deluge.ui.client import client
 import deluge.ui.client
 from deluge.configmanager import ConfigManager
-from deluge.error import AuthenticationRequired, BadLoginError
+from deluge.error import AuthenticationRequired, BadLoginError, 
IncompatibleClient
 import dialogs
 
 log = logging.getLogger(__name__)
@@ -512,7 +512,6 @@ class ConnectionManager(component.Component):
     def __on_connected_failed(self, reason, host_id, host, port, user, passwd,
                               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):
             log.debug("PasswordRequired exception")
@@ -527,6 +526,13 @@ class ConnectionManager(component.Component):
             d = dialog.run().addCallback(dialog_finished, host, port, user)
             return d
 
+        elif reason.trap(IncompatibleClient):
+            dialog = dialogs.ErrorDialog(
+                _("Incompatible Client"), reason.value.message
+            )
+            return dialog.run()
+
+
         if try_counter:
             log.info("Retrying connection.. Retries left: %s", try_counter)
             return reactor.callLater(

-- 
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