Mercurial > pidgin
changeset 7971:6fca0d9cc98b
[gaim-migrate @ 8648]
this particular work of art is topic changing support for jabber, and
support for setting the topic by just changing the text in the chat window.
hopefully someone less lazy than I will implement the right function for
IRC, and any other chats that do topics.
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Fri, 02 Jan 2004 06:16:44 +0000 |
parents | a6eb0e250417 |
children | ac01b7d67ff9 |
files | src/gtkconv.c src/protocols/jabber/chat.c src/protocols/jabber/chat.h src/protocols/jabber/jabber.c src/protocols/jabber/message.c src/protocols/jabber/message.h src/prpl.h |
diffstat | 7 files changed, 99 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/src/gtkconv.c Thu Jan 01 18:20:01 2004 +0000 +++ b/src/gtkconv.c Fri Jan 02 06:16:44 2004 +0000 @@ -3477,6 +3477,32 @@ return vbox; } +static void topic_callback(GtkWidget *w, GaimConversation *conv) +{ + GaimPluginProtocolInfo *prpl_info = NULL; + GaimConnection *gc; + GaimGtkConversation *gtkconv; + GaimGtkChatPane *gtkchat; + const char *topic; + + gc = gaim_conversation_get_gc(conv); + + if(!gc || !(prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl))) + return; + + if(prpl_info->set_chat_topic == NULL) + return; + + gtkconv = GAIM_GTK_CONVERSATION(conv); + gtkchat = gtkconv->u.chat; + topic = gtk_entry_get_text(GTK_ENTRY(gtkchat->topic_text)); + + if(!g_utf8_collate(topic, gaim_conv_chat_get_topic(GAIM_CONV_CHAT(conv)))) + return; + + prpl_info->set_chat_topic(gc, gaim_conv_chat_get_id(GAIM_CONV_CHAT(conv)), topic); +} + static GtkWidget * setup_chat_pane(GaimConversation *conv) { @@ -3522,7 +3548,13 @@ gtk_widget_show(label); gtkchat->topic_text = gtk_entry_new(); - gtk_editable_set_editable(GTK_EDITABLE(gtkchat->topic_text), FALSE); + if(prpl_info->set_chat_topic == NULL) { + gtk_editable_set_editable(GTK_EDITABLE(gtkchat->topic_text), FALSE); + } else { + g_signal_connect(GTK_OBJECT(gtkchat->topic_text), "activate", + G_CALLBACK(topic_callback), conv); + } + gtk_box_pack_start(GTK_BOX(hbox), gtkchat->topic_text, TRUE, TRUE, 5); gtk_widget_show(gtkchat->topic_text); }
--- a/src/protocols/jabber/chat.c Thu Jan 01 18:20:01 2004 +0000 +++ b/src/protocols/jabber/chat.c Fri Jan 02 06:16:44 2004 +0000 @@ -22,6 +22,7 @@ #include "debug.h" #include "multi.h" /* for proto_chat_entry */ #include "notify.h" +#include "util.h" #include "chat.h" #include "iq.h" @@ -531,4 +532,42 @@ jabber_iq_send(iq); } +/* merge this with the function below when we get everyone on the same page wrt /commands */ +void jabber_chat_change_topic(JabberChat *chat, const char *topic) +{ + if(topic && *topic) { + JabberMessage *jm; + jm = g_new0(JabberMessage, 1); + jm->js = chat->js; + jm->type = JABBER_MESSAGE_GROUPCHAT; + jm->subject = gaim_markup_strip_html(topic); + jm->to = g_strdup_printf("%s@%s", chat->room, chat->server); + jabber_message_send(jm); + jabber_message_free(jm); + } else { + const char *cur = gaim_conv_chat_get_topic(GAIM_CONV_CHAT(chat->conv)); + char *buf; + if(cur) + buf = g_strdup_printf(_("current topic is: %s"), topic); + else + buf = g_strdup(_("No topic is set")); + gaim_conv_chat_write(GAIM_CONV_CHAT(chat->conv), "", buf, + GAIM_MESSAGE_SYSTEM | GAIM_MESSAGE_NO_LOG, time(NULL)); + g_free(buf); + } + +} + +void jabber_chat_set_topic(GaimConnection *gc, int id, const char *topic) +{ + JabberStream *js = gc->proto_data; + JabberChat *chat = jabber_chat_find_by_id(js, id); + + if(!chat) + return; + + jabber_chat_change_topic(chat, topic); +} + +
--- a/src/protocols/jabber/chat.h Thu Jan 01 18:20:01 2004 +0000 +++ b/src/protocols/jabber/chat.h Fri Jan 02 06:16:44 2004 +0000 @@ -53,6 +53,9 @@ char *jabber_chat_buddy_real_name(GaimConnection *gc, int id, const char *who); void jabber_chat_request_room_configure(JabberChat *chat); void jabber_chat_create_instant_room(JabberChat *chat); +void jabber_chat_register(JabberChat *chat); +void jabber_chat_change_topic(JabberChat *chat, const char *topic); +void jabber_chat_set_topic(GaimConnection *gc, int id, const char *topic); #endif /* _GAIM_JABBER_CHAT_H_ */
--- a/src/protocols/jabber/jabber.c Thu Jan 01 18:20:01 2004 +0000 +++ b/src/protocols/jabber/jabber.c Fri Jan 02 06:16:44 2004 +0000 @@ -1134,7 +1134,8 @@ jabber_normalize, NULL, /* set_buddy_icon */ NULL, /* remove_group */ - jabber_chat_buddy_real_name + jabber_chat_buddy_real_name, + jabber_chat_set_topic }; static GaimPluginInfo info =
--- a/src/protocols/jabber/message.c Thu Jan 01 18:20:01 2004 +0000 +++ b/src/protocols/jabber/message.c Fri Jan 02 06:16:44 2004 +0000 @@ -178,9 +178,19 @@ if(!chat) return; - if(jm->subject) + if(jm->subject) { gaim_conv_chat_set_topic(GAIM_CONV_CHAT(chat->conv), jid->resource, jm->subject); + if(!jm->xhtml && !jm->body) { + char *msg; + if(jid->resource) + msg = g_strdup_printf(_("%s has set the topic to: %s"), jid->resource, jm->subject); + else + msg = g_strdup_printf(_("The topic is: %s"), jm->subject); + gaim_conv_chat_write(GAIM_CONV_CHAT(chat->conv), "", msg, GAIM_MESSAGE_SYSTEM, jm->sent); + g_free(msg); + } + } if(jm->xhtml || jm->body) { if(jid->resource) @@ -394,7 +404,7 @@ xmlnode_set_attrib(message, "to", jm->to); - if(jm->events || (!jm->body && !jm->xhtml)) { + if(jm->events || (!jm->body && !jm->xhtml && !jm->subject)) { child = xmlnode_new_child(message, "x"); xmlnode_set_attrib(child, "xmlns", "jabber:x:event"); if(jm->events & JABBER_MESSAGE_EVENT_COMPOSING) @@ -485,6 +495,10 @@ return 1; } else if(!strcmp(msg, "/register")) { jabber_chat_register(chat); + return 1; + } else if(!strncmp(msg, "/topic", 6)) { + jabber_chat_change_topic(chat, strlen(msg) > 7 ? msg+7 : NULL); + return 1; } jm = g_new0(JabberMessage, 1);
--- a/src/protocols/jabber/message.h Thu Jan 01 18:20:01 2004 +0000 +++ b/src/protocols/jabber/message.h Fri Jan 02 06:16:44 2004 +0000 @@ -50,6 +50,9 @@ GList *etc; } JabberMessage; +void jabber_message_free(JabberMessage *jm); + +void jabber_message_send(JabberMessage *jm); void jabber_message_parse(JabberStream *js, xmlnode *packet); int jabber_message_send_im(GaimConnection *gc, const char *who, const char *msg, @@ -58,4 +61,5 @@ int jabber_send_typing(GaimConnection *gc, const char *who, int typing); + #endif /* _GAIM_JABBER_MESSAGE_H_ */
--- a/src/prpl.h Thu Jan 01 18:20:01 2004 +0000 +++ b/src/prpl.h Fri Jan 02 06:16:44 2004 +0000 @@ -312,6 +312,8 @@ void (*remove_group)(GaimConnection *gc, const char *group); char *(*get_cb_real_name)(GaimConnection *gc, int id, const char *who); + + void (*set_chat_topic)(GaimConnection *gc, int id, const char *topic); }; #define GAIM_IS_PROTOCOL_PLUGIN(plugin) \