Fixing support to request_action callback
authorRagner Magalhaes <ragner.magalhaes@openbossa.org>
Tue, 16 Dec 2008 13:14:24 +0000 (13:14 +0000)
committerAnderson Briglia <anderson.briglia@openbossa.org>
Sat, 28 Feb 2009 21:11:24 +0000 (17:11 -0400)
Fixing support to request_action callback

Signed-off-by: Ragner Magalhaes <agner.magalhaes@openbossa.org>
Acked-by: Anderson Briglia <anderson.briglia@openbossa.org>

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

libpurple/request.pxd
purple.pyx
request_cbs.pxd

index 9289520..ea7f576 100644 (file)
@@ -61,6 +61,11 @@ cdef extern from "libpurple/request.h":
     ctypedef struct PurpleRequestField:
         pass
 
     ctypedef struct PurpleRequestField:
         pass
 
+    ctypedef void (*PurpleRequestActionCb)(void *, int)
+    ctypedef void (*PurpleRequestChoiceCb)(void *, int)
+    ctypedef void (*PurpleRequestFieldsCb)(void *, PurpleRequestFields *fields)
+    ctypedef void (*PurpleRequestFileCb)(void *, char *filename)
+
     ctypedef struct PurpleRequestUiOps:
         void *(*request_input) (const_char *title, const_char *primary,
                                 const_char *secondary,
     ctypedef struct PurpleRequestUiOps:
         void *(*request_input) (const_char *title, const_char *primary,
                                 const_char *secondary,
index e32c963..5de7e43 100644 (file)
@@ -429,6 +429,9 @@ cdef class Purple:
             iter = iter.next
         return protocol_list
 
             iter = iter.next
         return protocol_list
 
+    def call_action(self, i):
+        __call_action(i)
+
 include "protocol.pyx"
 #include "plugin.pyx"
 include "proxy.pyx"
 include "protocol.pyx"
 #include "plugin.pyx"
 include "proxy.pyx"
index 46af219..fd98e02 100644 (file)
@@ -23,9 +23,16 @@ cdef extern from *:
     ctypedef char const_char "const char"
     ctypedef int size_t
     ctypedef void* va_list
     ctypedef char const_char "const char"
     ctypedef int size_t
     ctypedef void* va_list
+    char* charptr "char *"
+    glib.GCallback glibcb "GCallback"
+    void* va_arg(void *action, void *type)
 
 request_cbs = {}
 
 
 request_cbs = {}
 
+cdef request.PurpleRequestActionCb req_actions_cb[10]
+cdef object req_actions_list = []
+cdef void *req_action_user_data = NULL
+
 cdef void *request_input(const_char *title, const_char *primary, \
         const_char *secondary, const_char *default_value, \
         glib.gboolean multiline, glib.gboolean masked, glib.gchar *hint, \
 cdef void *request_input(const_char *title, const_char *primary, \
         const_char *secondary, const_char *default_value, \
         glib.gboolean multiline, glib.gboolean masked, glib.gchar *hint, \
@@ -53,6 +60,17 @@ cdef void *request_choice(const_char *title, const_char *primary, \
     if request_cbs.has_key("request-choice"):
         (<object> request_cbs["request-choice"])("request-choice: TODO")
 
     if request_cbs.has_key("request-choice"):
         (<object> request_cbs["request-choice"])("request-choice: TODO")
 
+cdef void __call_action(int i):
+    global req_actions_cb
+    global req_actions_list
+    global req_action_user_data
+
+    cdef request.PurpleRequestActionCb cb 
+
+    if req_actions_list and len(req_actions_list) > i:
+        cb = req_actions_cb[i]
+        cb(req_action_user_data, i)
+
 cdef void *request_action(const_char *title, const_char *primary, \
         const_char *secondary, int default_action, \
         account.PurpleAccount *account, const_char *who, \
 cdef void *request_action(const_char *title, const_char *primary, \
         const_char *secondary, int default_action, \
         account.PurpleAccount *account, const_char *who, \
@@ -61,9 +79,30 @@ cdef void *request_action(const_char *title, const_char *primary, \
     """
     @see purple_request_action_varg().
     """
     """
     @see purple_request_action_varg().
     """
+    global req_actions_cb
+    global req_actions_list
+    global req_action_user_data
+    cdef int i
+    cdef char *btn_txt
+    cdef void *cb
+
+    i = 0
+
+    req_action_user_data = user_data
+    req_actions_list = []
+
+    #FIXME: i < 10 max size to req_actions_cb
+    while i < action_count and i < 10:
+        btn_txt = <char *> va_arg(actions, charptr)
+        req_actions_cb[i] = <request.PurpleRequestActionCb> va_arg(actions, glibcb)
+        req_actions_list.append(btn_txt)
+        i = i + 1
+
     debug.purple_debug_info("request", "%s", "request-action\n")
     if request_cbs.has_key("request-action"):
     debug.purple_debug_info("request", "%s", "request-action\n")
     if request_cbs.has_key("request-action"):
-        (<object> request_cbs["request-action"])("request-action: TODo")
+        (<object> request_cbs["request-action"])(<char *> title,
+                       <char *> primary, <char *> secondary,
+                       default_action, req_actions_list)
 
 cdef void *request_fields(const_char *title, const_char *primary, \
         const_char *secondary, request.PurpleRequestFields *fields, \
 
 cdef void *request_fields(const_char *title, const_char *primary, \
         const_char *secondary, request.PurpleRequestFields *fields, \