X-Git-Url: http://git.maemo.org/git/?p=python-purple;a=blobdiff_plain;f=purple.pyx;h=d4d53836becf1a1192e4548ffbd6143c2308e2d1;hp=b3ab8b14afe8183a9ce682f6a3468c1d1c7a34fb;hb=54c3652ebe4f40182214f4f37403ac13fcfeb7ff;hpb=663e1ae7b7cea174e57405cde0018bf4a9e20bf8 diff --git a/purple.pyx b/purple.pyx index b3ab8b1..d4d5383 100644 --- a/purple.pyx +++ b/purple.pyx @@ -62,7 +62,11 @@ cdef class Purple: @parm app_name: Set application name. @parm default_path: Full path for libpurple user files. """ + + cdef object accounts + def __init__(self, debug_enabled=True, app_name=__APP_NAME__, default_path=__DEFAULT_PATH__): + self.accounts = {} if app_name is not __APP_NAME__: __APP_NAME__ = app_name @@ -137,14 +141,12 @@ cdef class Purple: """ Initializes libpurple """ if callbacks_dict is not None: - global account_cbs global blist_cbs global connection_cbs global conversation_cbs global notify_cbs global request_cbs - account_cbs = callbacks_dict["account"] blist_cbs = callbacks_dict["blist"] connection_cbs = callbacks_dict["connection"] conversation_cbs = callbacks_dict["conversation"] @@ -248,6 +250,10 @@ cdef class Purple: return ret + def add_account_cb(self, name, func): + global account_cbs + account_cbs[name] = func + def connect(self): conn = Connection() conn.connect() @@ -285,6 +291,41 @@ cdef class Purple: acc = Account(username, protocol_id) return acc + def accounts_init(self): + cdef glib.GList *iter + cdef account.PurpleAccount *acc + iter = account.c_purple_accounts_get_all() + while iter: + acc = iter.data + if acc: + self.account_add(acc.username.split("/")[0], acc.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) + self.accounts_add_dict(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() + else: + print "Exists account" + + def account_verify(self, acc_username): + if self.accounts: + for username in self.accounts.keys(): + 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 + include "proxy.pyx" include "account.pyx" include "buddy.pyx"