X-Git-Url: http://git.maemo.org/git/?p=python-purple;a=blobdiff_plain;f=protocol.pyx;h=08c1e36e4a4cdc666272913ff72323ef30e649e2;hp=b482e6e8beeee8c28af23d05f29e38405b905800;hb=d498550db3bfd489d8319e7342cc10b76cf24ac9;hpb=fa83e5e05e62fa5c6707312d375b97195143e6b7;ds=sidebyside diff --git a/protocol.pyx b/protocol.pyx index b482e6e..08c1e36 100644 --- a/protocol.pyx +++ b/protocol.pyx @@ -22,21 +22,127 @@ cimport purple cdef class Protocol: """ Protocol class - @param protocol_id + @param id """ + cdef object __id + cdef object __exists - def __init__(self, account, protocol_id): - self.__account = account - self.__protocol_id = protocol_id + def __init__(self, id): + self.__id = id - cdef account.PurpleAccount *__account_get_structure(self): - return account.purple_accounts_find(self.__account.username, \ - self.__account.protocol_id) + if self._get_structure() != NULL: + self.__exists = True + else: + self.__exists = False - def __get_protocol_id(self): - return self.__protocol_id.protocol_id - protocol_id = property(__get_protocol_id) + cdef plugin.PurplePlugin *_get_structure(self): + return plugin.purple_plugins_find_with_id(self.__id) - def _set_protocol_id(self, protocol_id): - account.purple_account_set_protocol_id( \ - self.__account_get_structure(), protocol_id) + def __get_exists(self): + return self.__exists + exists = property(__get_exists) + + def __get_id(self): + return self.__id + id = property(__get_id) + + def __get_name(self): + cdef char *name = NULL + if self.__exists: + name = plugin.purple_plugin_get_name(self._get_structure()) + if name != NULL: + return name + else: + return None + return None + name = property(__get_name) + + def __get_options_labels(self): + cdef prpl.PurplePluginProtocolInfo *prpl_info + cdef glib.GList *iter + cdef accountopt.PurpleAccountOption *option + cdef prefs.PurplePrefType type + cdef const_char *label_name + cdef const_char *setting + + if not self.__exists: + return None + + prpl_info = plugin.PURPLE_PLUGIN_PROTOCOL_INFO(self._get_structure()) + + po = {} + + iter = prpl_info.protocol_options + + while iter: + + option = iter.data + 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) + + iter = iter.next + + po[sett] = label + + return po + options_labels = property(__get_options_labels) + + def __get_options_values(self): + cdef prpl.PurplePluginProtocolInfo *prpl_info + 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 not self.__exists: + return None + + prpl_info = plugin.PURPLE_PLUGIN_PROTOCOL_INFO(self._get_structure()) + + po = {} + + iter = prpl_info.protocol_options + + while iter: + + option = iter.data + type = accountopt.purple_account_option_get_type(option) + setting = accountopt.purple_account_option_get_setting(option) + + sett = str( setting) + + if type == prefs.PURPLE_PREF_STRING: + str_value = accountopt.purple_account_option_get_default_string(option) + # Hack to set string "" as default value when the + # protocol's option is NULL + if str_value == NULL: + str_value = "" + val = str( str_value) + + elif type == prefs.PURPLE_PREF_INT: + int_value = accountopt.purple_account_option_get_default_int(option) + val = int(int_value) + + elif type == prefs.PURPLE_PREF_BOOLEAN: + bool_value = accountopt.purple_account_option_get_default_bool(option) + + val = bool(bool_value) + + elif type == prefs.PURPLE_PREF_STRING_LIST: + str_value = accountopt.purple_account_option_get_default_list_value(option) + + val = str( str_value) + + iter = iter.next + + po[sett] = val + + return po + options_values = property(__get_options_values)