Mercurial > pidgin
comparison finch/gntconv.c @ 17177:d761647bc7c4
merge of '0a63bea05479d51972432a195d0c97c0309fbcf4'
and '8ff17e25184faaad69c1329218cd6898bc3e4c26'
author | Eric Polino <aluink@pidgin.im> |
---|---|
date | Sun, 13 May 2007 21:27:13 +0000 |
parents | f2137f75fd10 |
children | 46f2f86e08e4 |
comparison
equal
deleted
inserted
replaced
16936:f6de19624575 | 17177:d761647bc7c4 |
---|---|
54 #define PREF_ROOT "/finch/conversations" | 54 #define PREF_ROOT "/finch/conversations" |
55 #define PREF_CHAT PREF_ROOT "/chats" | 55 #define PREF_CHAT PREF_ROOT "/chats" |
56 #define PREF_USERLIST PREF_CHAT "/userlist" | 56 #define PREF_USERLIST PREF_CHAT "/userlist" |
57 | 57 |
58 #include "config.h" | 58 #include "config.h" |
59 | |
60 static void finch_write_common(PurpleConversation *conv, const char *who, | |
61 const char *message, PurpleMessageFlags flags, time_t mtime); | |
59 | 62 |
60 static void | 63 static void |
61 send_typing_notification(GntWidget *w, FinchConv *ggconv) | 64 send_typing_notification(GntWidget *w, FinchConv *ggconv) |
62 { | 65 { |
63 const char *text = gnt_entry_get_text(GNT_ENTRY(ggconv->entry)); | 66 const char *text = gnt_entry_get_text(GNT_ENTRY(ggconv->entry)); |
266 } | 269 } |
267 gnt_screen_rename_widget(ggc->window, title); | 270 gnt_screen_rename_widget(ggc->window, title); |
268 g_free(title); | 271 g_free(title); |
269 } | 272 } |
270 | 273 |
274 static void | |
275 chat_left_cb(PurpleConversation *conv, gpointer null) | |
276 { | |
277 finch_write_common(conv, NULL, _("You have left this chat."), | |
278 PURPLE_MESSAGE_SYSTEM, time(NULL)); | |
279 } | |
280 | |
271 static gpointer | 281 static gpointer |
272 finch_conv_get_handle() | 282 finch_conv_get_handle() |
273 { | 283 { |
274 static int handle; | 284 static int handle; |
275 return &handle; | 285 return &handle; |
301 | 311 |
302 static void | 312 static void |
303 get_info_cb(GntMenuItem *item, gpointer ggconv) | 313 get_info_cb(GntMenuItem *item, gpointer ggconv) |
304 { | 314 { |
305 FinchConv *ggc = ggconv; | 315 FinchConv *ggc = ggconv; |
316 PurpleNotifyUserInfo *info = purple_notify_user_info_new(); | |
317 purple_notify_user_info_add_pair(info, _("Information"), _("Retrieving...")); | |
318 purple_notify_userinfo(ggc->active_conv->account->gc, purple_conversation_get_name(ggc->active_conv), info, NULL, NULL); | |
319 purple_notify_user_info_destroy(info); | |
320 | |
306 serv_get_info(purple_conversation_get_gc(ggc->active_conv), | 321 serv_get_info(purple_conversation_get_gc(ggc->active_conv), |
307 purple_conversation_get_name(ggc->active_conv)); | 322 purple_conversation_get_name(ggc->active_conv)); |
308 } | 323 } |
309 | 324 |
310 static void | 325 static void |
394 purple_prefs_get_bool(PREF_ROOT "/timestamps")); | 409 purple_prefs_get_bool(PREF_ROOT "/timestamps")); |
395 gnt_menu_add_item(GNT_MENU(sub), item); | 410 gnt_menu_add_item(GNT_MENU(sub), item); |
396 gnt_menuitem_set_callback(item, toggle_timestamps_cb, ggc); | 411 gnt_menuitem_set_callback(item, toggle_timestamps_cb, ggc); |
397 | 412 |
398 if (purple_conversation_get_type(ggc->active_conv) == PURPLE_CONV_TYPE_IM) { | 413 if (purple_conversation_get_type(ggc->active_conv) == PURPLE_CONV_TYPE_IM) { |
399 item = gnt_menuitem_new(_("Send File")); | 414 PurpleAccount *account = purple_conversation_get_account(ggc->active_conv); |
400 gnt_menu_add_item(GNT_MENU(sub), item); | 415 PurplePluginProtocolInfo *pinfo = account->gc ? PURPLE_PLUGIN_PROTOCOL_INFO(account->gc->prpl) : NULL; |
401 gnt_menuitem_set_callback(item, send_file_cb, ggc); | 416 |
417 if (pinfo && pinfo->get_info) { | |
418 item = gnt_menuitem_new(_("Get Info")); | |
419 gnt_menu_add_item(GNT_MENU(sub), item); | |
420 gnt_menuitem_set_callback(item, get_info_cb, ggc); | |
421 } | |
402 | 422 |
403 item = gnt_menuitem_new(_("Add Buddy Pounce...")); | 423 item = gnt_menuitem_new(_("Add Buddy Pounce...")); |
404 gnt_menu_add_item(GNT_MENU(sub), item); | 424 gnt_menu_add_item(GNT_MENU(sub), item); |
405 gnt_menuitem_set_callback(item, add_pounce_cb, ggc); | 425 gnt_menuitem_set_callback(item, add_pounce_cb, ggc); |
406 | 426 |
407 item = gnt_menuitem_new(_("Get Info")); | 427 if (pinfo && pinfo->send_file && |
408 gnt_menu_add_item(GNT_MENU(sub), item); | 428 (!pinfo->can_receive_file || |
409 gnt_menuitem_set_callback(item, get_info_cb, ggc); | 429 pinfo->can_receive_file(account->gc, purple_conversation_get_name(ggc->active_conv)))) { |
430 item = gnt_menuitem_new(_("Send File")); | |
431 gnt_menu_add_item(GNT_MENU(sub), item); | |
432 gnt_menuitem_set_callback(item, send_file_cb, ggc); | |
433 } | |
410 | 434 |
411 generate_send_to_menu(ggc); | 435 generate_send_to_menu(ggc); |
412 } | 436 } |
413 } | 437 } |
414 | 438 |
467 if (type == PURPLE_CONV_TYPE_CHAT) { | 491 if (type == PURPLE_CONV_TYPE_CHAT) { |
468 GntWidget *hbox, *tree; | 492 GntWidget *hbox, *tree; |
469 FinchConvChat *fc = ggc->u.chat = g_new0(FinchConvChat, 1); | 493 FinchConvChat *fc = ggc->u.chat = g_new0(FinchConvChat, 1); |
470 hbox = gnt_hbox_new(FALSE); | 494 hbox = gnt_hbox_new(FALSE); |
471 gnt_box_set_pad(GNT_BOX(hbox), 0); | 495 gnt_box_set_pad(GNT_BOX(hbox), 0); |
472 tree = fc->userlist = gnt_tree_new(); | 496 tree = fc->userlist = gnt_tree_new_with_columns(2); |
497 gnt_tree_set_col_width(GNT_TREE(tree), 0, 1); /* The flag column */ | |
473 gnt_tree_set_compare_func(GNT_TREE(tree), (GCompareFunc)g_utf8_collate); | 498 gnt_tree_set_compare_func(GNT_TREE(tree), (GCompareFunc)g_utf8_collate); |
474 gnt_tree_set_hash_fns(GNT_TREE(tree), g_str_hash, g_str_equal, g_free); | 499 gnt_tree_set_hash_fns(GNT_TREE(tree), g_str_hash, g_str_equal, g_free); |
475 GNT_WIDGET_SET_FLAGS(tree, GNT_WIDGET_NO_BORDER); | 500 GNT_WIDGET_SET_FLAGS(tree, GNT_WIDGET_NO_BORDER); |
476 gnt_box_add_widget(GNT_BOX(hbox), ggc->tv); | 501 gnt_box_add_widget(GNT_BOX(hbox), ggc->tv); |
477 gnt_box_add_widget(GNT_BOX(hbox), tree); | 502 gnt_box_add_widget(GNT_BOX(hbox), tree); |
503 g_signal_connect(G_OBJECT(ggc->tv), "size_changed", G_CALLBACK(size_changed_cb), NULL); | 528 g_signal_connect(G_OBJECT(ggc->tv), "size_changed", G_CALLBACK(size_changed_cb), NULL); |
504 g_signal_connect(G_OBJECT(ggc->window), "position_set", G_CALLBACK(save_position_cb), NULL); | 529 g_signal_connect(G_OBJECT(ggc->window), "position_set", G_CALLBACK(save_position_cb), NULL); |
505 | 530 |
506 if (type == PURPLE_CONV_TYPE_IM) { | 531 if (type == PURPLE_CONV_TYPE_IM) { |
507 g_signal_connect(G_OBJECT(ggc->entry), "text_changed", G_CALLBACK(send_typing_notification), ggc); | 532 g_signal_connect(G_OBJECT(ggc->entry), "text_changed", G_CALLBACK(send_typing_notification), ggc); |
508 purple_signal_connect(purple_conversations_get_handle(), "buddy-typing", finch_conv_get_handle(), | |
509 PURPLE_CALLBACK(update_buddy_typing), NULL); | |
510 purple_signal_connect(purple_conversations_get_handle(), "buddy-typing-stopped", finch_conv_get_handle(), | |
511 PURPLE_CALLBACK(update_buddy_typing), NULL); | |
512 } | 533 } |
513 | 534 |
514 g_free(title); | 535 g_free(title); |
515 gnt_box_give_focus_to_child(GNT_BOX(ggc->window), ggc->entry); | 536 gnt_box_give_focus_to_child(GNT_BOX(ggc->window), ggc->entry); |
516 } | 537 } |
653 name = NULL; | 674 name = NULL; |
654 | 675 |
655 finch_write_common(conv, name, message, flags, mtime); | 676 finch_write_common(conv, name, message, flags, mtime); |
656 } | 677 } |
657 | 678 |
679 static const char * | |
680 chat_flag_text(PurpleConvChatBuddyFlags flags) | |
681 { | |
682 if (flags & PURPLE_CBFLAGS_FOUNDER) | |
683 return "~"; | |
684 if (flags & PURPLE_CBFLAGS_OP) | |
685 return "@"; | |
686 if (flags & PURPLE_CBFLAGS_HALFOP) | |
687 return "%"; | |
688 if (flags & PURPLE_CBFLAGS_VOICE) | |
689 return "+"; | |
690 return " "; | |
691 } | |
692 | |
658 static void | 693 static void |
659 finch_chat_add_users(PurpleConversation *conv, GList *users, gboolean new_arrivals) | 694 finch_chat_add_users(PurpleConversation *conv, GList *users, gboolean new_arrivals) |
660 { | 695 { |
661 FinchConv *ggc = conv->ui_data; | 696 FinchConv *ggc = conv->ui_data; |
662 GntEntry *entry = GNT_ENTRY(ggc->entry); | 697 GntEntry *entry = GNT_ENTRY(ggc->entry); |
687 PurpleConvChatBuddy *cbuddy = users->data; | 722 PurpleConvChatBuddy *cbuddy = users->data; |
688 GntTree *tree = GNT_TREE(ggc->u.chat->userlist); | 723 GntTree *tree = GNT_TREE(ggc->u.chat->userlist); |
689 gnt_entry_add_suggest(entry, cbuddy->name); | 724 gnt_entry_add_suggest(entry, cbuddy->name); |
690 gnt_entry_add_suggest(entry, cbuddy->alias); | 725 gnt_entry_add_suggest(entry, cbuddy->alias); |
691 gnt_tree_add_row_after(tree, g_strdup(cbuddy->name), | 726 gnt_tree_add_row_after(tree, g_strdup(cbuddy->name), |
692 gnt_tree_create_row(tree, cbuddy->alias), NULL, NULL); | 727 gnt_tree_create_row(tree, chat_flag_text(cbuddy->flags), cbuddy->alias), NULL, NULL); |
693 } | 728 } |
694 } | 729 } |
695 | 730 |
696 static void | 731 static void |
697 finch_chat_rename_user(PurpleConversation *conv, const char *old, const char *new_n, const char *new_a) | 732 finch_chat_rename_user(PurpleConversation *conv, const char *old, const char *new_n, const char *new_a) |
698 { | 733 { |
699 /* Update the name for string completion */ | 734 /* Update the name for string completion */ |
700 FinchConv *ggc = conv->ui_data; | 735 FinchConv *ggc = conv->ui_data; |
701 GntEntry *entry = GNT_ENTRY(ggc->entry); | 736 GntEntry *entry = GNT_ENTRY(ggc->entry); |
702 GntTree *tree = GNT_TREE(ggc->u.chat->userlist); | 737 GntTree *tree = GNT_TREE(ggc->u.chat->userlist); |
738 PurpleConvChatBuddy *cb = purple_conv_chat_cb_find(PURPLE_CONV_CHAT(conv), new_n); | |
739 | |
703 gnt_entry_remove_suggest(entry, old); | 740 gnt_entry_remove_suggest(entry, old); |
741 gnt_tree_remove(tree, (gpointer)old); | |
742 | |
704 gnt_entry_add_suggest(entry, new_n); | 743 gnt_entry_add_suggest(entry, new_n); |
705 gnt_entry_add_suggest(entry, new_a); | 744 gnt_entry_add_suggest(entry, new_a); |
706 gnt_tree_remove(tree, (gpointer)old); | |
707 gnt_tree_add_row_after(tree, g_strdup(new_n), | 745 gnt_tree_add_row_after(tree, g_strdup(new_n), |
708 gnt_tree_create_row(tree, new_a), NULL, NULL); | 746 gnt_tree_create_row(tree, chat_flag_text(cb->flags), new_a), NULL, NULL); |
709 } | 747 } |
710 | 748 |
711 static void | 749 static void |
712 finch_chat_remove_user(PurpleConversation *conv, GList *list) | 750 finch_chat_remove_user(PurpleConversation *conv, GList *list) |
713 { | 751 { |
722 } | 760 } |
723 | 761 |
724 static void | 762 static void |
725 finch_chat_update_user(PurpleConversation *conv, const char *user) | 763 finch_chat_update_user(PurpleConversation *conv, const char *user) |
726 { | 764 { |
765 PurpleConvChatBuddy *cb = purple_conv_chat_cb_find(PURPLE_CONV_CHAT(conv), user); | |
766 FinchConv *ggc = conv->ui_data; | |
767 gnt_tree_change_text(GNT_TREE(ggc->u.chat->userlist), (gpointer)user, 0, chat_flag_text(cb->flags)); | |
727 } | 768 } |
728 | 769 |
729 static PurpleConversationUiOps conv_ui_ops = | 770 static PurpleConversationUiOps conv_ui_ops = |
730 { | 771 { |
731 .create_conversation = finch_create_conversation, | 772 .create_conversation = finch_create_conversation, |
928 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM, NULL, | 969 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM, NULL, |
929 cmd_show_window, _("prefs: Show the preference window."), finch_prefs_show_all); | 970 cmd_show_window, _("prefs: Show the preference window."), finch_prefs_show_all); |
930 purple_cmd_register("status", "", PURPLE_CMD_P_DEFAULT, | 971 purple_cmd_register("status", "", PURPLE_CMD_P_DEFAULT, |
931 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM, NULL, | 972 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM, NULL, |
932 cmd_show_window, _("statuses: Show the savedstatuses window."), finch_savedstatus_show_all); | 973 cmd_show_window, _("statuses: Show the savedstatuses window."), finch_savedstatus_show_all); |
974 | |
975 purple_signal_connect(purple_conversations_get_handle(), "buddy-typing", finch_conv_get_handle(), | |
976 PURPLE_CALLBACK(update_buddy_typing), NULL); | |
977 purple_signal_connect(purple_conversations_get_handle(), "buddy-typing-stopped", finch_conv_get_handle(), | |
978 PURPLE_CALLBACK(update_buddy_typing), NULL); | |
979 purple_signal_connect(purple_conversations_get_handle(), "chat-left", finch_conv_get_handle(), | |
980 PURPLE_CALLBACK(chat_left_cb), NULL); | |
933 } | 981 } |
934 | 982 |
935 void finch_conversation_uninit() | 983 void finch_conversation_uninit() |
936 { | 984 { |
985 purple_signals_disconnect_by_handle(finch_conv_get_handle()); | |
937 } | 986 } |
938 | 987 |
939 void finch_conversation_set_active(PurpleConversation *conv) | 988 void finch_conversation_set_active(PurpleConversation *conv) |
940 { | 989 { |
941 FinchConv *ggconv = conv->ui_data; | 990 FinchConv *ggconv = conv->ui_data; |