comparison console/gntblist.c @ 13864:c7d84d4c5afa

[gaim-migrate @ 16328] Change the internals of GntTree. The change was required to accommodate expand/collapsing of the groups. I have added tooltips for Groups as well, which shows the online/total count. Do we like it? I have also added emblems at the beginning of the names of the buddies to indicate their status. Currently I am using ASCII-emblems ('o' for available, '.' for away, 'x' for offline (but I am not showing any offline buddies yet)), but I plan on using some cool unicode-emblems Sean suggested to me. committer: Tailor Script <tailor@pidgin.im>
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Sat, 24 Jun 2006 10:10:53 +0000
parents 55fb5cd9bac9
children d78ab363e02d
comparison
equal deleted inserted replaced
13863:cf3eb9f311b2 13864:c7d84d4c5afa
7 #include "gntgaim.h" 7 #include "gntgaim.h"
8 #include "gntbox.h" 8 #include "gntbox.h"
9 #include "gnttree.h" 9 #include "gnttree.h"
10 10
11 #include "gntblist.h" 11 #include "gntblist.h"
12 #include <string.h>
12 13
13 typedef struct 14 typedef struct
14 { 15 {
15 GntWidget *window; 16 GntWidget *window;
16 GntWidget *tree; 17 GntWidget *tree;
21 22
22 GGBlist *ggblist; 23 GGBlist *ggblist;
23 24
24 static void add_buddy(GaimBuddy *buddy, GGBlist *ggblist); 25 static void add_buddy(GaimBuddy *buddy, GGBlist *ggblist);
25 static void add_group(GaimGroup *group, GGBlist *ggblist); 26 static void add_group(GaimGroup *group, GGBlist *ggblist);
27 static void draw_tooltip(GGBlist *ggblist);
26 28
27 static void 29 static void
28 new_node(GaimBlistNode *node) 30 new_node(GaimBlistNode *node)
29 { 31 {
30 } 32 }
52 if (GAIM_BLIST_NODE_IS_BUDDY(node)) 54 if (GAIM_BLIST_NODE_IS_BUDDY(node))
53 { 55 {
54 GaimGroup *group = gaim_buddy_get_group((GaimBuddy*)node); 56 GaimGroup *group = gaim_buddy_get_group((GaimBuddy*)node);
55 if (gaim_blist_get_group_online_count(group) == 0) 57 if (gaim_blist_get_group_online_count(group) == 0)
56 node_remove(list, (GaimBlistNode*)group); 58 node_remove(list, (GaimBlistNode*)group);
59 else if (ggblist->tnode == (GaimBlistNode *)group) /* Need to update the counts */
60 draw_tooltip(ggblist);
57 } 61 }
58 62
59 if (ggblist->tnode == node) 63 if (ggblist->tnode == node)
60 { 64 {
61 remove_tooltip(ggblist); 65 remove_tooltip(ggblist);
66 node_update(GaimBuddyList *list, GaimBlistNode *node) 70 node_update(GaimBuddyList *list, GaimBlistNode *node)
67 { 71 {
68 if (GAIM_BLIST_NODE_IS_BUDDY(node)) 72 if (GAIM_BLIST_NODE_IS_BUDDY(node))
69 { 73 {
70 GaimBuddy *buddy = (GaimBuddy*)node; 74 GaimBuddy *buddy = (GaimBuddy*)node;
75 if (gaim_presence_is_online(gaim_buddy_get_presence(buddy)))
76 add_buddy(buddy, list->ui_data);
77 else
78 node_remove(gaim_get_blist(), node);
71 } 79 }
72 } 80 }
73 81
74 static void 82 static void
75 new_list(GaimBuddyList *list) 83 new_list(GaimBuddyList *list)
104 GaimBlistNode *node = (GaimBlistNode *)group; 112 GaimBlistNode *node = (GaimBlistNode *)group;
105 if (node->ui_data) 113 if (node->ui_data)
106 return; 114 return;
107 node->ui_data = gnt_tree_add_row_after(GNT_TREE(ggblist->tree), group, 115 node->ui_data = gnt_tree_add_row_after(GNT_TREE(ggblist->tree), group,
108 group->name, NULL, NULL); 116 group->name, NULL, NULL);
117 }
118
119 static const char *
120 get_buddy_display_name(GaimBuddy *buddy)
121 {
122 static char text[2096];
123 char status[8];
124 GaimStatusPrimitive prim;
125 GaimPresence *presence;
126 GaimStatus *now;
127
128 presence = gaim_buddy_get_presence(buddy);
129 now = gaim_presence_get_active_status(presence);
130
131 prim = gaim_status_type_get_primitive(gaim_status_get_type(now));
132
133 switch(prim)
134 {
135 #if 1
136 case GAIM_STATUS_OFFLINE:
137 strncpy(status, "x", sizeof(status) - 1);
138 break;
139 case GAIM_STATUS_AVAILABLE:
140 strncpy(status, "o", sizeof(status) - 1);
141 break;
142 default:
143 strncpy(status, ".", sizeof(status) - 1);
144 break;
145 #else
146 /* XXX: Let's use these some time */
147 case GAIM_STATUS_OFFLINE:
148 strncpy(status, "⊗", sizeof(status) - 1);
149 break;
150 case GAIM_STATUS_AVAILABLE:
151 /* XXX: Detect idleness */
152 strncpy(status, "◯", sizeof(status) - 1);
153 break;
154 default:
155 strncpy(status, "⊖", sizeof(status) - 1);
156 break;
157 #endif
158 }
159
160 snprintf(text, sizeof(text) - 1, "%s %s", status, gaim_buddy_get_alias(buddy));
161
162 return text;
109 } 163 }
110 164
111 static void 165 static void
112 add_buddy(GaimBuddy *buddy, GGBlist *ggblist) 166 add_buddy(GaimBuddy *buddy, GGBlist *ggblist)
113 { 167 {
118 172
119 group = gaim_buddy_get_group(buddy); 173 group = gaim_buddy_get_group(buddy);
120 add_group(group, ggblist); 174 add_group(group, ggblist);
121 175
122 node->ui_data = gnt_tree_add_row_after(GNT_TREE(ggblist->tree), buddy, 176 node->ui_data = gnt_tree_add_row_after(GNT_TREE(ggblist->tree), buddy,
123 gaim_buddy_get_alias(buddy), group, NULL); 177 get_buddy_display_name(buddy), group, NULL);
178
179 if (ggblist->tnode == (GaimBlistNode*)group)
180 draw_tooltip(ggblist);
124 } 181 }
125 182
126 static void 183 static void
127 buddy_signed_on(GaimBuddy *buddy, GGBlist *ggblist) 184 buddy_signed_on(GaimBuddy *buddy, GGBlist *ggblist)
128 { 185 {
145 { 202 {
146 gnt_widget_set_focus(widget, FALSE); 203 gnt_widget_set_focus(widget, FALSE);
147 } 204 }
148 205
149 static void 206 static void
150 selection_changed(GntWidget *widget, int old, int current, GGBlist *ggblist) 207 draw_tooltip(GGBlist *ggblist)
151 { 208 {
152 GaimBlistNode *node; 209 GaimBlistNode *node;
153 GntTree *tree = GNT_TREE(widget);
154 int x, y, top, width; 210 int x, y, top, width;
155 GString *str; 211 GString *str;
156 GaimPlugin *prpl; 212 GaimPlugin *prpl;
157 GaimPluginProtocolInfo *prpl_info; 213 GaimPluginProtocolInfo *prpl_info;
158 GaimAccount *account; 214 GaimAccount *account;
159 GntWidget *box, *label; 215 GntTree *tree;
160 char *title; 216 GntWidget *widget, *box, *label;
217 char *title = NULL;
218
219 widget = ggblist->tree;
220 tree = GNT_TREE(widget);
161 221
162 if (ggblist->tooltip) 222 if (ggblist->tooltip)
163 { 223 {
164 remove_tooltip(ggblist); 224 remove_tooltip(ggblist);
165 } 225 }
193 g_free(br); 253 g_free(br);
194 } 254 }
195 255
196 title = g_strdup(gaim_buddy_get_name(buddy)); 256 title = g_strdup(gaim_buddy_get_name(buddy));
197 } 257 }
258 else if (GAIM_BLIST_NODE_IS_GROUP(node))
259 {
260 GaimGroup *group = (GaimGroup *)node;
261
262 g_string_append_printf(str, _("Online: %d\nTotal: %d"),
263 gaim_blist_get_group_online_count(group),
264 gaim_blist_get_group_size(group, FALSE));
265
266 title = g_strdup(group->name);
267 }
198 else 268 else
199 { 269 {
200 g_string_free(str, TRUE); 270 g_string_free(str, TRUE);
201 return; 271 return;
202 } 272 }
215 285
216 gnt_box_add_widget(GNT_BOX(box), GNT_WIDGET(gnt_label_new(str->str))); 286 gnt_box_add_widget(GNT_BOX(box), GNT_WIDGET(gnt_label_new(str->str)));
217 287
218 gnt_widget_set_position(box, x, y); 288 gnt_widget_set_position(box, x, y);
219 gnt_widget_draw(box); 289 gnt_widget_draw(box);
220 290
291 g_free(title);
221 g_string_free(str, TRUE); 292 g_string_free(str, TRUE);
222 ggblist->tooltip = box; 293 ggblist->tooltip = box;
223 ggblist->tnode = node; 294 ggblist->tnode = node;
224 } 295 }
296
297 static void
298 selection_changed(GntWidget *widget, gpointer old, gpointer current, GGBlist *ggblist)
299 {
300 draw_tooltip(ggblist);
301 }
302
225 303
226 static gboolean 304 static gboolean
227 key_pressed(GntWidget *widget, const char *text, GGBlist *ggblist) 305 key_pressed(GntWidget *widget, const char *text, GGBlist *ggblist)
228 { 306 {
229 if (text[0] == 27 && text[1] == 0) 307 if (text[0] == 27 && text[1] == 0)
237 } 315 }
238 } 316 }
239 return FALSE; 317 return FALSE;
240 } 318 }
241 319
320 static void
321 buddy_status_changed(GaimBuddy *buddy, GaimStatus *old, GaimStatus *now, GGBlist *ggblist)
322 {
323 gnt_tree_change_text(GNT_TREE(ggblist->tree), buddy, get_buddy_display_name(buddy));
324 if (ggblist->tnode == (GaimBlistNode*)buddy)
325 draw_tooltip(ggblist);
326 }
327
242 void gg_blist_init() 328 void gg_blist_init()
243 { 329 {
244 ggblist = g_new0(GGBlist, 1); 330 ggblist = g_new0(GGBlist, 1);
245 331
246 gaim_get_blist()->ui_data = ggblist; 332 gaim_get_blist()->ui_data = ggblist;
254 GNT_WIDGET_SET_FLAGS(ggblist->tree, GNT_WIDGET_NO_BORDER); 340 GNT_WIDGET_SET_FLAGS(ggblist->tree, GNT_WIDGET_NO_BORDER);
255 gnt_widget_set_size(ggblist->tree, 25, getmaxy(stdscr) - 2); 341 gnt_widget_set_size(ggblist->tree, 25, getmaxy(stdscr) - 2);
256 342
257 gnt_box_add_widget(GNT_BOX(ggblist->window), ggblist->tree); 343 gnt_box_add_widget(GNT_BOX(ggblist->window), ggblist->tree);
258 gnt_widget_show(ggblist->window); 344 gnt_widget_show(ggblist->window);
345
346 gaim_signal_connect(gaim_blist_get_handle(), "buddy-status-changed", gg_blist_get_handle(),
347 GAIM_CALLBACK(buddy_status_changed), ggblist);
259 348
349 #if 0
260 gaim_signal_connect(gaim_blist_get_handle(), "buddy-signed-on", gg_blist_get_handle(), 350 gaim_signal_connect(gaim_blist_get_handle(), "buddy-signed-on", gg_blist_get_handle(),
261 GAIM_CALLBACK(buddy_signed_on), ggblist); 351 GAIM_CALLBACK(buddy_signed_on), ggblist);
262 gaim_signal_connect(gaim_blist_get_handle(), "buddy-signed-off", gg_blist_get_handle(), 352 gaim_signal_connect(gaim_blist_get_handle(), "buddy-signed-off", gg_blist_get_handle(),
263 GAIM_CALLBACK(buddy_signed_off), ggblist); 353 GAIM_CALLBACK(buddy_signed_off), ggblist);
264 354
265 #if 0
266 /* These I plan to use to indicate unread-messages etc. */ 355 /* These I plan to use to indicate unread-messages etc. */
267 gaim_signal_connect(gaim_conversations_get_handle(), "received-im-msg", gg_blist_get_handle(), 356 gaim_signal_connect(gaim_conversations_get_handle(), "received-im-msg", gg_blist_get_handle(),
268 GAIM_CALLBACK(received_im_msg), list); 357 GAIM_CALLBACK(received_im_msg), list);
269 gaim_signal_connect(gaim_conversations_get_handle(), "sent-im-msg", gg_blist_get_handle(), 358 gaim_signal_connect(gaim_conversations_get_handle(), "sent-im-msg", gg_blist_get_handle(),
270 GAIM_CALLBACK(sent_im_msg), NULL); 359 GAIM_CALLBACK(sent_im_msg), NULL);