comparison console/gntblist.c @ 14384:4a901f5d1312

[gaim-migrate @ 17090] Contactize the buddylist. But there's no way to move a buddy in some contact yet. Drag-dropping might be possible, but I'll probably go with a menuitem in the context-menu. committer: Tailor Script <tailor@pidgin.im>
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Thu, 31 Aug 2006 00:58:50 +0000
parents a7e29c0b51f4
children d1e4e986bbd1
comparison
equal deleted inserted replaced
14383:5f3058c7a7df 14384:4a901f5d1312
59 } StatusBoxItem; 59 } StatusBoxItem;
60 60
61 GGBlist *ggblist; 61 GGBlist *ggblist;
62 62
63 static void add_buddy(GaimBuddy *buddy, GGBlist *ggblist); 63 static void add_buddy(GaimBuddy *buddy, GGBlist *ggblist);
64 static void add_contact(GaimContact *contact, GGBlist *ggblist);
64 static void add_group(GaimGroup *group, GGBlist *ggblist); 65 static void add_group(GaimGroup *group, GGBlist *ggblist);
65 static void add_chat(GaimChat *chat, GGBlist *ggblist); 66 static void add_chat(GaimChat *chat, GGBlist *ggblist);
66 static void add_node(GaimBlistNode *node, GGBlist *ggblist); 67 static void add_node(GaimBlistNode *node, GGBlist *ggblist);
67 static void draw_tooltip(GGBlist *ggblist); 68 static void draw_tooltip(GGBlist *ggblist);
68 static gboolean remove_typing_cb(gpointer null); 69 static gboolean remove_typing_cb(gpointer null);
77 78
78 static void add_node(GaimBlistNode *node, GGBlist *ggblist) 79 static void add_node(GaimBlistNode *node, GGBlist *ggblist)
79 { 80 {
80 if (GAIM_BLIST_NODE_IS_BUDDY(node)) 81 if (GAIM_BLIST_NODE_IS_BUDDY(node))
81 add_buddy((GaimBuddy*)node, ggblist); 82 add_buddy((GaimBuddy*)node, ggblist);
83 else if (GAIM_BLIST_NODE_IS_CONTACT(node))
84 add_contact((GaimContact*)node, ggblist);
82 else if (GAIM_BLIST_NODE_IS_GROUP(node)) 85 else if (GAIM_BLIST_NODE_IS_GROUP(node))
83 add_group((GaimGroup*)node, ggblist); 86 add_group((GaimGroup*)node, ggblist);
84 else if (GAIM_BLIST_NODE_IS_CHAT(node)) 87 else if (GAIM_BLIST_NODE_IS_CHAT(node))
85 add_chat((GaimChat *)node, ggblist); 88 add_chat((GaimChat *)node, ggblist);
86 draw_tooltip(ggblist); 89 draw_tooltip(ggblist);
105 gnt_tree_remove(GNT_TREE(ggblist->tree), node); 108 gnt_tree_remove(GNT_TREE(ggblist->tree), node);
106 node->ui_data = NULL; 109 node->ui_data = NULL;
107 110
108 if (GAIM_BLIST_NODE_IS_BUDDY(node)) 111 if (GAIM_BLIST_NODE_IS_BUDDY(node))
109 { 112 {
110 GaimGroup *group = gaim_buddy_get_group((GaimBuddy*)node); 113 GaimContact *contact = (GaimContact*)node->parent;
111 if (gaim_blist_get_group_online_count(group) == 0) 114 if (contact->online < 1)
112 node_remove(list, (GaimBlistNode*)group); 115 node_remove(list, (GaimBlistNode*)contact);
113 } 116 }
114 draw_tooltip(ggblist); 117 draw_tooltip(ggblist);
115 } 118 }
116 119
117 static void 120 static void
345 get_display_name(GaimBlistNode *node) 348 get_display_name(GaimBlistNode *node)
346 { 349 {
347 static char text[2096]; 350 static char text[2096];
348 char status[8] = " "; 351 char status[8] = " ";
349 const char *name = NULL; 352 const char *name = NULL;
353
354 if (GAIM_BLIST_NODE_IS_CONTACT(node))
355 node = (GaimBlistNode*)gaim_contact_get_priority_buddy((GaimContact*)node); /* XXX: this can return NULL?! */
356
357 if (node == NULL)
358 return NULL;
350 359
351 if (GAIM_BLIST_NODE_IS_BUDDY(node)) 360 if (GAIM_BLIST_NODE_IS_BUDDY(node))
352 { 361 {
353 GaimBuddy *buddy = (GaimBuddy *)node; 362 GaimBuddy *buddy = (GaimBuddy *)node;
354 GaimStatusPrimitive prim; 363 GaimStatusPrimitive prim;
411 if (gaim_blist_node_get_bool((GaimBlistNode*)chat, "gnt-autojoin")) 420 if (gaim_blist_node_get_bool((GaimBlistNode*)chat, "gnt-autojoin"))
412 serv_join_chat(gaim_account_get_connection(chat->account), chat->components); 421 serv_join_chat(gaim_account_get_connection(chat->account), chat->components);
413 } 422 }
414 423
415 static void 424 static void
425 add_contact(GaimContact *contact, GGBlist *ggblist)
426 {
427 GaimGroup *group;
428 GaimBlistNode *node = (GaimBlistNode*)contact;
429 GaimBuddy *buddy;
430
431 if (node->ui_data)
432 return;
433
434 group = (GaimGroup*)node->parent;
435 add_node((GaimBlistNode*)group, ggblist);
436
437 node->ui_data = gnt_tree_add_row_after(GNT_TREE(ggblist->tree), contact,
438 gnt_tree_create_row(GNT_TREE(ggblist->tree), get_display_name(node)),
439 group, NULL);
440
441 gnt_tree_set_expanded(GNT_TREE(ggblist->tree), contact, FALSE);
442
443 buddy = gaim_contact_get_priority_buddy(contact);
444 if (gaim_presence_is_idle(gaim_buddy_get_presence(buddy)))
445 gnt_tree_set_row_flags(GNT_TREE(ggblist->tree), contact, GNT_TEXT_FLAG_DIM);
446 else
447 gnt_tree_set_row_flags(GNT_TREE(ggblist->tree), contact, 0);
448 }
449
450 static void
416 add_buddy(GaimBuddy *buddy, GGBlist *ggblist) 451 add_buddy(GaimBuddy *buddy, GGBlist *ggblist)
417 { 452 {
418 GaimGroup *group; 453 GaimContact *contact;
419 GaimBlistNode *node = (GaimBlistNode *)buddy; 454 GaimBlistNode *node = (GaimBlistNode *)buddy;
420 if (node->ui_data) 455 if (node->ui_data)
421 return; 456 return;
422 457
423 group = gaim_buddy_get_group(buddy); 458 contact = (GaimContact*)node->parent;
424 add_node((GaimBlistNode*)group, ggblist); 459 add_node((GaimBlistNode*)contact, ggblist);
425 460
426 gnt_tree_remove(GNT_TREE(ggblist->tree), buddy); 461 gnt_tree_remove(GNT_TREE(ggblist->tree), buddy);
427 node->ui_data = gnt_tree_add_row_after(GNT_TREE(ggblist->tree), buddy, 462 node->ui_data = gnt_tree_add_row_after(GNT_TREE(ggblist->tree), buddy,
428 gnt_tree_create_row(GNT_TREE(ggblist->tree), get_display_name(node)), 463 gnt_tree_create_row(GNT_TREE(ggblist->tree), get_display_name(node)),
429 group, NULL); 464 contact, NULL);
430 if (gaim_presence_is_idle(gaim_buddy_get_presence(buddy))) 465 if (gaim_presence_is_idle(gaim_buddy_get_presence(buddy)))
431 gnt_tree_set_row_flags(GNT_TREE(ggblist->tree), buddy, GNT_TEXT_FLAG_DIM); 466 gnt_tree_set_row_flags(GNT_TREE(ggblist->tree), buddy, GNT_TEXT_FLAG_DIM);
432 else 467 else
433 gnt_tree_set_row_flags(GNT_TREE(ggblist->tree), buddy, 0); 468 gnt_tree_set_row_flags(GNT_TREE(ggblist->tree), buddy, 0);
434 } 469 }
458 GntTree *tree = GNT_TREE(ggblist->tree); 493 GntTree *tree = GNT_TREE(ggblist->tree);
459 GaimBlistNode *node = gnt_tree_get_selection_data(tree); 494 GaimBlistNode *node = gnt_tree_get_selection_data(tree);
460 495
461 if (!node) 496 if (!node)
462 return; 497 return;
498
499 if (GAIM_BLIST_NODE_IS_CONTACT(node))
500 node = (GaimBlistNode*)gaim_contact_get_priority_buddy((GaimContact*)node);
463 501
464 if (GAIM_BLIST_NODE_IS_BUDDY(node)) 502 if (GAIM_BLIST_NODE_IS_BUDDY(node))
465 { 503 {
466 GaimBuddy *buddy = (GaimBuddy *)node; 504 GaimBuddy *buddy = (GaimBuddy *)node;
467 gaim_conversation_new(GAIM_CONV_TYPE_IM, 505 gaim_conversation_new(GAIM_CONV_TYPE_IM,
711 { 749 {
712 const char *name = newname; 750 const char *name = newname;
713 if (name && !*name) 751 if (name && !*name)
714 name = NULL; 752 name = NULL;
715 753
716 if (GAIM_BLIST_NODE_IS_BUDDY(node)) 754 if (GAIM_BLIST_NODE_IS_CONTACT(node))
755 gaim_blist_alias_contact((GaimContact*)node, name);
756 else if (GAIM_BLIST_NODE_IS_BUDDY(node))
717 gaim_blist_alias_buddy((GaimBuddy*)node, name); 757 gaim_blist_alias_buddy((GaimBuddy*)node, name);
718 else if (GAIM_BLIST_NODE_IS_CHAT(node)) 758 else if (GAIM_BLIST_NODE_IS_CHAT(node))
719 gaim_blist_alias_chat((GaimChat*)node, name); 759 gaim_blist_alias_chat((GaimChat*)node, name);
720 else if (GAIM_BLIST_NODE_IS_GROUP(node)) 760 else if (GAIM_BLIST_NODE_IS_GROUP(node))
721 gaim_blist_rename_group((GaimGroup*)node, name); 761 gaim_blist_rename_group((GaimGroup*)node, name);
727 gg_blist_rename_node_cb(GaimBlistNode *node, GaimBlistNode *null) 767 gg_blist_rename_node_cb(GaimBlistNode *node, GaimBlistNode *null)
728 { 768 {
729 const char *name = NULL; 769 const char *name = NULL;
730 char *prompt; 770 char *prompt;
731 771
732 if (GAIM_BLIST_NODE_IS_BUDDY(node)) 772 if (GAIM_BLIST_NODE_IS_CONTACT(node))
773 name = gaim_contact_get_alias((GaimContact*)node);
774 else if (GAIM_BLIST_NODE_IS_BUDDY(node))
733 name = gaim_buddy_get_contact_alias((GaimBuddy*)node); 775 name = gaim_buddy_get_contact_alias((GaimBuddy*)node);
734 else if (GAIM_BLIST_NODE_IS_CHAT(node)) 776 else if (GAIM_BLIST_NODE_IS_CHAT(node))
735 name = gaim_chat_get_name((GaimChat*)node); 777 name = gaim_chat_get_name((GaimChat*)node);
736 else if (GAIM_BLIST_NODE_IS_GROUP(node)) 778 else if (GAIM_BLIST_NODE_IS_GROUP(node))
737 name = ((GaimGroup*)node)->name; 779 name = ((GaimGroup*)node)->name;
786 } 828 }
787 829
788 static void 830 static void
789 gg_blist_remove_node(GaimBlistNode *node) 831 gg_blist_remove_node(GaimBlistNode *node)
790 { 832 {
791 if (GAIM_BLIST_NODE_IS_BUDDY(node)) 833 if (GAIM_BLIST_NODE_IS_CONTACT(node)) {
792 { 834 gaim_blist_remove_contact((GaimContact*)node);
835 } else if (GAIM_BLIST_NODE_IS_BUDDY(node)) {
793 GaimBuddy *buddy = (GaimBuddy*)node; 836 GaimBuddy *buddy = (GaimBuddy*)node;
794 GaimGroup *group = gaim_buddy_get_group(buddy); 837 GaimGroup *group = gaim_buddy_get_group(buddy);
795 gaim_account_remove_buddy(gaim_buddy_get_account(buddy), buddy, group); 838 gaim_account_remove_buddy(gaim_buddy_get_account(buddy), buddy, group);
796 gaim_blist_remove_buddy(buddy); 839 gaim_blist_remove_buddy(buddy);
797 } 840 } else if (GAIM_BLIST_NODE_IS_CHAT(node)) {
798 else if (GAIM_BLIST_NODE_IS_CHAT(node))
799 {
800 gaim_blist_remove_chat((GaimChat*)node); 841 gaim_blist_remove_chat((GaimChat*)node);
801 } 842 } else if (GAIM_BLIST_NODE_IS_GROUP(node)) {
802 else if (GAIM_BLIST_NODE_IS_GROUP(node))
803 {
804 remove_group((GaimGroup*)node); 843 remove_group((GaimGroup*)node);
805 } 844 }
806 } 845 }
807 846
808 static void 847 static void
809 gg_blist_remove_node_cb(GaimBlistNode *node, GaimBlistNode *null) 848 gg_blist_remove_node_cb(GaimBlistNode *node, GaimBlistNode *null)
810 { 849 {
811 char *primary; 850 char *primary;
812 const char *name, *sec = NULL; 851 const char *name, *sec = NULL;
813 852
814 if (GAIM_BLIST_NODE_IS_BUDDY(node)) 853 /* XXX: could be a contact */
854 if (GAIM_BLIST_NODE_IS_CONTACT(node))
855 name = gaim_contact_get_alias((GaimContact*)node);
856 else if (GAIM_BLIST_NODE_IS_BUDDY(node))
815 name = gaim_buddy_get_name((GaimBuddy*)node); 857 name = gaim_buddy_get_name((GaimBuddy*)node);
816 else if (GAIM_BLIST_NODE_IS_CHAT(node)) 858 else if (GAIM_BLIST_NODE_IS_CHAT(node))
817 name = gaim_chat_get_name((GaimChat*)node); 859 name = gaim_chat_get_name((GaimChat*)node);
818 else if (GAIM_BLIST_NODE_IS_GROUP(node)) 860 else if (GAIM_BLIST_NODE_IS_GROUP(node))
819 { 861 {
861 ggblist->context = context = gnt_tree_new(); 903 ggblist->context = context = gnt_tree_new();
862 GNT_WIDGET_SET_FLAGS(context, GNT_WIDGET_NO_BORDER); 904 GNT_WIDGET_SET_FLAGS(context, GNT_WIDGET_NO_BORDER);
863 gnt_widget_set_name(context, "context menu"); 905 gnt_widget_set_name(context, "context menu");
864 g_signal_connect(G_OBJECT(context), "activate", G_CALLBACK(context_menu_callback), ggblist); 906 g_signal_connect(G_OBJECT(context), "activate", G_CALLBACK(context_menu_callback), ggblist);
865 907
908 /* XXX: For now, for a contact, the context menu for the priority buddy will popup */
909 if (GAIM_BLIST_NODE_IS_CONTACT(node))
910 node = (GaimBlistNode*)gaim_contact_get_priority_buddy((GaimContact*)node);
911
866 if (GAIM_BLIST_NODE_IS_BUDDY(node)) 912 if (GAIM_BLIST_NODE_IS_BUDDY(node))
867 { 913 {
868 GaimBuddy *buddy = (GaimBuddy *)node; 914 GaimBuddy *buddy = (GaimBuddy *)node;
869 create_buddy_menu(GNT_TREE(context), buddy); 915 create_buddy_menu(GNT_TREE(context), buddy);
870 title = g_strdup(gaim_buddy_get_name(buddy)); 916 title = g_strdup(gaim_buddy_get_name(buddy));
910 gnt_widget_draw(window); 956 gnt_widget_draw(window);
911 g_free(title); 957 g_free(title);
912 } 958 }
913 959
914 static void 960 static void
961 tooltip_for_buddy(GaimBuddy *buddy, GString *str)
962 {
963 GaimPlugin *prpl;
964 GaimPluginProtocolInfo *prpl_info;
965 GaimAccount *account;
966
967 account = gaim_buddy_get_account(buddy);
968
969 g_string_append_printf(str, _("Account: %s (%s)"),
970 gaim_account_get_username(account),
971 gaim_account_get_protocol_name(account));
972
973 prpl = gaim_find_prpl(gaim_account_get_protocol_id(account));
974 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl);
975 if (prpl_info && prpl_info->tooltip_text) {
976 GString *tip = g_string_new("");
977 char *strip, *br;
978 prpl_info->tooltip_text(buddy, tip, TRUE);
979
980 br = gaim_strreplace(tip->str, "\n", "<br>");
981 strip = gaim_markup_strip_html(br);
982 g_string_append(str, strip);
983 g_string_free(tip, TRUE);
984 g_free(strip);
985 g_free(br);
986 }
987
988 if (gaim_prefs_get_bool("/gaim/gnt/blist/idletime")) {
989 GaimPresence *pre = gaim_buddy_get_presence(buddy);
990 if (gaim_presence_is_idle(pre)) {
991 time_t idle = gaim_presence_get_idle_time(pre);
992 if (idle > 0) {
993 char *st = gaim_str_seconds_to_string(time(NULL) - idle);
994 g_string_append_printf(str, _("\nIdle: %s"), st);
995 g_free(st);
996 }
997 }
998 }
999 }
1000
1001 static void
915 draw_tooltip(GGBlist *ggblist) 1002 draw_tooltip(GGBlist *ggblist)
916 { 1003 {
917 GaimBlistNode *node; 1004 GaimBlistNode *node;
918 int x, y, top, width; 1005 int x, y, top, width;
919 GString *str; 1006 GString *str;
920 GaimPlugin *prpl;
921 GaimPluginProtocolInfo *prpl_info;
922 GaimAccount *account;
923 GntTree *tree; 1007 GntTree *tree;
924 GntWidget *widget, *box; 1008 GntWidget *widget, *box;
925 char *title = NULL; 1009 char *title = NULL;
926 1010
927 widget = ggblist->tree; 1011 widget = ggblist->tree;
944 if (!node) 1028 if (!node)
945 return; 1029 return;
946 1030
947 str = g_string_new(""); 1031 str = g_string_new("");
948 1032
949 if (GAIM_BLIST_NODE_IS_BUDDY(node)) 1033 if (GAIM_BLIST_NODE_IS_CONTACT(node)) {
950 { 1034 GaimBuddy *pr = gaim_contact_get_priority_buddy((GaimContact*)node);
1035 title = g_strdup(gaim_contact_get_alias((GaimContact*)node));
1036 tooltip_for_buddy(pr, str);
1037 for (node = node->child; node; node = node->next) {
1038 if (node == (GaimBlistNode*)pr || !GAIM_BUDDY_IS_ONLINE((GaimBuddy*)node))
1039 continue;
1040 str = g_string_append(str, "\n----------\n");
1041 tooltip_for_buddy((GaimBuddy*)node, str);
1042 }
1043 } else if (GAIM_BLIST_NODE_IS_BUDDY(node)) {
951 GaimBuddy *buddy = (GaimBuddy *)node; 1044 GaimBuddy *buddy = (GaimBuddy *)node;
952 account = gaim_buddy_get_account(buddy); 1045 tooltip_for_buddy(buddy, str);
953 1046 title = g_strdup(gaim_buddy_get_name(buddy));
1047 } else if (GAIM_BLIST_NODE_IS_GROUP(node)) {
1048 GaimGroup *group = (GaimGroup *)node;
1049
1050 g_string_append_printf(str, _("Online: %d\nTotal: %d"),
1051 gaim_blist_get_group_online_count(group),
1052 gaim_blist_get_group_size(group, FALSE));
1053
1054 title = g_strdup(group->name);
1055 } else if (GAIM_BLIST_NODE_IS_CHAT(node)) {
1056 GaimChat *chat = (GaimChat *)node;
1057 GaimAccount *account = chat->account;
1058
954 g_string_append_printf(str, _("Account: %s (%s)"), 1059 g_string_append_printf(str, _("Account: %s (%s)"),
955 gaim_account_get_username(account), 1060 gaim_account_get_username(account),
956 gaim_account_get_protocol_name(account)); 1061 gaim_account_get_protocol_name(account));
957
958 prpl = gaim_find_prpl(gaim_account_get_protocol_id(account));
959 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl);
960 if (prpl_info && prpl_info->tooltip_text)
961 {
962 GString *tip = g_string_new("");
963 char *strip, *br;
964 prpl_info->tooltip_text(buddy, tip, TRUE);
965
966 br = gaim_strreplace(tip->str, "\n", "<br>");
967 strip = gaim_markup_strip_html(br);
968 g_string_append(str, strip);
969 g_string_free(tip, TRUE);
970 g_free(strip);
971 g_free(br);
972 }
973
974 if (gaim_prefs_get_bool("/gaim/gnt/blist/idletime"))
975 {
976 GaimPresence *pre = gaim_buddy_get_presence(buddy);
977 if (gaim_presence_is_idle(pre))
978 {
979 time_t idle = gaim_presence_get_idle_time(pre);
980 if (idle > 0) {
981 char *st = gaim_str_seconds_to_string(time(NULL) - idle);
982 g_string_append_printf(str, _("\nIdle: %s"), st);
983 g_free(st);
984 }
985 }
986 }
987
988 title = g_strdup(gaim_buddy_get_name(buddy));
989 }
990 else if (GAIM_BLIST_NODE_IS_GROUP(node))
991 {
992 GaimGroup *group = (GaimGroup *)node;
993
994 g_string_append_printf(str, _("Online: %d\nTotal: %d"),
995 gaim_blist_get_group_online_count(group),
996 gaim_blist_get_group_size(group, FALSE));
997
998 title = g_strdup(group->name);
999 }
1000 else if (GAIM_BLIST_NODE_IS_CHAT(node))
1001 {
1002 GaimChat *chat = (GaimChat *)node;
1003 GaimAccount *account = chat->account;
1004
1005 g_string_append_printf(str, _("Account: %s (%s)"),
1006 gaim_account_get_username(account),
1007 gaim_account_get_protocol_name(account));
1008 1062
1009 title = g_strdup(gaim_chat_get_name(chat)); 1063 title = g_strdup(gaim_chat_get_name(chat));
1010 } 1064 } else {
1011 else
1012 {
1013 g_string_free(str, TRUE); 1065 g_string_free(str, TRUE);
1014 return; 1066 return;
1015 } 1067 }
1016 1068
1017 gnt_widget_get_position(widget, &x, &y); 1069 gnt_widget_get_position(widget, &x, &y);