Mercurial > pidgin
annotate src/gtkconn.c @ 13272:0bfc9b72b9ce
[gaim-migrate @ 15638]
fix for double Proxy-Authorization Header by Anibal Avelar
committer: Tailor Script <tailor@pidgin.im>
author | Thomas Butter <tbutter> |
---|---|
date | Mon, 13 Feb 2006 07:34:59 +0000 |
parents | 8adf78fc630c |
children | 14d1892e0932 |
rev | line source |
---|---|
5717 | 1 /* |
10297
ec140184437b
[gaim-migrate @ 11480]
Luke Schierer <lschiere@pidgin.im>
parents:
10211
diff
changeset
|
2 * @file gtkconn.c GTK+ Connection API |
ec140184437b
[gaim-migrate @ 11480]
Luke Schierer <lschiere@pidgin.im>
parents:
10211
diff
changeset
|
3 * @ingroup gtkui |
ec140184437b
[gaim-migrate @ 11480]
Luke Schierer <lschiere@pidgin.im>
parents:
10211
diff
changeset
|
4 * |
5717 | 5 * gaim |
6 * | |
8046 | 7 * Gaim is the legal property of its developers, whose names are too numerous |
8 * to list here. Please refer to the COPYRIGHT file distributed with this | |
9 * source distribution. | |
5717 | 10 * |
11 * This program is free software; you can redistribute it and/or modify | |
12 * it under the terms of the GNU General Public License as published by | |
13 * the Free Software Foundation; either version 2 of the License, or | |
14 * (at your option) any later version. | |
15 * | |
16 * This program is distributed in the hope that it will be useful, | |
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 * GNU General Public License for more details. | |
20 * | |
21 * You should have received a copy of the GNU General Public License | |
22 * along with this program; if not, write to the Free Software | |
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
24 */ | |
9791 | 25 #include "internal.h" |
26 #include "gtkgaim.h" | |
5717 | 27 |
28 #include "account.h" | |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5746
diff
changeset
|
29 #include "debug.h" |
6460
ff4551719cc7
[gaim-migrate @ 6969]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
30 #include "notify.h" |
6216 | 31 #include "prefs.h" |
10643 | 32 #include "gtkblist.h" |
12404
7c7cb03e5475
[gaim-migrate @ 14711]
Richard Laager <rlaager@wiktel.com>
parents:
12296
diff
changeset
|
33 #include "gtkconn.h" |
7c7cb03e5475
[gaim-migrate @ 14711]
Richard Laager <rlaager@wiktel.com>
parents:
12296
diff
changeset
|
34 #include "gtkdialogs.h" |
10643 | 35 #include "gtkstatusbox.h" |
10297
ec140184437b
[gaim-migrate @ 11480]
Luke Schierer <lschiere@pidgin.im>
parents:
10211
diff
changeset
|
36 #include "gtkstock.h" |
12404
7c7cb03e5475
[gaim-migrate @ 14711]
Richard Laager <rlaager@wiktel.com>
parents:
12296
diff
changeset
|
37 #include "gtkutils.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5746
diff
changeset
|
38 #include "util.h" |
5717 | 39 |
11523 | 40 #define INITIAL_RECON_DELAY 8000 |
11721 | 41 #define MAX_RECON_DELAY 600000 |
11523 | 42 |
43 typedef struct { | |
44 int delay; | |
45 guint timeout; | |
46 } GaimAutoRecon; | |
47 | |
13014 | 48 /** |
49 * Contains accounts that are auto-reconnecting. | |
50 * The key is a pointer to the GaimAccount and the | |
51 * value is a pointer to a GaimAutoRecon. | |
13013 | 52 */ |
13014 | 53 static GHashTable *hash = NULL; |
54 static GHashTable *errored_accounts = NULL; | |
11523 | 55 |
13014 | 56 static void |
57 gaim_gtk_connection_connect_progress(GaimConnection *gc, | |
5717 | 58 const char *text, size_t step, size_t step_count) |
59 { | |
10643 | 60 GaimGtkBuddyList *gtkblist = gaim_gtk_blist_get_default_gtk_blist(); |
61 if (!gtkblist) | |
62 return; | |
63 gtk_gaim_status_box_set_connecting(GTK_GAIM_STATUS_BOX(gtkblist->statusbox), | |
64 (gaim_connections_get_connecting() != NULL)); | |
65 gtk_gaim_status_box_pulse_connecting(GTK_GAIM_STATUS_BOX(gtkblist->statusbox)); | |
5717 | 66 } |
67 | |
13014 | 68 static void |
69 gaim_gtk_connection_connected(GaimConnection *gc) | |
5717 | 70 { |
13014 | 71 GaimAccount *account; |
72 GaimGtkBuddyList *gtkblist; | |
73 | |
74 account = gaim_connection_get_account(gc); | |
75 gtkblist = gaim_gtk_blist_get_default_gtk_blist(); | |
76 | |
77 if (gtkblist != NULL) | |
78 gtk_gaim_status_box_set_connecting(GTK_GAIM_STATUS_BOX(gtkblist->statusbox), | |
10643 | 79 (gaim_connections_get_connecting() != NULL)); |
12607 | 80 |
11536 | 81 if (hash != NULL) |
82 g_hash_table_remove(hash, account); | |
13014 | 83 |
84 if (g_hash_table_size(errored_accounts) > 0) | |
85 { | |
86 g_hash_table_remove(errored_accounts, account); | |
13015 | 87 gaim_gtk_blist_update_account_error_state(account, NULL); |
13014 | 88 } |
5717 | 89 } |
90 | |
13014 | 91 static void |
92 gaim_gtk_connection_disconnected(GaimConnection *gc) | |
5717 | 93 { |
10643 | 94 GaimGtkBuddyList *gtkblist = gaim_gtk_blist_get_default_gtk_blist(); |
95 if (!gtkblist) | |
96 return; | |
97 gtk_gaim_status_box_set_connecting(GTK_GAIM_STATUS_BOX(gtkblist->statusbox), | |
98 (gaim_connections_get_connecting() != NULL)); | |
5883
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
99 |
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
100 if (gaim_connections_get_all() != NULL) |
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
101 return; |
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
102 |
9730 | 103 gaim_gtkdialogs_destroy_all(); |
5717 | 104 } |
105 | |
13014 | 106 static void |
107 gaim_gtk_connection_notice(GaimConnection *gc, | |
5717 | 108 const char *text) |
109 { | |
110 } | |
111 | |
7912 | 112 |
11523 | 113 static void |
114 free_auto_recon(gpointer data) | |
7493 | 115 { |
11523 | 116 GaimAutoRecon *info = data; |
7912 | 117 |
11523 | 118 if (info->timeout != 0) |
119 g_source_remove(info->timeout); | |
7912 | 120 |
11523 | 121 g_free(info); |
7493 | 122 } |
123 | |
11523 | 124 static gboolean |
125 do_signon(gpointer data) | |
7912 | 126 { |
11523 | 127 GaimAccount *account = data; |
128 GaimAutoRecon *info; | |
10916 | 129 |
13014 | 130 gaim_debug_info("autorecon", "do_signon called\n"); |
11523 | 131 g_return_val_if_fail(account != NULL, FALSE); |
132 info = g_hash_table_lookup(hash, account); | |
7912 | 133 |
11523 | 134 if (info) |
135 info->timeout = 0; | |
7912 | 136 |
13014 | 137 gaim_debug_info("autorecon", "calling gaim_account_connect\n"); |
11523 | 138 gaim_account_connect(account); |
13014 | 139 gaim_debug_info("autorecon", "done calling gaim_account_connect\n"); |
7912 | 140 |
11523 | 141 return FALSE; |
7912 | 142 } |
143 | |
13014 | 144 static void |
145 gaim_gtk_connection_report_disconnect(GaimConnection *gc, const char *text) | |
7399 | 146 { |
7431 | 147 GaimAccount *account = NULL; |
11523 | 148 GaimAutoRecon *info; |
13013 | 149 GSList* errored_account; |
7808 | 150 |
11523 | 151 account = gaim_connection_get_account(gc); |
152 info = g_hash_table_lookup(hash, account); | |
13014 | 153 errored_account = g_hash_table_lookup(errored_accounts, account); |
7912 | 154 |
13031 | 155 gaim_gtk_blist_update_account_error_state(account, text); |
11523 | 156 if (!gc->wants_to_die) { |
12009 | 157 if (info == NULL) { |
11523 | 158 info = g_new0(GaimAutoRecon, 1); |
159 g_hash_table_insert(hash, account, info); | |
160 info->delay = INITIAL_RECON_DELAY; | |
7483 | 161 } else { |
11523 | 162 info->delay = MIN(2 * info->delay, MAX_RECON_DELAY); |
163 if (info->timeout != 0) | |
164 g_source_remove(info->timeout); | |
7483 | 165 } |
11523 | 166 info->timeout = g_timeout_add(info->delay, do_signon, account); |
7912 | 167 |
13014 | 168 g_hash_table_insert(errored_accounts, account, NULL); |
11559 | 169 } else { |
13014 | 170 char *p, *s, *n=NULL ; |
171 if (info != NULL) | |
172 g_hash_table_remove(hash, account); | |
11721 | 173 |
13014 | 174 if (errored_account != NULL) |
175 g_hash_table_remove(errored_accounts, errored_account); | |
11721 | 176 |
13014 | 177 if (gaim_account_get_alias(account)) |
178 { | |
179 n = g_strdup_printf("%s (%s) (%s)", | |
180 gaim_account_get_username(account), | |
181 gaim_account_get_alias(account), | |
182 gaim_account_get_protocol_name(account)); | |
183 } | |
184 else | |
185 { | |
186 n = g_strdup_printf("%s (%s)", | |
187 gaim_account_get_username(account), | |
188 gaim_account_get_protocol_name(account)); | |
189 } | |
11721 | 190 |
13014 | 191 p = g_strdup_printf(_("%s disconnected"), n); |
13128 | 192 s = g_strdup_printf(_("%s was disconnected due to an error: %s\n" |
193 "Gaim will not attempt to reconnect the account until you " | |
194 "correct the error and reenable the account."), n, text); | |
13014 | 195 gaim_notify_error(NULL, NULL, p, s); |
196 g_free(p); | |
197 g_free(s); | |
198 g_free(n); | |
199 | |
200 /* | |
201 * TODO: Do we really want to disable the account when it's | |
202 * disconnected by wants_to_die? This happens when you sign | |
203 * on from somewhere else, or when you enter an invalid password. | |
204 */ | |
205 gaim_account_set_enabled(account, GAIM_GTK_UI, FALSE); | |
7399 | 206 } |
207 } | |
208 | |
5717 | 209 static GaimConnectionUiOps conn_ui_ops = |
210 { | |
211 gaim_gtk_connection_connect_progress, | |
212 gaim_gtk_connection_connected, | |
213 gaim_gtk_connection_disconnected, | |
6460
ff4551719cc7
[gaim-migrate @ 6969]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
214 gaim_gtk_connection_notice, |
11523 | 215 gaim_gtk_connection_report_disconnect, |
5717 | 216 }; |
217 | |
7035
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6460
diff
changeset
|
218 GaimConnectionUiOps * |
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6460
diff
changeset
|
219 gaim_gtk_connections_get_ui_ops(void) |
5717 | 220 { |
221 return &conn_ui_ops; | |
222 } | |
13014 | 223 |
224 static void | |
225 account_removed_cb(GaimAccount *account, gpointer user_data) | |
226 { | |
227 g_hash_table_remove(hash, account); | |
228 | |
229 if (g_hash_table_size(errored_accounts) > 0) | |
230 { | |
231 g_hash_table_remove(errored_accounts, account); | |
13015 | 232 gaim_gtk_blist_update_account_error_state(account, NULL); |
13014 | 233 } |
234 } | |
235 | |
236 | |
237 /************************************************************************** | |
238 * GTK+ connection glue | |
239 **************************************************************************/ | |
240 | |
241 void * | |
242 gaim_gtk_connection_get_handle(void) | |
243 { | |
244 static int handle; | |
245 | |
246 return &handle; | |
247 } | |
248 | |
249 void | |
250 gaim_gtk_connection_init(void) | |
251 { | |
252 hash = g_hash_table_new_full( | |
253 g_direct_hash, g_direct_equal, | |
254 NULL, free_auto_recon); | |
255 errored_accounts = g_hash_table_new_full( | |
256 g_direct_hash, g_direct_equal, | |
257 NULL, NULL); | |
258 | |
259 gaim_signal_connect(gaim_accounts_get_handle(), "account-removed", | |
260 gaim_gtk_connection_get_handle(), | |
261 GAIM_CALLBACK(account_removed_cb), NULL); | |
262 } | |
263 | |
264 void | |
265 gaim_gtk_connection_uninit(void) | |
266 { | |
267 gaim_signals_disconnect_by_handle(gaim_gtk_connection_get_handle()); | |
268 | |
269 g_hash_table_destroy(hash); | |
270 g_hash_table_destroy(errored_accounts); | |
271 } |