Mercurial > pidgin
comparison plugins/idle.c @ 12775:4dc5e71c5a57
[gaim-migrate @ 15122]
sf patch #1399993, from John Bailey and Sadrul Habib Chowdhury, I think
"Add ability to idle all accounts to I'dle Ma'ker"
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Mon, 09 Jan 2006 04:54:16 +0000 |
parents | 657895c5f3f2 |
children | 54ba44abf356 |
comparison
equal
deleted
inserted
replaced
12774:3aa8f7c58360 | 12775:4dc5e71c5a57 |
---|---|
37 #define IDLE_PLUGIN_ID "core-idle" | 37 #define IDLE_PLUGIN_ID "core-idle" |
38 | 38 |
39 static GList *idled_accts = NULL; | 39 static GList *idled_accts = NULL; |
40 | 40 |
41 static gboolean | 41 static gboolean |
42 idle_filter(GaimAccount *acct) | 42 unidle_filter(GaimAccount *acct) |
43 { | 43 { |
44 if (g_list_find(idled_accts, acct)) | 44 if (g_list_find(idled_accts, acct)) |
45 return TRUE; | 45 return TRUE; |
46 | 46 |
47 return FALSE; | 47 return FALSE; |
48 } | |
49 | |
50 static gboolean | |
51 idleable_filter(GaimAccount *acct) | |
52 { | |
53 /* LSchiere says we can't control idle time on IRC, so I think we should | |
54 * ignore it to avoid some bug reports :) - rekkanoryo */ | |
55 if(!strcmp(gaim_account_get_protocol_id(acct), "prpl-irc")) | |
56 return FALSE; | |
57 | |
58 return TRUE; | |
48 } | 59 } |
49 | 60 |
50 static void | 61 static void |
51 set_idle_time(GaimAccount *acct, int mins_idle) | 62 set_idle_time(GaimAccount *acct, int mins_idle) |
52 { | 63 { |
71 { | 82 { |
72 int tm = gaim_request_fields_get_integer(fields, "mins"); | 83 int tm = gaim_request_fields_get_integer(fields, "mins"); |
73 GaimAccount *acct = gaim_request_fields_get_account(fields, "acct"); | 84 GaimAccount *acct = gaim_request_fields_get_account(fields, "acct"); |
74 | 85 |
75 /* only add the account to the GList if it's not already been idled */ | 86 /* only add the account to the GList if it's not already been idled */ |
76 if (!idle_filter(acct)) | 87 if (!unidle_filter(acct)) |
77 { | 88 { |
78 gaim_debug_misc("idle", | 89 gaim_debug_misc("idle", |
79 "%s hasn't been idled yet; adding to list.\n", | 90 "%s hasn't been idled yet; adding to list.\n", |
80 gaim_account_get_username(acct)); | 91 gaim_account_get_username(acct)); |
81 idled_accts = g_list_append(idled_accts, acct); | 92 idled_accts = g_list_append(idled_accts, acct); |
83 | 94 |
84 set_idle_time(acct, tm); | 95 set_idle_time(acct, tm); |
85 } | 96 } |
86 | 97 |
87 static void | 98 static void |
99 idle_all_action_ok(void *ignored, GaimRequestFields *fields) | |
100 { | |
101 GaimAccount *acct = NULL; | |
102 GList *l = gaim_accounts_get_all_active(); | |
103 int tm = gaim_request_fields_get_integer(fields, "mins"); | |
104 const char *prpl_id = NULL; | |
105 | |
106 for(; l; l = l->next) { | |
107 acct = (GaimAccount *)(l->data); | |
108 | |
109 if(acct) | |
110 prpl_id = gaim_account_get_protocol_id(acct); | |
111 | |
112 if(acct && idleable_filter(acct)) { | |
113 gaim_debug_misc("idle", "Idling %s.\n", | |
114 gaim_account_get_username(acct)); | |
115 | |
116 set_idle_time(acct, tm); | |
117 | |
118 if(!g_list_find(idled_accts, acct)) | |
119 idled_accts = g_list_append(idled_accts, acct); | |
120 } | |
121 } | |
122 } | |
123 | |
124 static void | |
88 unidle_action_ok(void *ignored, GaimRequestFields *fields) | 125 unidle_action_ok(void *ignored, GaimRequestFields *fields) |
89 { | 126 { |
90 GaimAccount *acct = gaim_request_fields_get_account(fields, "acct"); | 127 GaimAccount *acct = gaim_request_fields_get_account(fields, "acct"); |
91 | 128 |
92 set_idle_time(acct, 0); /* unidle the account */ | 129 set_idle_time(acct, 0); /* unidle the account */ |
106 GaimRequestField *field; | 143 GaimRequestField *field; |
107 | 144 |
108 group = gaim_request_field_group_new(NULL); | 145 group = gaim_request_field_group_new(NULL); |
109 | 146 |
110 field = gaim_request_field_account_new("acct", _("Account"), NULL); | 147 field = gaim_request_field_account_new("acct", _("Account"), NULL); |
148 gaim_request_field_account_set_filter(field, idleable_filter); | |
111 gaim_request_field_account_set_show_all(field, FALSE); | 149 gaim_request_field_account_set_show_all(field, FALSE); |
112 gaim_request_field_group_add_field(group, field); | 150 gaim_request_field_group_add_field(group, field); |
113 | 151 |
114 field = gaim_request_field_int_new("mins", _("Minutes"), 10); | 152 field = gaim_request_field_int_new("mins", _("Minutes"), 10); |
115 gaim_request_field_group_add_field(group, field); | 153 gaim_request_field_group_add_field(group, field); |
141 } | 179 } |
142 | 180 |
143 group = gaim_request_field_group_new(NULL); | 181 group = gaim_request_field_group_new(NULL); |
144 | 182 |
145 field = gaim_request_field_account_new("acct", _("Account"), NULL); | 183 field = gaim_request_field_account_new("acct", _("Account"), NULL); |
146 gaim_request_field_account_set_filter(field, idle_filter); | 184 gaim_request_field_account_set_filter(field, unidle_filter); |
147 gaim_request_field_account_set_show_all(field, FALSE); | 185 gaim_request_field_account_set_show_all(field, FALSE); |
148 gaim_request_field_group_add_field(group, field); | 186 gaim_request_field_group_add_field(group, field); |
149 | 187 |
150 request = gaim_request_fields_new(); | 188 request = gaim_request_fields_new(); |
151 gaim_request_fields_add_group(request, group); | 189 gaim_request_fields_add_group(request, group); |
159 _("_Cancel"), NULL, | 197 _("_Cancel"), NULL, |
160 NULL); | 198 NULL); |
161 } | 199 } |
162 | 200 |
163 static void | 201 static void |
202 idle_all_action(GaimPluginAction *action) | |
203 { | |
204 GaimRequestFields *request; | |
205 GaimRequestFieldGroup *group; | |
206 GaimRequestField *field; | |
207 | |
208 group = gaim_request_field_group_new(NULL); | |
209 | |
210 field = gaim_request_field_int_new("mins", _("Minutes"), 10); | |
211 gaim_request_field_group_add_field(group, field); | |
212 | |
213 request = gaim_request_fields_new(); | |
214 gaim_request_fields_add_group(request, group); | |
215 | |
216 gaim_request_fields(action->plugin, | |
217 N_("I'dle Mak'er"), | |
218 _("Set Idle Time for All Accounts"), | |
219 NULL, | |
220 request, | |
221 _("_Set"), G_CALLBACK(idle_all_action_ok), | |
222 _("_Cancel"), NULL, | |
223 NULL); | |
224 } | |
225 | |
226 static void | |
164 unidle_all_action(GaimPluginAction *action) | 227 unidle_all_action(GaimPluginAction *action) |
165 { | 228 { |
166 GList *l; | 229 GList *l; |
167 | 230 |
168 /* freeing the list here will cause segfaults if the user idles an account | 231 /* freeing the list here will cause segfaults if the user idles an account |
187 idle_action); | 250 idle_action); |
188 l = g_list_append(l, act); | 251 l = g_list_append(l, act); |
189 | 252 |
190 act = gaim_plugin_action_new(_("Unset Account Idle Time"), | 253 act = gaim_plugin_action_new(_("Unset Account Idle Time"), |
191 unidle_action); | 254 unidle_action); |
255 l = g_list_append(l, act); | |
256 | |
257 act = gaim_plugin_action_new(_("Set Idle Time for All Accounts"), | |
258 idle_all_action); | |
192 l = g_list_append(l, act); | 259 l = g_list_append(l, act); |
193 | 260 |
194 act = gaim_plugin_action_new( | 261 act = gaim_plugin_action_new( |
195 _("Unset Idle Time for All Idled Accounts"), unidle_all_action); | 262 _("Unset Idle Time for All Idled Accounts"), unidle_all_action); |
196 l = g_list_append(l, act); | 263 l = g_list_append(l, act); |