Mercurial > pidgin
annotate src/gtkconn.c @ 12540:b0ba132271a9
[gaim-migrate @ 14853]
this doesn't make it work, but it does make it more correct
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Sat, 17 Dec 2005 21:01:40 +0000 |
parents | 7c7cb03e5475 |
children | 301e9f0841d7 |
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 | |
48 static GHashTable *hash = NULL; | |
49 static GSList *accountReconnecting = NULL; | |
50 | |
12228 | 51 static GtkGaimStatusBox * |
52 find_status_box_for_account(GaimAccount *account) | |
53 { | |
54 GaimGtkBuddyList *gtkblist; | |
55 GList *iter; | |
56 | |
57 gtkblist = gaim_gtk_blist_get_default_gtk_blist(); | |
58 if (!gtkblist) | |
59 return NULL; | |
60 | |
61 for (iter = gtkblist->statusboxes; iter; iter=iter->next) | |
62 { | |
63 GtkGaimStatusBox *box = iter->data; | |
64 if (box->account == account) | |
65 return box; | |
66 } | |
67 return NULL; | |
68 } | |
69 | |
5717 | 70 static void gaim_gtk_connection_connect_progress(GaimConnection *gc, |
71 const char *text, size_t step, size_t step_count) | |
72 { | |
10643 | 73 GaimGtkBuddyList *gtkblist = gaim_gtk_blist_get_default_gtk_blist(); |
12228 | 74 GtkGaimStatusBox *box; |
10643 | 75 if (!gtkblist) |
76 return; | |
77 gtk_gaim_status_box_set_connecting(GTK_GAIM_STATUS_BOX(gtkblist->statusbox), | |
78 (gaim_connections_get_connecting() != NULL)); | |
79 gtk_gaim_status_box_pulse_connecting(GTK_GAIM_STATUS_BOX(gtkblist->statusbox)); | |
12228 | 80 |
81 if ((box = find_status_box_for_account(gc->account)) != NULL) | |
82 { | |
83 gtk_gaim_status_box_set_error(box, NULL); | |
84 gtk_gaim_status_box_set_connecting(box, TRUE); | |
85 gtk_gaim_status_box_pulse_connecting(box); | |
86 } | |
5717 | 87 } |
88 | |
89 static void gaim_gtk_connection_connected(GaimConnection *gc) | |
90 { | |
10643 | 91 GaimGtkBuddyList *gtkblist = gaim_gtk_blist_get_default_gtk_blist(); |
12228 | 92 GtkGaimStatusBox *box; |
11523 | 93 GaimAccount *account = NULL; |
10643 | 94 if (!gtkblist) |
95 return; | |
96 gtk_gaim_status_box_set_connecting(GTK_GAIM_STATUS_BOX(gtkblist->statusbox), | |
97 (gaim_connections_get_connecting() != NULL)); | |
11523 | 98 account = gaim_connection_get_account(gc); |
12228 | 99 |
100 if ((box = find_status_box_for_account(account)) != NULL) | |
101 { | |
102 gtk_gaim_status_box_set_connecting(box, FALSE); | |
103 gtk_gaim_status_box_set_error(box, NULL); | |
104 } | |
105 | |
11536 | 106 if (hash != NULL) |
107 g_hash_table_remove(hash, account); | |
11523 | 108 if (accountReconnecting == NULL) |
109 return; | |
110 accountReconnecting = g_slist_remove(accountReconnecting, account); | |
111 if (accountReconnecting == NULL) | |
112 gtk_gaim_status_box_set_error(GTK_GAIM_STATUS_BOX(gtkblist->statusbox), NULL); | |
5717 | 113 } |
114 | |
6460
ff4551719cc7
[gaim-migrate @ 6969]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
115 static void gaim_gtk_connection_disconnected(GaimConnection *gc) |
5717 | 116 { |
10643 | 117 GaimGtkBuddyList *gtkblist = gaim_gtk_blist_get_default_gtk_blist(); |
118 if (!gtkblist) | |
119 return; | |
120 gtk_gaim_status_box_set_connecting(GTK_GAIM_STATUS_BOX(gtkblist->statusbox), | |
121 (gaim_connections_get_connecting() != NULL)); | |
12228 | 122 gtk_gaim_status_box_set_connecting(find_status_box_for_account(gc->account), |
123 FALSE); | |
5883
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
124 |
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
125 if (gaim_connections_get_all() != NULL) |
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
126 return; |
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
127 |
9730 | 128 gaim_gtkdialogs_destroy_all(); |
5717 | 129 } |
130 | |
131 static void gaim_gtk_connection_notice(GaimConnection *gc, | |
132 const char *text) | |
133 { | |
134 } | |
135 | |
7912 | 136 |
11523 | 137 static void |
138 free_auto_recon(gpointer data) | |
7493 | 139 { |
11523 | 140 GaimAutoRecon *info = data; |
7912 | 141 |
11523 | 142 if (info->timeout != 0) |
143 g_source_remove(info->timeout); | |
7912 | 144 |
11523 | 145 g_free(info); |
7493 | 146 } |
147 | |
11523 | 148 static gboolean |
149 do_signon(gpointer data) | |
7912 | 150 { |
11523 | 151 GaimAccount *account = data; |
152 GaimAutoRecon *info; | |
10916 | 153 |
11523 | 154 gaim_debug(GAIM_DEBUG_INFO, "autorecon", "do_signon called\n"); |
155 g_return_val_if_fail(account != NULL, FALSE); | |
156 info = g_hash_table_lookup(hash, account); | |
7912 | 157 |
11523 | 158 if (g_list_index(gaim_accounts_get_all(), account) < 0) |
159 return FALSE; | |
160 | |
161 if (info) | |
162 info->timeout = 0; | |
7912 | 163 |
11523 | 164 gaim_debug(GAIM_DEBUG_INFO, "autorecon", "calling gaim_account_connect\n"); |
165 gaim_account_connect(account); | |
166 gaim_debug(GAIM_DEBUG_INFO, "autorecon", "done calling gaim_account_connect\n"); | |
7912 | 167 |
11523 | 168 return FALSE; |
7912 | 169 } |
170 | |
11523 | 171 static void gaim_gtk_connection_report_disconnect(GaimConnection *gc, const char *text) |
7399 | 172 { |
12009 | 173 GaimGtkBuddyList *gtkblist = gaim_gtk_blist_get_default_gtk_blist(); |
7431 | 174 GaimAccount *account = NULL; |
11523 | 175 GaimAutoRecon *info; |
176 GSList* listAccount; | |
7808 | 177 |
11523 | 178 if (hash == NULL) { |
11721 | 179 hash = g_hash_table_new_full(g_int_hash, g_int_equal, NULL, |
180 free_auto_recon); | |
11523 | 181 } |
182 account = gaim_connection_get_account(gc); | |
183 info = g_hash_table_lookup(hash, account); | |
184 if (accountReconnecting) | |
185 listAccount = g_slist_find(accountReconnecting, account); | |
186 else | |
187 listAccount = NULL; | |
7912 | 188 |
11523 | 189 if (!gc->wants_to_die) { |
12009 | 190 if (gtkblist != NULL) |
191 gtk_gaim_status_box_set_error(GTK_GAIM_STATUS_BOX(gtkblist->statusbox), text); | |
12228 | 192 gtk_gaim_status_box_set_error(find_status_box_for_account(account), text); |
11721 | 193 |
12009 | 194 if (info == NULL) { |
11523 | 195 info = g_new0(GaimAutoRecon, 1); |
196 g_hash_table_insert(hash, account, info); | |
197 info->delay = INITIAL_RECON_DELAY; | |
7483 | 198 } else { |
11523 | 199 info->delay = MIN(2 * info->delay, MAX_RECON_DELAY); |
200 if (info->timeout != 0) | |
201 g_source_remove(info->timeout); | |
7483 | 202 } |
11523 | 203 info->timeout = g_timeout_add(info->delay, do_signon, account); |
7912 | 204 |
11523 | 205 if (!listAccount) |
206 accountReconnecting = g_slist_prepend(accountReconnecting, account); | |
11559 | 207 } else { |
208 char *p, *s, *n=NULL ; | |
11721 | 209 if (info != NULL) |
11559 | 210 g_hash_table_remove(hash, account); |
11721 | 211 |
11559 | 212 if (listAccount) |
213 accountReconnecting = g_slist_delete_link(accountReconnecting, listAccount); | |
11721 | 214 |
11559 | 215 if (gaim_account_get_alias(account)) { |
216 n = g_strdup_printf("%s (%s) (%s)", | |
217 gaim_account_get_username(account), | |
218 gaim_account_get_alias(account), | |
219 gaim_account_get_protocol_name(account)); | |
220 } else { | |
221 n = g_strdup_printf("%s (%s)", | |
222 gaim_account_get_username(account), | |
223 gaim_account_get_protocol_name(account)); | |
224 } | |
11721 | 225 |
11638 | 226 p = g_strdup_printf(_("%s disconnected"), n); |
227 s = g_strdup_printf(_("%s was disconnected due to an error. %s The account has been disabled. " | |
228 "Correct the error and reenable the account to connect."), n, text); | |
11559 | 229 gaim_notify_error(NULL, NULL, p, s); |
230 g_free(p); | |
231 g_free(s); | |
232 g_free(n); | |
11638 | 233 /* XXX: do we really want to disable the account when it's disconnected by wants_to_die? |
234 * This normally happens when you sign on from somewhere else. */ | |
11559 | 235 gaim_account_set_enabled(account, GAIM_GTK_UI, FALSE); |
7399 | 236 } |
237 } | |
238 | |
5717 | 239 static GaimConnectionUiOps conn_ui_ops = |
240 { | |
241 gaim_gtk_connection_connect_progress, | |
242 gaim_gtk_connection_connected, | |
243 gaim_gtk_connection_disconnected, | |
6460
ff4551719cc7
[gaim-migrate @ 6969]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
244 gaim_gtk_connection_notice, |
11523 | 245 gaim_gtk_connection_report_disconnect, |
5717 | 246 }; |
247 | |
7035
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6460
diff
changeset
|
248 GaimConnectionUiOps * |
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6460
diff
changeset
|
249 gaim_gtk_connections_get_ui_ops(void) |
5717 | 250 { |
251 return &conn_ui_ops; | |
252 } |