comparison finch/plugins/grouping.c @ 22190:bcaf4a037704

Init and uninit the buddylist managers at appropriate times.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Wed, 23 Jan 2008 21:46:54 +0000
parents d1b8c8bef05b
children 8a488151e07a
comparison
equal deleted inserted replaced
22189:4165bcd57486 22190:bcaf4a037704
31 /** 31 /**
32 * Online/Offline 32 * Online/Offline
33 */ 33 */
34 static PurpleBlistNode online = {.type = PURPLE_BLIST_OTHER_NODE}, 34 static PurpleBlistNode online = {.type = PURPLE_BLIST_OTHER_NODE},
35 offline = {.type = PURPLE_BLIST_OTHER_NODE}; 35 offline = {.type = PURPLE_BLIST_OTHER_NODE};
36
37 static gboolean on_offline_init()
38 {
39 GntTree *tree = finch_blist_get_tree();
40
41 gnt_tree_add_row_after(tree, &online,
42 gnt_tree_create_row(tree, _("Online")), NULL, NULL);
43 gnt_tree_add_row_after(tree, &offline,
44 gnt_tree_create_row(tree, _("Offline")), NULL, &online);
45
46 return TRUE;
47 }
36 48
37 static gboolean on_offline_can_add_node(PurpleBlistNode *node) 49 static gboolean on_offline_can_add_node(PurpleBlistNode *node)
38 { 50 {
39 switch (purple_blist_node_get_type(node)) { 51 switch (purple_blist_node_get_type(node)) {
40 case PURPLE_BLIST_CONTACT_NODE: 52 case PURPLE_BLIST_CONTACT_NODE:
68 } 80 }
69 81
70 static gpointer on_offline_find_parent(PurpleBlistNode *node) 82 static gpointer on_offline_find_parent(PurpleBlistNode *node)
71 { 83 {
72 gpointer ret = NULL; 84 gpointer ret = NULL;
73 GntTree *tree = finch_blist_get_tree();
74
75 if (!tree)
76 return NULL;
77
78 if (!g_list_find(gnt_tree_get_rows(tree), &online)) {
79 gnt_tree_remove_all(tree);
80 gnt_tree_add_row_after(tree, &online,
81 gnt_tree_create_row(tree, _("Online")), NULL, NULL);
82 gnt_tree_add_row_after(tree, &offline,
83 gnt_tree_create_row(tree, _("Offline")), NULL, &online);
84 }
85 85
86 switch (purple_blist_node_get_type(node)) { 86 switch (purple_blist_node_get_type(node)) {
87 case PURPLE_BLIST_CONTACT_NODE: 87 case PURPLE_BLIST_CONTACT_NODE:
88 node = (PurpleBlistNode*)purple_contact_get_priority_buddy((PurpleContact*)node); 88 node = (PurpleBlistNode*)purple_contact_get_priority_buddy((PurpleContact*)node);
89 ret = PURPLE_BUDDY_IS_ONLINE((PurpleBuddy*)node) ? &online : &offline; 89 ret = PURPLE_BUDDY_IS_ONLINE((PurpleBuddy*)node) ? &online : &offline;
123 123
124 static FinchBlistManager on_offline = 124 static FinchBlistManager on_offline =
125 { 125 {
126 "on-offline", 126 "on-offline",
127 N_("Online/Offline"), 127 N_("Online/Offline"),
128 on_offline_init,
129 NULL,
128 on_offline_can_add_node, 130 on_offline_can_add_node,
129 on_offline_find_parent, 131 on_offline_find_parent,
130 on_offline_create_tooltip, 132 on_offline_create_tooltip,
131 {NULL, NULL, NULL, NULL} 133 {NULL, NULL, NULL, NULL}
132 }; 134 };
133 135
134 /** 136 /**
135 * Meebo-like Grouping. 137 * Meebo-like Grouping.
136 */ 138 */
137 static PurpleBlistNode meebo = {.type = PURPLE_BLIST_OTHER_NODE}; 139 static PurpleBlistNode meebo = {.type = PURPLE_BLIST_OTHER_NODE};
140 static gboolean meebo_init()
141 {
142 GntTree *tree = finch_blist_get_tree();
143 if (!g_list_find(gnt_tree_get_rows(tree), &meebo)) {
144 gnt_tree_add_row_last(tree, &meebo,
145 gnt_tree_create_row(tree, _("Offline")), NULL);
146 }
147 return TRUE;
148 }
149
138 static gpointer meebo_find_parent(PurpleBlistNode *node) 150 static gpointer meebo_find_parent(PurpleBlistNode *node)
139 { 151 {
140 static FinchBlistManager *def = NULL; 152 static FinchBlistManager *def = NULL;
141 if (def == NULL) 153 if (def == NULL)
142 def = finch_blist_manager_find("default"); 154 def = finch_blist_manager_find("default");
143 155
144 if (PURPLE_BLIST_NODE_IS_CONTACT(node)) { 156 if (PURPLE_BLIST_NODE_IS_CONTACT(node)) {
145 PurpleBuddy *buddy = purple_contact_get_priority_buddy((PurpleContact*)node); 157 PurpleBuddy *buddy = purple_contact_get_priority_buddy((PurpleContact*)node);
146 if (buddy && !PURPLE_BUDDY_IS_ONLINE(buddy)) { 158 if (buddy && !PURPLE_BUDDY_IS_ONLINE(buddy)) {
147 GntTree *tree = finch_blist_get_tree();
148 if (!g_list_find(gnt_tree_get_rows(tree), &meebo)) {
149 gnt_tree_add_row_last(tree, &meebo,
150 gnt_tree_create_row(tree, _("Offline")), NULL);
151 }
152 return &meebo; 159 return &meebo;
153 } 160 }
154 } 161 }
155 return def->find_parent(node); 162 return def->find_parent(node);
156 } 163 }
157 164
158 static FinchBlistManager meebo_group = 165 static FinchBlistManager meebo_group =
159 { 166 {
160 "meebo", 167 "meebo",
161 N_("Meebo"), 168 N_("Meebo"),
169 meebo_init,
170 NULL,
162 NULL, 171 NULL,
163 meebo_find_parent, 172 meebo_find_parent,
164 NULL, 173 NULL,
165 {NULL, NULL, NULL, NULL} 174 {NULL, NULL, NULL, NULL}
166 }; 175 };
167 176
168 /** 177 /**
169 * No Grouping. 178 * No Grouping.
170 */ 179 */
180 static gboolean no_group_init()
181 {
182 GntTree *tree = finch_blist_get_tree();
183 g_object_set(G_OBJECT(tree), "expander-level", 0, NULL);
184 return TRUE;
185 }
186
187 static gboolean no_group_uninit()
188 {
189 GntTree *tree = finch_blist_get_tree();
190 g_object_set(G_OBJECT(tree), "expander-level", 1, NULL);
191 return TRUE;
192 }
193
171 static gboolean no_group_can_add_node(PurpleBlistNode *node) 194 static gboolean no_group_can_add_node(PurpleBlistNode *node)
172 { 195 {
173 return on_offline_can_add_node(node); /* These happen to be the same */ 196 return on_offline_can_add_node(node); /* These happen to be the same */
174 } 197 }
175 198
190 213
191 static FinchBlistManager no_group = 214 static FinchBlistManager no_group =
192 { 215 {
193 "no-group", 216 "no-group",
194 N_("No Grouping"), 217 N_("No Grouping"),
218 no_group_init,
219 no_group_uninit,
195 no_group_can_add_node, 220 no_group_can_add_node,
196 no_group_find_parent, 221 no_group_find_parent,
197 NULL, 222 NULL,
198 {NULL, NULL, NULL, NULL} 223 {NULL, NULL, NULL, NULL}
199 }; 224 };