comparison plugins/autorecon.c @ 9961:ff704c905239

[gaim-migrate @ 10869] The autoreconnection plugin should not be responsible for setting initial status for your accounts. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Tue, 07 Sep 2004 05:15:38 +0000
parents f8e395a054e2
children ab5db2c5da79
comparison
equal deleted inserted replaced
9960:faf9ccf3e0d5 9961:ff704c905239
16 typedef struct { 16 typedef struct {
17 int delay; 17 int delay;
18 guint timeout; 18 guint timeout;
19 } GaimAutoRecon; 19 } GaimAutoRecon;
20 20
21 /*
22 I use a struct here, but the visible/invisible isn't yet supported
23 in this plugin, so this is more for future implementation of those
24 features
25 */
26 typedef struct {
27 const char *state;
28 const char *message;
29 } GaimAwayState;
30
31 static GHashTable *hash = NULL; 21 static GHashTable *hash = NULL;
32 static GHashTable *awayStates = NULL;
33
34 22
35 #define AUTORECON_OPT "/plugins/core/autorecon" 23 #define AUTORECON_OPT "/plugins/core/autorecon"
36 #define OPT_HIDE_CONNECTED AUTORECON_OPT "/hide_connected_error" 24 #define OPT_HIDE_CONNECTED AUTORECON_OPT "/hide_connected_error"
37 #define OPT_HIDE_CONNECTING AUTORECON_OPT "/hide_connecting_error" 25 #define OPT_HIDE_CONNECTING AUTORECON_OPT "/hide_connecting_error"
38 #define OPT_RESTORE_STATE AUTORECON_OPT "/restore_state" 26 #define OPT_RESTORE_STATE AUTORECON_OPT "/restore_state"
39
40 27
41 /* storage of original (old_ops) and modified (new_ops) ui ops to allow us to 28 /* storage of original (old_ops) and modified (new_ops) ui ops to allow us to
42 intercept calls to report_disconnect */ 29 intercept calls to report_disconnect */
43 static GaimConnectionUiOps *old_ops = NULL; 30 static GaimConnectionUiOps *old_ops = NULL;
44 static GaimConnectionUiOps *new_ops = NULL; 31 static GaimConnectionUiOps *new_ops = NULL;
114 } 101 }
115 info->timeout = g_timeout_add(info->delay, do_signon, account); 102 info->timeout = g_timeout_add(info->delay, do_signon, account);
116 } else if (info != NULL) { 103 } else if (info != NULL) {
117 g_hash_table_remove(hash, account); 104 g_hash_table_remove(hash, account);
118 } 105 }
119
120 if (gc->wants_to_die)
121 g_hash_table_remove(awayStates, account);
122 }
123
124 static void save_state(GaimAccount *account, const char *state, const char *message) {
125 /* Saves whether the account is back/away/visible/invisible */
126
127 GaimAwayState *info;
128
129 if (!strcmp(state,GAIM_AWAY_CUSTOM)) {
130 info = g_new0(GaimAwayState, 1);
131 info->state = state;
132 info->message = message;
133
134 g_hash_table_insert(awayStates, account, info);
135 } else if(!strcmp(state,"Back"))
136 g_hash_table_remove(awayStates, account);
137 }
138
139 static void restore_state(GaimConnection *gc, void *m) {
140 /* Restore the state to what it was before the disconnect */
141 GaimAwayState *info;
142 GaimAccount *account;
143
144 g_return_if_fail(gc != NULL && gaim_prefs_get_bool(OPT_RESTORE_STATE));
145 account = gaim_connection_get_account(gc);
146
147 info = g_hash_table_lookup(awayStates, account);
148 if (info)
149 serv_set_away(gc, info->state, info->message);
150 } 106 }
151 107
152 static void 108 static void
153 free_auto_recon(gpointer data) 109 free_auto_recon(gpointer data)
154 { 110 {
183 gaim_connections_set_ui_ops(new_ops); 139 gaim_connections_set_ui_ops(new_ops);
184 140
185 hash = g_hash_table_new_full(g_int_hash, g_int_equal, NULL, 141 hash = g_hash_table_new_full(g_int_hash, g_int_equal, NULL,
186 free_auto_recon); 142 free_auto_recon);
187 143
188 awayStates = g_hash_table_new(g_int_hash, g_int_equal);
189
190 gaim_signal_connect(gaim_connections_get_handle(), "signed-off", 144 gaim_signal_connect(gaim_connections_get_handle(), "signed-off",
191 plugin, GAIM_CALLBACK(reconnect), NULL); 145 plugin, GAIM_CALLBACK(reconnect), NULL);
192 146
193 gaim_signal_connect(gaim_connections_get_handle(), "signed-on",
194 plugin, GAIM_CALLBACK(restore_state), NULL);
195
196 gaim_signal_connect(gaim_accounts_get_handle(), "account-away",
197 plugin, GAIM_CALLBACK(save_state), NULL);
198
199
200 return TRUE; 147 return TRUE;
201 } 148 }
202 149
203 150
204 static gboolean 151 static gboolean
205 plugin_unload(GaimPlugin *plugin) 152 plugin_unload(GaimPlugin *plugin)
206 { 153 {
207 gaim_signal_disconnect(gaim_connections_get_handle(), "signed-off", 154 gaim_signal_disconnect(gaim_connections_get_handle(), "signed-off",
208 plugin, GAIM_CALLBACK(reconnect)); 155 plugin, GAIM_CALLBACK(reconnect));
209 156
210 gaim_signal_disconnect(gaim_connections_get_handle(), "signed-on",
211 plugin, GAIM_CALLBACK(restore_state));
212
213 gaim_signal_disconnect(gaim_accounts_get_handle(), "account-away",
214 plugin, GAIM_CALLBACK(save_state));
215
216 g_hash_table_destroy(hash); 157 g_hash_table_destroy(hash);
217 hash = NULL; 158 hash = NULL;
218
219 g_hash_table_destroy(awayStates);
220 awayStates = NULL;
221 159
222 gaim_connections_set_ui_ops(old_ops); 160 gaim_connections_set_ui_ops(old_ops);
223 g_free(new_ops); 161 g_free(new_ops);
224 old_ops = new_ops = NULL; 162 old_ops = new_ops = NULL;
225 163
238 _("Hide Disconnect Errors")); 176 _("Hide Disconnect Errors"));
239 gaim_plugin_pref_frame_add(frame, pref); 177 gaim_plugin_pref_frame_add(frame, pref);
240 178
241 pref = gaim_plugin_pref_new_with_name_and_label(OPT_HIDE_CONNECTING, 179 pref = gaim_plugin_pref_new_with_name_and_label(OPT_HIDE_CONNECTING,
242 _("Hide Login Errors")); 180 _("Hide Login Errors"));
243 gaim_plugin_pref_frame_add(frame, pref);
244
245 pref = gaim_plugin_pref_new_with_name_and_label(OPT_RESTORE_STATE,
246 _("Restore Away State On Reconnect"));
247 gaim_plugin_pref_frame_add(frame, pref); 181 gaim_plugin_pref_frame_add(frame, pref);
248 182
249 return frame; 183 return frame;
250 } 184 }
251 185
291 init_plugin(GaimPlugin *plugin) 225 init_plugin(GaimPlugin *plugin)
292 { 226 {
293 gaim_prefs_add_none(AUTORECON_OPT); 227 gaim_prefs_add_none(AUTORECON_OPT);
294 gaim_prefs_add_bool(OPT_HIDE_CONNECTED, FALSE); 228 gaim_prefs_add_bool(OPT_HIDE_CONNECTED, FALSE);
295 gaim_prefs_add_bool(OPT_HIDE_CONNECTING, FALSE); 229 gaim_prefs_add_bool(OPT_HIDE_CONNECTING, FALSE);
296 gaim_prefs_add_bool(OPT_RESTORE_STATE, TRUE); 230 gaim_prefs_remove_bool(OPT_RESTORE_STATE);
297 } 231 }
298 232
299 GAIM_INIT_PLUGIN(autorecon, init_plugin, info) 233 GAIM_INIT_PLUGIN(autorecon, init_plugin, info)
300 234