Mercurial > pidgin
annotate plugins/autorecon.c @ 9707:0b1538126851
[gaim-migrate @ 10568]
Make sure the default smiley theme really is "default." I think
warren may have pointed this out just before 0.80 was released,
and I think this should fix the problem he was seeing.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Sat, 07 Aug 2004 23:28:51 +0000 |
parents | 14c1ffd053e5 |
children | 24550263874d |
rev | line source |
---|---|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5607
diff
changeset
|
1 #include "internal.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5607
diff
changeset
|
2 |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5607
diff
changeset
|
3 #include "connection.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5607
diff
changeset
|
4 #include "debug.h" |
8774 | 5 #include "pluginpref.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5607
diff
changeset
|
6 #include "prpl.h" |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
7 #include "signals.h" |
4202
59751fe608c5
[gaim-migrate @ 4438]
Christian Hammond <chipx86@chipx86.com>
parents:
4113
diff
changeset
|
8 |
8774 | 9 |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
10 #define AUTORECON_PLUGIN_ID "core-autorecon" |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
11 |
2216
66783ad29e55
[gaim-migrate @ 2226]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1818
diff
changeset
|
12 #define INITIAL 8000 |
4590 | 13 #define MAXTIME 2048000 |
2216
66783ad29e55
[gaim-migrate @ 2226]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1818
diff
changeset
|
14 |
6113 | 15 typedef struct { |
16 int delay; | |
17 guint timeout; | |
18 } GaimAutoRecon; | |
2216
66783ad29e55
[gaim-migrate @ 2226]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1818
diff
changeset
|
19 |
9546 | 20 /* |
21 I use a struct here, but the visible/invisible isn't yet supported | |
9549 | 22 in this plugin, so this is more for future implementation of those |
23 features | |
9546 | 24 */ |
25 typedef struct { | |
26 const char *state; | |
27 const char *message; | |
28 } GaimAwayState; | |
29 | |
6113 | 30 static GHashTable *hash = NULL; |
9546 | 31 static GHashTable *awayStates = NULL; |
99 | 32 |
8774 | 33 |
34 #define AUTORECON_OPT "/plugins/core/autorecon" | |
35 #define OPT_HIDE_CONNECTED AUTORECON_OPT "/hide_connected_error" | |
36 #define OPT_HIDE_CONNECTING AUTORECON_OPT "/hide_connecting_error" | |
9546 | 37 #define OPT_RESTORE_STATE AUTORECON_OPT "/restore_state" |
8774 | 38 |
39 | |
40 /* storage of original (old_ops) and modified (new_ops) ui ops to allow us to | |
41 intercept calls to report_disconnect */ | |
42 static GaimConnectionUiOps *old_ops = NULL; | |
43 static GaimConnectionUiOps *new_ops = NULL; | |
44 | |
45 | |
46 static void report_disconnect(GaimConnection *gc, const char *text) { | |
47 | |
48 if(old_ops == NULL || old_ops->report_disconnect == NULL) { | |
49 /* there's nothing to call through to, so don't bother | |
50 checking prefs */ | |
51 return; | |
52 | |
53 } else if(gc->state == GAIM_CONNECTED | |
54 && gaim_prefs_get_bool(OPT_HIDE_CONNECTED)) { | |
55 /* this is a connected error, and we're hiding those */ | |
56 gaim_debug(GAIM_DEBUG_INFO, "autorecon", | |
57 "hid disconnect error message\n"); | |
58 return; | |
59 | |
60 } else if(gc->state == GAIM_CONNECTING | |
61 && gaim_prefs_get_bool(OPT_HIDE_CONNECTING)) { | |
62 /* this is a connecting error, and we're hiding those */ | |
63 gaim_debug(GAIM_DEBUG_INFO, "autorecon", | |
64 "hid error message while connecting\n"); | |
65 return; | |
66 } | |
67 | |
68 /* if we haven't returned by now, then let's pass to the real | |
69 function */ | |
70 old_ops->report_disconnect(gc, text); | |
71 } | |
72 | |
73 | |
2216
66783ad29e55
[gaim-migrate @ 2226]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1818
diff
changeset
|
74 static gboolean do_signon(gpointer data) { |
5587
1c55b1540e18
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5227
diff
changeset
|
75 GaimAccount *account = data; |
6113 | 76 GaimAutoRecon *info; |
77 | |
5227
6d1707dc8c3d
[gaim-migrate @ 5597]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
78 gaim_debug(GAIM_DEBUG_INFO, "autorecon", "do_signon called\n"); |
6113 | 79 g_return_val_if_fail(account != NULL, FALSE); |
80 info = g_hash_table_lookup(hash, account); | |
4494
b5a50a6a13b0
[gaim-migrate @ 4769]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4491
diff
changeset
|
81 |
5607 | 82 if (g_list_index(gaim_accounts_get_all(), account) < 0) |
1817
b367beee6448
[gaim-migrate @ 1827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1404
diff
changeset
|
83 return FALSE; |
6113 | 84 |
7372 | 85 if(info) |
86 info->timeout = 0; | |
87 | |
5587
1c55b1540e18
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5227
diff
changeset
|
88 gaim_debug(GAIM_DEBUG_INFO, "autorecon", "calling gaim_account_connect\n"); |
1c55b1540e18
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5227
diff
changeset
|
89 gaim_account_connect(account); |
1c55b1540e18
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5227
diff
changeset
|
90 gaim_debug(GAIM_DEBUG_INFO, "autorecon", "done calling gaim_account_connect\n"); |
6113 | 91 |
1817
b367beee6448
[gaim-migrate @ 1827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1404
diff
changeset
|
92 return FALSE; |
1378
aedeb1218a0a
[gaim-migrate @ 1388]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1165
diff
changeset
|
93 } |
aedeb1218a0a
[gaim-migrate @ 1388]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1165
diff
changeset
|
94 |
8774 | 95 |
5587
1c55b1540e18
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5227
diff
changeset
|
96 static void reconnect(GaimConnection *gc, void *m) { |
6113 | 97 GaimAccount *account; |
98 GaimAutoRecon *info; | |
99 | |
100 g_return_if_fail(gc != NULL); | |
101 account = gaim_connection_get_account(gc); | |
102 info = g_hash_table_lookup(hash, account); | |
103 | |
2216
66783ad29e55
[gaim-migrate @ 2226]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1818
diff
changeset
|
104 if (!gc->wants_to_die) { |
6113 | 105 if (info == NULL) { |
106 info = g_new0(GaimAutoRecon, 1); | |
107 g_hash_table_insert(hash, account, info); | |
108 info->delay = INITIAL; | |
8249 | 109 } else { |
6113 | 110 info->delay = MIN(2 * info->delay, MAXTIME); |
8250 | 111 if (info->timeout != 0) |
112 g_source_remove(info->timeout); | |
8249 | 113 } |
6113 | 114 info->timeout = g_timeout_add(info->delay, do_signon, account); |
115 } else if (info != NULL) { | |
116 g_hash_table_remove(hash, account); | |
2216
66783ad29e55
[gaim-migrate @ 2226]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1818
diff
changeset
|
117 } |
9546 | 118 |
119 if (gc->wants_to_die) | |
120 g_hash_table_remove(awayStates, account); | |
99 | 121 } |
122 | |
9546 | 123 static void save_state(GaimAccount *account, const char *state, const char *message) { |
9549 | 124 /* Saves whether the account is back/away/visible/invisible */ |
9546 | 125 |
9549 | 126 GaimAwayState *info; |
9546 | 127 |
128 if (!strcmp(state,GAIM_AWAY_CUSTOM)) { | |
9549 | 129 info = g_new0(GaimAwayState, 1); |
130 info->state = state; | |
131 info->message = message; | |
9546 | 132 |
9549 | 133 g_hash_table_insert(awayStates, account, info); |
9546 | 134 } else if(!strcmp(state,"Back")) |
135 g_hash_table_remove(awayStates, account); | |
136 } | |
137 | |
138 static void restore_state(GaimConnection *gc, void *m) { | |
9549 | 139 /* Restore the state to what it was before the disconnect */ |
140 GaimAwayState *info; | |
141 GaimAccount *account; | |
9546 | 142 |
9549 | 143 g_return_if_fail(gc != NULL && gaim_prefs_get_bool(OPT_RESTORE_STATE)); |
144 account = gaim_connection_get_account(gc); | |
9546 | 145 |
9549 | 146 info = g_hash_table_lookup(awayStates, account); |
147 if (info) | |
148 serv_set_away(gc, info->state, info->message); | |
9546 | 149 } |
8774 | 150 |
6113 | 151 static void |
152 free_auto_recon(gpointer data) | |
153 { | |
154 GaimAutoRecon *info = data; | |
155 | |
156 if (info->timeout != 0) | |
157 g_source_remove(info->timeout); | |
158 | |
159 g_free(info); | |
160 } | |
161 | |
8774 | 162 |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
163 static gboolean |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
164 plugin_load(GaimPlugin *plugin) |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
165 { |
8774 | 166 |
167 /* this was the suggested way to override a single function of the | |
168 real ui ops. However, there's a mild concern of having more than one | |
169 bit of code making a new ui op call-through copy. If plugins A and B | |
170 both override the ui ops (in that order), B thinks that the | |
171 overridden ui ops A created was the original. If A unloads first, | |
172 and swaps out and frees its overridden version, then B is calling | |
173 through to a free'd ui op. There needs to be a way to "stack up" | |
174 overridden ui ops or something... I have a good idea of how to write | |
175 such a creature if someone wants it done. - siege 2004-04-20 */ | |
176 | |
177 /* get old ops, make a copy with a minor change */ | |
178 old_ops = gaim_connections_get_ui_ops(); | |
179 new_ops = (GaimConnectionUiOps *) g_memdup(old_ops, | |
180 sizeof(GaimConnectionUiOps)); | |
181 new_ops->report_disconnect = report_disconnect; | |
182 gaim_connections_set_ui_ops(new_ops); | |
183 | |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
184 hash = g_hash_table_new_full(g_int_hash, g_int_equal, NULL, |
8774 | 185 free_auto_recon); |
3630 | 186 |
9546 | 187 awayStates = g_hash_table_new(g_int_hash, g_int_equal); |
188 | |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
189 gaim_signal_connect(gaim_connections_get_handle(), "signed-off", |
8774 | 190 plugin, GAIM_CALLBACK(reconnect), NULL); |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
191 |
9546 | 192 gaim_signal_connect(gaim_connections_get_handle(), "signed-on", |
193 plugin, GAIM_CALLBACK(restore_state), NULL); | |
194 | |
195 gaim_signal_connect(gaim_accounts_get_handle(), "account-away", | |
196 plugin, GAIM_CALLBACK(save_state), NULL); | |
197 | |
198 | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
199 return TRUE; |
3802 | 200 } |
201 | |
8774 | 202 |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
203 static gboolean |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
204 plugin_unload(GaimPlugin *plugin) |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
205 { |
8243 | 206 gaim_signal_disconnect(gaim_connections_get_handle(), "signed-off", |
207 plugin, GAIM_CALLBACK(reconnect)); | |
9546 | 208 |
209 gaim_signal_disconnect(gaim_connections_get_handle(), "signed-on", | |
210 plugin, GAIM_CALLBACK(restore_state)); | |
211 | |
212 gaim_signal_disconnect(gaim_accounts_get_handle(), "account-away", | |
213 plugin, GAIM_CALLBACK(save_state)); | |
9549 | 214 |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
215 g_hash_table_destroy(hash); |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
216 hash = NULL; |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
217 |
9546 | 218 g_hash_table_destroy(awayStates); |
219 awayStates = NULL; | |
220 | |
8774 | 221 gaim_connections_set_ui_ops(old_ops); |
222 g_free(new_ops); | |
223 old_ops = new_ops = NULL; | |
224 | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
225 return TRUE; |
3630 | 226 } |
227 | |
8774 | 228 |
229 static GaimPluginPrefFrame *get_plugin_pref_frame(GaimPlugin *plugin) { | |
230 GaimPluginPrefFrame *frame = gaim_plugin_pref_frame_new(); | |
231 GaimPluginPref *pref; | |
232 | |
233 pref = gaim_plugin_pref_new_with_label(_("Error Message Suppression")); | |
9549 | 234 gaim_plugin_pref_frame_add(frame, pref); |
8774 | 235 |
236 pref = gaim_plugin_pref_new_with_name_and_label(OPT_HIDE_CONNECTED, | |
237 _("Hide Disconnect Errors")); | |
238 gaim_plugin_pref_frame_add(frame, pref); | |
239 | |
240 pref = gaim_plugin_pref_new_with_name_and_label(OPT_HIDE_CONNECTING, | |
241 _("Hide Login Errors")); | |
242 gaim_plugin_pref_frame_add(frame, pref); | |
243 | |
9546 | 244 pref = gaim_plugin_pref_new_with_name_and_label(OPT_RESTORE_STATE, |
9666 | 245 _("Restore Away State On Reconnect")); |
9546 | 246 gaim_plugin_pref_frame_add(frame, pref); |
247 | |
8774 | 248 return frame; |
249 } | |
250 | |
251 | |
252 static GaimPluginUiInfo pref_info = { | |
253 get_plugin_pref_frame | |
254 }; | |
255 | |
256 | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
257 static GaimPluginInfo info = |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
258 { |
8749
d7b8eb1f0a18
[gaim-migrate @ 9504]
Christian Hammond <chipx86@chipx86.com>
parents:
8250
diff
changeset
|
259 GAIM_PLUGIN_API_VERSION, /**< api_version */ |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
260 GAIM_PLUGIN_STANDARD, /**< type */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
261 NULL, /**< ui_requirement */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
262 0, /**< flags */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
263 NULL, /**< dependencies */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
264 GAIM_PRIORITY_DEFAULT, /**< priority */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
265 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
266 AUTORECON_PLUGIN_ID, /**< id */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
267 N_("Auto-Reconnect"), /**< name */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
268 VERSION, /**< version */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
269 /** summary */ |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
270 N_("When you are kicked offline, this reconnects you."), |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
271 /** description */ |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
272 N_("When you are kicked offline, this reconnects you."), |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
273 "Eric Warmenhoven <eric@warmenhoven.org>", /**< author */ |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
274 GAIM_WEBSITE, /**< homepage */ |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
275 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
276 plugin_load, /**< load */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
277 plugin_unload, /**< unload */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
278 NULL, /**< destroy */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
279 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
280 NULL, /**< ui_info */ |
8774 | 281 NULL, /**< extra_info */ |
8993 | 282 &pref_info, /**< prefs_info */ |
283 NULL | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
284 }; |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
285 |
8774 | 286 |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
287 static void |
5920
7d385de2f9cd
[gaim-migrate @ 6360]
Christian Hammond <chipx86@chipx86.com>
parents:
5873
diff
changeset
|
288 init_plugin(GaimPlugin *plugin) |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
289 { |
8774 | 290 gaim_prefs_add_none(AUTORECON_OPT); |
291 gaim_prefs_add_bool(OPT_HIDE_CONNECTED, FALSE); | |
292 gaim_prefs_add_bool(OPT_HIDE_CONNECTING, FALSE); | |
9546 | 293 gaim_prefs_add_bool(OPT_RESTORE_STATE, TRUE); |
3630 | 294 } |
295 | |
6063 | 296 GAIM_INIT_PLUGIN(autorecon, init_plugin, info) |
8774 | 297 |