Implemented request_add callback.
[python-purple] / signal_cbs.pxd
index ad2ce83..ed1ab71 100644 (file)
@@ -21,13 +21,16 @@ cimport purple
 
 signal_cbs = {}
 
+cdef extern from *:
+    ctypedef char const_gchar "const gchar"
+
 cdef void signal_signed_on_cb(connection.PurpleConnection *gc, \
         glib.gpointer null):
     """
     Emitted when a connection has signed on.
     @params gc  The connection that has signed on.
     """
-    cdef account.PurpleAccount *acc = connection.c_purple_connection_get_account(gc)
+    cdef account.PurpleAccount *acc = connection.purple_connection_get_account(gc)
     cdef char *c_username = NULL
     cdef char *c_protocol_id = NULL
 
@@ -52,7 +55,7 @@ cdef void signal_signed_off_cb(connection.PurpleConnection *gc, \
     Emitted when a connection has signed off.
     @params gc  The connection that has signed off.
     """
-    cdef account.PurpleAccount *acc = connection.c_purple_connection_get_account(gc)
+    cdef account.PurpleAccount *acc = connection.purple_connection_get_account(gc)
     cdef char *c_username = NULL
     cdef char *c_protocol_id = NULL
 
@@ -72,13 +75,28 @@ cdef void signal_signed_off_cb(connection.PurpleConnection *gc, \
         (<object> signal_cbs["signed-off"])(username, protocol_id)
 
 cdef void signal_connection_error_cb(connection.PurpleConnection *gc, \
-        connection.PurpleConnectionError err, char *c_desc):
+        connection.PurpleConnectionError err, const_gchar *c_desc):
     """
     Emitted when a connection error occurs, before signed-off.
     @params gc   The connection on which the error has occured
     @params err  The error that occured
     @params desc A description of the error, giving more information
     """
+    cdef account.PurpleAccount *acc = connection.purple_connection_get_account(gc)
+    cdef char *c_username = NULL
+    cdef char *c_protocol_id = NULL
+
+    c_username = <char *> account.purple_account_get_username(acc)
+    if c_username:
+        username = <char *> c_username
+    else:
+        username = None
+
+    c_protocol_id = <char *> account.purple_account_get_protocol_id(acc)
+    if c_protocol_id:
+        protocol_id = <char *> c_protocol_id
+    else:
+        protocol_id = None
 
     short_desc = {
         0: "Network error",
@@ -97,15 +115,16 @@ cdef void signal_connection_error_cb(connection.PurpleConnection *gc, \
         13: "SSL certificate fingerprint mismatch",
         14: "SSL certificate self signed",
         15: "SSL certificate other error",
-        16: "Other error" }[<int>err]
+        16: "Other error" }[<int> err]
 
-    if c_desc == NULL:
-        desc = None
+    if c_desc:
+        desc = str(<char *> c_desc)
     else:
-        desc = c_desc
+        desc = None
 
     if signal_cbs.has_key("connection-error"):
-        (<object> signal_cbs["connection-error"])(short_desc, desc)
+        (<object> signal_cbs["connection-error"])(username, protocol_id, \
+                short_desc, desc)
 
 cdef void signal_buddy_signed_on_cb(blist.PurpleBuddy *buddy):
     """
@@ -115,13 +134,13 @@ cdef void signal_buddy_signed_on_cb(blist.PurpleBuddy *buddy):
     cdef char *c_name = NULL
     cdef char *c_alias = NULL
 
-    c_name = <char *> blist.c_purple_buddy_get_name(buddy)
+    c_name = <char *> blist.purple_buddy_get_name(buddy)
     if c_name == NULL:
         name = None
     else:
         name = c_name
 
-    c_alias = <char *> blist.c_purple_buddy_get_alias_only(buddy)
+    c_alias = <char *> blist.purple_buddy_get_alias_only(buddy)
     if c_alias == NULL:
         alias = None
     else:
@@ -138,13 +157,13 @@ cdef void signal_buddy_signed_off_cb(blist.PurpleBuddy *buddy):
     cdef char *c_name = NULL
     cdef char *c_alias = NULL
 
-    c_name = <char *> blist.c_purple_buddy_get_name(buddy)
+    c_name = <char *> blist.purple_buddy_get_name(buddy)
     if c_name == NULL:
         name = None
     else:
         name = c_name
 
-    c_alias = <char *> blist.c_purple_buddy_get_alias_only(buddy)
+    c_alias = <char *> blist.purple_buddy_get_alias_only(buddy)
     if c_alias == NULL:
         alias = None
     else:
@@ -168,16 +187,16 @@ cdef glib.gboolean signal_receiving_im_msg_cb(account.PurpleAccount *account, \
     @params conv     The IM conversation.
     @params flags    A pointer to the IM message flags.
     """
-    cdef blist.PurpleBuddy *buddy = blist.c_purple_find_buddy(account, sender[0])
+    cdef blist.PurpleBuddy *buddy = blist.purple_find_buddy(account, sender[0])
     cdef char *c_alias = NULL
 
-    c_alias = <char *> blist.c_purple_buddy_get_alias_only(buddy)
+    c_alias = <char *> blist.purple_buddy_get_alias_only(buddy)
     if c_alias == NULL:
         alias = None
     else:
         alias = c_alias
 
-    stripped = util.c_purple_markup_strip_html(message[0])
+    stripped = util.purple_markup_strip_html(message[0])
 
     if signal_cbs.has_key("receiving-im-msg"):
         return (<object> signal_cbs["receiving-im-msg"])(sender[0], alias, stripped)