From: Ragner Magalhaes Date: Tue, 2 Dec 2008 20:08:49 +0000 (+0000) Subject: Moved purple core ui ops to Cython code. X-Git-Url: http://git.maemo.org/git/?p=python-purple;a=commitdiff_plain;h=f93f815832876018b863a9595a9a0341baba7f7d;ds=sidebyside Moved purple core ui ops to Cython code. FIXES: - Added glib definitions used by purple core ui ops. - Moved purple core ui ops structures to Cython. Signed-off-by: Bruno Abinader git-svn-id: https://garage.maemo.org/svn/carman/branches/carman-0.7-beta2/python-purple@1274 596f6dd7-e928-0410-a184-9e12fd12cf7e --- diff --git a/c_purple.c b/c_purple.c index 5c1cb23..1130a5b 100644 --- a/c_purple.c +++ b/c_purple.c @@ -37,7 +37,8 @@ typedef struct _PurpleGLibIOClosure { gpointer data; } PurpleGLibIOClosure; -static gboolean purple_glib_io_invoke(GIOChannel *source, GIOCondition condition, gpointer data) +static gboolean purple_glib_io_invoke(GIOChannel *source, GIOCondition condition, + gpointer data) { PurpleGLibIOClosure *closure = data; PurpleInputCondition purple_cond = 0; @@ -53,7 +54,7 @@ static gboolean purple_glib_io_invoke(GIOChannel *source, GIOCondition condition return TRUE; } -static guint glib_input_add(gint fd, PurpleInputCondition condition, PurpleInputFunction function, +guint glib_input_add(gint fd, PurpleInputCondition condition, PurpleInputFunction function, gpointer data) { PurpleGLibIOClosure *closure = g_new0(PurpleGLibIOClosure, 1); @@ -75,95 +76,3 @@ static guint glib_input_add(gint fd, PurpleInputCondition condition, PurpleInput g_io_channel_unref(channel); return closure->result; } - -static PurpleEventLoopUiOps glib_eventloops = -{ - g_timeout_add, - g_source_remove, - glib_input_add, - g_source_remove, - NULL, -#if GLIB_CHECK_VERSION(2,14,0) - g_timeout_add_seconds, -#else - NULL, -#endif - - /* padding */ - NULL, - NULL, - NULL -}; -/*** End of the eventloop functions. ***/ - -/*** Conversation uiops ***/ -/* FIXME: Revisit this function. Is it needed? How it should be more general?*/ -static void -write_conv(PurpleConversation *conv, const char *who, const char *alias, - const char *message, PurpleMessageFlags flags, time_t mtime) -{ - const char *name; - if (alias && *alias) - name = alias; - else if (who && *who) - name = who; - else - name = NULL; - - printf("(%s) %s %s: %s\n", purple_conversation_get_name(conv), - purple_utf8_strftime("(%H:%M:%S)", localtime(&mtime)), - name, message); -} - -static PurpleConversationUiOps conv_uiops = -{ - NULL, /* create_conversation */ - NULL, /* destroy_conversation */ - NULL, /* write_chat */ - NULL, /* write_im */ - write_conv, /* write_conv */ - NULL, /* chat_add_users */ - NULL, /* chat_rename_user */ - NULL, /* chat_remove_users */ - NULL, /* chat_update_user */ - NULL, /* present */ - NULL, /* has_focus */ - NULL, /* custom_smiley_add */ - NULL, /* custom_smiley_write */ - NULL, /* custom_smiley_close */ - NULL, /* send_confirm */ - NULL, - NULL, - NULL, - NULL -}; - -/* FIXME: Is this a valid struct? */ -static void ui_init(void) -{ - /** - * This should initialize the UI components for all the modules. Here we - * just initialize the UI for conversations. - */ - purple_conversations_set_ui_ops(&conv_uiops); -} - -static PurpleCoreUiOps core_uiops = -{ - NULL, - NULL, - ui_init, - NULL, - - /* padding */ - NULL, - NULL, - NULL, - NULL -}; - -void set_uiops(void) -{ - purple_core_set_ui_ops(&core_uiops); - purple_eventloop_set_ui_ops(&glib_eventloops); -} diff --git a/c_purple.h b/c_purple.h index 016f186..84aa659 100644 --- a/c_purple.h +++ b/c_purple.h @@ -18,4 +18,5 @@ * */ -void set_uiops(void); +guint glib_input_add(gint fd, PurpleInputCondition condition, + PurpleInputFunction function, gpointer data); diff --git a/glib.pxd b/glib.pxd index b0a5d32..d71cb32 100644 --- a/glib.pxd +++ b/glib.pxd @@ -38,3 +38,6 @@ cdef extern from "glib.h": _GList *next _GList *prev ctypedef _GList GList + + guint g_timeout_add(guint interval, GSourceFunc function, gpointer data) + gboolean g_source_remove(guint tag) diff --git a/purple.pyx b/purple.pyx index efe8eed..8a9080c 100644 --- a/purple.pyx +++ b/purple.pyx @@ -26,8 +26,16 @@ cdef extern from "time.h": ctypedef long int time_t cdef extern from "libpurple/core.h": + ctypedef struct PurpleCoreUiOps: + void (*ui_prefs_init) () + void (*debug_ui_init) () + void (*ui_init) () + void (*quit) () + GHashTable (*get_ui_info) () + gboolean c_purple_core_init "purple_core_init" (const_char_ptr ui_name) void c_purple_core_quit "purple_core_quit" () + void c_purple_core_set_ui_ops "purple_core_set_ui_ops" (PurpleCoreUiOps *ops) gboolean c_purple_core_ensure_single_instance "purple_core_ensure_single_instance" () cdef extern from "libpurple/debug.h": @@ -42,17 +50,58 @@ cdef extern from "libpurple/debug.h": void c_purple_debug "purple_debug" (PurpleDebugLevel level, const_char_ptr category, const_char_ptr format) void c_purple_debug_set_enabled "purple_debug_set_enabled" (gboolean debug_enabled) +cdef extern from "libpurple/eventloop.h": + ctypedef enum PurpleInputCondition: + PURPLE_INPUT_READ + PURPLE_INPUT_WRITE + + ctypedef void (*PurpleInputFunction) (gpointer , gint, PurpleInputCondition) + + ctypedef struct PurpleEventLoopUiOps: + guint (*timeout_add) (guint interval, GSourceFunc function, gpointer data) + gboolean (*timeout_remove) (guint handle) + guint (*input_add) (int fd, PurpleInputCondition cond, PurpleInputFunction func, gpointer user_data) + gboolean (*input_remove) (guint handle) + int (*input_get_error) (int fd, int *error) + guint (*timeout_add_seconds)(guint interval, GSourceFunc function, gpointer data) + + void c_purple_eventloop_set_ui_ops "purple_eventloop_set_ui_ops" (PurpleEventLoopUiOps *ops) + cdef extern from "libpurple/plugin.h": void c_purple_plugins_add_search_path "purple_plugins_add_search_path" (const_char_ptr path) +cdef extern from "libpurple/prefs.h": + void c_purple_prefs_rename "purple_prefs_rename" (const_char_ptr oldname, const_char_ptr newname) + const_char_ptr c_purple_prefs_get_string "purple_prefs_get_string" (const_char_ptr name) + gboolean c_purple_prefs_load "purple_prefs_load" () + cdef extern from "libpurple/util.h": void c_purple_util_set_user_dir "purple_util_set_user_dir" (char *dir) cdef extern from "c_purple.h": void set_uiops() + guint glib_input_add(gint fd, PurpleInputCondition condition, PurpleInputFunction function, gpointer data) + +cdef void ui_init(): + pass class Purple(object): def __init__(self): + cdef PurpleCoreUiOps c_core_ui_ops + c_core_ui_ops.ui_prefs_init = NULL + c_core_ui_ops.debug_ui_init = NULL + c_core_ui_ops.ui_init = ui_init + c_core_ui_ops.quit = NULL + c_core_ui_ops.get_ui_info = NULL + + cdef PurpleEventLoopUiOps c_eventloop_ui_ops + c_eventloop_ui_ops.timeout_add = g_timeout_add + c_eventloop_ui_ops.timeout_remove = g_source_remove + c_eventloop_ui_ops.input_add = glib_input_add + c_eventloop_ui_ops.input_remove = g_source_remove + c_eventloop_ui_ops.input_get_error = NULL + c_eventloop_ui_ops.timeout_add_seconds = NULL + self.DEFAULT_PATH = "/home/user/MyDocs/Carman" self.APP_NAME = "carman-purple-python" @@ -60,7 +109,8 @@ class Purple(object): self.util_set_user_dir(self.DEFAULT_PATH) self.plugin_add_search_path(self.DEFAULT_PATH) - set_uiops() + c_purple_core_set_ui_ops(&c_core_ui_ops) + c_purple_eventloop_set_ui_ops(&c_eventloop_ui_ops) ret = self.core_init(self.APP_NAME) if ret is False: @@ -133,6 +183,18 @@ class Purple(object): c_purple_plugins_add_search_path(path) # plugin_add_search_path + def prefs_rename(self, old_name, new_name): + c_purple_prefs_rename(old_name, new_name) + # prefs_rename + + def prefs_get_string(self, name): + return c_purple_prefs_get_string(name) + # prefs_get_string + + def prefs_load(self): + return c_purple_prefs_load() + # prefs_load + def util_set_user_dir(self, dir): c_purple_util_set_user_dir(dir) # util_set_user_dir @@ -141,7 +203,5 @@ class Purple(object): #include "core/blist.pxd" #include "core/connection.pxd" #include "core/core.pxd" -#include "core/eventloop.pxd" #include "core/idle.pxd" #include "core/pounce.pxd" -#include "core/prefs.pxd" diff --git a/setup.py b/setup.py index 128df44..d492a9c 100755 --- a/setup.py +++ b/setup.py @@ -23,9 +23,8 @@ setup( version = '0.1', author ='Bruno Abinader', author_email='bruno.abinader@openbossa.org', + cmdclass = {'build_ext': pypurple_build_ext}, ext_modules=[Extension('purple', sources=['c_purple.c','purple.pyx'], extra_compile_args=cflags, - extra_link_args=ldflags)], - cmdclass = {'build_ext': pypurple_build_ext}, -) + extra_link_args=ldflags)])