Improves calls to set proxy's options of the Account
authorRagner Magalhaes <ragner.magalhaes@openbossa.org>
Tue, 2 Dec 2008 20:37:48 +0000 (20:37 +0000)
committerAnderson Briglia <anderson.briglia@openbossa.org>
Sat, 28 Feb 2009 21:11:12 +0000 (17:11 -0400)
    Improves calls to set proxy's options of the Account
    Using property(get_proxy) method to access the ProxyInfo's instance
    Some improvements at how represent PurpleProxyInfoType enumerator
as python(class ProxyInfoType)

Signed-off-by: Ragner Magalhaes <ragner.magalhaes@indt.org.br>

git-svn-id: https://garage.maemo.org/svn/carman/branches/carman-0.7-beta2/python-purple@1328 596f6dd7-e928-0410-a184-9e12fd12cf7e

account.pyx
nullclient.py
proxy.pyx

index 257c425..80b0b0e 100644 (file)
@@ -28,14 +28,23 @@ cdef class Account:
     cdef plugin.PurplePlugin *c_plugin
     cdef prpl.PurplePluginProtocolInfo *c_prpl_info
     cdef plugin.PurplePluginInfo *c_plugin_info
-
     cdef savedstatuses.PurpleSavedStatus *__sstatus
+    cdef ProxyInfo __proxy
 
     def __init__(self, char *username, char *protocol_id):
+        cdef proxy.PurpleProxyInfo *c_proxyinfo
         self.__account = account.c_purple_account_new(username, protocol_id)
         self.c_plugin = plugin.c_purple_plugins_find_with_id(protocol_id)
         self.c_prpl_info = plugin.c_PURPLE_PLUGIN_PROTOCOL_INFO(self.c_plugin)
 
+        c_proxyinfo = account.c_purple_account_get_proxy_info(self.__account)
+        if c_proxyinfo == NULL:
+            c_proxyinfo = proxy.c_purple_proxy_info_new()
+            proxy.c_purple_proxy_info_set_type(c_proxyinfo, proxy.PURPLE_PROXY_NONE)
+        account.c_purple_account_set_proxy_info(self.__account, c_proxyinfo)
+        self.__proxy = ProxyInfo()
+        self.__proxy.c_proxyinfo = c_proxyinfo
+
 
     def set_password(self, password):
         account.c_purple_account_set_password(self.__account, password)
@@ -55,6 +64,11 @@ cdef class Account:
         self.__sstatus = savedstatuses.c_purple_savedstatus_new(NULL, status.PURPLE_STATUS_AVAILABLE)
         savedstatuses.c_purple_savedstatus_activate(self.__sstatus)
 
+    def get_proxy(self):
+        return self.__proxy
+
+    proxy = property(get_proxy)
+
     def get_buddies_online(self):
         cdef glib.GSList *iter
         cdef blist.PurpleBuddy *buddy
@@ -69,19 +83,6 @@ cdef class Account:
             iter = iter.next
         return buddies
 
-    def get_proxyinfo(self):
-        cdef proxy.PurpleProxyInfo *c_proxyinfo
-        c_proxyinfo = account.c_purple_account_get_proxy_info(self.__account)
-        if c_proxyinfo == NULL:
-            return None
-        cdef ProxyInfo proxyinfo
-        proxyinfo = proxy.ProxyInfo()
-        proxyinfo.c_proxyinfo = c_proxyinfo
-        return proxyinfo
-
-    def set_proxyinfo(self, ProxyInfo proxyinf):
-        account.c_purple_account_set_proxy_info(self.__account, proxyinf.c_proxyinfo)
-
     def get_protocol_options(self):
         ''' FIXME: It is just a hack, to set the XMPP's options. '''
         cdef glib.GList *iter
index 6e717c3..5fc826c 100644 (file)
@@ -149,17 +149,9 @@ class NullClient:
         self.account = purple.Account(username, protocol.get_id())
         self.account.set_password(password)
 
-        proxy = self.account.get_proxyinfo()
-        if proxy is None:
-            print "None"
-            proxy = purple.ProxyInfo()
-            proxy.cnew()
-
-        proxy.set_type(purple.ProxyInfoType().HTTP())
-        proxy.set_host("172.18.216.211")
-        proxy.set_port(8080)
-
-        self.account.set_proxyinfo(proxy)
+        self.account.proxy.set_type(purple.ProxyInfoType().HTTP)
+        self.account.proxy.set_host("172.18.216.211")
+        self.account.proxy.set_port(8080)
 
         self.account.get_protocol_options()
 
index b52a0c9..bb03d6d 100644 (file)
--- a/proxy.pyx
+++ b/proxy.pyx
 cimport proxy
 
 cdef class ProxyInfoType:
-
-    cdef proxy.PurpleProxyType c_proxyinfotype
+    cdef proxy.PurpleProxyType c_type
 
     def __init__(self):
-        self.c_proxyinfotype = proxy.PURPLE_PROXY_NONE
+        self.c_type = proxy.PURPLE_PROXY_NONE
+
+    def get_NONE(self):
+        self.c_type = proxy.PURPLE_PROXY_NONE
+        return self
+    NONE = property(get_NONE)
 
-    def USE_GLOBAL(self):
-        self.c_proxyinfotype = proxy.PURPLE_PROXY_USE_GLOBAL
+    def get_USE_GLOBAL(self):
+        self.c_type = proxy.PURPLE_PROXY_USE_GLOBAL
         return self
+    USE_GLOBAL = property(get_USE_GLOBAL)
 
-    def HTTP(self):
-        self.c_proxyinfotype = proxy.PURPLE_PROXY_HTTP
+    def get_HTTP(self):
+        self.c_type = proxy.PURPLE_PROXY_HTTP
         return self
+    HTTP = property(get_HTTP)
 
-    def SOCKS4(self):
-        self.c_proxyinfotype = proxy.PURPLE_PROXY_SOCKS4
+    def get_SOCKS4(self):
+        self.c_type = proxy.PURPLE_PROXY_SOCKS4
         return self
 
-    def SOCKS5(self):
-        self.c_proxyinfotype = proxy.PURPLE_PROXY_SOCKS5
+    def get_SOCKS5(self):
+        self.c_type = proxy.PURPLE_PROXY_SOCKS5
         return self
 
-    def USE_ENVVAR(self):
-        self.c_proxyinfotype = proxy.PURPLE_PROXY_USE_ENVVAR
+    def get_USE_ENVVAR (self):
+        self.c_type = proxy.PURPLE_PROXY_USE_ENVVAR
         return self
+    USE_ENVVAR = property(get_USE_ENVVAR)
 
 cdef class ProxyInfo:
 
@@ -53,13 +60,9 @@ cdef class ProxyInfo:
     def __init__(self):
         self.c_proxyinfo = NULL
 
-    def cnew(self):
-        if self.c_proxyinfo == NULL:
-            self.c_proxyinfo = proxy.c_purple_proxy_info_new()
-
     def set_type(self, ProxyInfoType type):
         if self.c_proxyinfo:
-            proxy.c_purple_proxy_info_set_type(self.c_proxyinfo, type.c_proxyinfotype)
+            proxy.c_purple_proxy_info_set_type(self.c_proxyinfo, type.c_type)
 
     def set_host(self, char *host):
         if self.c_proxyinfo: