Mon, 12 Sep 2005 06:46:43 +0000
[gaim-migrate @ 13771]
Incorporated Autorecon's code into the core.
Removed the Disconnected window
Shows connection errors in status box.
This works _ok_ when signed on with a single account, but won't currently
Handle multiple accounts at all. I wanted to get this in before going to
bed tonight, so I can work on it later, though.
Feel free to help.
| 5717 | 1 | /* |
|
10297
b36800725b7a
[gaim-migrate @ 11480]
Evan Schoenberg <evands@pidgin.im>
parents:
10211
diff
changeset
|
2 | * @file gtkconn.c GTK+ Connection API |
|
b36800725b7a
[gaim-migrate @ 11480]
Evan Schoenberg <evands@pidgin.im>
parents:
10211
diff
changeset
|
3 | * @ingroup gtkui |
|
b36800725b7a
[gaim-migrate @ 11480]
Evan Schoenberg <evands@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
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5746
diff
changeset
|
29 | #include "debug.h" |
|
6460
fc288e7221ca
[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
b36800725b7a
[gaim-migrate @ 11480]
Evan Schoenberg <evands@pidgin.im>
parents:
10211
diff
changeset
|
34 | #include "gtkstock.h" |
|
5872
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5746
diff
changeset
|
35 | #include "util.h" |
| 5717 | 36 | |
|
5872
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5746
diff
changeset
|
37 | #include "gtkblist.h" |
|
9730
e59812364b8b
[gaim-migrate @ 10591]
Mark Doliner <markdoliner@pidgin.im>
parents:
9709
diff
changeset
|
38 | #include "gtkdialogs.h" |
|
5872
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5746
diff
changeset
|
39 | #include "gtkutils.h" |
|
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5746
diff
changeset
|
40 | |
| 11523 | 41 | #define INITIAL_RECON_DELAY 8000 |
| 42 | #define MAX_RECON_DELAY 2048000 | |
| 43 | ||
| 44 | typedef struct { | |
| 45 | int delay; | |
| 46 | guint timeout; | |
| 47 | } GaimAutoRecon; | |
| 48 | ||
| 49 | static GHashTable *hash = NULL; | |
| 50 | static GSList *accountReconnecting = NULL; | |
| 51 | ||
| 5717 | 52 | static void gaim_gtk_connection_connect_progress(GaimConnection *gc, |
| 53 | const char *text, size_t step, size_t step_count) | |
| 54 | { | |
| 10643 | 55 | GaimGtkBuddyList *gtkblist = gaim_gtk_blist_get_default_gtk_blist(); |
| 56 | if (!gtkblist) | |
| 57 | return; | |
| 58 | gtk_gaim_status_box_set_connecting(GTK_GAIM_STATUS_BOX(gtkblist->statusbox), | |
| 59 | (gaim_connections_get_connecting() != NULL)); | |
| 60 | gtk_gaim_status_box_pulse_connecting(GTK_GAIM_STATUS_BOX(gtkblist->statusbox)); | |
| 5717 | 61 | } |
| 62 | ||
| 63 | static void gaim_gtk_connection_connected(GaimConnection *gc) | |
| 64 | { | |
| 10643 | 65 | GaimGtkBuddyList *gtkblist = gaim_gtk_blist_get_default_gtk_blist(); |
| 11523 | 66 | GaimAccount *account = NULL; |
| 10643 | 67 | if (!gtkblist) |
| 68 | return; | |
| 69 | gtk_gaim_status_box_set_connecting(GTK_GAIM_STATUS_BOX(gtkblist->statusbox), | |
| 70 | (gaim_connections_get_connecting() != NULL)); | |
| 11523 | 71 | account = gaim_connection_get_account(gc); |
| 72 | g_hash_table_remove(hash, account); | |
| 73 | if (accountReconnecting == NULL) | |
| 74 | return; | |
| 75 | accountReconnecting = g_slist_remove(accountReconnecting, account); | |
| 76 | if (accountReconnecting == NULL) | |
| 77 | gtk_gaim_status_box_set_error(GTK_GAIM_STATUS_BOX(gtkblist->statusbox), NULL); | |
|
5936
4bac764cc792
[gaim-migrate @ 6376]
Christian Hammond <chipx86@chipx86.com>
parents:
5885
diff
changeset
|
78 | gaim_gtk_blist_update_protocol_actions(); |
| 5717 | 79 | } |
| 80 | ||
|
6460
fc288e7221ca
[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)); | |
|
5936
4bac764cc792
[gaim-migrate @ 6376]
Christian Hammond <chipx86@chipx86.com>
parents:
5885
diff
changeset
|
88 | gaim_gtk_blist_update_protocol_actions(); |
|
5883
290fe1d16e60
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
89 | |
|
290fe1d16e60
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
90 | if (gaim_connections_get_all() != NULL) |
|
290fe1d16e60
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
91 | return; |
|
290fe1d16e60
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
92 | |
|
9730
e59812364b8b
[gaim-migrate @ 10591]
Mark Doliner <markdoliner@pidgin.im>
parents:
9709
diff
changeset
|
93 | gaim_gtkdialogs_destroy_all(); |
| 5717 | 94 | } |
| 95 | ||
| 96 | static void gaim_gtk_connection_notice(GaimConnection *gc, | |
| 97 | const char *text) | |
| 98 | { | |
| 99 | } | |
| 100 | ||
|
7912
b8f84918e7c1
[gaim-migrate @ 8573]
Mark Doliner <markdoliner@pidgin.im>
parents:
7890
diff
changeset
|
101 | |
| 11523 | 102 | static void |
| 103 | free_auto_recon(gpointer data) | |
| 7493 | 104 | { |
| 11523 | 105 | GaimAutoRecon *info = data; |
|
7912
b8f84918e7c1
[gaim-migrate @ 8573]
Mark Doliner <markdoliner@pidgin.im>
parents:
7890
diff
changeset
|
106 | |
| 11523 | 107 | if (info->timeout != 0) |
| 108 | g_source_remove(info->timeout); | |
|
7912
b8f84918e7c1
[gaim-migrate @ 8573]
Mark Doliner <markdoliner@pidgin.im>
parents:
7890
diff
changeset
|
109 | |
| 11523 | 110 | g_free(info); |
| 7493 | 111 | } |
| 112 | ||
| 11523 | 113 | static gboolean |
| 114 | do_signon(gpointer data) | |
|
7912
b8f84918e7c1
[gaim-migrate @ 8573]
Mark Doliner <markdoliner@pidgin.im>
parents:
7890
diff
changeset
|
115 | { |
| 11523 | 116 | GaimAccount *account = data; |
| 117 | GaimAutoRecon *info; | |
|
10916
3de20dd2dade
[gaim-migrate @ 12675]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10915
diff
changeset
|
118 | |
| 11523 | 119 | gaim_debug(GAIM_DEBUG_INFO, "autorecon", "do_signon called\n"); |
| 120 | g_return_val_if_fail(account != NULL, FALSE); | |
| 121 | info = g_hash_table_lookup(hash, account); | |
|
7912
b8f84918e7c1
[gaim-migrate @ 8573]
Mark Doliner <markdoliner@pidgin.im>
parents:
7890
diff
changeset
|
122 | |
| 11523 | 123 | if (g_list_index(gaim_accounts_get_all(), account) < 0) |
| 124 | return FALSE; | |
| 125 | ||
| 126 | if (info) | |
| 127 | info->timeout = 0; | |
|
7912
b8f84918e7c1
[gaim-migrate @ 8573]
Mark Doliner <markdoliner@pidgin.im>
parents:
7890
diff
changeset
|
128 | |
| 11523 | 129 | gaim_debug(GAIM_DEBUG_INFO, "autorecon", "calling gaim_account_connect\n"); |
| 130 | gaim_account_connect(account); | |
| 131 | gaim_debug(GAIM_DEBUG_INFO, "autorecon", "done calling gaim_account_connect\n"); | |
|
7912
b8f84918e7c1
[gaim-migrate @ 8573]
Mark Doliner <markdoliner@pidgin.im>
parents:
7890
diff
changeset
|
132 | |
| 11523 | 133 | return FALSE; |
|
7912
b8f84918e7c1
[gaim-migrate @ 8573]
Mark Doliner <markdoliner@pidgin.im>
parents:
7890
diff
changeset
|
134 | } |
|
b8f84918e7c1
[gaim-migrate @ 8573]
Mark Doliner <markdoliner@pidgin.im>
parents:
7890
diff
changeset
|
135 | |
| 11523 | 136 | static void gaim_gtk_connection_report_disconnect(GaimConnection *gc, const char *text) |
| 7399 | 137 | { |
| 11523 | 138 | GaimGtkBuddyList *list = gaim_gtk_blist_get_default_gtk_blist(); |
| 7431 | 139 | GaimAccount *account = NULL; |
| 11523 | 140 | GaimAutoRecon *info; |
| 141 | GSList* listAccount; | |
| 7808 | 142 | |
| 11523 | 143 | gtk_gaim_status_box_set_error(GTK_GAIM_STATUS_BOX(list->statusbox), text); |
| 144 | if (hash == NULL) { | |
| 145 | hash = g_hash_table_new_full(g_int_hash, g_int_equal, NULL, | |
| 146 | free_auto_recon); | |
| 147 | } | |
| 148 | account = gaim_connection_get_account(gc); | |
| 149 | info = g_hash_table_lookup(hash, account); | |
| 150 | if (accountReconnecting) | |
| 151 | listAccount = g_slist_find(accountReconnecting, account); | |
| 152 | else | |
| 153 | listAccount = NULL; | |
|
7912
b8f84918e7c1
[gaim-migrate @ 8573]
Mark Doliner <markdoliner@pidgin.im>
parents:
7890
diff
changeset
|
154 | |
| 11523 | 155 | if (!gc->wants_to_die) { |
| 156 | if (info == NULL) { | |
| 157 | info = g_new0(GaimAutoRecon, 1); | |
| 158 | g_hash_table_insert(hash, account, info); | |
| 159 | info->delay = INITIAL_RECON_DELAY; | |
|
7483
08237091e8a5
[gaim-migrate @ 8096]
Mark Doliner <markdoliner@pidgin.im>
parents:
7431
diff
changeset
|
160 | } else { |
| 11523 | 161 | info->delay = MIN(2 * info->delay, MAX_RECON_DELAY); |
| 162 | if (info->timeout != 0) | |
| 163 | g_source_remove(info->timeout); | |
|
7483
08237091e8a5
[gaim-migrate @ 8096]
Mark Doliner <markdoliner@pidgin.im>
parents:
7431
diff
changeset
|
164 | } |
| 11523 | 165 | info->timeout = g_timeout_add(info->delay, do_signon, account); |
|
7912
b8f84918e7c1
[gaim-migrate @ 8573]
Mark Doliner <markdoliner@pidgin.im>
parents:
7890
diff
changeset
|
166 | |
| 11523 | 167 | if (!listAccount) |
| 168 | accountReconnecting = g_slist_prepend(accountReconnecting, account); | |
| 169 | } else if (info != NULL) { | |
| 170 | g_hash_table_remove(hash, account); | |
| 7643 | 171 | |
| 11523 | 172 | if (listAccount) |
| 173 | accountReconnecting = g_slist_delete_link(accountReconnecting, listAccount); | |
| 7399 | 174 | } |
| 175 | } | |
| 176 | ||
| 5717 | 177 | static GaimConnectionUiOps conn_ui_ops = |
| 178 | { | |
| 179 | gaim_gtk_connection_connect_progress, | |
| 180 | gaim_gtk_connection_connected, | |
| 181 | gaim_gtk_connection_disconnected, | |
|
6460
fc288e7221ca
[gaim-migrate @ 6969]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
182 | gaim_gtk_connection_notice, |
| 11523 | 183 | gaim_gtk_connection_report_disconnect, |
| 5717 | 184 | }; |
| 185 | ||
|
7035
76bca80cd91d
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6460
diff
changeset
|
186 | GaimConnectionUiOps * |
|
76bca80cd91d
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6460
diff
changeset
|
187 | gaim_gtk_connections_get_ui_ops(void) |
| 5717 | 188 | { |
| 189 | return &conn_ui_ops; | |
| 190 | } |