Adding function set_info to ProxyInfo class
[python-purple] / purple.pyx
index 54be931..b984590 100644 (file)
@@ -55,6 +55,8 @@ include "request_cbs.pxd"
 #include "roomlist_cbs.pxd"
 include "signal_cbs.pxd"
 
+include "util.pxd"
+
 cdef class Purple:
     """ Purple class.
 
@@ -137,20 +139,9 @@ cdef class Purple:
         glib.g_main_context_iteration(NULL, False)
         return True
 
-    def purple_init(self, callbacks_dict=None):
+    def purple_init(self):
         """ Initializes libpurple """
 
-        if callbacks_dict is not None:
-            global connection_cbs
-            global conversation_cbs
-            global notify_cbs
-            global request_cbs
-
-            connection_cbs = callbacks_dict["connection"]
-            conversation_cbs = callbacks_dict["conversation"]
-            notify_cbs = callbacks_dict["notify"]
-            request_cbs = callbacks_dict["request"]
-
         c_account_ui_ops.notify_added = notify_added
         c_account_ui_ops.status_changed = status_changed
         c_account_ui_ops.request_add = request_add
@@ -251,17 +242,23 @@ cdef class Purple:
 
         return ret
 
-    def add_account_cb(self, name, func):
+    def add_callback(self, type, name, func):
+        """ Adds a callback 'func' with given name 'name' inside type 'type'.
+        Example: add_callback("account", "notify-added", notify_added_cb)
+        """
         global account_cbs
-        account_cbs[name] = func
-
-    def add_blist_cb(self, name, func):
         global blist_cbs
-        blist_cbs[name] = func
-
-    def connect(self):
-        conn = Connection()
-        conn.connect()
+        global connection_cbs
+        global conversation_cbs
+        global notify_cbs
+        global request_cbs
+
+        { "account": account_cbs,
+          "blist": blist_cbs,
+          "connection": connection_cbs,
+          "conversation": conversation_cbs,
+          "notify": notify_cbs,
+          "request": request_cbs }[type][name] = func
 
     def signal_connect(self, name=None, cb=None):
         cdef int handle
@@ -277,7 +274,27 @@ cdef class Purple:
         global signal_cbs
         signal_cbs[name] = cb
 
-        if name == "buddy-signed-off":
+        if name == "signed-on":
+            signals.c_purple_signal_connect(
+                    connection.c_purple_connections_get_handle(),
+                    "signed-on", &handle,
+                    <signals.PurpleCallback> signal_signed_on_cb, NULL)
+        elif name == "signed-off":
+            signals.c_purple_signal_connect(
+                    connection.c_purple_connections_get_handle(),
+                    "signed-off", &handle,
+                    <signals.PurpleCallback> signal_signed_off_cb, NULL)
+        elif name == "connection-error":
+            signals.c_purple_signal_connect(
+                    connection.c_purple_connections_get_handle(),
+                    "connection-error", &handle,
+                    <signals.PurpleCallback> signal_connection_error_cb, NULL)
+        elif name == "buddy-signed-on":
+            signals.c_purple_signal_connect(
+                    blist.c_purple_blist_get_handle(),
+                    "buddy-signed-on", &handle,
+                    <signals.PurpleCallback> signal_buddy_signed_on_cb, NULL)
+        elif name == "buddy-signed-off":
             signals.c_purple_signal_connect(
                     blist.c_purple_blist_get_handle(),
                     "buddy-signed-off", &handle,
@@ -333,5 +350,5 @@ cdef class Purple:
 include "proxy.pyx"
 include "account.pyx"
 include "buddy.pyx"
-include "connection.pyx"
+#include "connection.pyx"
 include "conversation.pyx"