From: Ragner Magalhaes Date: Tue, 2 Dec 2008 20:28:01 +0000 (+0000) Subject: Added PurpleNotifyUiOps callbacks. X-Git-Url: http://git.maemo.org/git/?p=python-purple;a=commitdiff_plain;h=b78bc0997c89809be6986f4daf7ec162e0009c72;ds=sidebyside Added PurpleNotifyUiOps callbacks. FIXES: - Added missing structures on notify.pxd. - Added notify callbacks forwarding on purple.pyx. - Added notify callbacks example on nullclient.py. - Added c-based callbacks on notify_cbs.pxd. Signed-off-by: Bruno Abinader git-svn-id: https://garage.maemo.org/svn/carman/branches/carman-0.7-beta2/python-purple@1307 596f6dd7-e928-0410-a184-9e12fd12cf7e --- diff --git a/libpurple/notify.pxd b/libpurple/notify.pxd index c45c60a..e94ceb7 100644 --- a/libpurple/notify.pxd +++ b/libpurple/notify.pxd @@ -17,8 +17,79 @@ # along with this program. If not, see . # +cimport glib + +cimport connection + +cdef extern from *: + ctypedef char const_char "const char" + ctypedef int size_t + cdef extern from "libpurple/notify.h": + ctypedef struct PurpleNotifyUserInfoEntry + ctypedef struct PurpleNotifyUserInfo + + ctypedef void (*PurpleNotifyCloseCallback) (glib.gpointer user_data) + + ctypedef enum PurpleNotifyType: + PURPLE_NOTIFY_MESSAGE = 0 + PURPLE_NOTIFY_EMAIL + PURPLE_NOTIFY_EMAILS + PURPLE_NOTIFY_FORMATTED + PURPLE_NOTIFY_SEARCHRESULTS + PURPLE_NOTIFY_USERINFO + PURPLE_NOTIFY_URI + + ctypedef enum PurpleNotifyMsgType: + PURPLE_NOTIFY_MSG_ERROR = 0 + PURPLE_NOTIFY_MSG_WARNING + PURPLE_NOTIFY_MSG_INFO + + ctypedef enum PurpleNotifySearchButtonType: + PURPLE_NOTIFY_BUTTON_LABELED = 0 + PURPLE_NOTIFY_BUTTON_CONTINUE = 1 + PURPLE_NOTIFY_BUTTON_ADD + PURPLE_NOTIFY_BUTTON_INFO + PURPLE_NOTIFY_BUTTON_IM + PURPLE_NOTIFY_BUTTON_JOIN + PURPLE_NOTIFY_BUTTON_INVITE + + ctypedef struct PurpleNotifySearchResults: + glib.GList *columns + glib.GList *rows + glib.GList *buttons + + ctypedef struct PurpleNotifySearchColumn: + char *title + + ctypedef void (*PurpleNotifySearchResultsCallback) (connection.PurpleConnection *c, glib.GList *row, glib.gpointer user_data) + + ctypedef struct purpleNotifySearchButton: + PurpleNotifySearchButtonType type + PurpleNotifySearchResultsCallback callback + char *label + ctypedef struct PurpleNotifyUiOps: - pass + void *(*notify_message) (PurpleNotifyMsgType type, const_char *title, \ + const_char *primary, const_char *secondary) + void *(*notify_email) (connection.PurpleConnection *gc, \ + const_char *subject, const_char *_from, const_char *to, \ + const_char *url) + void *(*notify_emails) (connection.PurpleConnection *gc, + size_t count, glib.gboolean detailed, const_char **subjects, \ + const_char **froms, const_char **tos, const_char **urls) + void *(*notify_formatted) (const_char *title, const_char *primary, \ + const_char *secondary, const_char *text) + void *(*notify_searchresults) (connection.PurpleConnection *gc, \ + const_char *title, const_char *primary, \ + const_char *secondary, PurpleNotifySearchResults *results, \ + glib.gpointer user_data) + void (*notify_searchresults_new_rows) \ + (connection.PurpleConnection *gc, \ + PurpleNotifySearchResults *results, void *data) + void *(*notify_userinfo) (connection.PurpleConnection *gc, \ + const_char *who, PurpleNotifyUserInfo *user_info) + void *(*notify_uri) (const_char *uri) + void (*close_notify) (PurpleNotifyType type, void *ui_handle) void c_purple_notify_set_ui_ops "purple_notify_set_ui_ops" (PurpleNotifyUiOps *ops) diff --git a/notify_cbs.pxd b/notify_cbs.pxd new file mode 100644 index 0000000..d029ef9 --- /dev/null +++ b/notify_cbs.pxd @@ -0,0 +1,104 @@ +# +# 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 . +# + +cimport purple + +notify_cbs = {} + +cdef extern from *: + ctypedef char const_char "const char" + ctypedef int size_t + +cdef void *notify_message (notify.PurpleNotifyMsgType type, const_char *title, + const_char *primary, const_char *secondary): + debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "notify", "notify_message\n") + try: + (notify_cbs["notify_message"])("notify_message") + except KeyError: + pass + +cdef void *notify_email (connection.PurpleConnection *gc, const_char *subject, + const_char *_from, const_char *to, const_char *url): + debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "notify", "notify_email\n") + try: + (notify_cbs["notify_email"])("notify_email") + except KeyError: + pass + +cdef void *notify_emails (connection.PurpleConnection *gc, size_t count, + glib.gboolean detailed, const_char **subjects, + const_char **froms, const_char **tos, + const_char **urls): + debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "notify", "notify_emails\n") + try: + (notify_cbs["notify_emails"])("notify_emails") + except KeyError: + pass + +cdef void *notify_formatted (const_char *title, const_char *primary, + const_char *secondary, const_char *text): + debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "notify", "notify_formatted\n") + try: + (notify_cbs["notify_formatted"])("notify_formatted") + except KeyError: + pass + +cdef void *notify_searchresults (connection.PurpleConnection *gc, + const_char *title, const_char *primary, + const_char *secondary, + notify.PurpleNotifySearchResults *results, + glib.gpointer user_data): + debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "notify", + "notify_searchresults\n") + try: + (notify_cbs["notify_searchresults"])("notify_searchresults") + except KeyError: + pass + +cdef void notify_searchresults_new_rows (connection.PurpleConnection *gc, + notify.PurpleNotifySearchResults *results, + void *data): + debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "notify", + "notify_searchresults_new_rows\n") + try: + (notify_cbs["notify_searchresults_new_rows"])("notify_searchresults_new_rows") + except KeyError: + pass + +cdef void *notify_userinfo (connection.PurpleConnection *gc, const_char *who, + notify.PurpleNotifyUserInfo *user_info): + debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "notify", "notify_userinfo\n") + try: + (notify_cbs["notify_userinfo"])("notify_userinfo") + except KeyError: + pass + +cdef void *notify_uri (const_char *uri): + debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "notify", "notify_uri\n") + try: + (notify_cbs["notify_uri"])("notify_uri") + except KeyError: + pass + +cdef void close_notify (notify.PurpleNotifyType type, void *ui_handle): + debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "notify", "close_notify\n") + try: + (notify_cbs["close_notify"])("close_notify") + except KeyError: + pass diff --git a/nullclient.py b/nullclient.py index 4953a1f..546f013 100644 --- a/nullclient.py +++ b/nullclient.py @@ -8,6 +8,7 @@ acc_cbs = {} blist_cbs = {} conn_cbs = {} conv_cbs = {} +notify_cbs = {} def account_callback(name): print "---- account callback example: %s" % name @@ -71,9 +72,24 @@ conv_cbs["send_confirm"] = conv_callback cbs["conversation"] = conv_cbs +def notify_callback(name): + print "---- notify callback example: %s" % name + +notify_cbs["notify_message"] = notify_callback +notify_cbs["notify_email"] = notify_callback +notify_cbs["notify_emails"] = notify_callback +notify_cbs["notify_formatted"] = notify_callback +notify_cbs["notify_searchresults"] = notify_callback +notify_cbs["notify_searchresults_new_rows"] = notify_callback +notify_cbs["notify_userinfo"] = notify_callback +notify_cbs["notify_uri"] = notify_callback +notify_cbs["close_notify"] = notify_callback + +cbs["notify"] = notify_cbs + class NullClient: def __init__(self): - self.p = purple.Purple() + self.p = purple.Purple(debug_enabled=False) self.account = None def execute(self): diff --git a/purple.pyx b/purple.pyx index 10dcd62..94317e9 100644 --- a/purple.pyx +++ b/purple.pyx @@ -35,7 +35,7 @@ cdef conversation.PurpleConversationUiOps c_conv_ui_ops 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 notify.PurpleNotifyUiOps c_notify_ui_ops #cdef request.PurpleRequestUiOps c_request_ui_ops #cdef roomlist.PurpleRoomlistUiOps c_rlist_ui_ops @@ -47,6 +47,7 @@ include "account_cbs.pxd" include "blist_cbs.pxd" include "connection_cbs.pxd" include "conversation_cbs.pxd" +include "notify_cbs.pxd" cdef class Purple: """ Purple class. @@ -89,7 +90,7 @@ cdef class Purple: connection.c_purple_connections_set_ui_ops(&c_conn_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) + notify.c_purple_notify_set_ui_ops(&c_notify_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) @@ -104,9 +105,9 @@ 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) - request.c_purple_request_set_ui_ops(NULL) - ft.c_purple_xfers_set_ui_ops(NULL) - roomlist.c_purple_roomlist_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) if c_ui_info: glib.g_hash_table_destroy(c_ui_info) @@ -133,11 +134,13 @@ cdef class Purple: global blist_cbs global connection_cbs global conversation_cbs + global notify_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"] c_account_ui_ops.notify_added = notify_added c_account_ui_ops.status_changed = status_changed @@ -181,6 +184,16 @@ cdef class Purple: c_conv_ui_ops.custom_smiley_close = custom_smiley_close c_conv_ui_ops.send_confirm = send_confirm + c_notify_ui_ops.notify_message = notify_message + c_notify_ui_ops.notify_email = notify_email + c_notify_ui_ops.notify_emails = notify_emails + c_notify_ui_ops.notify_formatted = notify_formatted + c_notify_ui_ops.notify_searchresults = notify_searchresults + c_notify_ui_ops.notify_searchresults_new_rows = notify_searchresults_new_rows + c_notify_ui_ops.notify_userinfo = notify_userinfo + c_notify_ui_ops.notify_uri = notify_uri + c_notify_ui_ops.close_notify = close_notify + c_core_ui_ops.ui_prefs_init = self.__core_ui_ops_ui_prefs_init c_core_ui_ops.debug_ui_init = self.__core_ui_ops_debug_init c_core_ui_ops.ui_init = self.__core_ui_ops_ui_init