comparison finch/gntconv.c @ 23392:eac0561dfd55

propagate from branch 'im.pidgin.pidgin.2.4.3' (head 260d5ee6ca276e761c5b0bd1b612edc5743eaf67) to branch 'im.pidgin.pidgin' (head dba36543cdde6db127857b0edfdc3ad1969bbd39)
author Stu Tomlinson <stu@nosnilmot.com>
date Thu, 26 Jun 2008 19:08:55 +0000
parents 54aaea893a89
children a2c625152c52
comparison
equal deleted inserted replaced
23058:00b442421563 23392:eac0561dfd55
36 #include "gntblist.h" 36 #include "gntblist.h"
37 #include "gntconv.h" 37 #include "gntconv.h"
38 #include "gntdebug.h" 38 #include "gntdebug.h"
39 #include "gntlog.h" 39 #include "gntlog.h"
40 #include "gntplugin.h" 40 #include "gntplugin.h"
41 #include "gntpounce.h"
41 #include "gntprefs.h" 42 #include "gntprefs.h"
43 #include "gntrequest.h"
42 #include "gntsound.h" 44 #include "gntsound.h"
43 #include "gntstatus.h" 45 #include "gntstatus.h"
44 #include "gntpounce.h"
45 46
46 #include "gnt.h" 47 #include "gnt.h"
47 #include "gntbox.h" 48 #include "gntbox.h"
48 #include "gntentry.h" 49 #include "gntentry.h"
49 #include "gntlabel.h" 50 #include "gntlabel.h"
138 139
139 static void 140 static void
140 entry_key_pressed(GntWidget *w, FinchConv *ggconv) 141 entry_key_pressed(GntWidget *w, FinchConv *ggconv)
141 { 142 {
142 const char *text = gnt_entry_get_text(GNT_ENTRY(ggconv->entry)); 143 const char *text = gnt_entry_get_text(GNT_ENTRY(ggconv->entry));
143 if (*text == '/') 144 if (*text == '/' && *(text + 1) != '/')
144 { 145 {
145 PurpleConversation *conv = ggconv->active_conv; 146 PurpleConversation *conv = ggconv->active_conv;
146 PurpleCmdStatus status; 147 PurpleCmdStatus status;
147 const char *cmdline = text + 1; 148 const char *cmdline = text + 1;
148 char *error = NULL, *escape; 149 char *error = NULL, *escape;
188 purple_conversation_write(ggconv->active_conv, "", _("Message was not sent, because you are not signed on."), 189 purple_conversation_write(ggconv->active_conv, "", _("Message was not sent, because you are not signed on."),
189 PURPLE_MESSAGE_ERROR | PURPLE_MESSAGE_NO_LOG, time(NULL)); 190 PURPLE_MESSAGE_ERROR | PURPLE_MESSAGE_NO_LOG, time(NULL));
190 } 191 }
191 else 192 else
192 { 193 {
193 char *escape = g_markup_escape_text(text, -1); 194 char *escape = g_markup_escape_text((*text == '/' ? text + 1 : text), -1);
194 char *apos = purple_strreplace(escape, "&apos;", "'"); 195 char *apos = purple_strreplace(escape, "&apos;", "'");
195 g_free(escape); 196 g_free(escape);
196 escape = apos; 197 escape = apos;
197 switch (purple_conversation_get_type(ggconv->active_conv)) 198 switch (purple_conversation_get_type(ggconv->active_conv))
198 { 199 {
555 g_object_set_data_full(G_OBJECT(item), "purple_buddy_name", name, g_free); 556 g_object_set_data_full(G_OBJECT(item), "purple_buddy_name", name, g_free);
556 } 557 }
557 } 558 }
558 559
559 static void 560 static void
561 invite_select_cb(FinchConv *fc, PurpleRequestFields *fields)
562 {
563 PurpleConversation *conv = fc->active_conv;
564 const char *buddy = purple_request_fields_get_string(fields, "screenname");
565 const char *message = purple_request_fields_get_string(fields, "message");
566 serv_chat_invite(purple_conversation_get_gc(conv),
567 purple_conv_chat_get_id(PURPLE_CONV_CHAT(conv)),
568 message, buddy);
569
570 }
571
572 static void
573 invite_cb(GntMenuItem *item, gpointer ggconv)
574 {
575 PurpleRequestFields *fields;
576 PurpleRequestFieldGroup *group;
577 PurpleRequestField *field;
578
579 fields = purple_request_fields_new();
580
581 group = purple_request_field_group_new(NULL);
582 purple_request_fields_add_group(fields, group);
583
584 field = purple_request_field_string_new("screenname", _("Name"), NULL, FALSE);
585 purple_request_field_set_type_hint(field, "screenname");
586 purple_request_field_set_required(field, TRUE);
587 purple_request_field_group_add_field(group, field);
588 field = purple_request_field_string_new("message", _("Invite message"), NULL, FALSE);
589 purple_request_field_group_add_field(group, field);
590 purple_request_fields(finch_conv_get_handle(), _("Invite"),
591 NULL,
592 _("Please enter the name of the user "
593 "you wish to invite,\nalong with an optional invite message."),
594 fields,
595 _("OK"), G_CALLBACK(invite_select_cb),
596 _("Cancel"), NULL,
597 NULL, NULL, NULL,
598 ggconv);
599 }
600
601 static void
560 gg_create_menu(FinchConv *ggc) 602 gg_create_menu(FinchConv *ggc)
561 { 603 {
562 GntWidget *menu, *sub; 604 GntWidget *menu, *sub;
563 GntMenuItem *item; 605 GntMenuItem *item;
564 606
604 gnt_menu_add_item(GNT_MENU(sub), item); 646 gnt_menu_add_item(GNT_MENU(sub), item);
605 gnt_menuitem_set_callback(item, send_file_cb, ggc); 647 gnt_menuitem_set_callback(item, send_file_cb, ggc);
606 } 648 }
607 649
608 generate_send_to_menu(ggc); 650 generate_send_to_menu(ggc);
651 } else if (purple_conversation_get_type(ggc->active_conv) == PURPLE_CONV_TYPE_CHAT) {
652 item = gnt_menuitem_new(_("Invite..."));
653 gnt_menu_add_item(GNT_MENU(sub), item);
654 gnt_menuitem_set_callback(item, invite_cb, ggc);
609 } 655 }
610 656
611 item = gnt_menuitem_new(_("View Log...")); 657 item = gnt_menuitem_new(_("View Log..."));
612 gnt_menu_add_item(GNT_MENU(sub), item); 658 gnt_menu_add_item(GNT_MENU(sub), item);
613 gnt_menuitem_set_callback(item, view_log_cb, ggc); 659 gnt_menuitem_set_callback(item, view_log_cb, ggc);
1189 static PurpleCmdRet 1235 static PurpleCmdRet
1190 cmd_show_window(PurpleConversation *conv, const char *cmd, char **args, char **error, gpointer data) 1236 cmd_show_window(PurpleConversation *conv, const char *cmd, char **args, char **error, gpointer data)
1191 { 1237 {
1192 void (*callback)(void) = data; 1238 void (*callback)(void) = data;
1193 callback(); 1239 callback();
1240 return PURPLE_CMD_STATUS_OK;
1241 }
1242
1243 static PurpleCmdRet
1244 cmd_message_color(PurpleConversation *conv, const char *cmd, char **args, char **error, gpointer data)
1245 {
1246 int *msgclass = NULL;
1247 int fg, bg;
1248
1249 if (strcmp(args[0], "receive") == 0)
1250 msgclass = &color_message_receive;
1251 else if (strcmp(args[0], "send") == 0)
1252 msgclass = &color_message_send;
1253 else if (strcmp(args[0], "highlight") == 0)
1254 msgclass = &color_message_highlight;
1255 else if (strcmp(args[0], "action") == 0)
1256 msgclass = &color_message_action;
1257 else if (strcmp(args[0], "timestamp") == 0)
1258 msgclass = &color_timestamp;
1259 else {
1260 if (error)
1261 *error = g_strdup_printf(_("%s is not a valid message class. See '/help msgcolor' for valid message classes."), args[0]);
1262 return PURPLE_CMD_STATUS_FAILED;
1263 }
1264
1265 fg = gnt_colors_get_color(args[1]);
1266 if (fg == -EINVAL) {
1267 if (error)
1268 *error = g_strdup_printf(_("%s is not a valid color. See '/help msgcolor' for valid colors."), args[1]);
1269 return PURPLE_CMD_STATUS_FAILED;
1270 }
1271
1272 bg = gnt_colors_get_color(args[2]);
1273 if (bg == -EINVAL) {
1274 if (error)
1275 *error = g_strdup_printf(_("%s is not a valid color. See '/help msgcolor' for valid colors."), args[2]);
1276 return PURPLE_CMD_STATUS_FAILED;
1277 }
1278
1279 init_pair(*msgclass, fg, bg);
1280
1194 return PURPLE_CMD_STATUS_OK; 1281 return PURPLE_CMD_STATUS_OK;
1195 } 1282 }
1196 1283
1197 static PurpleCmdRet 1284 static PurpleCmdRet
1198 users_command_cb(PurpleConversation *conv, const char *cmd, char **args, char **error, gpointer data) 1285 users_command_cb(PurpleConversation *conv, const char *cmd, char **args, char **error, gpointer data)
1276 cmd_show_window, _("prefs: Show the preference window."), finch_prefs_show_all); 1363 cmd_show_window, _("prefs: Show the preference window."), finch_prefs_show_all);
1277 purple_cmd_register("status", "", PURPLE_CMD_P_DEFAULT, 1364 purple_cmd_register("status", "", PURPLE_CMD_P_DEFAULT,
1278 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM, NULL, 1365 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM, NULL,
1279 cmd_show_window, _("statuses: Show the savedstatuses window."), finch_savedstatus_show_all); 1366 cmd_show_window, _("statuses: Show the savedstatuses window."), finch_savedstatus_show_all);
1280 1367
1368 /* Allow customizing the message colors using a command during run-time */
1369 purple_cmd_register("msgcolor", "www", PURPLE_CMD_P_DEFAULT,
1370 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM, NULL,
1371 cmd_message_color, _("msgcolor &lt;class&gt; &lt;foreground&gt; &lt;background&gt;: "
1372 "Set the color for different classes of messages in the conversation window.<br>"
1373 " &lt;class&gt;: receive, send, highlight, action, timestamp<br>"
1374 " &lt;foreground/background&gt;: black, red, green, blue, white, gray, darkgray, magenta, cyan, default<br><br>"
1375 "EXAMPLE:<br> msgcolor send cyan default"),
1376 NULL);
1377
1281 purple_signal_connect(purple_conversations_get_handle(), "buddy-typing", finch_conv_get_handle(), 1378 purple_signal_connect(purple_conversations_get_handle(), "buddy-typing", finch_conv_get_handle(),
1282 PURPLE_CALLBACK(update_buddy_typing), NULL); 1379 PURPLE_CALLBACK(update_buddy_typing), NULL);
1283 purple_signal_connect(purple_conversations_get_handle(), "buddy-typing-stopped", finch_conv_get_handle(), 1380 purple_signal_connect(purple_conversations_get_handle(), "buddy-typing-stopped", finch_conv_get_handle(),
1284 PURPLE_CALLBACK(update_buddy_typing), NULL); 1381 PURPLE_CALLBACK(update_buddy_typing), NULL);
1285 purple_signal_connect(purple_conversations_get_handle(), "chat-left", finch_conv_get_handle(), 1382 purple_signal_connect(purple_conversations_get_handle(), "chat-left", finch_conv_get_handle(),