Mercurial > pidgin
annotate src/gtkconn.c @ 13013:8fe78402c010
[gaim-migrate @ 15366]
Rename some variables that were bugging me
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Mon, 23 Jan 2006 05:50:32 +0000 |
parents | 78048f8af66f |
children | 5efbb0162f86 |
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; | |
13013 | 49 /* |
50 * TODO: Remove an account from this list if the account is deleted. | |
51 */ | |
52 static GSList *errored_accounts = NULL; | |
11523 | 53 |
5717 | 54 static void gaim_gtk_connection_connect_progress(GaimConnection *gc, |
55 const char *text, size_t step, size_t step_count) | |
56 { | |
10643 | 57 GaimGtkBuddyList *gtkblist = gaim_gtk_blist_get_default_gtk_blist(); |
58 if (!gtkblist) | |
59 return; | |
60 gtk_gaim_status_box_set_connecting(GTK_GAIM_STATUS_BOX(gtkblist->statusbox), | |
61 (gaim_connections_get_connecting() != NULL)); | |
62 gtk_gaim_status_box_pulse_connecting(GTK_GAIM_STATUS_BOX(gtkblist->statusbox)); | |
5717 | 63 } |
64 | |
65 static void gaim_gtk_connection_connected(GaimConnection *gc) | |
66 { | |
10643 | 67 GaimGtkBuddyList *gtkblist = gaim_gtk_blist_get_default_gtk_blist(); |
11523 | 68 GaimAccount *account = NULL; |
10643 | 69 if (!gtkblist) |
70 return; | |
71 gtk_gaim_status_box_set_connecting(GTK_GAIM_STATUS_BOX(gtkblist->statusbox), | |
72 (gaim_connections_get_connecting() != NULL)); | |
11523 | 73 account = gaim_connection_get_account(gc); |
12607 | 74 |
11536 | 75 if (hash != NULL) |
76 g_hash_table_remove(hash, account); | |
13013 | 77 if (errored_accounts == NULL) |
11523 | 78 return; |
13013 | 79 errored_accounts = g_slist_remove(errored_accounts, account); |
80 if (errored_accounts == NULL) | |
11523 | 81 gtk_gaim_status_box_set_error(GTK_GAIM_STATUS_BOX(gtkblist->statusbox), NULL); |
5717 | 82 } |
83 | |
6460
ff4551719cc7
[gaim-migrate @ 6969]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
84 static void gaim_gtk_connection_disconnected(GaimConnection *gc) |
5717 | 85 { |
10643 | 86 GaimGtkBuddyList *gtkblist = gaim_gtk_blist_get_default_gtk_blist(); |
87 if (!gtkblist) | |
88 return; | |
89 gtk_gaim_status_box_set_connecting(GTK_GAIM_STATUS_BOX(gtkblist->statusbox), | |
90 (gaim_connections_get_connecting() != NULL)); | |
5883
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
91 |
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
92 if (gaim_connections_get_all() != NULL) |
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
93 return; |
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
94 |
9730 | 95 gaim_gtkdialogs_destroy_all(); |
5717 | 96 } |
97 | |
98 static void gaim_gtk_connection_notice(GaimConnection *gc, | |
99 const char *text) | |
100 { | |
101 } | |
102 | |
7912 | 103 |
11523 | 104 static void |
105 free_auto_recon(gpointer data) | |
7493 | 106 { |
11523 | 107 GaimAutoRecon *info = data; |
7912 | 108 |
11523 | 109 if (info->timeout != 0) |
110 g_source_remove(info->timeout); | |
7912 | 111 |
11523 | 112 g_free(info); |
7493 | 113 } |
114 | |
11523 | 115 static gboolean |
116 do_signon(gpointer data) | |
7912 | 117 { |
11523 | 118 GaimAccount *account = data; |
119 GaimAutoRecon *info; | |
10916 | 120 |
11523 | 121 gaim_debug(GAIM_DEBUG_INFO, "autorecon", "do_signon called\n"); |
122 g_return_val_if_fail(account != NULL, FALSE); | |
123 info = g_hash_table_lookup(hash, account); | |
7912 | 124 |
11523 | 125 if (g_list_index(gaim_accounts_get_all(), account) < 0) |
126 return FALSE; | |
127 | |
128 if (info) | |
129 info->timeout = 0; | |
7912 | 130 |
11523 | 131 gaim_debug(GAIM_DEBUG_INFO, "autorecon", "calling gaim_account_connect\n"); |
132 gaim_account_connect(account); | |
133 gaim_debug(GAIM_DEBUG_INFO, "autorecon", "done calling gaim_account_connect\n"); | |
7912 | 134 |
11523 | 135 return FALSE; |
7912 | 136 } |
137 | |
11523 | 138 static void gaim_gtk_connection_report_disconnect(GaimConnection *gc, const char *text) |
7399 | 139 { |
12009 | 140 GaimGtkBuddyList *gtkblist = gaim_gtk_blist_get_default_gtk_blist(); |
7431 | 141 GaimAccount *account = NULL; |
11523 | 142 GaimAutoRecon *info; |
13013 | 143 GSList* errored_account; |
7808 | 144 |
11523 | 145 if (hash == NULL) { |
11721 | 146 hash = g_hash_table_new_full(g_int_hash, g_int_equal, NULL, |
147 free_auto_recon); | |
11523 | 148 } |
149 account = gaim_connection_get_account(gc); | |
150 info = g_hash_table_lookup(hash, account); | |
13013 | 151 if (errored_accounts) |
152 errored_account = g_slist_find(errored_accounts, account); | |
11523 | 153 else |
13013 | 154 errored_account = NULL; |
7912 | 155 |
11523 | 156 if (!gc->wants_to_die) { |
12009 | 157 if (gtkblist != NULL) |
158 gtk_gaim_status_box_set_error(GTK_GAIM_STATUS_BOX(gtkblist->statusbox), text); | |
13013 | 159 |
12009 | 160 if (info == NULL) { |
11523 | 161 info = g_new0(GaimAutoRecon, 1); |
162 g_hash_table_insert(hash, account, info); | |
163 info->delay = INITIAL_RECON_DELAY; | |
7483 | 164 } else { |
11523 | 165 info->delay = MIN(2 * info->delay, MAX_RECON_DELAY); |
166 if (info->timeout != 0) | |
167 g_source_remove(info->timeout); | |
7483 | 168 } |
11523 | 169 info->timeout = g_timeout_add(info->delay, do_signon, account); |
7912 | 170 |
13013 | 171 if (!errored_account) |
172 errored_accounts = g_slist_prepend(errored_accounts, account); | |
11559 | 173 } else { |
174 char *p, *s, *n=NULL ; | |
11721 | 175 if (info != NULL) |
11559 | 176 g_hash_table_remove(hash, account); |
11721 | 177 |
13013 | 178 if (errored_account) |
179 errored_accounts = g_slist_delete_link(errored_accounts, errored_account); | |
11721 | 180 |
11559 | 181 if (gaim_account_get_alias(account)) { |
182 n = g_strdup_printf("%s (%s) (%s)", | |
183 gaim_account_get_username(account), | |
184 gaim_account_get_alias(account), | |
185 gaim_account_get_protocol_name(account)); | |
186 } else { | |
187 n = g_strdup_printf("%s (%s)", | |
188 gaim_account_get_username(account), | |
189 gaim_account_get_protocol_name(account)); | |
190 } | |
11721 | 191 |
11638 | 192 p = g_strdup_printf(_("%s disconnected"), n); |
193 s = g_strdup_printf(_("%s was disconnected due to an error. %s The account has been disabled. " | |
194 "Correct the error and reenable the account to connect."), n, text); | |
11559 | 195 gaim_notify_error(NULL, NULL, p, s); |
196 g_free(p); | |
197 g_free(s); | |
198 g_free(n); | |
11638 | 199 /* XXX: do we really want to disable the account when it's disconnected by wants_to_die? |
200 * This normally happens when you sign on from somewhere else. */ | |
11559 | 201 gaim_account_set_enabled(account, GAIM_GTK_UI, FALSE); |
7399 | 202 } |
203 } | |
204 | |
5717 | 205 static GaimConnectionUiOps conn_ui_ops = |
206 { | |
207 gaim_gtk_connection_connect_progress, | |
208 gaim_gtk_connection_connected, | |
209 gaim_gtk_connection_disconnected, | |
6460
ff4551719cc7
[gaim-migrate @ 6969]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
210 gaim_gtk_connection_notice, |
11523 | 211 gaim_gtk_connection_report_disconnect, |
5717 | 212 }; |
213 | |
7035
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6460
diff
changeset
|
214 GaimConnectionUiOps * |
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6460
diff
changeset
|
215 gaim_gtk_connections_get_ui_ops(void) |
5717 | 216 { |
217 return &conn_ui_ops; | |
218 } |