Adding new functions to get protocol's default options
authorRagner Magalhaes <ragner.magalhaes@openbossa.org>
Tue, 2 Dec 2008 21:13:04 +0000 (21:13 +0000)
committerAnderson Briglia <anderson.briglia@openbossa.org>
Sat, 28 Feb 2009 21:11:19 +0000 (17:11 -0400)
Adding new functions to return the default values to protocol options
and protocol options labels.
Also defining __id and __exists as object to fix execution's failure.

Signed-off-by: Ragner Magalhaes <ragner.magalhaes@indt.org.br>
Acked-by: Bruno Abinader <bruno.abinader@indt.org.br>
Acked-by: Ricardo Guimaraes <ricardo.guimaraes@indt.org.br>

git-svn-id: https://garage.maemo.org/svn/carman/branches/carman-0.7-beta2/python-purple@1425 596f6dd7-e928-0410-a184-9e12fd12cf7e

libpurple/plugin.pxd
protocol.pyx
purple.pyx

index abcd0d2..7939bb2 100644 (file)
@@ -38,16 +38,12 @@ cdef extern from "libpurple/plugin.h":
         glib.gboolean unloadable
         glib.GList *dependent_plugins
 
-    prpl.PurplePluginProtocolInfo *c_PURPLE_PLUGIN_PROTOCOL_INFO \
-                "PURPLE_PLUGIN_PROTOCOL_INFO" (PurplePlugin *plugin)
-    PurplePlugin *c_purple_plugin_new  "purple_plugin_new" \
-            (glib.gboolean native, char* path)
-
-    void c_purple_plugins_add_search_path "purple_plugins_add_search_path" \
-            (char *path)
-    glib.GList *c_purple_plugins_get_protocols "purple_plugins_get_protocols" ()
-    PurplePlugin *c_purple_plugins_find_with_name "purple_plugins_find_with_name" \
-            (char *name)
+    prpl.PurplePluginProtocolInfo *PURPLE_PLUGIN_PROTOCOL_INFO(PurplePlugin *plugin)
+    PurplePlugin *purple_plugin_new(glib.gboolean native, char* path)
+
+    void purple_plugins_add_search_path(char *path)
+    glib.GList *purple_plugins_get_protocols()
+    PurplePlugin purple_plugins_find_with_name(char *name)
     PurplePlugin *purple_plugins_find_with_id(char *id)
     char *purple_plugin_get_name(PurplePlugin *plugin)
 
index ed335e2..c348d7f 100644 (file)
@@ -22,8 +22,10 @@ cimport purple
 cdef class Protocol:
     """
     Protocol class
-    @param protocol_id
+    @param id
     """
+    cdef object __id
+    cdef object __exists
 
     def __init__(self, id):
         self.__id = id
@@ -34,7 +36,7 @@ cdef class Protocol:
             self.__exists = False
 
     cdef plugin.PurplePlugin *_get_structure(self):
-        return plugin.purple_plugins_find_with_id(self.__protocol_id)
+        return plugin.purple_plugins_find_with_id(self.__id)
 
     def __get_exists(self):
         return self.__exists
@@ -54,3 +56,96 @@ cdef class Protocol:
                 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 = <accountopt.PurpleAccountOption *> 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(<char *> setting)
+            label = str(<char *> 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 = <accountopt.PurpleAccountOption *> iter.data
+            type = accountopt.purple_account_option_get_type(option)
+            setting = accountopt.purple_account_option_get_setting(option)
+
+            sett = str(<char *> setting)
+
+            if type == prefs.PURPLE_PREF_STRING:
+                str_value = accountopt.purple_account_option_get_default_string(option)
+                # Google Talk default domain hackery!
+                if str_value == NULL and sett == "connect_server":
+                    str_value = "talk.google.com"
+
+                val = str(<char *> str_value)
+
+            elif type == prefs.PURPLE_PREF_INT:
+                int_value = accountopt.purple_account_option_get_default_int(option)
+                if sett == "port":
+                        int_value = int(443)
+
+                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(<char *> str_value)
+
+            iter = iter.next
+
+            po[sett] = val
+
+        return po
+    options_values = property(__get_options_values)
index 26a972f..ca6fd8e 100644 (file)
@@ -340,7 +340,7 @@ cdef class Purple:
         cdef glib.GList *iter
         cdef plugin.PurplePlugin *pp
 
-        iter = plugin.c_purple_plugins_get_protocols()
+        iter = plugin.purple_plugins_get_protocols()
         protocol_list = []
         while iter:
             pp = <plugin.PurplePlugin*> iter.data