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