More fixes on purple.pyx.
authorRagner Magalhaes <ragner.magalhaes@openbossa.org>
Tue, 2 Dec 2008 20:49:26 +0000 (20:49 +0000)
committerAnderson Briglia <anderson.briglia@openbossa.org>
Sat, 28 Feb 2009 21:11:13 +0000 (17:11 -0400)
FIXES:
 - accounts dict is now private.
 - load_accounts is now called inside purple_init.
 - Internal PurpleAccount data is now caught using libpurple functions.
 - Fixed some logic in account_add and account_verify.
 - Updated changes on nullclient.py and nullclient-ecore.py.

Signed-off-by: Bruno Abinader <bruno.abinader@indt.org.br>

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

nullclient-ecore.py
nullclient.py
purple.pyx

index 351e37c..72cc655 100644 (file)
@@ -203,9 +203,9 @@ class MainWindow:
             if acc:
                 return acc
             else:
             if acc:
                 return acc
             else:
-                return "None"
+                return None
         except:
         except:
-            return "None"
+            return None
 
     def _new_account(self, pointer):
         if self.new_acc_bt_cbs.has_key("on_clicked"):
 
     def _new_account(self, pointer):
         if self.new_acc_bt_cbs.has_key("on_clicked"):
@@ -277,9 +277,7 @@ class NullClientPurple:
         self.p.add_account_cb("request_authorize", account_callback)
         self.p.add_account_cb("close_account_request", account_callback)
 
         self.p.add_account_cb("request_authorize", account_callback)
         self.p.add_account_cb("close_account_request", account_callback)
 
-
         self.p.purple_init(cbs)
         self.p.purple_init(cbs)
-        self.p.accounts_init()
 
         #Initializing UI
         self.window.add_bt_conn_cb(self.connect)
 
         #Initializing UI
         self.window.add_bt_conn_cb(self.connect)
@@ -294,7 +292,7 @@ class NullClientPurple:
                 b = purple.Buddy()
                 b.new_buddy(self.account, name, alias)
                 self.buddies[name] = b
                 b = purple.Buddy()
                 b.new_buddy(self.account, name, alias)
                 self.buddies[name] = b
-            elif self.buddies[name].online is True:
+            elif self.buddies[name].online:
                 self.window.new_buddy(name)
 
     def _purple_signal_sign_off_cb(self, name, bname):
                 self.window.new_buddy(name)
 
     def _purple_signal_sign_off_cb(self, name, bname):
@@ -313,19 +311,20 @@ class NullClientPurple:
 
     def connect(self, password):
         username_acc = self.window.selected_accs()
 
     def connect(self, password):
         username_acc = self.window.selected_accs()
-        self.account = self.p.account_verify(username_acc)
-        self.account.get_protocol_options()
-        self.account.set_enabled("carman-purple-python", True)
-        self.account.password = password
-        self.p.connect()
-        self.p.signal_connect("buddy-signed-off", self._purple_signal_sign_off_cb)
+        if username_acc:
+            self.account = self.p.account_verify(username_acc)
+            self.account.get_protocol_options()
+            self.account.set_enabled("carman-purple-python", True)
+            self.account.password = password
+            self.p.connect()
+            self.p.signal_connect("buddy-signed-off", self._purple_signal_sign_off_cb)
 
     def add_account(self):
         username = "carmanplugintest@gmail.com"
         host = "172.18.216.211"
         port = 8080
         self.p.account_add(username, self.protocol_id, host, port)
 
     def add_account(self):
         username = "carmanplugintest@gmail.com"
         host = "172.18.216.211"
         port = 8080
         self.p.account_add(username, self.protocol_id, host, port)
-        self.accs = self.p.accounts_get_dict()
+        self.accs = self.p.accounts
         for acc in self.accs.keys():
             self.window.new_account(acc)
 
         for acc in self.accs.keys():
             self.window.new_account(acc)
 
@@ -346,6 +345,5 @@ class NullClientPurple:
         ecore.main_loop_quit()
 
 if __name__ == '__main__':
         ecore.main_loop_quit()
 
 if __name__ == '__main__':
-
     nullpurple = NullClientPurple()
     ecore.main_loop_begin()
     nullpurple = NullClientPurple()
     ecore.main_loop_begin()
index d4dabc4..a79f3da 100644 (file)
@@ -230,7 +230,6 @@ if __name__ == '__main__':
     client.p.signal_connect("jabber-receiving-xmlnode", jabber_received_xmlnode_cb)
     username = getuser()
     password = getpassword()
     client.p.signal_connect("jabber-receiving-xmlnode", jabber_received_xmlnode_cb)
     username = getuser()
     password = getpassword()
-    client.new_account(username, password)
 
     client.p.connect()
     ecore.timer_add(20, client.get_buddies)
 
     client.p.connect()
     ecore.timer_add(20, client.get_buddies)
index d4d5383..36e01de 100644 (file)
@@ -63,10 +63,10 @@ cdef class Purple:
     @parm default_path: Full path for libpurple user files.
     """
 
     @parm default_path: Full path for libpurple user files.
     """
 
-    cdef object accounts
+    cdef object __accounts
 
     def __init__(self, debug_enabled=True, app_name=__APP_NAME__, default_path=__DEFAULT_PATH__):
 
     def __init__(self, debug_enabled=True, app_name=__APP_NAME__, default_path=__DEFAULT_PATH__):
-        self.accounts = {}
+        self.__accounts = {}
         if app_name is not __APP_NAME__:
             __APP_NAME__ = app_name
 
         if app_name is not __APP_NAME__:
             __APP_NAME__ = app_name
 
@@ -248,6 +248,9 @@ cdef class Purple:
         # load pounces
         pounce.c_purple_pounces_load()
 
         # load pounces
         pounce.c_purple_pounces_load()
 
+        # initialize accounts
+        self.load_accounts()
+
         return ret
 
     def add_account_cb(self, name, func):
         return ret
 
     def add_account_cb(self, name, func):
@@ -287,44 +290,43 @@ cdef class Purple:
                     jabber, "jabber-receiving-xmlnode", &handle,
                     <signals.PurpleCallback> jabber_receiving_xmlnode_cb, NULL)
 
                     jabber, "jabber-receiving-xmlnode", &handle,
                     <signals.PurpleCallback> jabber_receiving_xmlnode_cb, NULL)
 
+    def __get_accounts(self):
+        return self.__accounts
+    accounts = property(__get_accounts)
+
     def new_account(self, username, protocol_id):
         acc = Account(username, protocol_id)
         return acc
 
     def new_account(self, username, protocol_id):
         acc = Account(username, protocol_id)
         return acc
 
-    def accounts_init(self):
+    def load_accounts(self):
         cdef glib.GList *iter
         cdef account.PurpleAccount *acc
         iter = account.c_purple_accounts_get_all()
         while iter:
             acc = <account.PurpleAccount *> iter.data
             if <account.PurpleAccount *>acc:
         cdef glib.GList *iter
         cdef account.PurpleAccount *acc
         iter = account.c_purple_accounts_get_all()
         while iter:
             acc = <account.PurpleAccount *> iter.data
             if <account.PurpleAccount *>acc:
-                self.account_add(acc.username.split("/")[0], acc.protocol_id, "172.18.216.211", 8080)
+                username = account.c_purple_account_get_username(acc)
+                protocol_id = account.c_purple_account_get_protocol_id(acc)
+                self.account_add(username.split("/")[0], protocol_id, "172.18.216.211", 8080)
             iter = iter.next
 
     def account_add(self, username, protocol_id, host, port):
         if not self.account_verify(username):
             acc = purple.Account(username, protocol_id)
             iter = iter.next
 
     def account_add(self, username, protocol_id, host, port):
         if not self.account_verify(username):
             acc = purple.Account(username, protocol_id)
-            self.accounts_add_dict(username, acc)
+            self.__accounts[username] = acc
             if not account.c_purple_accounts_find(username, protocol_id):
                 acc.proxy.set_type(purple.ProxyInfoType().HTTP)
                 acc.proxy.set_host(host)
                 acc.proxy.set_port(port)
                 acc.save_into_xml()
             if not account.c_purple_accounts_find(username, protocol_id):
                 acc.proxy.set_type(purple.ProxyInfoType().HTTP)
                 acc.proxy.set_host(host)
                 acc.proxy.set_port(port)
                 acc.save_into_xml()
-        else:
-            print "Exists account"
 
     def account_verify(self, acc_username):
 
     def account_verify(self, acc_username):
-        if self.accounts:
-            for username in self.accounts.keys():
+        if self.__accounts:
+            for username in self.__accounts.keys():
                 if acc_username == username:
                 if acc_username == username:
-                    return self.accounts[username]
-        return None
-
-    def accounts_add_dict(self, username, acc):
-        self.accounts[username] = acc
-
-    def accounts_get_dict(self):
-        return self.accounts
+                    return self.__accounts[username]
+        else:
+            return None
 
 include "proxy.pyx"
 include "account.pyx"
 
 include "proxy.pyx"
 include "account.pyx"