Fix compilation error using python2.7
[python-purple] / purple.pyx
index 0005f73..5ff3e77 100644 (file)
@@ -22,7 +22,7 @@ cimport purple
 cdef extern from "c_purple.h":
     glib.guint glib_input_add(glib.gint fd, eventloop.PurpleInputCondition condition, eventloop.PurpleInputFunction function, glib.gpointer data)
 
-import ecore
+import signal
 
 cdef glib.GHashTable *c_ui_info
 
@@ -59,11 +59,17 @@ include "signal_cbs.pxd"
 include "util.pxd"
 
 cdef class Purple:
-    """ Purple class.
+    '''Purple class.
+
+    @param ui_name ID of the UI using the purple.
+        This should be a unique ID, registered with the purple team.
+    @param ui_version UI version.
+    @param ui_website UI website.
+    @param ui_dev_website UI development website.
+    @param debug_enabled True to enable debug messages.
+    @param default_path Custom settings directory
+    '''
 
-    @param debug_enabled: Toggle debug messages.
-    @param default_path: Full path for libpurple user files.
-    """
 
     def __init__(self, ui_name, ui_version, ui_website, ui_dev_website, \
             debug_enabled=None, default_path=None):
@@ -84,13 +90,21 @@ cdef class Purple:
         if default_path:
             util.purple_util_set_user_dir(default_path)
 
-        # adds glib iteration inside ecore main loop
-        ecore.timer_add(0.001, self.__glib_iteration_when_idle)
+        # libpurple's built-in DNS resolution forks processes to perform
+        # blocking lookups without blocking the main process.  It does not
+        # handle SIGCHLD itself, so if the UI does not you quickly get an army
+        # of zombie subprocesses marching around.
+        signal.signal(signal.SIGCHLD, signal.SIG_IGN)
 
     def destroy(self):
         core.purple_core_quit()
 
     def __get_ui_name(self):
+        '''Returns the UI name.
+
+        @return UI name.
+        '''
+
         global c_ui_name
         return str(c_ui_name)
     ui_name = property(__get_ui_name)
@@ -151,12 +165,12 @@ cdef class Purple:
             glib.g_hash_table_insert(c_ui_info, "dev_website", c_ui_dev_website)
         return c_ui_info
 
-    def __glib_iteration_when_idle(self):
-        glib.g_main_context_iteration(NULL, False)
-        return True
-
     def purple_init(self):
-        """ Initializes libpurple """
+        '''Initializes the purple.
+
+        This will setup preferences for all the core subsystems.
+        '''
+
         global c_ui_name
 
         c_account_ui_ops.notify_added = notify_added
@@ -259,13 +273,13 @@ cdef class Purple:
         return ret
 
     def add_callback(self, type, name, callback):
-        """
-        Adds a callback with given name inside callback's type.
+        '''Adds a callback with given name inside callback's type.
 
         @param type     Callback type (e.g. "account")
         @param name     Callback name (e.g. "notify-added")
         @param callback Callback to be called
-        """
+        '''
+
         global account_cbs
         global blist_cbs
         global connection_cbs
@@ -281,6 +295,14 @@ cdef class Purple:
           "request": request_cbs }[type][name] = callback
 
     def signal_connect(self, name=None, cb=None):
+        '''Connects a signal handler to a callback for a particular object.
+        Take care not to register a handler function twice. Purple will
+        not correct any mistakes for you in this area.
+
+        @param name Name of the signal to connect.
+        @param cb Callback function.
+        '''
+
         cdef int handle
         cdef plugin.PurplePlugin *jabber
 
@@ -330,6 +352,11 @@ cdef class Purple:
                     <signals.PurpleCallback> jabber_receiving_xmlnode_cb, NULL)
 
     def accounts_get_all(self):
+        '''Returns a list of all accounts.
+
+        @return A list of all accounts.
+        '''
+
         cdef glib.GList *iter
         cdef account.PurpleAccount *acc
         cdef char *username
@@ -353,11 +380,19 @@ cdef class Purple:
         return account_list
 
     def accounts_get_all_active(self):
+        '''Returns a list of all enabled accounts.
+
+        @return A list of all enabled accounts.
+        '''
+
         cdef glib.GList *iter
         cdef account.PurpleAccount *acc
         cdef char *username
         cdef char *protocol_id
 
+        #FIXME: The list is owned by the caller, and must be g_list_free()d
+        #       to avoid leaking the nodes.
+
         iter = account.purple_accounts_get_all_active()
         account_list = []
 
@@ -375,7 +410,16 @@ cdef class Purple:
 
         return account_list
 
+    def iterate_main_loop(self):
+        glib.g_main_context_iteration(NULL, False)
+        return True
+
     def protocols_get_all(self):
+        '''Returns a list of all protocols.
+
+        @return A list of all protocols.
+        '''
+
         cdef glib.GList *iter
         cdef plugin.PurplePlugin *pp
 
@@ -388,11 +432,11 @@ cdef class Purple:
             iter = iter.next
         return protocol_list
 
+    def call_action(self, i):
+        __call_action(i)
+
 include "protocol.pyx"
 #include "plugin.pyx"
 include "proxy.pyx"
-#include "protocol.pyx"
 include "account.pyx"
-include "buddy.pyx"
-#include "connection.pyx"
 include "conversation.pyx"