Moved debug methods outside Purple class, added core ui ops callback examples.
authorRagner Magalhaes <ragner.magalhaes@openbossa.org>
Tue, 2 Dec 2008 20:10:12 +0000 (20:10 +0000)
committerAnderson Briglia <anderson.briglia@openbossa.org>
Sat, 28 Feb 2009 21:11:09 +0000 (17:11 -0400)
FIXES:
 - Moved debug_* methods outside Purple class, so they can be used by anyone.
 - Added core ui ops callback examples.

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@1277 596f6dd7-e928-0410-a184-9e12fd12cf7e

glib.pxd
purple.pyx

index d71cb32..e24b2ed 100644 (file)
--- a/glib.pxd
+++ b/glib.pxd
@@ -19,6 +19,7 @@
 
 cdef extern from "glib.h":
     ctypedef void *gpointer
 
 cdef extern from "glib.h":
     ctypedef void *gpointer
+    ctypedef void *gconstpointer
     ctypedef int gint
     ctypedef unsigned int guint
     ctypedef gint gboolean
     ctypedef int gint
     ctypedef unsigned int guint
     ctypedef gint gboolean
@@ -39,5 +40,15 @@ cdef extern from "glib.h":
         _GList *prev
     ctypedef _GList GList
 
         _GList *prev
     ctypedef _GList GList
 
+    ctypedef guint GHashFunc (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 )
+
     guint g_timeout_add(guint interval, GSourceFunc function, gpointer data)
     guint g_timeout_add(guint interval, GSourceFunc function, gpointer data)
+    guint g_timeout_add_seconds(guint interval, GSourceFunc function, gpointer data)
+
     gboolean g_source_remove(guint tag)
     gboolean g_source_remove(guint tag)
index 63d008c..0ca9b87 100644 (file)
@@ -82,17 +82,72 @@ cdef extern from "c_purple.h":
      void set_uiops()
      guint glib_input_add(gint fd, PurpleInputCondition condition, PurpleInputFunction function, gpointer data)
 
      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):
+__DEFAULT_PATH__ = "/home/user/MyDocs/Carman"
+__APP_NAME__ = "carman-purple-python"
+__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
+
+cdef class Purple:
+    def __cinit__(self):
         cdef PurpleCoreUiOps c_core_ui_ops
         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
+        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
 
         cdef PurpleEventLoopUiOps c_eventloop_ui_ops
         c_eventloop_ui_ops.timeout_add = g_timeout_add
@@ -100,26 +155,23 @@ class Purple(object):
         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.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"
+        c_eventloop_ui_ops.timeout_add_seconds = g_timeout_add_seconds
 
         self.debug_set_enabled(True)
 
         self.debug_set_enabled(True)
-        self.util_set_user_dir(self.DEFAULT_PATH)
-        self.plugin_add_search_path(self.DEFAULT_PATH)
+        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)
 
 
         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)
+        ret = self.core_init(__APP_NAME__)
         if ret is False:
         if ret is False:
-            self.debug_info("main", "Exiting because libpurple initialization failed.")
+            debug_info("main", "Exiting because libpurple initialization failed.")
             return
 
         # check if there is another instance of libpurple running
         if self.core_ensure_single_instance() == False:
             return
 
         # check if there is another instance of libpurple running
         if self.core_ensure_single_instance() == False:
-            self.debug_info("main", "Exiting because another instance of libpurple is already running.")
+            debug_info("main", "Exiting because another instance of libpurple is already running.")
             self.core_quit()
             return
     # __init__
             self.core_quit()
             return
     # __init__
@@ -140,41 +192,6 @@ class Purple(object):
         c_purple_core_quit()
     # core_quit
 
         c_purple_core_quit()
     # core_quit
 
-    def debug_misc(self, 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(self, 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(self, 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(self, 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(self, category, format):
-        if category == None:
-            c_purple_debug(PURPLE_DEBUG_FATAL, NULL, format)
-        else:
-            c_purple_debug(PURPLE_DEBUG_FATAL, category, format)
-    # debug_fatal
-
     def debug_set_enabled(self, debug_enabled):
         c_purple_debug_set_enabled(debug_enabled)
     # debug_set_enabled
     def debug_set_enabled(self, debug_enabled):
         c_purple_debug_set_enabled(debug_enabled)
     # debug_set_enabled