From: Ragner Magalhaes Date: Tue, 2 Dec 2008 20:10:51 +0000 (+0000) Subject: Moved all Purple class callbacks inside, moved blist and pounce inside Purple. X-Git-Url: http://git.maemo.org/git/?p=python-purple;a=commitdiff_plain;h=61d2c35c5084836d751dda7bd0ee63ad09a9e9ea;hp=4dd540b8a4896ede6e99f7c7869fddf417d90f1a Moved all Purple class callbacks inside, moved blist and pounce inside Purple. FIXES: - Moved all Purple class callbacks inside. - Moved blist and pounce inside Purple. - All C-functions are now called directly. Signed-off-by: Bruno Abinader git-svn-id: https://garage.maemo.org/svn/carman/branches/carman-0.7-beta2/python-purple@1278 596f6dd7-e928-0410-a184-9e12fd12cf7e --- diff --git a/core/blist.pxd b/core/blist.pxd deleted file mode 100644 index cb94f6b..0000000 --- a/core/blist.pxd +++ /dev/null @@ -1,44 +0,0 @@ -# -# 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 . -# - -cdef extern from "libpurple/blist.h": - ctypedef struct PurpleBuddyList: - pass - - void c_purple_set_blist "purple_set_blist" (PurpleBuddyList *list) - void c_purple_blist_load "purple_blist_load" () - PurpleBuddyList* purple_blist_new "purple_blist_new" () - -class BList(object): - """ BList class """ - - def __init__(self): - purple_buddy_list = None - - # FIXME - """ - def purple_set_blist(self, list): - c_purple_set_blist(list) - - def purple_blist_load(self): - c_purple_blist_load() - - def purple_blist_new(self): - return c_purple_blist_new() - """ diff --git a/core/pounce.pxd b/core/pounce.pxd deleted file mode 100644 index 2421569..0000000 --- a/core/pounce.pxd +++ /dev/null @@ -1,30 +0,0 @@ -# -# 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 . -# - -cdef extern from "libpurple/pounce.h": - gboolean c_purple_pounces_load "purple_pounces_load" () - -class Pounce(object): - """ Pounce class """ - - def __init__(self): - pass - - def purple_pounces_load(): - return c_purple_pounces_load() diff --git a/glib.pxd b/glib.pxd index e24b2ed..d0cf22f 100644 --- a/glib.pxd +++ b/glib.pxd @@ -27,7 +27,7 @@ cdef extern from "glib.h": # GHashTable is an opaque data structure ctypedef struct GHashTable: - void *none + pass struct _GSList: gpointer data @@ -41,12 +41,13 @@ cdef extern from "glib.h": ctypedef _GList GList ctypedef guint GHashFunc (gconstpointer) + ctypedef gboolean GEqualFunc (gconstpointer, gconstpointer) gboolean g_str_equal (gconstpointer, gconstpointer) guint g_str_hash (gconstpointer) GHashTable *g_hash_table_new (GHashFunc, GEqualFunc) - void g_hash_table_insert (GHashTable*, gpointer, gpointer ) + void g_hash_table_insert (GHashTable*, gpointer, gpointer) guint g_timeout_add(guint interval, GSourceFunc function, gpointer data) guint g_timeout_add_seconds(guint interval, GSourceFunc function, gpointer data) diff --git a/purple.pyx b/purple.pyx index 0ca9b87..94613f2 100644 --- a/purple.pyx +++ b/purple.pyx @@ -25,6 +25,14 @@ cdef extern from *: cdef extern from "time.h": ctypedef long int time_t +cdef extern from "libpurple/blist.h": + ctypedef struct PurpleBuddyList: + pass + + void c_purple_set_blist "purple_set_blist" (PurpleBuddyList *list) + void c_purple_blist_load "purple_blist_load" () + PurpleBuddyList* c_purple_blist_new "purple_blist_new" () + cdef extern from "libpurple/core.h": ctypedef struct PurpleCoreUiOps: void (*ui_prefs_init) () @@ -70,7 +78,11 @@ cdef extern from "libpurple/eventloop.h": 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/pounce.h": + gboolean c_purple_pounces_load "purple_pounces_load" () + cdef extern from "libpurple/prefs.h": + void c_purple_prefs_add_none "purple_prefs_add_none" (const_char_ptr name) 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" () @@ -79,7 +91,6 @@ 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) __DEFAULT_PATH__ = "/home/user/MyDocs/Carman" @@ -88,138 +99,108 @@ __APP_VERSION__ = "0.1" global __DEFAULT_PATH__ global __APP_NAME__ - -def debug_misc(category, format): - if category == None: - c_purple_debug(PURPLE_DEBUG_MISC, NULL, format) - else: - c_purple_debug(PURPLE_DEBUG_MISC, category, format) -# debug_misc - -def debug_info(category, format): - if category == None: - c_purple_debug(PURPLE_DEBUG_INFO, NULL, format) - else: - c_purple_debug(PURPLE_DEBUG_INFO, category, format) -# debug_info - -def debug_warning(category, format): - if category == None: - c_purple_debug(PURPLE_DEBUG_WARNING, NULL, format) - else: - c_purple_debug(PURPLE_DEBUG_WARNING, category, format) -# debug_warning - -def debug_error(category, format): - if category == None: - c_purple_debug(PURPLE_DEBUG_ERROR, NULL, format) - else: - c_purple_debug(PURPLE_DEBUG_ERROR, category, format) -# debug_error - -def debug_fatal(category, format): - if category == None: - c_purple_debug(PURPLE_DEBUG_FATAL, NULL, format) - else: - c_purple_debug(PURPLE_DEBUG_FATAL, category, format) -# debug_fatal - -cdef void core_ui_ops_ui_prefs_init(): - debug_info("core_ui_ops", "ui_prefs_init") -# core_ui_ops_ui_prefs_init - -cdef void core_ui_ops_debug_ui_init(): - debug_info("core_ui_ops", "debug_ui_init") -# core_ui_ops_debug_ui_init - -cdef void core_ui_ops_ui_init(): - debug_info("core_ui_ops", "ui_init") -# core_ui_ops_ui_init - -cdef void core_ui_ops_quit(): - debug_info("core_ui_ops", "quit") -# core_ui_ops_quit +global __APP_VERSION__ cdef class Purple: - def __cinit__(self): - cdef PurpleCoreUiOps c_core_ui_ops - c_core_ui_ops.ui_prefs_init = core_ui_ops_ui_prefs_init - c_core_ui_ops.debug_ui_init = core_ui_ops_debug_ui_init - c_core_ui_ops.ui_init = core_ui_ops_ui_init - c_core_ui_ops.quit = core_ui_ops_quit - c_core_ui_ops.get_ui_info = NULL # FIXME - - 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 = g_timeout_add_seconds - - self.debug_set_enabled(True) - self.util_set_user_dir(__DEFAULT_PATH__) - self.plugin_add_search_path(__DEFAULT_PATH__) - - c_purple_core_set_ui_ops(&c_core_ui_ops) - c_purple_eventloop_set_ui_ops(&c_eventloop_ui_ops) - - ret = self.core_init(__APP_NAME__) - if ret is False: - debug_info("main", "Exiting because libpurple initialization failed.") - return + """ Purple class """ + cdef PurpleCoreUiOps c_core_ui_ops + cdef PurpleEventLoopUiOps c_eventloop_ui_ops + cdef GHashTable *c_ui_info - # check if there is another instance of libpurple running - if self.core_ensure_single_instance() == False: - debug_info("main", "Exiting because another instance of libpurple is already running.") - self.core_quit() - return - # __init__ + def __cinit__(self, debug_enabled=True, app_name=__APP_NAME__, default_path=__DEFAULT_PATH__): + self.c_ui_info = NULL - def __del__(self): - self.core_quit() - # __del__ + if app_name is not __APP_NAME__: + __APP_NAME__ = app_name - def core_ensure_single_instance(self): - return c_purple_core_ensure_single_instance() - # core_ensure_single_instance - - def core_init(self, ui_name): - return c_purple_core_init(ui_name) - # core_init + if default_path is not __DEFAULT_PATH__: + __DEFAULT_PATH__ = default_path - def core_quit(self): - c_purple_core_quit() - # core_quit - - def debug_set_enabled(self, debug_enabled): c_purple_debug_set_enabled(debug_enabled) - # debug_set_enabled - - def plugin_add_search_path(self, path): - c_purple_plugins_add_search_path(path) - # plugin_add_search_path + c_purple_util_set_user_dir(default_path) + c_purple_plugins_add_search_path(default_path) + # __cinit__ - def prefs_rename(self, old_name, new_name): - c_purple_prefs_rename(old_name, new_name) - # prefs_rename + def __del__(self): + c_purple_core_quit() + # __del__ - def prefs_get_string(self, name): - return c_purple_prefs_get_string(name) - # prefs_get_string + cdef void __core_ui_ops_ui_prefs_init(self): + c_purple_debug(PURPLE_DEBUG_INFO, "core_ui_ops", "ui_prefs_init\n") + c_purple_prefs_load() + + c_purple_prefs_add_none("/carman") + c_purple_prefs_add_none("/carman/plugins") + # __core_ui_ops_ui_prefs_init + + cdef void __core_ui_ops_debug_init(self): + c_purple_debug(PURPLE_DEBUG_INFO, "core_ui_ops", "debug_ui_init\n") + # __core_ui_ops_debug_init + + cdef void __core_ui_ops_ui_init(self): + c_purple_debug(PURPLE_DEBUG_INFO, "core_ui_ops", "ui_init\n") + # __core_ui_ops_ui_init + + cdef void __core_ui_ops_quit(self): + c_purple_debug(PURPLE_DEBUG_INFO, "core_ui_ops", "quit\n") + # __core_ui_ops_quit + + cdef GHashTable *__core_ui_ops_get_ui_info(self): + # FIXME: warning: assignment from incompatible pointer type + if self.c_ui_info == NULL: + self.c_ui_info = g_hash_table_new(g_str_hash, g_str_equal) + + g_hash_table_insert(self.c_ui_info, "name", __APP_NAME__) + g_hash_table_insert(self.c_ui_info, "version", __APP_VERSION__) + return self.c_ui_info + # __core_ui_ops_get_ui_info + + def purple_init(self): + """ Initializes libpurple """ + # initialize c_core_ui_ops structure + self.c_core_ui_ops.ui_prefs_init = self.__core_ui_ops_ui_prefs_init + self.c_core_ui_ops.debug_ui_init = self.__core_ui_ops_debug_init + self.c_core_ui_ops.ui_init = self.__core_ui_ops_ui_init + self.c_core_ui_ops.quit = self.__core_ui_ops_quit + self.c_core_ui_ops.get_ui_info = self.__core_ui_ops_get_ui_info + + c_purple_core_set_ui_ops(&self.c_core_ui_ops) + + # initialize c_eventloop_ui_ops structure + self.c_eventloop_ui_ops.timeout_add = g_timeout_add + self.c_eventloop_ui_ops.timeout_remove = g_source_remove + self.c_eventloop_ui_ops.input_add = glib_input_add + self.c_eventloop_ui_ops.input_remove = g_source_remove + self.c_eventloop_ui_ops.input_get_error = NULL + self.c_eventloop_ui_ops.timeout_add_seconds = g_timeout_add_seconds + + c_purple_eventloop_set_ui_ops(&self.c_eventloop_ui_ops) + + # initialize purple core + ret = c_purple_core_init(__APP_NAME__) + if ret is False: + c_purple_debug(PURPLE_DEBUG_INFO, "main", "Exiting because libpurple initialization failed.\n") + return False - def prefs_load(self): - return c_purple_prefs_load() - # prefs_load + # check if there is another instance of libpurple running + if c_purple_core_ensure_single_instance() == False: + c_purple_debug(PURPLE_DEBUG_INFO, "main", "Exiting because another instance of libpurple is already running.\n") + c_purple_core_quit() + return False + + # create and load the buddy list + c_purple_set_blist(c_purple_blist_new()) + c_purple_blist_load() + + # load pounces + c_purple_pounces_load() + return ret + # core_init - def util_set_user_dir(self, dir): - c_purple_util_set_user_dir(dir) - # util_set_user_dir +# Purple include "core/account.pxd" include "core/buddy.pxd" -#include "core/blist.pxd" #include "core/connection.pxd" #include "core/core.pxd" #include "core/idle.pxd" -#include "core/pounce.pxd"