| |
1 #include <gaim/account.h> |
| |
2 #include <gaim/blist.h> |
| |
3 #include <signal.h> |
| |
4 #include <gaim/util.h> |
| |
5 #include <gaim/server.h> |
| |
6 |
| |
7 #include "gntgaim.h" |
| |
8 #include "gntbox.h" |
| |
9 #include "gnttree.h" |
| |
10 |
| |
11 #define TAB_SIZE 3 |
| |
12 |
| |
13 /** |
| |
14 * NOTES: |
| |
15 * |
| |
16 * 1. signal-callbacks should check for module_in_focus() before redrawing anything. |
| |
17 * 2. call module_lost_focus() before opening a new window, and module_gained_focus() when |
| |
18 * the new window is closed. This is to make sure the signal callbacks don't screw up |
| |
19 * the display. |
| |
20 */ |
| |
21 |
| |
22 static GaimBlistUiOps blist_ui_ops = |
| |
23 { |
| |
24 NULL, |
| |
25 NULL, |
| |
26 NULL, |
| |
27 NULL, /* This doesn't do crap */ |
| |
28 NULL, |
| |
29 NULL, |
| |
30 NULL, |
| |
31 NULL, |
| |
32 NULL, |
| |
33 NULL |
| |
34 }; |
| |
35 |
| |
36 typedef struct |
| |
37 { |
| |
38 GntWidget *window; |
| |
39 GntWidget *tree; |
| |
40 } GGBlist; |
| |
41 |
| |
42 GGBlist *ggblist; |
| |
43 |
| |
44 static gpointer |
| |
45 gg_blist_get_handle() |
| |
46 { |
| |
47 static int handle; |
| |
48 |
| |
49 return &handle; |
| |
50 } |
| |
51 |
| |
52 static void |
| |
53 add_group(GaimGroup *group, GGBlist *ggblist) |
| |
54 { |
| |
55 GaimBlistNode *node = (GaimBlistNode *)group; |
| |
56 if (node->ui_data) |
| |
57 return; |
| |
58 gnt_tree_add_row_after(GNT_TREE(ggblist->tree), group, |
| |
59 group->name, NULL, NULL); |
| |
60 node->ui_data = GINT_TO_POINTER(TRUE); |
| |
61 } |
| |
62 |
| |
63 static void |
| |
64 buddy_signed_on(GaimBuddy *buddy, GGBlist *ggblist) |
| |
65 { |
| |
66 GaimGroup *group = gaim_buddy_get_group(buddy); |
| |
67 char *text; |
| |
68 |
| |
69 add_group(group, ggblist); |
| |
70 |
| |
71 text = g_strdup_printf("%*s%s", TAB_SIZE, "", gaim_buddy_get_alias(buddy)); |
| |
72 gnt_tree_add_row_after(GNT_TREE(ggblist->tree), buddy, text, group, NULL); |
| |
73 g_free(text); |
| |
74 } |
| |
75 |
| |
76 static void |
| |
77 buddy_signed_off(GaimBuddy *buddy, GGBlist *ggblist) |
| |
78 { |
| |
79 gnt_tree_remove(GNT_TREE(ggblist->tree), buddy); |
| |
80 } |
| |
81 |
| |
82 GaimBlistUiOps *gg_get_blist_ui_ops() |
| |
83 { |
| |
84 return &blist_ui_ops; |
| |
85 } |
| |
86 |
| |
87 static void |
| |
88 selection_activate(GntWidget *widget, GGBlist *ggblist) |
| |
89 { |
| |
90 gnt_widget_set_focus(widget, FALSE); |
| |
91 } |
| |
92 |
| |
93 void gg_blist_init() |
| |
94 { |
| |
95 ggblist = g_new0(GGBlist, 1); |
| |
96 |
| |
97 ggblist->window = gnt_box_new(FALSE, FALSE); |
| |
98 gnt_box_set_title(GNT_BOX(ggblist->window), _("Buddy List")); |
| |
99 |
| |
100 ggblist->tree = gnt_tree_new(); |
| |
101 gnt_widget_set_size(ggblist->tree, 25, getmaxy(stdscr)); |
| |
102 |
| |
103 gnt_box_add_widget(GNT_BOX(ggblist->window), ggblist->tree); |
| |
104 gnt_widget_show(ggblist->window); |
| |
105 |
| |
106 gaim_signal_connect(gaim_blist_get_handle(), "buddy-signed-on", gg_blist_get_handle(), |
| |
107 GAIM_CALLBACK(buddy_signed_on), ggblist); |
| |
108 gaim_signal_connect(gaim_blist_get_handle(), "buddy-signed-off", gg_blist_get_handle(), |
| |
109 GAIM_CALLBACK(buddy_signed_off), ggblist); |
| |
110 |
| |
111 g_signal_connect(G_OBJECT(ggblist->tree), "activate", G_CALLBACK(selection_activate), ggblist); |
| |
112 |
| |
113 /*gaim_signal_connect(gaim_conversations_get_handle(), "received-im-msg", gg_blist_get_handle(),*/ |
| |
114 /*GAIM_CALLBACK(received_im_msg), list);*/ |
| |
115 /*gaim_signal_connect(gaim_conversations_get_handle(), "sent-im-msg", gg_blist_get_handle(),*/ |
| |
116 /*GAIM_CALLBACK(sent_im_msg), NULL);*/ |
| |
117 |
| |
118 /*gaim_signal_connect(gaim_conversations_get_handle(), "received-chat-msg", gg_blist_get_handle(),*/ |
| |
119 /*GAIM_CALLBACK(received_chat_msg), list);*/ |
| |
120 } |
| |
121 |