Mercurial > pidgin
annotate src/gtkconn.c @ 12264:2be62353f708
[gaim-migrate @ 14566]
this was TRUE in oldstatus
committer: Tailor Script <tailor@pidgin.im>
| author | Nathan Walp <nwalp@pidgin.im> |
|---|---|
| date | Tue, 29 Nov 2005 23:50:39 +0000 |
| parents | f28e51bf9be8 |
| children | 2f4577ae3810 |
| 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); | |
|
5936
1b56a833d665
[gaim-migrate @ 6376]
Christian Hammond <chipx86@chipx86.com>
parents:
5885
diff
changeset
|
114 gaim_gtk_blist_update_protocol_actions(); |
| 5717 | 115 } |
| 116 | |
|
6460
ff4551719cc7
[gaim-migrate @ 6969]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
117 static void gaim_gtk_connection_disconnected(GaimConnection *gc) |
| 5717 | 118 { |
| 10643 | 119 GaimGtkBuddyList *gtkblist = gaim_gtk_blist_get_default_gtk_blist(); |
| 120 if (!gtkblist) | |
| 121 return; | |
| 122 gtk_gaim_status_box_set_connecting(GTK_GAIM_STATUS_BOX(gtkblist->statusbox), | |
| 123 (gaim_connections_get_connecting() != NULL)); | |
| 12228 | 124 gtk_gaim_status_box_set_connecting(find_status_box_for_account(gc->account), |
| 125 FALSE); | |
|
5936
1b56a833d665
[gaim-migrate @ 6376]
Christian Hammond <chipx86@chipx86.com>
parents:
5885
diff
changeset
|
126 gaim_gtk_blist_update_protocol_actions(); |
|
5883
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
127 |
|
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
128 if (gaim_connections_get_all() != NULL) |
|
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
129 return; |
|
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
130 |
| 9730 | 131 gaim_gtkdialogs_destroy_all(); |
| 5717 | 132 } |
| 133 | |
| 134 static void gaim_gtk_connection_notice(GaimConnection *gc, | |
| 135 const char *text) | |
| 136 { | |
| 137 } | |
| 138 | |
| 7912 | 139 |
| 11523 | 140 static void |
| 141 free_auto_recon(gpointer data) | |
| 7493 | 142 { |
| 11523 | 143 GaimAutoRecon *info = data; |
| 7912 | 144 |
| 11523 | 145 if (info->timeout != 0) |
| 146 g_source_remove(info->timeout); | |
| 7912 | 147 |
| 11523 | 148 g_free(info); |
| 7493 | 149 } |
| 150 | |
| 11523 | 151 static gboolean |
| 152 do_signon(gpointer data) | |
| 7912 | 153 { |
| 11523 | 154 GaimAccount *account = data; |
| 155 GaimAutoRecon *info; | |
| 10916 | 156 |
| 11523 | 157 gaim_debug(GAIM_DEBUG_INFO, "autorecon", "do_signon called\n"); |
| 158 g_return_val_if_fail(account != NULL, FALSE); | |
| 159 info = g_hash_table_lookup(hash, account); | |
| 7912 | 160 |
| 11523 | 161 if (g_list_index(gaim_accounts_get_all(), account) < 0) |
| 162 return FALSE; | |
| 163 | |
| 164 if (info) | |
| 165 info->timeout = 0; | |
| 7912 | 166 |
| 11523 | 167 gaim_debug(GAIM_DEBUG_INFO, "autorecon", "calling gaim_account_connect\n"); |
| 168 gaim_account_connect(account); | |
| 169 gaim_debug(GAIM_DEBUG_INFO, "autorecon", "done calling gaim_account_connect\n"); | |
| 7912 | 170 |
| 11523 | 171 return FALSE; |
| 7912 | 172 } |
| 173 | |
| 11523 | 174 static void gaim_gtk_connection_report_disconnect(GaimConnection *gc, const char *text) |
| 7399 | 175 { |
| 12009 | 176 GaimGtkBuddyList *gtkblist = gaim_gtk_blist_get_default_gtk_blist(); |
| 7431 | 177 GaimAccount *account = NULL; |
| 11523 | 178 GaimAutoRecon *info; |
| 179 GSList* listAccount; | |
| 7808 | 180 |
| 11523 | 181 if (hash == NULL) { |
| 11721 | 182 hash = g_hash_table_new_full(g_int_hash, g_int_equal, NULL, |
| 183 free_auto_recon); | |
| 11523 | 184 } |
| 185 account = gaim_connection_get_account(gc); | |
| 186 info = g_hash_table_lookup(hash, account); | |
| 187 if (accountReconnecting) | |
| 188 listAccount = g_slist_find(accountReconnecting, account); | |
| 189 else | |
| 190 listAccount = NULL; | |
| 7912 | 191 |
| 11523 | 192 if (!gc->wants_to_die) { |
| 12009 | 193 if (gtkblist != NULL) |
| 194 gtk_gaim_status_box_set_error(GTK_GAIM_STATUS_BOX(gtkblist->statusbox), text); | |
| 12228 | 195 gtk_gaim_status_box_set_error(find_status_box_for_account(account), text); |
| 11721 | 196 |
| 12009 | 197 if (info == NULL) { |
| 11523 | 198 info = g_new0(GaimAutoRecon, 1); |
| 199 g_hash_table_insert(hash, account, info); | |
| 200 info->delay = INITIAL_RECON_DELAY; | |
| 7483 | 201 } else { |
| 11523 | 202 info->delay = MIN(2 * info->delay, MAX_RECON_DELAY); |
| 203 if (info->timeout != 0) | |
| 204 g_source_remove(info->timeout); | |
| 7483 | 205 } |
| 11523 | 206 info->timeout = g_timeout_add(info->delay, do_signon, account); |
| 7912 | 207 |
| 11523 | 208 if (!listAccount) |
| 209 accountReconnecting = g_slist_prepend(accountReconnecting, account); | |
| 11559 | 210 } else { |
| 211 char *p, *s, *n=NULL ; | |
| 11721 | 212 if (info != NULL) |
| 11559 | 213 g_hash_table_remove(hash, account); |
| 11721 | 214 |
| 11559 | 215 if (listAccount) |
| 216 accountReconnecting = g_slist_delete_link(accountReconnecting, listAccount); | |
| 11721 | 217 |
| 11559 | 218 if (gaim_account_get_alias(account)) { |
| 219 n = g_strdup_printf("%s (%s) (%s)", | |
| 220 gaim_account_get_username(account), | |
| 221 gaim_account_get_alias(account), | |
| 222 gaim_account_get_protocol_name(account)); | |
| 223 } else { | |
| 224 n = g_strdup_printf("%s (%s)", | |
| 225 gaim_account_get_username(account), | |
| 226 gaim_account_get_protocol_name(account)); | |
| 227 } | |
| 11721 | 228 |
| 11638 | 229 p = g_strdup_printf(_("%s disconnected"), n); |
| 230 s = g_strdup_printf(_("%s was disconnected due to an error. %s The account has been disabled. " | |
| 231 "Correct the error and reenable the account to connect."), n, text); | |
| 11559 | 232 gaim_notify_error(NULL, NULL, p, s); |
| 233 g_free(p); | |
| 234 g_free(s); | |
| 235 g_free(n); | |
| 11638 | 236 /* XXX: do we really want to disable the account when it's disconnected by wants_to_die? |
| 237 * This normally happens when you sign on from somewhere else. */ | |
| 11559 | 238 gaim_account_set_enabled(account, GAIM_GTK_UI, FALSE); |
| 7399 | 239 } |
| 240 } | |
| 241 | |
| 5717 | 242 static GaimConnectionUiOps conn_ui_ops = |
| 243 { | |
| 244 gaim_gtk_connection_connect_progress, | |
| 245 gaim_gtk_connection_connected, | |
| 246 gaim_gtk_connection_disconnected, | |
|
6460
ff4551719cc7
[gaim-migrate @ 6969]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
247 gaim_gtk_connection_notice, |
| 11523 | 248 gaim_gtk_connection_report_disconnect, |
| 5717 | 249 }; |
| 250 | |
|
7035
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6460
diff
changeset
|
251 GaimConnectionUiOps * |
|
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6460
diff
changeset
|
252 gaim_gtk_connections_get_ui_ops(void) |
| 5717 | 253 { |
| 254 return &conn_ui_ops; | |
| 255 } |
