Added PurpleRequestUiOps callbacks. (UPDATE)
authorRagner Magalhaes <ragner.magalhaes@openbossa.org>
Tue, 2 Dec 2008 20:28:31 +0000 (20:28 +0000)
committerAnderson Briglia <anderson.briglia@openbossa.org>
Sat, 28 Feb 2009 21:11:11 +0000 (17:11 -0400)
FIXES:
 - Added missing structures on request.pxd.
 - Added request callbacks forwarding on purple.pyx.
 - Added request callbacks example on nullclient.py.
 - Added c-based callbacks on request_cbs.pxd.
 - Added missing GCallback definition on glib.pxd.

ps: Fixed typo in purple.pyx.

Signed-off-by: Bruno Abinader <bruno.abinader@indt.org.br>

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

libpurple/glib.pxd
libpurple/request.pxd
nullclient.py
purple.pyx
request_cbs.pxd [new file with mode: 0644]

index 4038da3..7478033 100644 (file)
@@ -29,6 +29,8 @@ cdef extern from "glib.h":
     ctypedef char gchar
     ctypedef unsigned char guchar
 
     ctypedef char gchar
     ctypedef unsigned char guchar
 
+    ctypedef void (*GCallback) ()
+
     ctypedef struct GHashTable:
         pass
 
     ctypedef struct GHashTable:
         pass
 
index f575125..f49b694 100644 (file)
 #  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 
 #  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 
+cimport glib
+
+cimport account
+cimport conversation
+
+cdef extern from *:
+    ctypedef char const_char "const char"
+    ctypedef int size_t
+    ctypedef void* va_list
+
 cdef extern from "libpurple/request.h":
 cdef extern from "libpurple/request.h":
-    ctypedef struct PurpleRequestUiOps:
+    ctypedef enum PurpleRequestType:
+        PURPLE_REQUEST_INPUT = 0
+        PURPLE_REQUEST_CHOICE
+        PURPLE_REQUEST_ACTION
+        PURPLE_REQUEST_FIELDS
+        PURPLE_REQUEST_FILE
+        PURPLE_REQUEST_FOLDER
+
+    ctypedef enum PurpleRequestFieldType:
+        PURPLE_REQUEST_FIELD_NONE
+        PURPLE_REQUEST_FIELD_STRING
+        PURPLE_REQUEST_FIELD_INTEGER
+        PURPLE_REQUEST_FIELD_BOOLEAN
+        PURPLE_REQUEST_FIELD_CHOICE
+        PURPLE_REQUEST_FIELD_LIST
+        PURPLE_REQUEST_FIELD_LABEL
+        PURPLE_REQUEST_FIELD_IMAGE
+        PURPLE_REQUEST_FIELD_ACCOUNT
+
+    ctypedef struct PurpleRequestFields:
+        glib.GList *groups
+        glib.GHashTable *fields
+        glib.GList required_fields
+        void *ui_data
+
+    ctypedef struct PurpleRequestFieldGroup:
+        PurpleRequestFields *fields_list
+        char *title
+        glib.GList *fields
+
+    ctypedef struct PurpleRequestField:
         pass
 
         pass
 
+    ctypedef struct PurpleRequestUiOps:
+        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, const_char *ok_text,
+                                glib.GCallback ok_cb, const_char *cancel_text,
+                                glib.GCallback cancel_cb,
+                                account.PurpleAccount *account,
+                                const_char *who,
+                                conversation.PurpleConversation *conv,
+                                void *user_data)
+        void *(*request_choice) (const_char *title, const_char *primary,
+                                 const_char *secondary, int default_value,
+                                 const_char *ok_text, glib.GCallback ok_cb,
+                                 const_char *cancel_text,
+                                 glib.GCallback cancel_cb,
+                                 account.PurpleAccount *account,
+                                 const_char *who,
+                                 conversation.PurpleConversation *conv,
+                                 void *user_data, va_list choices)
+        void *(*request_action) (const_char *title, const_char *primary,
+                                 const_char *secondary, int default_action,
+                                 account.PurpleAccount *account,
+                                 const_char *who,
+                                 conversation.PurpleConversation *conv,
+                                 void *user_data, size_t action_count,
+                                 va_list actions)
+        void *(*request_fields) (const_char *title, const_char *primary,
+                                 const_char *secondary,
+                                 PurpleRequestFields *fields,
+                                 const_char *ok_text, glib.GCallback ok_cb,
+                                 const_char *cancel_text,
+                                 glib.GCallback cancel_cb,
+                                 account.PurpleAccount *account,
+                                 const_char *who,
+                                 conversation.PurpleConversation *conv,
+                                 void *user_data)
+        void *(*request_file) (const_char *title, const_char *filename,
+                               glib.gboolean savedialog, glib.GCallback ok_cb,
+                               glib.GCallback cancel_cb,
+                               account.PurpleAccount *account,
+                               const_char *who,
+                               conversation.PurpleConversation *conv,
+                               void *user_data)
+        void (*close_request) (PurpleRequestType type, void *ui_handle)
+        void *(*request_folder) (const_char *title, const_char *dirname,
+                                 glib.GCallback ok_cb,
+                                 glib.GCallback cancel_cb,
+                                 account.PurpleAccount *account,
+                                 const_char *who,
+                                 conversation.PurpleConversation *conv,
+                                 void *user_data)
+
     void c_purple_request_set_ui_ops "purple_request_set_ui_ops" (PurpleRequestUiOps *ops)
     void c_purple_request_set_ui_ops "purple_request_set_ui_ops" (PurpleRequestUiOps *ops)
index 546f013..76f5e74 100644 (file)
@@ -9,6 +9,7 @@ blist_cbs = {}
 conn_cbs = {}
 conv_cbs = {}
 notify_cbs = {}
 conn_cbs = {}
 conv_cbs = {}
 notify_cbs = {}
+request_cbs = {}
 
 def account_callback(name):
     print "---- account callback example: %s" % name
 
 def account_callback(name):
     print "---- account callback example: %s" % name
@@ -87,6 +88,19 @@ notify_cbs["close_notify"] = notify_callback
 
 cbs["notify"] = notify_cbs
 
 
 cbs["notify"] = notify_cbs
 
+def request_callback(name):
+    print "---- request callback example: %s" % name
+
+request_cbs["request_input"] = request_callback
+request_cbs["request_choice"] = request_callback
+request_cbs["request_action"] = request_callback
+request_cbs["request_fields"] = request_callback
+request_cbs["request_file"] = request_callback
+request_cbs["close_request"] = request_callback
+request_cbs["request_folder"] = request_callback
+
+cbs["request"] = request_cbs
+
 class NullClient:
     def __init__(self):
         self.p = purple.Purple(debug_enabled=False)
 class NullClient:
     def __init__(self):
         self.p = purple.Purple(debug_enabled=False)
index 94317e9..bd2bed5 100644 (file)
@@ -36,7 +36,7 @@ cdef core.PurpleCoreUiOps c_core_ui_ops
 cdef eventloop.PurpleEventLoopUiOps c_eventloop_ui_ops
 #cdef ft.PurpleXferUiOps c_ft_ui_ops
 cdef notify.PurpleNotifyUiOps c_notify_ui_ops
 cdef eventloop.PurpleEventLoopUiOps c_eventloop_ui_ops
 #cdef ft.PurpleXferUiOps c_ft_ui_ops
 cdef notify.PurpleNotifyUiOps c_notify_ui_ops
-#cdef request.PurpleRequestUiOps c_request_ui_ops
+cdef request.PurpleRequestUiOps c_request_ui_ops
 #cdef roomlist.PurpleRoomlistUiOps c_rlist_ui_ops
 
 cdef glib.GHashTable *c_ui_info
 #cdef roomlist.PurpleRoomlistUiOps c_rlist_ui_ops
 
 cdef glib.GHashTable *c_ui_info
@@ -47,7 +47,10 @@ include "account_cbs.pxd"
 include "blist_cbs.pxd"
 include "connection_cbs.pxd"
 include "conversation_cbs.pxd"
 include "blist_cbs.pxd"
 include "connection_cbs.pxd"
 include "conversation_cbs.pxd"
+#include "xfer_cbs.pxd"
 include "notify_cbs.pxd"
 include "notify_cbs.pxd"
+include "request_cbs.pxd"
+#include "roomlist_cbs.pxd"
 
 cdef class Purple:
     """ Purple class.
 
 cdef class Purple:
     """ Purple class.
@@ -91,7 +94,7 @@ cdef class Purple:
         blist.c_purple_blist_set_ui_ops(&c_blist_ui_ops)
         conversation.c_purple_conversations_set_ui_ops(&c_conv_ui_ops)
         notify.c_purple_notify_set_ui_ops(&c_notify_ui_ops)
         blist.c_purple_blist_set_ui_ops(&c_blist_ui_ops)
         conversation.c_purple_conversations_set_ui_ops(&c_conv_ui_ops)
         notify.c_purple_notify_set_ui_ops(&c_notify_ui_ops)
-        #request.c_purple_request_set_ui_ops(&c_request_ui_ops)
+        request.c_purple_request_set_ui_ops(&c_request_ui_ops)
         #ft.c_purple_xfers_set_ui_ops(&c_ft_ui_ops)
         #roomlist.c_purple_roomlist_set_ui_ops(&c_rlist_ui_ops)
 
         #ft.c_purple_xfers_set_ui_ops(&c_ft_ui_ops)
         #roomlist.c_purple_roomlist_set_ui_ops(&c_rlist_ui_ops)
 
@@ -105,7 +108,7 @@ cdef class Purple:
         blist.c_purple_blist_set_ui_ops(NULL)
         conversation.c_purple_conversations_set_ui_ops(NULL)
         notify.c_purple_notify_set_ui_ops(NULL)
         blist.c_purple_blist_set_ui_ops(NULL)
         conversation.c_purple_conversations_set_ui_ops(NULL)
         notify.c_purple_notify_set_ui_ops(NULL)
-        #request.c_purple_request_set_ui_ops(NULL)
+        request.c_purple_request_set_ui_ops(NULL)
         #ft.c_purple_xfers_set_ui_ops(NULL)
         #roomlist.c_purple_roomlist_set_ui_ops(NULL)
 
         #ft.c_purple_xfers_set_ui_ops(NULL)
         #roomlist.c_purple_roomlist_set_ui_ops(NULL)
 
@@ -135,12 +138,14 @@ cdef class Purple:
             global connection_cbs
             global conversation_cbs
             global notify_cbs
             global connection_cbs
             global conversation_cbs
             global notify_cbs
+            global request_cbs
 
             account_cbs = callbacks_dict["account"]
             blist_cbs = callbacks_dict["blist"]
             connection_cbs = callbacks_dict["connection"]
             conversation_cbs = callbacks_dict["conversation"]
             notify_cbs = callbacks_dict["notify"]
 
             account_cbs = callbacks_dict["account"]
             blist_cbs = callbacks_dict["blist"]
             connection_cbs = callbacks_dict["connection"]
             conversation_cbs = callbacks_dict["conversation"]
             notify_cbs = callbacks_dict["notify"]
+            request_cbs = callbacks_dict["request"]
 
         c_account_ui_ops.notify_added = notify_added
         c_account_ui_ops.status_changed = status_changed
 
         c_account_ui_ops.notify_added = notify_added
         c_account_ui_ops.status_changed = status_changed
@@ -194,6 +199,14 @@ cdef class Purple:
         c_notify_ui_ops.notify_uri = notify_uri
         c_notify_ui_ops.close_notify = close_notify
 
         c_notify_ui_ops.notify_uri = notify_uri
         c_notify_ui_ops.close_notify = close_notify
 
+        c_request_ui_ops.request_input = request_input
+        c_request_ui_ops.request_choice = request_choice
+        c_request_ui_ops.request_action = request_action
+        c_request_ui_ops.request_fields = request_fields
+        c_request_ui_ops.request_file = request_file
+        c_request_ui_ops.close_request = close_request
+        c_request_ui_ops.request_folder = request_folder
+
         c_core_ui_ops.ui_prefs_init = <void (*)()> self.__core_ui_ops_ui_prefs_init
         c_core_ui_ops.debug_ui_init = <void (*)()> self.__core_ui_ops_debug_init
         c_core_ui_ops.ui_init = <void (*)()> self.__core_ui_ops_ui_init
         c_core_ui_ops.ui_prefs_init = <void (*)()> self.__core_ui_ops_ui_prefs_init
         c_core_ui_ops.debug_ui_init = <void (*)()> self.__core_ui_ops_debug_init
         c_core_ui_ops.ui_init = <void (*)()> self.__core_ui_ops_ui_init
diff --git a/request_cbs.pxd b/request_cbs.pxd
new file mode 100644 (file)
index 0000000..3057bdc
--- /dev/null
@@ -0,0 +1,118 @@
+#
+#  Copyright (c) 2008 INdT - Instituto Nokia de Tecnologia
+#
+#  This file is part of python-purple.
+#
+#  python-purple is free software: you can redistribute it and/or modify
+#  it under the terms of the GNU General Public License as published by
+#  the Free Software Foundation, either version 3 of the License, or
+#  (at your option) any later version.
+#
+#  python-purple is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+cimport purple
+
+cdef extern from *:
+    ctypedef char const_char "const char"
+    ctypedef int size_t
+    ctypedef void* va_list
+
+request_cbs = {}
+
+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, const_char *ok_text,
+                          glib.GCallback ok_cb, const_char *cancel_text,
+                          glib.GCallback cancel_cb,
+                          account.PurpleAccount *account, const_char *who,
+                          conversation.PurpleConversation *conv,
+                          void *user_data):
+    debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "request", "request_input\n")
+    try:
+        (<object>request_cbs["request_input"])("request_input")
+    except KeyError:
+        pass
+
+cdef void *request_choice (const_char *title, const_char *primary,
+                           const_char *secondary, int default_value,
+                           const_char *ok_text, glib.GCallback ok_cb,
+                           const_char *cancel_text,
+                           glib.GCallback cancel_cb,
+                           account.PurpleAccount *account, const_char *who,
+                           conversation.PurpleConversation *conv,
+                           void *user_data, va_list choices):
+    debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "request",
+                         "request_choice\n")
+    try:
+        (<object>request_cbs["request_choice"])("request_choice")
+    except KeyError:
+        pass
+
+cdef void *request_action (const_char *title, const_char *primary,
+                           const_char *secondary, int default_action,
+                           account.PurpleAccount *account, const_char *who,
+                           conversation.PurpleConversation *conv,
+                           void *user_data, size_t action_count,
+                           va_list actions):
+    debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "request",
+                         "request_action\n")
+    try:
+        (<object>request_cbs["request_action"])("request_action")
+    except KeyError:
+        pass
+
+cdef void *request_fields (const_char *title, const_char *primary,
+                           const_char *secondary,
+                           request.PurpleRequestFields *fields,
+                           const_char *ok_text, glib.GCallback ok_cb,
+                           const_char *cancel_text, glib.GCallback cancel_cb,
+                           account.PurpleAccount *account, const_char *who,
+                           conversation.PurpleConversation *conv,
+                           void *user_data):
+    debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "request",
+                         "request_fields\n")
+    try:
+        (<object>request_cbs["request_fields"])("request_fields")
+    except KeyError:
+        pass
+
+cdef void *request_file (const_char *title, const_char *filename,
+                         glib.gboolean savedialog, glib.GCallback ok_cb,
+                         glib.GCallback cancel_cb,
+                         account.PurpleAccount *account, const_char *who,
+                         conversation.PurpleConversation *conv,
+                         void *user_data):
+    debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "request", "request_file\n")
+    try:
+        (<object>request_cbs["request_file"])("request_file")
+    except KeyError:
+        pass
+
+cdef void close_request (request.PurpleRequestType type, void *ui_handle):
+    debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "request", "close_request\n")
+    try:
+        (<object>request_cbs["close_request"])("close_request")
+    except KeyError:
+        pass
+
+cdef void *request_folder (const_char *title, const_char *dirname,
+                           glib.GCallback ok_cb,
+                           glib.GCallback cancel_cb,
+                           account.PurpleAccount *account,
+                           const_char *who,
+                           conversation.PurpleConversation *conv,
+                           void *user_data):
+    debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "request",
+                         "request_folder\n")
+    try:
+        (<object>request_cbs["request_folder"])("request_folder")
+    except KeyError:
+        pass