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