From: Ragner Magalhaes Date: Tue, 2 Dec 2008 21:07:56 +0000 (+0000) Subject: Initial 'dev' branch commit. X-Git-Url: http://git.maemo.org/git/?p=python-purple;a=commitdiff_plain;h=33091059fda101f7c4105945a677db2632d4ffcc;ds=sidebyside Initial 'dev' branch commit. FIXES: - Refactory on account.pxd/accountopt.pxd. - New account.pyx model. - New protocol.pyx model. - Updated other files with changes made on .pxd files. Signed-off-by: Bruno Abinader git-svn-id: https://garage.maemo.org/svn/carman/branches/carman-0.7-beta2/python-purple@1409 596f6dd7-e928-0410-a184-9e12fd12cf7e --- diff --git a/account.pyx b/account.pyx index 5e92065..a1a657f 100644 --- a/account.pyx +++ b/account.pyx @@ -19,481 +19,43 @@ cimport purple -cdef extern from *: - ctypedef char const_char "const char" +from protocol import Protocol cdef class Account: - """ Account class """ - cdef account.PurpleAccount *c_account - cdef plugin.PurplePlugin *c_plugin - cdef prpl.PurplePluginProtocolInfo *c_prpl_info - cdef plugin.PurplePluginInfo *c_plugin_info - cdef savedstatuses.PurpleSavedStatus *__sstatus + """ + Account class + @param username + @param protocol_id + """ - cdef object __proxy - cdef object __protocol + def __init__(self, username, protocol_id): + self.__username = username + self.__protocol_id = Protocol(self, protocol_id) - def __init__(self): - self.__proxy = purple.ProxyInfo() - self.__protocol = purple.Plugin() - - ''' - def __init__(self, char *username, char *protocol_id): - cdef proxy.PurpleProxyInfo *c_proxyinfo - cdef account.PurpleAccount *acc = NULL - - acc = account.c_purple_accounts_find(username, protocol_id) - if acc: - self.c_account = acc - c_proxyinfo = account.c_purple_account_get_proxy_info(self.c_account) + if self.__get_structure() == NULL: + self.__exists = False else: - self.c_account = account.c_purple_account_new(username, protocol_id) - c_proxyinfo = account.c_purple_account_get_proxy_info(self.c_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.c_account, c_proxyinfo) - self.__proxy = ProxyInfo() - self.__proxy.c_proxyinfo = c_proxyinfo - acc = NULL - - 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) - ''' + self.__exists = True 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): - 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) + return self.__username + username = property(__get_username) 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_options(self): - cdef glib.GList *iter - cdef accountopt.PurpleAccountOption *option - cdef prefs.PurplePrefType type - cdef const_char *label_name - cdef const_char *str_value - cdef const_char *setting - cdef int int_value - cdef glib.gboolean bool_value - - if self.c_account == NULL: - return None - - po = {} - - iter = self.c_prpl_info.protocol_options - - while iter: - - option = iter.data - type = accountopt.c_purple_account_option_get_type(option) - label_name = accountopt.c_purple_account_option_get_text(option) - setting = accountopt.c_purple_account_option_get_setting(option) - - sett = str( setting) - - if type == prefs.PURPLE_PREF_STRING: - - str_value = accountopt.c_purple_account_option_get_default_string(option) - - # Google Talk default domain hackery! - if str_value == NULL and str( label_name) == "Connect server": - str_value = "talk.google.com" - str_value = account.c_purple_account_get_string(self.c_account, setting, str_value) - - val = str( str_value) - - elif type == prefs.PURPLE_PREF_INT: - - int_value = accountopt.c_purple_account_option_get_default_int(option) - int_value = account.c_purple_account_get_int(self.c_account, setting, int_value) - - val = int(int_value) - - elif type == prefs.PURPLE_PREF_BOOLEAN: - - bool_value = accountopt.c_purple_account_option_get_default_bool(option) - bool_value = account.c_purple_account_get_bool(self.c_account, setting, bool_value) - - val = bool(bool_value) - - elif type == prefs.PURPLE_PREF_STRING_LIST: - - str_value = accountopt.c_purple_account_option_get_default_list_value(option) - str_value = account.c_purple_account_get_string(self.c_account, setting, str_value) - - val = str( str_value) - - iter = iter.next - - po[sett] = val - - return po - - def _set_protocol_options(self, po): - cdef glib.GList *iter - cdef accountopt.PurpleAccountOption *option - cdef prefs.PurplePrefType type - cdef const_char *str_value - cdef const_char *setting - cdef int int_value - cdef glib.gboolean bool_value - - if self.c_account == NULL: - return - - po = {} - - iter = self.c_prpl_info.protocol_options - - while iter: - - option = iter.data - type = accountopt.c_purple_account_option_get_type(option) - setting = accountopt.c_purple_account_option_get_setting(option) - - sett = str( setting) - - if type == prefs.PURPLE_PREF_STRING: - - str_value = po[sett] - account.c_purple_account_set_string(self.c_account, setting, str_value) - - elif type == prefs.PURPLE_PREF_INT: - - int_value = int(po[sett]) - account.c_purple_account_set_int(self.c_account, setting, int_value) - - elif type == prefs.PURPLE_PREF_BOOLEAN: - - bool_value = bool(po[sett]) - account.c_purple_account_set_bool(self.c_account, setting, bool_value) - - elif type == prefs.PURPLE_PREF_STRING_LIST: - - str_value = po[sett] - account.c_purple_account_set_string(self.c_account, setting, str_value) - - iter = iter.next - - protocol_options = property(_get_protocol_options, _set_protocol_options) - - def _get_protocol_labels(self): - cdef glib.GList *iter - cdef accountopt.PurpleAccountOption *option - cdef const_char *label_name - cdef const_char *setting - - if self.c_account == NULL: - return None - - po = {} - - iter = self.c_prpl_info.protocol_options - - while iter: - - option = iter.data - label_name = accountopt.c_purple_account_option_get_text(option) - setting = accountopt.c_purple_account_option_get_setting(option) + return self.__protocol_id.protocol_id + protocol_id = property(__get_protocol_id) - sett = str( setting) - label = str( label_name) + def __get_exists(self): + return self.__exists + exists = property(__get_exists) - po[sett] = label + cdef purple.account.PurpleAccount *__get_structure(self): + return purple.account.purple_accounts_find(self.username, self.protocol_id) - return po - - protocol_labels = property(_get_protocol_labels) - - def __get_proxy(self): - return self.__proxy - proxy = property(__get_proxy) - - def __get_protocol(self): - return self.__protocol - protocol = property(__get_protocol) - - def get_protocol_name(self): - if self.c_account: - return account.c_purple_account_get_protocol_name(self.c_account) - else: - return None - - 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_buddies_online(self, acc): - cdef account.PurpleAccount *c_account - cdef glib.GSList *iter - cdef blist.PurpleBuddy *buddy - cdef char *c_name = NULL - cdef char *c_alias = NULL - - c_account = account.c_purple_accounts_find(acc[0], acc[1]) - if c_account: - iter = blist.c_purple_find_buddies(c_account, NULL) - else: - return None - - buddies = [] - while iter: - c_name = NULL - c_alias = NULL - buddy = iter.data - if buddy and \ - account.c_purple_account_is_connected(blist.c_purple_buddy_get_account(buddy)) and \ - status.c_purple_presence_is_online(blist.c_purple_buddy_get_presence(buddy)): - c_name = blist.c_purple_buddy_get_name(buddy) - if c_name == NULL: - name = None - else: - name = c_name - c_alias = blist.c_purple_buddy_get_alias_only(buddy) - if c_alias == NULL: - alias = None - else: - alias = c_alias - buddies.append((name, alias)) - iter = iter.next - return buddies - - def new(self, username, protocol_id): - cdef account.PurpleAccount *c_account - c_account = account.c_purple_account_new(username, protocol_id) - - if c_account == NULL: - return None - - account.c_purple_accounts_add(c_account) - - return (username, protocol_id) - - def get_all(self): - cdef glib.GList *iter - cdef account.PurpleAccount *acc - - accounts = [] - - iter = account.c_purple_accounts_get_all() - while iter: - acc = iter.data - if acc: - username = account.c_purple_account_get_username(acc) - protocol_id = account.c_purple_account_get_protocol_id(acc) - - accounts.append((username, protocol_id)) - iter = iter.next - - return accounts - - def get_password(self, acc): - ''' @param acc Tuple (username, protocol id) ''' - cdef account.PurpleAccount *c_account - cdef char *value - value = NULL - - c_account = account.c_purple_accounts_find(acc[0], acc[1]) - if c_account: - value = account.c_purple_account_get_password(c_account) - - if value == NULL: - return None - else: - return value - - - def set_password(self, acc, password): - ''' @param acc Tuple (username, protocol id) ''' - ''' @param password The account's password ''' - cdef account.PurpleAccount *c_account - - if not password: - return - - c_account = account.c_purple_accounts_find(acc[0], acc[1]) - if c_account: - account.c_purple_account_set_password(c_account, password) - - def get_alias(self, acc): - ''' @param acc Tuple (username, protocol id) ''' - cdef account.PurpleAccount *c_account - cdef char *value - value = NULL - - c_account = account.c_purple_accounts_find(acc[0], acc[1]) - if c_account: - value = account.c_purple_account_get_alias(c_account) - - if value == NULL: - return None - else: - return value - - def set_alias(self, acc, alias): - ''' @param acc Tuple (username, protocol id) ''' - ''' @param alias The account's alias ''' - cdef account.PurpleAccount *c_account - - if not alias: - return - - c_account = account.c_purple_accounts_find(acc[0], acc[1]) - if c_account: - account.c_purple_account_set_alias(c_account, alias) - - def set_protocol_id(self, acc, protocol_id): - ''' @param acc Tuple (username, protocol id) ''' - ''' @param protocol_id The new account's protocol id ''' - cdef account.PurpleAccount *c_account - - if not protocol_id: - return - - c_account = account.c_purple_accounts_find(acc[0], acc[1]) - if c_account: - account.c_purple_account_set_protocol_id(c_account, protocol_id) - - def get_protocol_id(self, acc): - ''' @param acc Tuple (username, protocol id) ''' - ''' @return account's protocol id ''' - cdef account.PurpleAccount *c_account - cdef char *value - value = NULL - - c_account = account.c_purple_accounts_find(acc[0], acc[1]) - if c_account: - value = account.c_purple_account_get_protocol_id(c_account) - - if value == NULL: - return None - else: - return value - - - def set_enabled(self, acc, ui, value): - ''' @param acc Tuple (username, protocol id) ''' - ''' @param ui The UI ''' - ''' @param value True to enabled or False to disabled ''' - cdef account.PurpleAccount *c_account - - c_account = account.c_purple_accounts_find(acc[0], acc[1]) - if c_account: - account.c_purple_account_set_enabled(c_account, ui, bool(value)) - - def get_enabled(self, acc, ui): - ''' @param acc Tuple (username, protocol id) ''' - ''' @param ui The UI ''' - cdef account.PurpleAccount *c_account - - c_account = account.c_purple_accounts_find(acc[0], acc[1]) - if c_account: - return account.c_purple_account_get_enabled(c_account, ui) - else: + def new(self): + if self.__exists: return False - def is_connected(self, acc): - ''' @param acc Tuple (username, protocol id) ''' - ''' @param ui The UI ''' - cdef account.PurpleAccount *c_account - - c_account = account.c_purple_accounts_find(acc[0], acc[1]) - if c_account: - return account.c_purple_account_is_connected(c_account) - else: - return False - - def connect(self, acc): - ''' @param acc Tuple (username, protocol id) ''' - ''' @param ui The UI ''' - cdef account.PurpleAccount *c_account - - c_account = account.c_purple_accounts_find(acc[0], acc[1]) - if c_account: - account.c_purple_account_connect(c_account) - - def disconnect(self, acc): - ''' @param acc Tuple (username, protocol id) ''' - ''' @param ui The UI ''' - cdef account.PurpleAccount *c_account - - c_account = account.c_purple_accounts_find(acc[0], acc[1]) - if c_account: - account.c_purple_account_disconnect(c_account) - - def set_remember_password(self, acc, value): - cdef account.PurpleAccount *c_account - c_account = account.c_purple_accounts_find(acc[0], acc[1]) - if c_account: - account.c_purple_account_set_remember_password(c_account, value) - - def get_remember_password(self, acc): - cdef account.PurpleAccount *c_account - c_account = account.c_purple_accounts_find(acc[0], acc[1]) - if c_account: - return account.c_purple_account_get_remember_password(c_account) - else: - return None - - def remove(self, acc): - cdef account.PurpleAccount *c_account - - c_account = account.c_purple_accounts_find(acc[0], acc[1]) - if c_account: - account.c_purple_accounts_delete(c_account) + purple.account.purple_account_new(self.username, self.protocol_id) + self.__exists = True + return True diff --git a/buddy.pyx b/buddy.pyx index 2e1e132..5238396 100644 --- a/buddy.pyx +++ b/buddy.pyx @@ -47,11 +47,13 @@ cdef class Buddy: return None name = property(__get_name) + """ def __get_online(self): # FIXME name = self.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, name, alias): self.__acc = acc diff --git a/conversation.pyx b/conversation.pyx index 5d5b3c3..2c73830 100644 --- a/conversation.pyx +++ b/conversation.pyx @@ -48,7 +48,7 @@ cdef class Conversation: self.__acc = acc self.__name = name - c_account = account.c_purple_accounts_find(acc[0], acc[1]) + c_account = account.purple_accounts_find( acc[0], acc[1]) if not c_account: return diff --git a/conversation_cbs.pxd b/conversation_cbs.pxd index 87218be..731eaa1 100644 --- a/conversation_cbs.pxd +++ b/conversation_cbs.pxd @@ -79,7 +79,7 @@ cdef void write_im(conversation.PurpleConversation *conv, const_char *who, \ cdef char *c_username = NULL cdef char *c_sender_alias = NULL - c_username = account.c_purple_account_get_username(acc) + c_username = account.purple_account_get_username(acc) if c_username: username = c_username else: diff --git a/libpurple/account.pxd b/libpurple/account.pxd index 15be88d..4466b69 100644 --- a/libpurple/account.pxd +++ b/libpurple/account.pxd @@ -19,14 +19,21 @@ cimport glib -cdef extern from *: - ctypedef char const_char "const char" - # hack to avoid recursive loops by cython +cdef extern from "libpurple/blist.h": + ctypedef struct PurpleBuddy: + pass + + ctypedef struct PurpleGroup: + pass + cdef extern from "libpurple/connection.h": ctypedef struct PurpleConnection: pass + ctypedef struct PurpleConnectionErrorInfo: + pass + cdef extern from "libpurple/log.h": ctypedef struct PurpleLog: pass @@ -39,6 +46,12 @@ cdef extern from "libpurple/status.h": ctypedef struct PurpleStatus: pass + ctypedef struct PurpleStatusType: + pass + + ctypedef struct PurpleStatusPrimitive: + pass + ctypedef struct PurplePresence: pass @@ -57,14 +70,14 @@ cdef extern from "libpurple/account.h": PURPLE_ACCOUNT_REQUEST_AUTHORIZATION = 0 ctypedef struct PurpleAccountUiOps: - void (*notify_added) (PurpleAccount *account, const_char *remote_user, \ - const_char *id, const_char *alias, const_char *message) + void (*notify_added) (PurpleAccount *account, char *remote_user, \ + char *id, char *alias, char *message) void (*status_changed) (PurpleAccount *account, PurpleStatus *status) - void (*request_add) (PurpleAccount *account, const_char *remote_user, \ - const_char *id, const_char *alias, const_char *message) + void (*request_add) (PurpleAccount *account, char *remote_user, \ + char *id, char *alias, char *message) void *(*request_authorize) (PurpleAccount *account, \ - const_char *remote_user, const_char *id, const_char *alias, \ - const_char *message, glib.gboolean on_list, \ + char *remote_user, char *id, char *alias, \ + char *message, glib.gboolean on_list, \ PurpleAccountRequestAuthorizationCb authorize_cb, \ PurpleAccountRequestAuthorizationCb deny_cb, void *user_data) void (*close_account_request) (void *ui_handle) @@ -92,73 +105,142 @@ cdef extern from "libpurple/account.h": void *registration_cb_user_data glib.gpointer priv - PurpleAccount *c_purple_account_new "purple_account_new" \ - (char *username, char *protocol_id) - - 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) - 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" \ - (PurpleAccountUiOps *ops) - void c_purple_account_connect "purple_account_connect" \ - (PurpleAccount *account) - void c_purple_account_disconnect "purple_account_disconnect" \ - (PurpleAccount *account) - glib.gboolean c_purple_account_is_connected "purple_account_is_connected" \ - (PurpleAccount *account) - PurpleProxyInfo *c_purple_account_get_proxy_info \ - "purple_account_get_proxy_info" (PurpleAccount *account) - void c_purple_account_set_proxy_info "purple_account_set_proxy_info" \ - (PurpleAccount *account, PurpleProxyInfo *info) - char *c_purple_account_get_string "purple_account_get_string" \ - (PurpleAccount *account, char *name, char *default_value) - int c_purple_account_get_int "purple_account_get_int" \ - (PurpleAccount *account, char *name, int default_value) - glib.gboolean c_purple_account_get_bool "purple_account_get_bool" \ - (PurpleAccount *account, char *name, glib.gboolean default_value) - void c_purple_account_clear_settings "purple_account_clear_settings" \ - (PurpleAccount *account) - void c_purple_account_set_int "purple_account_set_int" \ - (PurpleAccount *account, char *name, int value) - void c_purple_account_set_string "purple_account_set_string" \ - (PurpleAccount *account, char *name, char *value) - void c_purple_account_set_bool "purple_account_set_bool" \ - (PurpleAccount *account, char *name, glib.gboolean value) - PurpleAccount *c_purple_accounts_find "purple_accounts_find" \ - (char *name, char *protocol) - glib.GList *c_purple_accounts_get_all "purple_accounts_get_all" () - void c_purple_accounts_add "purple_accounts_add" (PurpleAccount *account) - void c_purple_accounts_delete "purple_accounts_delete" (PurpleAccount - *account) + # Account API + PurpleAccount *purple_account_new(char *username, char *protocol_id) + void purple_account_destroy(PurpleAccount *account) + void purple_account_connect(PurpleAccount *account) + void purple_account_set_register_callback(PurpleAccount *account, PurpleAccountRegistrationCb cb, void *user_data) + void purple_account_register(PurpleAccount *account) + void purple_account_unregister(PurpleAccount *account, PurpleAccountUnregistrationCb cb, void *user_data) + void purple_account_disconnect(PurpleAccount *account) + void purple_account_notify_added(PurpleAccount *account, \ + char *remote_user, char *id, char *alias, \ + char *message) + void purple_account_request_add(PurpleAccount *account, \ + char *remote_user, char *id, char *alias, \ + char *message) + void *purple_account_request_authorization(PurpleAccount *account, \ + char *remote_user, char *id, char *alias, \ + char *message, glib.gboolean on_list, \ + PurpleAccountRequestAuthorizationCb auth_cb, \ + PurpleAccountRequestAuthorizationCb deny_cb, void *user_data) + void purple_account_request_close_with_account(PurpleAccount *account) + void purple_account_request_close(void *ui_handle) + void purple_account_request_password(PurpleAccount *account, \ + glib.GCallback ok_cb, glib.GCallback cancel_cb, void *user_data) + void purple_account_request_change_password(PurpleAccount *account) + void purple_account_request_change_user_info(PurpleAccount *account) + void purple_account_set_username(PurpleAccount *account, char *username) + void purple_account_set_password(PurpleAccount *account, char *password) + void purple_account_set_alias(PurpleAccount *account, char *alias) + void purple_account_set_user_info(PurpleAccount *account, char *user_info) + void purple_account_set_buddy_icon_path(PurpleAccount *account, char *path) + void purple_account_set_protocol_id(PurpleAccount *account, \ + char *protocol_id) + void purple_account_set_connection(PurpleAccount *account, \ + PurpleConnection *gc) + void purple_account_set_remember_password(PurpleAccount *account, \ + glib.gboolean value) + void purple_account_set_check_mail(PurpleAccount *account, \ + glib.gboolean value) + void purple_account_set_enabled(PurpleAccount *account, \ + char *ui, glib.gboolean value) + void purple_account_set_proxy_info(PurpleAccount *account, \ + PurpleProxyInfo *info) + void purple_account_set_status_types(PurpleAccount *account, \ + glib.GList *status_types) + void purple_account_set_status_list(PurpleAccount *account, \ + char *status_id, glib.gboolean active, glib.GList *attrs) + void purple_account_set_status(PurpleAccount *account, \ + char *status_id, glib.gboolean active, NULL) # FIXME + void purple_account_set_status_list(PurpleAccount *account, \ + char *status_id, glib.gboolean active, glib.GList *attrs) + void purple_account_clear_settings(PurpleAccount *account) + void purple_account_set_int(PurpleAccount *account, char *name, \ + int value) + void purple_account_set_string(PurpleAccount *account, char *name, \ + char *value) + void purple_account_set_bool(PurpleAccount *account, char *name, \ + glib.gboolean value) + void purple_account_set_ui_int(PurpleAccount *account, char *ui, \ + char *name, int value) + void purple_account_set_ui_string(PurpleAccount *account, char *ui, \ + char *name, char *value) + void purple_account_set_ui_bool(PurpleAccount *account, char *ui, \ + char *name, glib.gboolean value) + glib.gboolean purple_account_is_connected(PurpleAccount *account) + glib.gboolean purple_account_is_connecting(PurpleAccount *account) + glib.gboolean purple_account_is_disconnected(PurpleAccount *account) + char *purple_account_get_username(PurpleAccount *account) + char *purple_account_get_password(PurpleAccount *account) + char *purple_account_get_alias(PurpleAccount *account) + char *purple_account_get_user_info(PurpleAccount *account) + char *purple_account_get_buddy_icon_path(PurpleAccount *account) + char *purple_account_get_protocol_id(PurpleAccount *account) + char *purple_account_get_protocol_name(PurpleAccount *account) + PurpleConnection *purple_account_get_connection(PurpleAccount *account) + glib.gboolean purple_account_get_remember_password(PurpleAccount *account) + glib.gboolean purple_account_get_check_mail(PurpleAccount *account) + glib.gboolean purple_account_get_enabled(PurpleAccount *account, char *ui) + PurpleProxyInfo *purple_account_get_proxy_info(PurpleAccount *account) + PurpleStatus *purple_account_get_active_status(PurpleAccount *account) + PurpleStatus *purple_account_get_status(PurpleAccount *account, \ + char *status_id) + PurpleStatusType *purple_account_get_status_type(PurpleAccount *account, \ + char *id) + PurpleStatusType *purple_account_get_status_type_with_primitive( \ + PurpleAccount *account, PurpleStatusPrimitive primitive) + PurplePresence *purple_account_get_presence(PurpleAccount *account) + glib.gboolean purple_account_is_status_active(PurpleAccount *account, \ + char *status_id) + glib.GList *purple_account_get_status_types(PurpleAccount *account) + int purple_account_get_int(PurpleAccount *account, char *name, \ + int default_value) + char *purple_account_get_string(PurpleAccount *account, \ + char *name, char *default_value) + glib.gboolean purple_account_get_bool(PurpleAccount *account, \ + char *name, glib.gboolean default_value) + int purple_account_get_ui_int(PurpleAccount *account, \ + char *ui, char *name, int default_value) + char *purple_account_get_ui_string(PurpleAccount *account, \ + char *ui, char *name, char *default_value) + glib.gboolean purple_account_get_ui_bool(PurpleAccount *account, \ + char *ui, char *name, glib.gboolean default_value) + PurpleLog *purple_account_get_log(PurpleAccount *account, \ + glib.gboolean create) + void purple_account_destroy_log(PurpleAccount *account) + void purple_account_add_buddy(PurpleAccount *account, PurpleBuddy *buddy) + void purple_account_add_buddies(PurpleAccount *account, \ + glib.GList *buddies) + void purple_account_remove_buddy(PurpleAccount *account, \ + PurpleBuddy *buddy, PurpleGroup *group) + void purple_account_remove_buddies(PurpleAccount *account, \ + glib.GList *buddies, glib.GList *groups) + void purple_account_remove_group(PurpleAccount *account, \ + PurpleGroup *group) + void purple_account_change_password(PurpleAccount *account, \ + char *orig_pw, char *new_pw) + glib.gboolean purple_account_supports_offline_message( \ + PurpleAccount *account, PurpleBuddy *buddy) + PurpleConnectionErrorInfo *purple_account_get_current_error( \ + PurpleAccount *account) + void purple_account_clear_current_error(PurpleAccount *account) + + # Accounts API + void purple_accounts_add(PurpleAccount *account) + void purple_accounts_remove(PurpleAccount *account) + void purple_accounts_delete(PurpleAccount *account) + void purple_accounts_reorder(PurpleAccount *account, glib.gint new_index) + glib.GList *purple_accounts_get_all() + glib.GList *purple_accounts_get_all_active() + PurpleAccount *purple_accounts_find(char *name, char *protocol) + void purple_accounts_restore_current_statuses() + + # UI Registration Functions + void purple_accounts_set_ui_ops(PurpleAccountUiOps *ops) + PurpleAccountUiOps *purple_accounts_get_ui_ops() + + # Accounts Subsystem + void *purple_accounts_get_handle() + void purple_accounts_init() + void purple_accounts_uninit() diff --git a/libpurple/accountopt.pxd b/libpurple/accountopt.pxd index 1de76fc..2625d9e 100644 --- a/libpurple/accountopt.pxd +++ b/libpurple/accountopt.pxd @@ -21,9 +21,6 @@ cimport glib cimport prefs -cdef extern from *: - ctypedef char const_char "const char" - cdef extern from "libpurple/accountopt.h": ctypedef struct UnionType: @@ -39,10 +36,58 @@ cdef extern from "libpurple/accountopt.h": UnionType default_value glib.gboolean masked - prefs.PurplePrefType c_purple_account_option_get_type "purple_account_option_get_type" (PurpleAccountOption *option) - char *c_purple_account_option_get_setting "purple_account_option_get_setting" (PurpleAccountOption *option) - char *c_purple_account_option_get_default_string "purple_account_option_get_default_string" (PurpleAccountOption *option) - int c_purple_account_option_get_default_int "purple_account_option_get_default_int" (PurpleAccountOption *option) - glib.gboolean c_purple_account_option_get_default_bool "purple_account_option_get_default_bool" (PurpleAccountOption *option) - const_char *c_purple_account_option_get_default_list_value "purple_account_option_get_default_list_value" (PurpleAccountOption *option) - const_char *c_purple_account_option_get_text "purple_account_option_get_text" (PurpleAccountOption *option) + ctypedef struct PurpleAccountUserSplit: + char *text + char *default_value + char field_sep + glib.gboolean reverse + + # Account Option API + PurpleAccountOption *purple_account_option_new(prefs.PurplePrefType type, \ + char *text, char *pref_name) + PurpleAccountOption *purple_account_option_bool_new(char *text, \ + char *pref_name, glib.gboolean default_value) + PurpleAccountOption *purple_account_option_int_new(char *text, \ + char *pref_name, int default_value) + PurpleAccountOption *purple_account_option_string_new(char *text, \ + char *pref_name, char *default_value) + PurpleAccountOption *purple_account_option_list_new(char *text, \ + char *pref_name, glib.GList *list) + void purple_account_option_destroy(PurpleAccountOption *option) + void purple_account_option_set_default_bool(PurpleAccountOption *option, \ + glib.gboolean value) + void purple_account_option_set_default_int(PurpleAccountOption *option, \ + int value) + void purple_account_option_set_default_string( \ + PurpleAccountOption *option, char *value) + void purple_account_option_set_masked(PurpleAccountOption *option, \ + glib.gboolean masked) + void purple_account_option_set_list(PurpleAccountOption *option, \ + glib.GList *values) + void purple_account_option_add_list_item(PurpleAccountOption *option, \ + char *key, char *value) + prefs.PurplePrefType purple_account_option_get_type( \ + PurpleAccountOption *option) + char *purple_account_option_get_text( PurpleAccountOption *option) + char *purple_account_option_get_setting( PurpleAccountOption *option) + glib.gboolean purple_account_option_get_default_bool( \ + PurpleAccountOption *option) + int purple_account_option_get_default_int(PurpleAccountOption *option) + char *purple_account_option_get_default_string(PurpleAccountOption *option) + char *purple_account_option_get_default_list_value( \ + PurpleAccountOption *option) + glib.gboolean purple_account_option_get_masked( \ + PurpleAccountOption *option) + glib.GList *purple_account_option_get_list( \ + PurpleAccountOption *option) + PurpleAccountUserSplit *purple_account_user_split_new(char *text, \ + char *default_value, char sep) + void purple_account_user_split_destroy(PurpleAccountUserSplit *split) + char *purple_account_user_split_get_text( PurpleAccountUserSplit *split) + char *purple_account_user_split_get_default_value( \ + PurpleAccountUserSplit *split) + char purple_account_user_split_get_separator(PurpleAccountUserSplit *split) + glib.gboolean purple_account_user_split_get_reverse( \ + PurpleAccountUserSplit *split) + void purple_account_user_split_set_reverse(PurpleAccountUserSplit *split, \ + glib.gboolean reverse) diff --git a/plugin.pyx b/plugin.pyx index 811adb7..c2b6538 100644 --- a/plugin.pyx +++ b/plugin.pyx @@ -76,7 +76,7 @@ cdef class Plugin: c_account = NULL if username: - c_account = account.c_purple_accounts_find(username, id) + c_account = account.purple_accounts_find(username, id) c_plugin = plugin.c_purple_plugins_find_with_id(id) c_prpl_info = plugin.c_PURPLE_PLUGIN_PROTOCOL_INFO(c_plugin) @@ -88,43 +88,43 @@ cdef class Plugin: while iter: option = iter.data - type = accountopt.c_purple_account_option_get_type(option) - label_name = accountopt.c_purple_account_option_get_text(option) - setting = accountopt.c_purple_account_option_get_setting(option) + type = accountopt.purple_account_option_get_type(option) + label_name = accountopt.purple_account_option_get_text(option) + setting = accountopt.purple_account_option_get_setting(option) sett = str( setting) label = str( label_name) if type == prefs.PURPLE_PREF_STRING: - str_value = accountopt.c_purple_account_option_get_default_string(option) + str_value = accountopt.purple_account_option_get_default_string(option) # Google Talk default domain hackery! if str_value == NULL and label == "Connect server": str_value = "talk.google.com" if c_account != NULL: - str_value = account.c_purple_account_get_string(c_account, setting, str_value) + str_value = account.purple_account_get_string(c_account, setting, str_value) val = str( str_value) elif type == prefs.PURPLE_PREF_INT: - int_value = accountopt.c_purple_account_option_get_default_int(option) + int_value = accountopt.purple_account_option_get_default_int(option) if sett == "port": int_value = int(443) if c_account != NULL: - int_value = account.c_purple_account_get_int(c_account, setting, int_value) + int_value = account.purple_account_get_int(c_account, setting, int_value) val = int(int_value) elif type == prefs.PURPLE_PREF_BOOLEAN: - bool_value = accountopt.c_purple_account_option_get_default_bool(option) + bool_value = accountopt.purple_account_option_get_default_bool(option) if c_account != NULL: - bool_value = account.c_purple_account_get_bool(c_account, setting, bool_value) + bool_value = account.purple_account_get_bool(c_account, setting, bool_value) val = bool(bool_value) elif type == prefs.PURPLE_PREF_STRING_LIST: - str_value = accountopt.c_purple_account_option_get_default_list_value(option) + str_value = accountopt.purple_account_option_get_default_list_value(option) if c_account != NULL: - str_value = account.c_purple_account_get_string(c_account, setting, str_value) + str_value = account.purple_account_get_string(c_account, setting, str_value) val = str( str_value) @@ -154,7 +154,7 @@ cdef class Plugin: c_account = NULL - c_account = account.c_purple_accounts_find(acc[0], acc[1]) + c_account = account.purple_accounts_find(acc[0], acc[1]) if c_account == NULL: # FIXME: Message error or call a error handler return False @@ -167,8 +167,8 @@ cdef class Plugin: while iter: option = iter.data - type = accountopt.c_purple_account_option_get_type(option) - setting = accountopt.c_purple_account_option_get_setting(option) + type = accountopt.purple_account_option_get_type(option) + setting = accountopt.purple_account_option_get_setting(option) sett = str( setting) @@ -180,22 +180,22 @@ cdef class Plugin: if type == prefs.PURPLE_PREF_STRING: str_value = po[sett] - account.c_purple_account_set_string(c_account, setting, str_value) + account.purple_account_set_string(c_account, setting, str_value) elif type == prefs.PURPLE_PREF_INT: int_value = int(po[sett]) - account.c_purple_account_set_int(c_account, setting, int_value) + account.purple_account_set_int(c_account, setting, int_value) elif type == prefs.PURPLE_PREF_BOOLEAN: bool_value = bool(po[sett]) - account.c_purple_account_set_bool(c_account, setting, bool_value) + account.purple_account_set_bool(c_account, setting, bool_value) elif type == prefs.PURPLE_PREF_STRING_LIST: str_value = po[sett] - account.c_purple_account_set_string(c_account, setting, str_value) + account.purple_account_set_string(c_account, setting, str_value) return True diff --git a/protocol.pyx b/protocol.pyx new file mode 100644 index 0000000..2e36aa4 --- /dev/null +++ b/protocol.pyx @@ -0,0 +1,31 @@ +# +# Copyright (c) 2008 INdT - Instituto Nokia de Tecnologia +# +# This file is part of python-purple. +# +# python-purple is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# python-purple is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +cdef class Protocol: + """ + Protocol class + @param protocol_id + """ + + def __init__(self, protocol_id): + self.__protocol_id = protocol_id + + def __get_protocol_id(self): + return self.__protocol_id.protocol_id + protocol_id = property(__get_protocol_id) diff --git a/proxy.pyx b/proxy.pyx index cb24823..7deb3ac 100644 --- a/proxy.pyx +++ b/proxy.pyx @@ -99,16 +99,16 @@ cdef class ProxyInfo: cdef account.PurpleAccount *c_account cdef proxy.PurpleProxyInfo *c_proxyinfo - c_account = account.c_purple_accounts_find(acc[0], acc[1]) + c_account = account.purple_accounts_find(acc[0], acc[1]) if c_account == NULL: #FIXME: Message error or call a callback handle to error return False - c_proxyinfo = account.c_purple_account_get_proxy_info(c_account) + c_proxyinfo = account.purple_account_get_proxy_info(c_account) if c_proxyinfo == NULL: c_proxyinfo = proxy.c_purple_proxy_info_new() - account.c_purple_account_set_proxy_info(c_account, c_proxyinfo) + account.purple_account_set_proxy_info(c_account, c_proxyinfo) if info.has_key('type') and info['type']: type = info['type'] diff --git a/purple.pyx b/purple.pyx index e69a966..96a5241 100644 --- a/purple.pyx +++ b/purple.pyx @@ -98,7 +98,7 @@ cdef class Purple: cdef void __core_ui_ops_ui_init(self): debug.c_purple_debug_info("core_ui_ops", "%s", "ui_init\n") - account.c_purple_accounts_set_ui_ops(&c_account_ui_ops) + account.purple_accounts_set_ui_ops(&c_account_ui_ops) connection.c_purple_connections_set_ui_ops(&c_conn_ui_ops) blist.c_purple_blist_set_ui_ops(&c_blist_ui_ops) conversation.c_purple_conversations_set_ui_ops(&c_conv_ui_ops) @@ -113,7 +113,7 @@ cdef class Purple: global c_ui_info - account.c_purple_accounts_set_ui_ops(NULL) + account.purple_accounts_set_ui_ops(NULL) connection.c_purple_connections_set_ui_ops(NULL) blist.c_purple_blist_set_ui_ops(NULL) conversation.c_purple_conversations_set_ui_ops(NULL) @@ -324,20 +324,21 @@ cdef class Purple: def load_accounts(self): cdef glib.GList *iter cdef account.PurpleAccount *acc - iter = account.c_purple_accounts_get_all() + iter = account.purple_accounts_get_all() while iter: acc = iter.data if acc: - 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) + username = account.purple_account_get_username(acc) + protocol_id = account.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) self.__accounts[username] = acc - if not account.c_purple_accounts_find(username, protocol_id): + if not account.purple_accounts_find(username, protocol_id): acc.proxy.set_type(purple.ProxyInfoType().HTTP) acc.proxy.set_host(host) acc.proxy.set_port(port) @@ -353,7 +354,9 @@ cdef class Purple: include "plugin.pyx" include "proxy.pyx" +#include "protocol.pyx" include "account.pyx" include "buddy.pyx" #include "connection.pyx" include "conversation.pyx" + diff --git a/signal_cbs.pxd b/signal_cbs.pxd index 0e496b8..ad2ce83 100644 --- a/signal_cbs.pxd +++ b/signal_cbs.pxd @@ -31,13 +31,13 @@ cdef void signal_signed_on_cb(connection.PurpleConnection *gc, \ cdef char *c_username = NULL cdef char *c_protocol_id = NULL - c_username = account.c_purple_account_get_username(acc) + c_username = account.purple_account_get_username(acc) if c_username == NULL: username = None else: username = c_username - c_protocol_id = account.c_purple_account_get_protocol_id(acc) + c_protocol_id = account.purple_account_get_protocol_id(acc) if c_protocol_id == NULL: protocol_id = None else: @@ -56,13 +56,13 @@ cdef void signal_signed_off_cb(connection.PurpleConnection *gc, \ cdef char *c_username = NULL cdef char *c_protocol_id = NULL - c_username = account.c_purple_account_get_username(acc) + c_username = account.purple_account_get_username(acc) if c_username == NULL: username = None else: username = c_username - c_protocol_id = account.c_purple_account_get_protocol_id(acc) + c_protocol_id = account.purple_account_get_protocol_id(acc) if c_protocol_id == NULL: protocol_id = None else: