Adding support to get buddy's active status
[python-purple] / conversation_cbs.pxd
index 4688985..f3a6bd7 100644 (file)
@@ -26,140 +26,209 @@ cdef extern from *:
 
 conversation_cbs = {}
 
-cdef void create_conversation (conversation.PurpleConversation *conv):
-    debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "conversation",
-                         "create_conversation\n")
-    try:
-        (<object>conversation_cbs["create_conversation"])("create_conversation")
-    except KeyError:
-        pass
-
-cdef void destroy_conversation (conversation.PurpleConversation *conv):
-    debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "conversation",
-                         "destroy_conversation\n")
-    try:
-        (<object>conversation_cbs["destroy_conversation"])("destroy_conversation")
-    except KeyError:
-        pass
-
-cdef void write_chat (conversation.PurpleConversation *conv, const_char *who,
-                      const_char *message, conversation.PurpleMessageFlags flags,
-                      time_t mtime):
-    debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "conversation",
-                         "write_chat\n")
-    try:
-        (<object>conversation_cbs["write_chat"])("write_chat")
-    except KeyError:
-        pass
-
-cdef void write_im (conversation.PurpleConversation *conv, const_char *who,
-                    const_char *message, conversation.PurpleMessageFlags flags,
-                    time_t mtime):
-    debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "conversation", "write_im\n")
-    try:
-        (<object>conversation_cbs["write_im"])("write_im")
-    except KeyError:
-        pass
-
-cdef void write_conv (conversation.PurpleConversation *conv, const_char *name,
-                      const_char *alias, const_char *message,
-                      conversation.PurpleMessageFlags flags, time_t mtime):
-    debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "conversation",
-                         "write_conv\n")
-    try:
-        (<object>conversation_cbs["write_conv"])("write_conv")
-    except KeyError:
-        pass
-
-cdef void chat_add_users (conversation.PurpleConversation *conv,
-                          glib.GList *cbuddies, glib.gboolean new_arrivals):
-    debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "conversation",
-                         "chat_add_users\n")
-    try:
-        (<object>conversation_cbs["chat_add_users"])("chat_add_users")
-    except KeyError:
-        pass
-
-cdef void chat_rename_user (conversation.PurpleConversation *conv,
-                            const_char *old_name, const_char *new_name,
-                            const_char *new_alias):
-    debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "conversation",
-                         "chat_rename_user\n")
-    try:
-        (<object>conversation_cbs["chat_rename_user"])("chat_rename_user")
-    except KeyError:
-        pass
-
-cdef void chat_remove_users (conversation.PurpleConversation *conv,
-                             glib.GList *users):
-    debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "conversation",
-                         "chat_remove_users\n")
-    try:
-        (<object>conversation_cbs["chat_remove_users"])("chat_remove_users")
-    except KeyError:
-        pass
-
-cdef void chat_update_user (conversation.PurpleConversation *conv,
-                            const_char *user):
-    debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "conversation",
-                         "chat_update_user\n")
-    try:
-        (<object>conversation_cbs["chat_update_user"])("chat_update_user")
-    except KeyError:
-        pass
-
-cdef void present (conversation.PurpleConversation *conv):
-    debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "conversation",
-                         "present\n")
-    try:
-        (<object>conversation_cbs["present"])("present")
-    except KeyError:
-        pass
-
-cdef glib.gboolean has_focus (conversation.PurpleConversation *conv):
-    debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "conversation",
-                         "has_focus\n")
-    try:
-        (<object>conversation_cbs["has_focus"])("has_focus")
-        return False
-    except KeyError:
-        return False
-
-cdef glib.gboolean custom_smiley_add (conversation.PurpleConversation *conv,
-                                      const_char *smile, glib.gboolean remote):
-    debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "conversation",
-                         "custom_smiley_add\n")
-    try:
-        (<object>conversation_cbs["custom_smiley_add"])("custom_smiley_add")
-        return False
-    except KeyError:
-        return False
-
-cdef void custom_smiley_write (conversation.PurpleConversation *conv,
-                               const_char *smile, const_guchar *data,
-                               glib.gsize size):
-    debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "conversation",
-                         "custom_smiley_write\n")
-    try:
-        (<object>conversation_cbs["custom_smiley_write"])("custom_smiley_write")
-    except KeyError:
-        pass
-
-
-cdef void custom_smiley_close (conversation.PurpleConversation *conv,
-                               const_char *smile):
-    debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "conversation",
-                         "custom_smiley_close\n")
-    try:
-        (<object>conversation_cbs["custom_smiley_close"])("custom_smiley_close")
-    except KeyError:
-        pass
-
-cdef void send_confirm (conversation.PurpleConversation *conv,
-                        const_char *message):
-    debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "conversation",
-                         "send_confirm\n")
-    try:
-        (<object>conversation_cbs["send_confirm"])("send_confirm")
-    except KeyError:
-        pass
+cdef void create_conversation(conversation.PurpleConversation *conv):
+    """
+    Called when a conv is created (but before the conversation-created
+    signal is emitted).
+    """
+    debug.purple_debug_info("conversation", "%s", "create-conversation\n")
+    cdef char *c_name = NULL
+
+    c_name = <char *> conversation.purple_conversation_get_name(conv)
+    if c_name == NULL:
+        name = None
+    else:
+        name = c_name
+
+    type = conversation.purple_conversation_get_type(conv)
+
+    if conversation_cbs.has_key("create-conversation"):
+        (<object> conversation_cbs["create-conversation"])(name, type)
+
+cdef void destroy_conversation(conversation.PurpleConversation *conv):
+    """
+    Called just before a conv is freed.
+    """
+    debug.purple_debug_info("conversation", "%s", "destroy-conversation\n")
+    if conversation_cbs.has_key("destroy-conversation"):
+        (<object> conversation_cbs["destroy-conversation"])("destroy-conversation: TODO")
+
+cdef void write_chat(conversation.PurpleConversation *conv, const_char *who, \
+        const_char *message, conversation.PurpleMessageFlags flags, \
+        time_t mtime):
+    """
+    Write a message to a chat. If this field is NULL, libpurple will fall
+    back to using write_conv.
+    @see purple_conv_chat_write()
+    """
+    debug.purple_debug_info("conversation", "%s", "write-chat\n")
+    if conversation_cbs.has_key("write-chat"):
+        (<object> conversation_cbs["write-chat"])("write-chat: TODO")
+
+cdef void write_im(conversation.PurpleConversation *conv, const_char *who, \
+        const_char *c_message, conversation.PurpleMessageFlags flags, \
+        time_t mtime):
+    """
+    Write a message to an IM conversation. If this field is NULL, libpurple
+    will fall back to using write_conv.
+    @see purple_conv_im_write()
+    """
+    debug.purple_debug_info("conversation", "%s", "write-im\n")
+    cdef account.PurpleAccount *acc = conversation.purple_conversation_get_account(conv)
+    cdef blist.PurpleBuddy *buddy = NULL
+    cdef char *c_username = NULL
+    cdef char *c_sender_alias = NULL
+
+    c_username = <char *> account.purple_account_get_username(acc)
+    if c_username:
+        username = c_username
+    else:
+        username = None
+
+    if who == NULL:
+        who = conversation.purple_conversation_get_name(conv)
+
+    sender = <char *> who
+    buddy = blist.purple_find_buddy(acc, <char *> who)
+    if buddy:
+        c_sender_alias = <char *> blist.purple_buddy_get_alias_only(buddy)
+
+    if c_sender_alias:
+        sender_alias = unicode(c_sender_alias, 'utf-8')
+    else:
+        sender_alias = None
+
+    if c_message:
+        message = <char *> c_message
+    else:
+        message = None
+
+    # FIXME: Maybe we need add more purple flags in the future
+    if flags & conversation.PURPLE_MESSAGE_SEND:
+        flag = "SEND"
+    else:
+        flag = "RECV"
+
+    if conversation_cbs.has_key("write-im"):
+        (<object> conversation_cbs["write-im"])(username, sender, \
+                               sender_alias, message, flag)
+
+cdef void write_conv(conversation.PurpleConversation *conv, const_char *name, \
+        const_char *alias, const_char *message, \
+        conversation.PurpleMessageFlags flags, time_t mtime):
+    """
+    Write a message to a conversation. This is used rather than the chat- or
+    im-specific ops for errors, system messages (such as "x is now known as
+    y"), and as the fallback if write_im and write_chat are not implemented.
+    It should be implemented, or the UI will miss conversation error messages
+    and your users will hate you.
+    @see purple_conversation_write()
+    """
+    debug.purple_debug_info("conversation", "%s", "write-conv\n")
+    if conversation_cbs.has_key("write-conv"):
+        (<object> conversation_cbs["write-conv"])("write-conv: TODO")
+
+cdef void chat_add_users(conversation.PurpleConversation *conv, \
+        glib.GList *cbuddies, glib.gboolean new_arrivals):
+    """
+    Add cbuddies to a chat.
+    @param cbuddies  A GList of PurpleConvChatBuddy structs.
+    @param new_arrivals  Wheter join notices should be shown.
+                         (Join notices are actually written to the
+                         conversation by purple_conv_chat_add_users().)
+    @see purple_conv_chat_add_users()
+    """
+    debug.purple_debug_info("conversation", "%s", "chat-add-users\n")
+    if conversation_cbs.has_key("chat-add-users"):
+        (<object> conversation_cbs["chat-add-users"])("chat-add-users: TODO")
+
+cdef void chat_rename_user(conversation.PurpleConversation *conv, \
+        const_char *old_name, const_char *new_name,
+        const_char *new_alias):
+    """
+    Rename the user in this chat name old_name to new_name. (The rename
+    message is written to the conversation by libpurple.)
+    @param new_alias  new_name's new_alias, if they have one.
+    @see purple_conv_chat_rename_user()
+    """
+    debug.purple_debug_info("conversation", "%s", "chat-rename-user\n")
+    if conversation_cbs.has_key("chat-rename-user"):
+        (<object> conversation_cbs["chat-rename-user"])("chat-rename-user: TODO")
+
+cdef void chat_remove_users(conversation.PurpleConversation *conv, \
+        glib.GList *users):
+    """
+    Remove users from a chat.
+    @param  users  A GList of const char *s.
+    """
+    debug.purple_debug_info("conversation", "%s", "chat-remove-users\n")
+    if conversation_cbs.has_key("chat-remove-users"):
+        (<object> conversation_cbs["chat-remove-users"])("chat-remove-users: TODO")
+
+cdef void chat_update_user(conversation.PurpleConversation *conv, \
+        const_char *user):
+    """
+    Called when a user's flags are changed.
+    @see purple_conv_chat_user_set_flags()
+    """
+    debug.purple_debug_info("conversation", "%s", "chat-update-user\n")
+    if conversation_cbs.has_key("chat-update-user"):
+        (<object> conversation_cbs["chat-update-user"])("chat-update-user: TODO")
+
+cdef void present(conversation.PurpleConversation *conv):
+    """
+    Present this conversation to the user; for example, by displaying the IM
+    dialog.
+    """
+    debug.purple_debug_info("conversation", "%s", "present\n")
+    if conversation_cbs.has_key("present"):
+        (<object> conversation_cbs["present"])("present: TODO")
+
+cdef glib.gboolean has_focus(conversation.PurpleConversation *conv):
+    """
+    If this UI has a concept of focus (as in a windowing system) and this
+    conversation has the focus, return TRUE; otherwise, return FALSE.
+    """
+    debug.purple_debug_info("conversation", "%s", "has-focus\n")
+    if conversation_cbs.has_key("has-focus"):
+        (<object> conversation_cbs["has-focus"])("has-focus: TODO")
+    return False
+
+cdef glib.gboolean custom_smiley_add(conversation.PurpleConversation *conv, \
+        const_char *smile, glib.gboolean remote):
+    """
+    Custom smileys (add).
+    """
+    debug.purple_debug_info("conversation", "%s", "custom-smiley-add\n")
+    if conversation_cbs.has_key("custom-smiley-add"):
+        (<object> conversation_cbs["custom-smiley-add"])("custom-smiley-add: TODO")
+    return False
+
+cdef void custom_smiley_write(conversation.PurpleConversation *conv, \
+        const_char *smile, const_guchar *data, glib.gsize size):
+    """
+    Custom smileys (write).
+    """
+    debug.purple_debug_info("conversation", "%s", "custom-smiley-write\n")
+    if conversation_cbs.has_key("custom-smiley-write"):
+        (<object> conversation_cbs["custom-smiley-write"])("custom-smiley-write: TODO")
+
+cdef void custom_smiley_close(conversation.PurpleConversation *conv, \
+        const_char *smile):
+    """
+    Custom smileys (close).
+    """
+    debug.purple_debug_info("conversation", "%s", "custom-smiley-close\n")
+    if conversation_cbs.has_key("custom-smiley-close"):
+        (<object> conversation_cbs["custom-smiley-close"])("custom-smiley-close: TODO")
+
+cdef void send_confirm(conversation.PurpleConversation *conv, \
+        const_char *message):
+    """
+    Prompt the user for confirmation to send mesage. This function should
+    arrange for the message to be sent if the user accepts. If this field
+    is NULL, libpurple will fall back to using purple_request_action().
+    """
+    debug.purple_debug_info("conversation", "%s", "send-confirm\n")
+    if conversation_cbs.has_key("send-confirm"):
+        (<object> conversation_cbs["send-confirm"])("send-confirm: TODO")