comparison finch/plugins/grouping.c @ 22173:85c365822504

Add a plugin to provide 'Online/Offline' grouping and no grouping.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Tue, 22 Jan 2008 07:54:48 +0000
parents
children d1b8c8bef05b
comparison
equal deleted inserted replaced
22172:0934fa012c8c 22173:85c365822504
1 /**
2 * @file grouping.c Provides different grouping options.
3 *
4 * Copyright (C) 2008 Sadrul Habib Chowdhury <sadrul@users.sourceforge.net>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 #define PURPLE_PLUGIN
22
23 #include "internal.h"
24 #include "purple.h"
25
26 #include "gntblist.h"
27 #include "gntplugin.h"
28
29 #include "gnttree.h"
30
31 /**
32 * Online/Offline
33 */
34 static PurpleBlistNode online = {.type = PURPLE_BLIST_OTHER_NODE},
35 offline = {.type = PURPLE_BLIST_OTHER_NODE};
36
37 static gboolean on_offline_can_add_node(PurpleBlistNode *node)
38 {
39 switch (purple_blist_node_get_type(node)) {
40 case PURPLE_BLIST_CONTACT_NODE:
41 {
42 PurpleContact *contact = (PurpleContact*)node;
43 if (contact->currentsize > 0)
44 return TRUE;
45 return FALSE;
46 }
47 break;
48 case PURPLE_BLIST_BUDDY_NODE:
49 {
50 PurpleBuddy *buddy = (PurpleBuddy*)node;
51 if (PURPLE_BUDDY_IS_ONLINE(buddy))
52 return TRUE;
53 if (purple_prefs_get_bool("/finch/blist/showoffline") &&
54 purple_account_is_connected(purple_buddy_get_account(buddy)))
55 return TRUE;
56 return FALSE;
57 }
58 break;
59 case PURPLE_BLIST_CHAT_NODE:
60 {
61 PurpleChat *chat = (PurpleChat*)node;
62 return purple_account_is_connected(purple_chat_get_account(chat));
63 }
64 break;
65 default:
66 return FALSE;
67 }
68 }
69
70 static gpointer on_offline_find_parent(PurpleBlistNode *node)
71 {
72 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
86 switch (purple_blist_node_get_type(node)) {
87 case PURPLE_BLIST_CONTACT_NODE:
88 node = (PurpleBlistNode*)purple_contact_get_priority_buddy((PurpleContact*)node);
89 ret = PURPLE_BUDDY_IS_ONLINE((PurpleBuddy*)node) ? &online : &offline;
90 break;
91 case PURPLE_BLIST_BUDDY_NODE:
92 ret = purple_blist_node_get_parent(node);
93 finch_blist_manager_add_node(ret);
94 break;
95 case PURPLE_BLIST_CHAT_NODE:
96 ret = &online;
97 break;
98 default:
99 break;
100 }
101 return ret;
102 }
103
104 static gboolean on_offline_create_tooltip(gpointer selected_row, GString **body, char **tool_title)
105 {
106 static FinchBlistManager *def = NULL;
107 PurpleBlistNode *node = selected_row;
108
109 if (def == NULL)
110 def = finch_blist_manager_find("default");
111
112 if (purple_blist_node_get_type(node) == PURPLE_BLIST_OTHER_NODE) {
113 /* There should be some easy way of getting the total online count,
114 * or total number of chats. Doing a loop here will probably be pretty
115 * expensive. */
116 if (body)
117 *body = g_string_new(node == &online ? _("Online Buddies") : _("Offline Buddies"));
118 return TRUE;
119 } else {
120 return def ? def->create_tooltip(selected_row, body, tool_title) : FALSE;
121 }
122 }
123
124 static FinchBlistManager on_offline =
125 {
126 "on-offline",
127 N_("Online/Offline"),
128 on_offline_can_add_node,
129 on_offline_find_parent,
130 on_offline_create_tooltip,
131 {NULL, NULL, NULL, NULL}
132 };
133
134 /**
135 * No Grouping.
136 */
137 static gboolean no_group_can_add_node(PurpleBlistNode *node)
138 {
139 return on_offline_can_add_node(node); /* These happen to be the same */
140 }
141
142 static gpointer no_group_find_parent(PurpleBlistNode *node)
143 {
144 gpointer ret = NULL;
145
146 switch (purple_blist_node_get_type(node)) {
147 case PURPLE_BLIST_BUDDY_NODE:
148 ret = purple_blist_node_get_parent(node);
149 finch_blist_manager_add_node(ret);
150 break;
151 default:
152 break;
153 }
154 return ret;
155 }
156
157 static FinchBlistManager no_group =
158 {
159 "no-group",
160 N_("No Grouping"),
161 no_group_can_add_node,
162 no_group_find_parent,
163 NULL,
164 {NULL, NULL, NULL, NULL}
165 };
166
167 static gboolean
168 plugin_load(PurplePlugin *plugin)
169 {
170 finch_blist_install_manager(&on_offline);
171 finch_blist_install_manager(&no_group);
172 return TRUE;
173 }
174
175 static gboolean
176 plugin_unload(PurplePlugin *plugin)
177 {
178 finch_blist_uninstall_manager(&on_offline);
179 finch_blist_uninstall_manager(&no_group);
180 return TRUE;
181 }
182
183 static PurplePluginInfo info =
184 {
185 PURPLE_PLUGIN_MAGIC,
186 PURPLE_MAJOR_VERSION,
187 PURPLE_MINOR_VERSION,
188 PURPLE_PLUGIN_STANDARD,
189 FINCH_PLUGIN_TYPE,
190 0,
191 NULL,
192 PURPLE_PRIORITY_DEFAULT,
193 "grouping",
194 N_("Grouping"),
195 VERSION,
196 N_("Provides alternate buddylist grouping options."),
197 N_("Provides alternate buddylist grouping options."),
198 "Sadrul H Chowdhury <sadrul@users.sourceforge.net>",
199 PURPLE_WEBSITE,
200 plugin_load,
201 plugin_unload,
202 NULL,
203 NULL,
204 NULL,
205 NULL,
206 NULL,
207 NULL,NULL,NULL,NULL
208 };
209
210 static void
211 init_plugin(PurplePlugin *plugin)
212 {
213 }
214
215 PURPLE_INIT_PLUGIN(ignore, init_plugin, info)
216
217