From: Ragner Magalhaes Date: Tue, 2 Dec 2008 20:47:04 +0000 (+0000) Subject: Added more properties to account and buddy. X-Git-Url: http://git.maemo.org/git/?p=python-purple;a=commitdiff_plain;h=b18104778893417ea6ce29ceffe33adb526c86f6;ds=sidebyside Added more properties to account and buddy. FIXES: - Added more properties to account and buddy. - Fixed corresponding core on nullclients. Signed-off-by: Bruno Abinader git-svn-id: https://garage.maemo.org/svn/carman/branches/carman-0.7-beta2/python-purple@1350 596f6dd7-e928-0410-a184-9e12fd12cf7e --- diff --git a/account.pyx b/account.pyx index 5438d24..e569c52 100644 --- a/account.pyx +++ b/account.pyx @@ -45,28 +45,89 @@ cdef class Account: self.__proxy = ProxyInfo() self.__proxy.c_proxyinfo = c_proxyinfo - def set_password(self, password): - account.c_purple_account_set_password(self.c_account, password) - - def set_enabled(self, ui, value): - account.c_purple_account_set_enabled(self.c_account, ui, value) - - def get_acc_username(self): + def __get_username(self): if self.c_account: return account.c_purple_account_get_username(self.c_account) + else: + return None + def __set_username(self, username): + if self.c_account: + account.c_purple_account_set_username(self.c_account, username) + username = property(__get_password, __set_username) - def get_password(self): + def __get_password(self): if self.c_account: return account.c_purple_account_get_password(self.c_account) + else: + return None + def __set_password(self, password): + if self.c_account: + account.c_purple_account_set_password(self.c_account, password) + password = property(__get_password, __set_password) + + def __get_alias(self): + if self.c_account: + return account.c_purple_account_get_alias(self.c_account) + else: + return None + def __set_alias(self, alias): + if self.c_account: + account.c_purple_account_set_alias(self.c_account, alias) + alias = property(__get_alias, __set_alias) + + def __get_user_info(self): + if self.c_account: + return account.c_purple_account_get_user_info(self.c_account) + else: + return None + def __set_user_info(self, user_info): + if self.c_account: + account.c_purple_account_set_user_info(self.c_account, user_info) + user_info = property(__get_user_info, __set_user_info) + + def __get_protocol_id(self): + if self.c_account: + return account.c_purple_account_get_protocol_id(self.c_account) + else: + return None + def __set_protocol_id(self, protocol_id): + if self.c_account: + account.c_purple_account_set_protocol_id(self.c_account, protocol_id) + protocol_id = property(__get_protocol_id, __set_protocol_id) + + def __get_remember_password(self): + if self.c_account: + return account.c_purple_account_get_remember_password(self.c_account) + else: + return None + def __set_remember_password(self, value): + if self.c_account: + account.c_purple_account_set_remember_password(self.c_account, value) + remember_password = property(__get_remember_password, __set_remember_password) + + def get_protocol_name(self): + if self.c_account: + return account.c_purple_account_get_protocol_name(self.c_account) + else: + return None + + def get_enabled(self, ui): + if self.c_account: + return account.c_purple_account_get_enabled(self.c_account, ui) + else: + return None + + def set_enabled(self, ui, value): + if self.c_account: + account.c_purple_account_set_enabled(self.c_account, ui, value) def set_status(self): self.__sstatus = savedstatuses.c_purple_savedstatus_new(NULL, status.PURPLE_STATUS_AVAILABLE) savedstatuses.c_purple_savedstatus_activate(self.__sstatus) - def get_proxy(self): + def __get_proxy(self): return self.__proxy - - proxy = property(get_proxy) + proxy = property(__get_proxy) def get_buddies_online(self): cdef glib.GSList *iter diff --git a/buddy.pyx b/buddy.pyx index 1c3be6c..a465b6f 100644 --- a/buddy.pyx +++ b/buddy.pyx @@ -22,26 +22,38 @@ cimport purple cdef class Buddy: """ Buddy class """ cdef blist.PurpleBuddy *c_buddy - cdef Account __acc + cdef Account _acc def __init__(self): self.c_buddy = NULL - def new_buddy(self, acc, char *scr, char *alias): - self.__acc = acc - self.c_buddy = blist.c_purple_buddy_new(\ - self.__acc.c_account, scr, alias) + def __get_account(self): + return self.__acc + def __set_account(self, acc): + self._acc = acc + account = property(__get_account, __set_account) def __get_alias(self): - return blist.c_purple_buddy_get_alias_only(self.c_buddy) + if self.c_buddy: + return blist.c_purple_buddy_get_alias_only(self.c_buddy) + else: + return None alias = property(__get_alias) def __get_name(self): - return blist.c_purple_buddy_get_name(self.c_buddy) + if self.c_buddy: + return blist.c_purple_buddy_get_name(self.c_buddy) + else: + return None name = property(__get_name) - def __get_online(self): + def __get_online(self): # FIXME name = self.name - self.c_buddy = blist.c_purple_find_buddy(self.__acc.c_account, name) + self.c_buddy = blist.c_purple_find_buddy(self._acc.c_account, name) return status.c_purple_presence_is_online(blist.c_purple_buddy_get_presence(self.c_buddy)) online = property(__get_online) + + def new_buddy(self, acc, char *scr, char *alias): + self.__acc = acc + self.c_buddy = blist.c_purple_buddy_new(\ + self.__acc.c_account, scr, alias) diff --git a/libpurple/account.pxd b/libpurple/account.pxd index 20b8440..d72b8de 100644 --- a/libpurple/account.pxd +++ b/libpurple/account.pxd @@ -94,14 +94,40 @@ cdef extern from "libpurple/account.h": PurpleAccount *c_purple_account_new "purple_account_new" \ (char *username, char *protocol_id) - void c_purple_account_set_password "purple_account_set_password" \ - (PurpleAccount *account, char *password) + + glib.gboolean c_purple_account_get_enabled "purple_account_get_enabled" \ + (PurpleAccount *account, char *ui) + char *c_purple_account_get_username "purple_account_get_username" \ + (PurpleAccount *account) char *c_purple_account_get_password "purple_account_get_password" \ (PurpleAccount *account) + char *c_purple_account_get_alias "purple_account_get_alias" \ + (PurpleAccount *account) + char *c_purple_account_get_user_info "purple_account_get_user_info" \ + (PurpleAccount *account) + char *c_purple_account_get_protocol_id "purple_account_get_protocol_id" \ + (PurpleAccount *account) + char *c_purple_account_get_protocol_name \ + "purple_account_get_protocol_name" (PurpleAccount *account) + glib.gboolean c_purple_account_get_remember_password \ + "purple_account_get_remember_password" (PurpleAccount *account) + void c_purple_account_set_enabled "purple_account_set_enabled" \ (PurpleAccount *account, char *ui, glib.gboolean value) - char *c_purple_account_get_username "purple_account_get_username" \ - (PurpleAccount *account) + void c_purple_account_set_username "purple_account_set_username" \ + (PurpleAccount *account, char *username) + void c_purple_account_set_password "purple_account_set_password" \ + (PurpleAccount *account, char *password) + void c_purple_account_set_alias "purple_account_set_alias" \ + (PurpleAccount *account, char *alias) + void c_purple_account_set_user_info "purple_account_set_user_info" \ + (PurpleAccount *account, char *user_info) + void c_purple_account_set_protocol_id "purple_account_set_protocol_id" \ + (PurpleAccount *account, char *protocol_id) + void c_purple_account_set_remember_password \ + "purple_account_set_remember_password" (PurpleAccount *account, \ + glib.gboolean value) + glib.GList *c_purple_accounts_get_all_active \ "purple_accounts_get_all_active" () void c_purple_accounts_set_ui_ops "purple_accounts_set_ui_ops" \ @@ -126,4 +152,3 @@ cdef extern from "libpurple/account.h": (PurpleAccount *account, char *name, char *value) void c_purple_account_set_bool "purple_account_set_bool" \ (PurpleAccount *account, char *name, glib.gboolean value) - diff --git a/nullclient-ecore.py b/nullclient-ecore.py index 53e970d..d2df7ff 100644 --- a/nullclient-ecore.py +++ b/nullclient-ecore.py @@ -266,7 +266,7 @@ class NullClientPurple: def connect(self): self.account = purple.Account(self.username, self.protocol_id) - self.account.set_password(self.password) + self.account.password = self.password self.account.proxy.set_type(purple.ProxyInfoType().HTTP) self.account.proxy.set_host("172.18.216.211") diff --git a/nullclient.py b/nullclient.py index 2904196..d4dabc4 100644 --- a/nullclient.py +++ b/nullclient.py @@ -201,7 +201,7 @@ class NullClient: def new_account(self, username, password): self.account = purple.Account(username, self.protocol_id) - self.account.set_password(password) + self.account.password = password self.account.proxy.set_type(purple.ProxyInfoType().HTTP) self.account.proxy.set_host("172.18.216.211") @@ -225,7 +225,6 @@ def getpassword(): if __name__ == '__main__': client = NullClient() client.execute() - client.set_protocol("XMPP") client.p.signal_connect("buddy-signed-off", buddy_signed_off_cb) client.p.signal_connect("receiving-im-msg", receiving_im_msg_cb) client.p.signal_connect("jabber-receiving-xmlnode", jabber_received_xmlnode_cb)