X-Git-Url: http://git.maemo.org/git/?p=python-purple;a=blobdiff_plain;f=plugin.pyx;h=e9cff1f5312987b48a8fb4c4fff83954078ecb15;hp=0ea893f880eca5d89f983ef4d5bd06bead234f9e;hb=a227e6107cedaa8a3bf4b6868b74ba4f39d2c0e0;hpb=cf6b24f0281dd8bec0d836e254f0675a072c9e7c
diff --git a/plugin.pyx b/plugin.pyx
index 0ea893f..e9cff1f 100644
--- a/plugin.pyx
+++ b/plugin.pyx
@@ -17,10 +17,8 @@
# along with this program. If not, see .
#
-cimport prpl
cimport purple
-
cdef class Plugin:
cdef plugin.PurplePlugin *c_plugin
cdef prpl.PurplePluginProtocolInfo *c_prpl_info
@@ -36,6 +34,104 @@ cdef class Plugin:
def get_id(self):
return self.c_plugin.info.id
+ def get_all(self):
+ ''' @return A string list of protocols' (id, name) '''
+ ''' [('prpl-jabber', 'XMPP'), ('foo', 'MSN'), ...] '''
+ cdef glib.GList *iter
+ cdef plugin.PurplePlugin *pp
+
+ protocols = []
+
+ iter = plugin.c_purple_plugins_get_protocols()
+ while iter:
+ pp = iter.data
+ if pp.info and pp.info.name:
+ protocols.append((pp.info.id, pp.info.name))
+ iter = iter.next
+
+ return protocols
+
+ def get_options(self, id, username=None):
+ ''' @param id The protocol's id '''
+ ''' @param username The account's username '''
+ ''' @return {'setting type': ('UI label', str|int|bool value)} '''
+
+ cdef plugin.PurplePlugin *c_plugin
+ cdef prpl.PurplePluginProtocolInfo *c_prpl_info
+ cdef account.PurpleAccount *c_account
+ 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
+
+ c_account = NULL
+
+ if username:
+ c_account = account.c_purple_accounts_find(username, id)
+ if c_account == NULL:
+ # FIXME: Message error or call a error handler
+ return None
+
+ c_plugin = plugin.c_purple_plugins_find_with_id(id)
+ c_prpl_info = plugin.c_PURPLE_PLUGIN_PROTOCOL_INFO(c_plugin)
+
+ po = {}
+
+ iter = 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)
+ label = str( lanel_name)
+
+ 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 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)
+
+ val = str( str_value)
+
+ elif type == prefs.PURPLE_PREF_INT:
+ int_value = accountopt.c_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)
+
+ val = int(int_value)
+
+ elif type == prefs.PURPLE_PREF_BOOLEAN:
+ bool_value = accountopt.c_purple_account_option_get_default_bool(option)
+ if c_account != NULL:
+ bool_value = account.c_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)
+ if c_account != NULL:
+ str_value = account.c_purple_account_get_string(c_account, setting, str_value)
+
+ val = str( str_value)
+
+ iter = iter.next
+
+ po[sett] = (label, val)
+
+ return po
+
cdef class Plugins: