Replaced all 'dict.has_key(item)' with 'item in dict' expressions.
[python-purple] / request_cbs.pxd
index 2c7b7ba..e45bc24 100644 (file)
@@ -23,9 +23,16 @@ cdef extern from *:
     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 = {}
 
+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, \
@@ -36,8 +43,8 @@ cdef void *request_input(const_char *title, const_char *primary, \
     """
     @see purple_request_input().
     """
-    debug.c_purple_debug_info("request", "%s", "request-input\n")
-    if request_cbs.has_key("request-input"):
+    debug.purple_debug_info("request", "%s", "request-input\n")
+    if "request-input" in request_cbs:
         (<object> request_cbs["request-input"])("request-input: TODO")
 
 cdef void *request_choice(const_char *title, const_char *primary, \
@@ -49,10 +56,21 @@ cdef void *request_choice(const_char *title, const_char *primary, \
     """
     @see purple_request_choice_varg().
     """
-    debug.c_purple_debug_info("request", "%s", "request-choice\n")
-    if request_cbs.has_key("request-choice"):
+    debug.purple_debug_info("request", "%s", "request-choice\n")
+    if "request-choice" in request_cbs:
         (<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, \
@@ -61,9 +79,30 @@ cdef void *request_action(const_char *title, const_char *primary, \
     """
     @see purple_request_action_varg().
     """
-    debug.c_purple_debug_info("request", "%s", "request-action\n")
-    if request_cbs.has_key("request-action"):
-        (<object> request_cbs["request-action"])("request-action: TODo")
+    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-action" in request_cbs:
+        (<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, \
@@ -74,8 +113,8 @@ cdef void *request_fields(const_char *title, const_char *primary, \
     """
     @see purple_request_fields().
     """
-    debug.c_purple_debug_info("request", "%s", "request-fields\n")
-    if request_cbs.has_key("request-fields"):
+    debug.purple_debug_info("request", "%s", "request-fields\n")
+    if "request-fields" in request_cbs:
         (<object> request_cbs["request-fields"])("request-fields: TODO")
 
 cdef void *request_file(const_char *title, const_char *filename, \
@@ -86,16 +125,16 @@ cdef void *request_file(const_char *title, const_char *filename, \
     """
     @see purple_request_file().
     """
-    debug.c_purple_debug_info("request", "%s", "request-file\n")
-    if request_cbs.has_key("request-file"):
+    debug.purple_debug_info("request", "%s", "request-file\n")
+    if "request-file" in request_cbs:
         (<object> request_cbs["request-file"])("request-file: TODO")
 
 cdef void close_request(request.PurpleRequestType type, void *ui_handle):
     """
     TODO
     """
-    debug.c_purple_debug_info("request", "%s", "close-request\n")
-    if request_cbs.has_key("close-request"):
+    debug.purple_debug_info("request", "%s", "close-request\n")
+    if "close-request" in request_cbs:
         (<object> request_cbs["close-request"])("close-request: TODO")
 
 cdef void *request_folder(const_char *title, const_char *dirname, \
@@ -105,6 +144,6 @@ cdef void *request_folder(const_char *title, const_char *dirname, \
     """
     @see purple_request_folder().
     """
-    debug.c_purple_debug_info("request", "%s", "request-folder\n")
-    if request_cbs.has_key("request-folder"):
+    debug.purple_debug_info("request", "%s", "request-folder\n")
+    if "request-folder" in request_cbs:
         (<object> request_cbs["request-folder"])("request-folder: TODO")