comparison finch/gntconv.c @ 25717:907ca9a36fe0

explicit merge of '714a7c7f903d11c96ffade34966121da549d998f' and 'd2c40fe4e2181eda5c1c631c7805f17e6b5d22c3' to branch 'org.darkrain42.pidgin.xmpp'
author Paul Aurich <paul@darkrain42.org>
date Thu, 20 Nov 2008 21:13:56 +0000
parents f4b2fecfb557
children 240d847e9e88
comparison
equal deleted inserted replaced
25614:94ccccab4e98 25717:907ca9a36fe0
139 139
140 static void 140 static void
141 entry_key_pressed(GntWidget *w, FinchConv *ggconv) 141 entry_key_pressed(GntWidget *w, FinchConv *ggconv)
142 { 142 {
143 const char *text = gnt_entry_get_text(GNT_ENTRY(ggconv->entry)); 143 const char *text = gnt_entry_get_text(GNT_ENTRY(ggconv->entry));
144 if (*text == '/') 144 if (*text == '/' && *(text + 1) != '/')
145 { 145 {
146 PurpleConversation *conv = ggconv->active_conv; 146 PurpleConversation *conv = ggconv->active_conv;
147 PurpleCmdStatus status; 147 PurpleCmdStatus status;
148 const char *cmdline = text + 1; 148 const char *cmdline = text + 1;
149 char *error = NULL, *escape; 149 char *error = NULL, *escape;
189 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."),
190 PURPLE_MESSAGE_ERROR | PURPLE_MESSAGE_NO_LOG, time(NULL)); 190 PURPLE_MESSAGE_ERROR | PURPLE_MESSAGE_NO_LOG, time(NULL));
191 } 191 }
192 else 192 else
193 { 193 {
194 char *escape = g_markup_escape_text(text, -1); 194 char *escape = g_markup_escape_text((*text == '/' ? text + 1 : text), -1);
195 char *apos = purple_strreplace(escape, "&apos;", "'"); 195 char *apos = purple_strreplace(escape, "&apos;", "'");
196 g_free(escape); 196 g_free(escape);
197 escape = apos; 197 escape = apos;
198 switch (purple_conversation_get_type(ggconv->active_conv)) 198 switch (purple_conversation_get_type(ggconv->active_conv))
199 { 199 {
690 } 690 }
691 691
692 static void 692 static void
693 completion_cb(GntEntry *entry, const char *start, const char *end) 693 completion_cb(GntEntry *entry, const char *start, const char *end)
694 { 694 {
695 if (start == entry->start) 695 if (start == entry->start && *start != '/')
696 gnt_widget_key_pressed(GNT_WIDGET(entry), ": "); 696 gnt_widget_key_pressed(GNT_WIDGET(entry), ": ");
697 }
698
699 static void
700 gg_setup_commands(FinchConv *fconv, gboolean remove_first)
701 {
702 GList *commands;
703 char command[256] = "/";
704
705 if (remove_first) {
706 commands = purple_cmd_list(NULL);
707 for (; commands; commands = g_list_delete_link(commands, commands)) {
708 g_strlcpy(command + 1, commands->data, sizeof(command) - 1);
709 gnt_entry_remove_suggest(GNT_ENTRY(fconv->entry), command);
710 }
711 }
712
713 commands = purple_cmd_list(fconv->active_conv);
714 for (; commands; commands = g_list_delete_link(commands, commands)) {
715 g_strlcpy(command + 1, commands->data, sizeof(command) - 1);
716 gnt_entry_add_suggest(GNT_ENTRY(fconv->entry), command);
717 }
718 }
719
720 static void
721 cmd_added_cb(const char *cmd, PurpleCmdPriority prior, PurpleCmdFlag flags,
722 FinchConv *fconv)
723 {
724 gg_setup_commands(fconv, TRUE);
725 }
726
727 static void
728 cmd_removed_cb(const char *cmd, FinchConv *fconv)
729 {
730 char command[256] = "/";
731 g_strlcpy(command + 1, cmd, sizeof(command) - 1);
732 gnt_entry_remove_suggest(GNT_ENTRY(fconv->entry), command);
733 gg_setup_commands(fconv, TRUE);
697 } 734 }
698 735
699 static void 736 static void
700 finch_create_conversation(PurpleConversation *conv) 737 finch_create_conversation(PurpleConversation *conv)
701 { 738 {
817 if ((convnode && purple_blist_node_get_bool(convnode, "gnt-mute-sound")) || 854 if ((convnode && purple_blist_node_get_bool(convnode, "gnt-mute-sound")) ||
818 !finch_sound_is_enabled()) 855 !finch_sound_is_enabled())
819 ggc->flags |= FINCH_CONV_NO_SOUND; 856 ggc->flags |= FINCH_CONV_NO_SOUND;
820 857
821 gg_create_menu(ggc); 858 gg_create_menu(ggc);
859 gg_setup_commands(ggc, FALSE);
860
861 purple_signal_connect(purple_cmds_get_handle(), "cmd-added", ggc,
862 G_CALLBACK(cmd_added_cb), ggc);
863 purple_signal_connect(purple_cmds_get_handle(), "cmd-removed", ggc,
864 G_CALLBACK(cmd_removed_cb), ggc);
822 865
823 g_free(title); 866 g_free(title);
824 gnt_box_give_focus_to_child(GNT_BOX(ggc->window), ggc->entry); 867 gnt_box_give_focus_to_child(GNT_BOX(ggc->window), ggc->entry);
825 g_signal_connect(G_OBJECT(ggc->window), "gained-focus", G_CALLBACK(gained_focus_cb), ggc); 868 g_signal_connect(G_OBJECT(ggc->window), "gained-focus", G_CALLBACK(gained_focus_cb), ggc);
826 } 869 }
829 finch_destroy_conversation(PurpleConversation *conv) 872 finch_destroy_conversation(PurpleConversation *conv)
830 { 873 {
831 /* do stuff here */ 874 /* do stuff here */
832 FinchConv *ggc = FINCH_GET_DATA(conv); 875 FinchConv *ggc = FINCH_GET_DATA(conv);
833 ggc->list = g_list_remove(ggc->list, conv); 876 ggc->list = g_list_remove(ggc->list, conv);
834 if (ggc->list && conv == ggc->active_conv) 877 if (ggc->list && conv == ggc->active_conv) {
835 ggc->active_conv = ggc->list->data; 878 ggc->active_conv = ggc->list->data;
836 879 gg_setup_commands(ggc, TRUE);
880 }
881
837 if (ggc->list == NULL) { 882 if (ggc->list == NULL) {
838 g_free(ggc->u.chat); 883 g_free(ggc->u.chat);
884 purple_signals_disconnect_by_handle(ggc);
839 if (ggc->window) 885 if (ggc->window)
840 gnt_widget_destroy(ggc->window); 886 gnt_widget_destroy(ggc->window);
841 g_free(ggc); 887 g_free(ggc);
842 } 888 }
843 } 889 }
1011 GntEntry *entry = GNT_ENTRY(ggc->entry); 1057 GntEntry *entry = GNT_ENTRY(ggc->entry);
1012 1058
1013 if (!new_arrivals) 1059 if (!new_arrivals)
1014 { 1060 {
1015 /* Print the list of users in the room */ 1061 /* Print the list of users in the room */
1016 GString *string = g_string_new(_("List of users:\n")); 1062 GString *string = g_string_new(NULL);
1017 GList *iter; 1063 GList *iter;
1018 1064 int count = g_list_length(users);
1065
1066 g_string_printf(string,
1067 ngettext("List of %d user:\n", "List of %d users:\n", count), count);
1019 for (iter = users; iter; iter = iter->next) 1068 for (iter = users; iter; iter = iter->next)
1020 { 1069 {
1021 PurpleConvChatBuddy *cbuddy = iter->data; 1070 PurpleConvChatBuddy *cbuddy = iter->data;
1022 char *str; 1071 char *str;
1023 1072
1402 PurpleAccount *account; 1451 PurpleAccount *account;
1403 char *title; 1452 char *title;
1404 1453
1405 g_return_if_fail(ggconv); 1454 g_return_if_fail(ggconv);
1406 g_return_if_fail(g_list_find(ggconv->list, conv)); 1455 g_return_if_fail(g_list_find(ggconv->list, conv));
1456 if (ggconv->active_conv == conv)
1457 return;
1407 1458
1408 ggconv->active_conv = conv; 1459 ggconv->active_conv = conv;
1460 gg_setup_commands(ggconv, TRUE);
1409 account = purple_conversation_get_account(conv); 1461 account = purple_conversation_get_account(conv);
1410 title = get_conversation_title(conv, account); 1462 title = get_conversation_title(conv, account);
1411 gnt_screen_rename_widget(ggconv->window, title); 1463 gnt_screen_rename_widget(ggconv->window, title);
1412 g_free(title); 1464 g_free(title);
1413 } 1465 }