Mercurial > pidgin
diff libpurple/conversation.c @ 32819:2c6510167895 default tip
propagate from branch 'im.pidgin.pidgin.2.x.y' (head 3315c5dfbd0ad16511bdcf865e5b07c02d07df24)
to branch 'im.pidgin.pidgin' (head cbd1eda6bcbf0565ae7766396bb8f6f419cb6a9a)
author | Elliott Sales de Andrade <qulogic@pidgin.im> |
---|---|
date | Sat, 02 Jun 2012 02:30:49 +0000 |
parents | 3a4a35f6f873 |
children |
line wrap: on
line diff
--- a/libpurple/conversation.c Sat Jun 02 02:30:13 2012 +0000 +++ b/libpurple/conversation.c Sat Jun 02 02:30:49 2012 +0000 @@ -35,6 +35,131 @@ #define SEND_TYPED_TIMEOUT_SECONDS 5 +/** + * Data specific to Chats. + */ +struct _PurpleConvChat +{ + PurpleConversation *conv; /**< The parent conversation. */ + + GList *in_room; /**< The users in the room. + * @deprecated Will be removed in 3.0.0 + */ + GList *ignored; /**< Ignored users. */ + char *who; /**< The person who set the topic. */ + char *topic; /**< The topic. */ + int id; /**< The chat ID. */ + char *nick; /**< Your nick in this chat. */ + + gboolean left; /**< We left the chat and kept the window open */ + GHashTable *users; /**< Hash table of the users in the room. */ +}; + +/** + * Data specific to Instant Messages. + */ +struct _PurpleConvIm +{ + PurpleConversation *conv; /**< The parent conversation. */ + + PurpleTypingState typing_state; /**< The current typing state. */ + guint typing_timeout; /**< The typing timer handle. */ + time_t type_again; /**< The type again time. */ + guint send_typed_timeout; /**< The type again timer handle. */ + + PurpleBuddyIcon *icon; /**< The buddy icon. */ +}; + +/** + * Data for "Chat Buddies" + */ +struct _PurpleConvChatBuddy +{ + /** The chat participant's name in the chat. */ + char *name; + + /** The chat participant's alias, if known; @a NULL otherwise. */ + char *alias; + + /** + * A string by which this buddy will be sorted, or @c NULL if the + * buddy should be sorted by its @c name. (This is currently always + * @c NULL. + */ + char *alias_key; + + /** + * @a TRUE if this chat participant is on the buddy list; + * @a FALSE otherwise. + */ + gboolean buddy; + + /** + * A bitwise OR of flags for this participant, such as whether they + * are a channel operator. + */ + PurpleConvChatBuddyFlags flags; + + /** + * A hash table of attributes about the user, such as real name, + * user\@host, etc. + */ + GHashTable *attributes; + + /** The UI can put whatever it wants here. */ + gpointer ui_data; +}; + +/** + * A core representation of a conversation between two or more people. + * + * The conversation can be an IM or a chat. + */ +struct _PurpleConversation +{ + PurpleConversationType type; /**< The type of conversation. */ + + PurpleAccount *account; /**< The user using this conversation. */ + + + char *name; /**< The name of the conversation. */ + char *title; /**< The window title. */ + + gboolean logging; /**< The status of logging. */ + + GList *logs; /**< This conversation's logs */ + + union + { + PurpleConvIm *im; /**< IM-specific data. */ + PurpleConvChat *chat; /**< Chat-specific data. */ + void *misc; /**< Misc. data. */ + + } u; + + PurpleConversationUiOps *ui_ops; /**< UI-specific operations. */ + void *ui_data; /**< UI-specific data. */ + + GHashTable *data; /**< Plugin-specific data. */ + + PurpleConnectionFlags features; /**< The supported features */ + GList *message_history; /**< Message history, as a GList of PurpleConvMessage's */ +}; + +/** + * Description of a conversation message + */ +struct _PurpleConvMessage +{ + char *who; + char *what; + PurpleMessageFlags flags; + time_t when; + PurpleConversation *conv; + char *alias; +}; + + static GList *conversations = NULL; static GList *ims = NULL; static GList *chats = NULL; @@ -116,7 +241,7 @@ g_return_val_if_fail(conv != NULL, FALSE); - gc = purple_conversation_get_gc(conv); + gc = purple_conversation_get_connection(conv); name = purple_conversation_get_name(conv); if (gc != NULL && name != NULL) { @@ -146,7 +271,7 @@ return; account = purple_conversation_get_account(conv); - gc = purple_conversation_get_gc(conv); + gc = purple_conversation_get_connection(conv); g_return_if_fail(account != NULL); g_return_if_fail(gc != NULL); @@ -262,7 +387,7 @@ if (gc) me = purple_connection_get_display_name(gc); if (!me) - me = conv->account->username; + me = purple_account_get_username(conv->account); who = me; } @@ -381,7 +506,7 @@ conv->data = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); /* copy features from the connection. */ - conv->features = gc->flags; + conv->features = purple_connection_get_flags(gc); if (type == PURPLE_CONV_TYPE_IM) { @@ -416,7 +541,7 @@ chats = g_list_prepend(chats, conv); - if ((disp = purple_connection_get_display_name(account->gc))) + if ((disp = purple_connection_get_display_name(purple_account_get_connection(account)))) purple_conv_chat_set_nick(conv->u.chat, disp); else purple_conv_chat_set_nick(conv->u.chat, @@ -469,7 +594,7 @@ purple_request_close_with_handle(conv); ops = purple_conversation_get_ui_ops(conv); - gc = purple_conversation_get_gc(conv); + gc = purple_conversation_get_connection(conv); name = purple_conversation_get_name(conv); if (gc != NULL) @@ -694,7 +819,7 @@ } PurpleConnection * -purple_conversation_get_gc(const PurpleConversation *conv) +purple_conversation_get_connection(const PurpleConversation *conv) { PurpleAccount *account; @@ -705,7 +830,7 @@ if (account == NULL) return NULL; - return account->gc; + return purple_account_get_connection(account); } void @@ -990,7 +1115,7 @@ purple_account_get_username(account)); if (purple_account_get_alias(account) != NULL) - alias = account->alias; + alias = purple_account_get_alias(account); else if (b != NULL && !purple_strequal(purple_buddy_get_name(b), purple_buddy_get_contact_alias(b))) alias = purple_buddy_get_contact_alias(b); else if (purple_connection_get_display_name(gc) != NULL) @@ -1379,16 +1504,6 @@ } GList * -purple_conv_chat_set_users(PurpleConvChat *chat, GList *users) -{ - g_return_val_if_fail(chat != NULL, NULL); - - chat->in_room = users; - - return users; -} - -GList * purple_conv_chat_get_users(const PurpleConvChat *chat) { g_return_val_if_fail(chat != NULL, NULL); @@ -1544,7 +1659,7 @@ g_return_if_fail(message != NULL); conv = purple_conv_chat_get_conversation(chat); - gc = purple_conversation_get_gc(conv); + gc = purple_conversation_get_connection(conv); account = purple_connection_get_account(gc); /* Don't display this if the person who wrote it is ignored. */ @@ -1660,7 +1775,7 @@ conv = purple_conv_chat_get_conversation(chat); ops = purple_conversation_get_ui_ops(conv); - gc = purple_conversation_get_gc(conv); + gc = purple_conversation_get_connection(conv); g_return_if_fail(gc != NULL); prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(purple_connection_get_prpl(gc)); g_return_if_fail(prpl_info != NULL); @@ -1687,7 +1802,7 @@ } } else { PurpleBuddy *buddy; - if ((buddy = purple_find_buddy(gc->account, user)) != NULL) + if ((buddy = purple_find_buddy(purple_connection_get_account(gc), user)) != NULL) alias = purple_buddy_get_contact_alias(buddy); } } @@ -1761,7 +1876,7 @@ conv = purple_conv_chat_get_conversation(chat); ops = purple_conversation_get_ui_ops(conv); - gc = purple_conversation_get_gc(conv); + gc = purple_conversation_get_connection(conv); g_return_if_fail(gc != NULL); prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(purple_connection_get_prpl(gc)); g_return_if_fail(prpl_info != NULL); @@ -1780,12 +1895,12 @@ { const char *display_name = purple_connection_get_display_name(gc); if (display_name != NULL) - alias = display_name; + new_alias = display_name; } } } else if (!(prpl_info->options & OPT_PROTO_UNIQUE_CHATNAME)) { PurpleBuddy *buddy; - if ((buddy = purple_find_buddy(gc->account, new_user)) != NULL) + if ((buddy = purple_find_buddy(purple_connection_get_account(gc), new_user)) != NULL) new_alias = purple_buddy_get_contact_alias(buddy); } @@ -1834,9 +1949,9 @@ if (!(prpl_info->options & OPT_PROTO_UNIQUE_CHATNAME)) { PurpleBuddy *buddy; - if ((buddy = purple_find_buddy(gc->account, old_user)) != NULL) + if ((buddy = purple_find_buddy(purple_connection_get_account(gc), old_user)) != NULL) old_alias = purple_buddy_get_contact_alias(buddy); - if ((buddy = purple_find_buddy(gc->account, new_user)) != NULL) + if ((buddy = purple_find_buddy(purple_connection_get_account(gc), new_user)) != NULL) new_alias = purple_buddy_get_contact_alias(buddy); } @@ -1880,7 +1995,7 @@ conv = purple_conv_chat_get_conversation(chat); - gc = purple_conversation_get_gc(conv); + gc = purple_conversation_get_connection(conv); g_return_if_fail(gc != NULL); prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(purple_connection_get_prpl(gc)); g_return_if_fail(prpl_info != NULL); @@ -1911,7 +2026,7 @@ if (!(prpl_info->options & OPT_PROTO_UNIQUE_CHATNAME)) { PurpleBuddy *buddy; - if ((buddy = purple_find_buddy(gc->account, user)) != NULL) + if ((buddy = purple_find_buddy(purple_connection_get_account(gc), user)) != NULL) alias = purple_buddy_get_contact_alias(buddy); } @@ -2065,7 +2180,7 @@ conv = (PurpleConversation *)l->data; if (purple_conv_chat_get_id(PURPLE_CONV_CHAT(conv)) == id && - purple_conversation_get_gc(conv) == gc) + purple_conversation_get_connection(conv) == gc) return conv; } @@ -2093,7 +2208,7 @@ user = purple_request_fields_get_string(fields, "screenname"); message = purple_request_fields_get_string(fields, "message"); - serv_chat_invite(purple_conversation_get_gc(conv), chat->id, message, user); + serv_chat_invite(purple_conversation_get_connection(conv), chat->id, message, user); } void purple_conv_chat_invite_user(PurpleConvChat *chat, const char *user, @@ -2194,14 +2309,51 @@ g_free(cb); } +void purple_conv_chat_cb_set_ui_data(PurpleConvChatBuddy *cb, gpointer ui_data) +{ + g_return_if_fail(cb != NULL); + + cb->ui_data = ui_data; +} + +gpointer purple_conv_chat_cb_get_ui_data(const PurpleConvChatBuddy *cb) +{ + g_return_val_if_fail(cb != NULL, NULL); + + return cb->ui_data; +} + const char * -purple_conv_chat_cb_get_name(PurpleConvChatBuddy *cb) +purple_conv_chat_cb_get_alias(const PurpleConvChatBuddy *cb) +{ + g_return_val_if_fail(cb != NULL, NULL); + + return cb->alias; +} + +const char * +purple_conv_chat_cb_get_name(const PurpleConvChatBuddy *cb) { g_return_val_if_fail(cb != NULL, NULL); return cb->name; } +PurpleConvChatBuddyFlags +purple_conv_chat_cb_get_flags(const PurpleConvChatBuddy *cb) +{ + g_return_val_if_fail(cb != NULL, PURPLE_CBFLAGS_NONE); + + return cb->flags; +} + +gboolean purple_conv_chat_cb_is_buddy(const PurpleConvChatBuddy *cb) +{ + g_return_val_if_fail(cb != NULL, FALSE); + + return cb->buddy; +} + const char * purple_conv_chat_cb_get_attribute(PurpleConvChatBuddy *cb, const char *key) { @@ -2299,30 +2451,57 @@ return conv->message_history; } -const char *purple_conversation_message_get_sender(PurpleConvMessage *msg) +const char *purple_conversation_message_get_sender(const PurpleConvMessage *msg) { g_return_val_if_fail(msg, NULL); return msg->who; } -const char *purple_conversation_message_get_message(PurpleConvMessage *msg) +const char *purple_conversation_message_get_message(const PurpleConvMessage *msg) { g_return_val_if_fail(msg, NULL); return msg->what; } -PurpleMessageFlags purple_conversation_message_get_flags(PurpleConvMessage *msg) +PurpleMessageFlags purple_conversation_message_get_flags(const PurpleConvMessage *msg) { g_return_val_if_fail(msg, 0); return msg->flags; } -time_t purple_conversation_message_get_timestamp(PurpleConvMessage *msg) +time_t purple_conversation_message_get_timestamp(const PurpleConvMessage *msg) { g_return_val_if_fail(msg, 0); return msg->when; } +const char *purple_conversation_message_get_alias(const PurpleConvMessage *msg) +{ + g_return_val_if_fail(msg, NULL); + return msg->alias; +} + +PurpleConversation *purple_conversation_message_get_conv(const PurpleConvMessage *msg) +{ + g_return_val_if_fail(msg, NULL); + return msg->conv; +} + +void purple_conversation_set_ui_data(PurpleConversation *conv, gpointer ui_data) +{ + g_return_if_fail(conv != NULL); + + conv->ui_data = ui_data; +} + +gpointer purple_conversation_get_ui_data(const PurpleConversation *conv) +{ + g_return_val_if_fail(conv != NULL, NULL); + + return conv->ui_data; +} + + gboolean purple_conversation_do_command(PurpleConversation *conv, const gchar *cmdline, const gchar *markup, gchar **error)