Add support to console's input to nullclient.py
[python-purple] / purple.pyx
index 94613f2..35f5a09 100644 (file)
@@ -21,79 +21,36 @@ include "glib.pxd"
 
 cdef extern from *:
     ctypedef char* const_char_ptr "const char *"
 
 cdef extern from *:
     ctypedef char* const_char_ptr "const char *"
+    ctypedef char* const_guchar_ptr "const guchar *"
 
 cdef extern from "time.h":
     ctypedef long int time_t
 
 
 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) ()
-        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":
-    ctypedef enum PurpleDebugLevel:
-        PURPLE_DEBUG_ALL
-        PURPLE_DEBUG_MISC
-        PURPLE_DEBUG_INFO
-        PURPLE_DEBUG_WARNING
-        PURPLE_DEBUG_ERROR
-        PURPLE_DEBUG_FATAL
-
-    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/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" ()
-
-cdef extern from "libpurple/util.h":
-    void c_purple_util_set_user_dir "purple_util_set_user_dir" (char *dir)
+include "libpurple/account.pxd"
+include "libpurple/buddyicon.pxd"
+include "libpurple/blist.pxd"
+include "libpurple/connection.pxd"
+include "libpurple/conversation.pxd"
+include "libpurple/core.pxd"
+include "libpurple/debug.pxd"
+include "libpurple/eventloop.pxd"
+include "libpurple/idle.pxd"
+include "libpurple/plugin.pxd"
+include "libpurple/pounce.pxd"
+include "libpurple/prefs.pxd"
+include "libpurple/proxy.pxd"
+include "libpurple/signals.pxd"
+include "libpurple/status.pxd"
+include "libpurple/savedstatuses.pxd"
+include "libpurple/util.pxd"
 
 cdef extern from "c_purple.h":
 
 cdef extern from "c_purple.h":
-     guint glib_input_add(gint fd, PurpleInputCondition condition, PurpleInputFunction function, gpointer data)
+    void connect_to_signals_for_demonstration_purposes_only ()
+    guint glib_input_add(gint fd, PurpleInputCondition condition, PurpleInputFunction function, gpointer data)
 
 
-__DEFAULT_PATH__ = "/home/user/MyDocs/Carman"
+import ecore
+
+__DEFAULT_PATH__ = "/tmp"
 __APP_NAME__ = "carman-purple-python"
 __APP_VERSION__ = "0.1"
 
 __APP_NAME__ = "carman-purple-python"
 __APP_VERSION__ = "0.1"
 
@@ -119,6 +76,9 @@ cdef class Purple:
         c_purple_debug_set_enabled(debug_enabled)
         c_purple_util_set_user_dir(default_path)
         c_purple_plugins_add_search_path(default_path)
         c_purple_debug_set_enabled(debug_enabled)
         c_purple_util_set_user_dir(default_path)
         c_purple_plugins_add_search_path(default_path)
+
+        # adds glib iteration inside ecore main loop
+        ecore.idler_add(self.__glib_iteration_when_idle)
      # __cinit__
 
     def __del__(self):
      # __cinit__
 
     def __del__(self):
@@ -146,7 +106,6 @@ cdef class Purple:
     # __core_ui_ops_quit
 
     cdef GHashTable *__core_ui_ops_get_ui_info(self):
     # __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)
 
         if self.c_ui_info == NULL:
             self.c_ui_info = g_hash_table_new(g_str_hash, g_str_equal)
 
@@ -155,6 +114,11 @@ cdef class Purple:
         return self.c_ui_info
     # __core_ui_ops_get_ui_info
 
         return self.c_ui_info
     # __core_ui_ops_get_ui_info
 
+    def __glib_iteration_when_idle(self):
+        g_main_context_iteration(NULL, False)
+        return True
+    # __glib_iteration_when_idle
+
     def purple_init(self):
         """ Initializes libpurple """
         # initialize c_core_ui_ops structure
     def purple_init(self):
         """ Initializes libpurple """
         # initialize c_core_ui_ops structure
@@ -162,7 +126,7 @@ cdef class Purple:
         self.c_core_ui_ops.debug_ui_init = <void (*)()> self.__core_ui_ops_debug_init
         self.c_core_ui_ops.ui_init = <void (*)()> self.__core_ui_ops_ui_init
         self.c_core_ui_ops.quit = <void (*)()> self.__core_ui_ops_quit
         self.c_core_ui_ops.debug_ui_init = <void (*)()> self.__core_ui_ops_debug_init
         self.c_core_ui_ops.ui_init = <void (*)()> self.__core_ui_ops_ui_init
         self.c_core_ui_ops.quit = <void (*)()> self.__core_ui_ops_quit
-        self.c_core_ui_ops.get_ui_info = <GHashTable (*)()> self.__core_ui_ops_get_ui_info
+        self.c_core_ui_ops.get_ui_info = <GHashTable* (*)()> self.__core_ui_ops_get_ui_info
 
         c_purple_core_set_ui_ops(&self.c_core_ui_ops)
 
 
         c_purple_core_set_ui_ops(&self.c_core_ui_ops)
 
@@ -194,13 +158,30 @@ cdef class Purple:
 
         # load pounces
         c_purple_pounces_load()
 
         # load pounces
         c_purple_pounces_load()
-        return ret
-    # core_init
 
 
+        return ret
+    # purple_init
+
+    def get_protocols(self):
+        cdef GList *iter
+        cdef PurplePlugin *plugin
+        protocols = []
+        iter = c_purple_plugins_get_protocols()
+        while iter:
+            plugin = <PurplePlugin*> iter.data
+            if plugin.info and plugin.info.name:
+                protocols += [(plugin.info.id, plugin.info.name)]
+            iter = iter.next
+        return protocols
+    # get_protocols
+
+    def connect(self):
+        conn = Connection()
+        conn.connect()
+    # connect
 # Purple
 
 # Purple
 
-include "core/account.pxd"
-include "core/buddy.pxd"
-#include "core/connection.pxd"
-#include "core/core.pxd"
-#include "core/idle.pxd"
+include "account.pxd"
+include "buddy.pxd"
+include "connection.pxd"
+include "conversation.pxd"