Tue, 03 Jun 2003 19:55:47 +0000
[gaim-migrate @ 6138]
this almost kinda sorta works. It's the wonderful connecting dialog
that shows you how far along you are in connecting. This also gets rid of
the ever-present signon dialog.
Oh, and I ended up digging through header hell and changing a lot. Hopefully
I didn't break anything too badly.
| 5717 | 1 | /* |
| 2 | * gaim | |
| 3 | * | |
| 4 | * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net> | |
| 5 | * | |
| 6 | * This program is free software; you can redistribute it and/or modify | |
| 7 | * it under the terms of the GNU General Public License as published by | |
| 8 | * the Free Software Foundation; either version 2 of the License, or | |
| 9 | * (at your option) any later version. | |
| 10 | * | |
| 11 | * This program is distributed in the hope that it will be useful, | |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | * GNU General Public License for more details. | |
| 15 | * | |
| 16 | * You should have received a copy of the GNU General Public License | |
| 17 | * along with this program; if not, write to the Free Software | |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 19 | * | |
| 20 | */ | |
| 21 | ||
| 22 | #include <string.h> | |
| 23 | #include <gtk/gtk.h> | |
| 24 | ||
| 25 | #include "account.h" | |
| 26 | #include "gtkblist.h" | |
| 27 | #include "gaim.h" | |
| 28 | ||
| 29 | #ifdef _WIN32 | |
| 30 | #include "win32dep.h" | |
| 31 | #endif | |
| 32 | ||
| 33 | struct signon_meter { | |
| 34 | GaimAccount *account; | |
| 35 | GtkWidget *button; | |
| 36 | GtkWidget *progress; | |
| 37 | GtkWidget *status; | |
| 38 | }; | |
| 39 | ||
| 40 | struct meter_window { | |
| 41 | GtkWidget *window; | |
| 42 | GtkWidget *table; | |
| 43 | gint rows; | |
| 44 | gint active_count; | |
| 45 | GSList *meters; | |
| 46 | } *meter_win = NULL; | |
| 47 | ||
| 48 | static void cancel_signon(GtkWidget *button, struct signon_meter *meter) | |
| 49 | { | |
| 50 | meter->account->gc->wants_to_die = TRUE; | |
| 51 | gaim_connection_destroy(meter->account->gc); | |
| 52 | } | |
| 53 | ||
| 54 | static void cancel_all () { | |
| 55 | GSList *m = meter_win ? meter_win->meters : NULL; | |
| 56 | ||
| 57 | while (m) { | |
| 58 | cancel_signon(NULL, m->data); | |
| 59 | m = meter_win ? meter_win->meters : NULL; | |
| 60 | } | |
| 61 | } | |
| 62 | ||
| 63 | static gint meter_destroy(GtkWidget *window, GdkEvent *evt, struct signon_meter *meter) | |
| 64 | { | |
| 65 | return TRUE; | |
| 66 | } | |
| 67 | ||
| 68 | static struct signon_meter *find_signon_meter(GaimConnection *gc) | |
| 69 | { | |
| 70 | GSList *m = meter_win ? meter_win->meters : NULL; | |
| 71 | ||
| 72 | while (m) { | |
| 73 | if (((struct signon_meter *)m->data)->account == gc->account) | |
| 74 | return m->data; | |
| 75 | m = m->next; | |
| 76 | } | |
| 77 | ||
| 78 | return NULL; | |
| 79 | } | |
| 80 | ||
| 81 | static GtkWidget* create_meter_pixmap (GaimConnection *gc) | |
| 82 | { | |
| 83 | GdkPixbuf *pb = create_prpl_icon(gc->account); | |
| 84 | GdkPixbuf *scale = gdk_pixbuf_scale_simple(pb, 30,30,GDK_INTERP_BILINEAR); | |
| 85 | GtkWidget *image = | |
| 86 | gtk_image_new_from_pixbuf(scale); | |
| 87 | g_object_unref(G_OBJECT(pb)); | |
| 88 | g_object_unref(G_OBJECT(scale)); | |
| 89 | return image; | |
| 90 | } | |
| 91 | ||
| 92 | ||
| 93 | ||
| 94 | static struct signon_meter * | |
| 95 | new_meter(GaimConnection *gc, GtkWidget *widget, | |
| 96 | GtkWidget *table, gint *rows) | |
| 97 | { | |
| 98 | GtkWidget *graphic; | |
| 99 | GtkWidget *label; | |
| 100 | GtkWidget *nest_vbox; | |
| 101 | GString *name_to_print; | |
| 102 | struct signon_meter *meter; | |
| 103 | ||
| 104 | ||
| 105 | meter = g_new0(struct signon_meter, 1); | |
| 106 | ||
| 107 | meter->account = gaim_connection_get_account(gc); | |
| 108 | name_to_print = g_string_new(gaim_account_get_username(meter->account)); | |
| 109 | ||
| 110 | (*rows)++; | |
| 111 | gtk_table_resize (GTK_TABLE(table), *rows, 4); | |
| 112 | ||
| 113 | graphic = create_meter_pixmap(gc); | |
| 114 | ||
| 115 | nest_vbox = gtk_vbox_new (FALSE, 0); | |
| 116 | ||
| 117 | g_string_prepend(name_to_print, _("Signon: ")); | |
| 118 | label = gtk_label_new (name_to_print->str); | |
| 119 | g_string_free(name_to_print, TRUE); | |
| 120 | gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); | |
| 121 | ||
| 122 | meter->status = gtk_label_new(""); | |
| 123 | gtk_misc_set_alignment(GTK_MISC(meter->status), 0, 0.5); | |
| 124 | gtk_widget_set_size_request(meter->status, 250, -1); | |
| 125 | ||
| 126 | meter->progress = gtk_progress_bar_new (); | |
| 127 | ||
| 128 | meter->button = gaim_pixbuf_button_from_stock (_("Cancel"), GTK_STOCK_CANCEL, GAIM_BUTTON_HORIZONTAL); | |
| 129 | g_signal_connect(G_OBJECT (meter->button), "clicked", | |
| 130 | G_CALLBACK (cancel_signon), meter); | |
| 131 | ||
| 132 | gtk_table_attach (GTK_TABLE (table), graphic, 0, 1, *rows, *rows+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); | |
| 133 | gtk_table_attach (GTK_TABLE (table), nest_vbox, 1, 2, *rows, *rows+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); | |
| 134 | gtk_box_pack_start (GTK_BOX (nest_vbox), GTK_WIDGET (label), FALSE, FALSE, 0); | |
| 135 | gtk_box_pack_start (GTK_BOX (nest_vbox), GTK_WIDGET (meter->status), FALSE, FALSE, 0); | |
| 136 | gtk_table_attach (GTK_TABLE (table), meter->progress, 2, 3, *rows, *rows+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); | |
| 137 | gtk_table_attach (GTK_TABLE (table), meter->button, 3, 4, *rows, *rows+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); | |
| 138 | ||
| 139 | gtk_widget_show_all (GTK_WIDGET (meter_win->window)); | |
| 140 | ||
| 141 | meter_win->active_count++; | |
| 142 | ||
| 143 | return meter; | |
| 144 | } | |
| 145 | ||
| 146 | static void kill_meter(struct signon_meter *meter, const char *text) { | |
| 147 | gtk_widget_set_sensitive (meter->button, FALSE); | |
| 148 | gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(meter->progress), 1); | |
| 149 | gtk_label_set_text(GTK_LABEL(meter->status), text); | |
| 150 | meter_win->active_count--; | |
| 151 | if (meter_win->active_count == 0) { | |
| 152 | gtk_widget_destroy(meter_win->window); | |
| 153 | g_free (meter_win); | |
| 154 | meter_win = NULL; | |
| 155 | } | |
| 156 | } | |
| 157 | ||
| 158 | static void gaim_gtk_connection_connect_progress(GaimConnection *gc, | |
| 159 | const char *text, size_t step, size_t step_count) | |
| 160 | { | |
| 161 | struct signon_meter *meter; | |
| 162 | ||
| 163 | if(!meter_win) { | |
| 164 | GtkWidget *vbox; | |
| 165 | GtkWidget *cancel_button; | |
| 166 | ||
| 167 | if(mainwindow) | |
| 168 | gtk_widget_hide(mainwindow); | |
| 169 | ||
| 170 | meter_win = g_new0(struct meter_window, 1); | |
| 171 | meter_win->window = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
| 172 | gtk_window_set_resizable(GTK_WINDOW(meter_win->window), FALSE); | |
| 173 | gtk_window_set_role(GTK_WINDOW(meter_win->window), "signon"); | |
| 174 | gtk_container_set_border_width(GTK_CONTAINER(meter_win->window), 5); | |
| 175 | gtk_window_set_title(GTK_WINDOW(meter_win->window), _("Signon")); | |
| 176 | gtk_widget_realize(meter_win->window); | |
| 177 | ||
| 178 | vbox = gtk_vbox_new (FALSE, 0); | |
| 179 | gtk_container_add(GTK_CONTAINER(meter_win->window), vbox); | |
| 180 | ||
| 181 | meter_win->table = gtk_table_new(1, 4, FALSE); | |
| 182 | gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(meter_win->table), | |
| 183 | FALSE, FALSE, 0); | |
| 184 | gtk_container_set_border_width(GTK_CONTAINER(meter_win->table), 5); | |
| 185 | gtk_table_set_row_spacings(GTK_TABLE(meter_win->table), 5); | |
| 186 | gtk_table_set_col_spacings(GTK_TABLE(meter_win->table), 10); | |
| 187 | ||
| 188 | cancel_button = gaim_pixbuf_button_from_stock(_("Cancel All"), | |
| 189 | GTK_STOCK_QUIT, GAIM_BUTTON_HORIZONTAL); | |
| 190 | g_signal_connect_swapped(G_OBJECT(cancel_button), "clicked", | |
| 191 | G_CALLBACK(cancel_all), NULL); | |
| 192 | gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(cancel_button), | |
| 193 | FALSE, FALSE, 0); | |
| 194 | ||
| 195 | g_signal_connect(G_OBJECT(meter_win->window), "delete_event", | |
| 196 | G_CALLBACK(meter_destroy), NULL); | |
| 197 | } | |
| 198 | ||
| 199 | meter = find_signon_meter(gc); | |
| 200 | if(!meter) { | |
| 201 | meter = new_meter(gc, meter_win->window, meter_win->table, | |
| 202 | &meter_win->rows); | |
| 203 | ||
| 204 | meter_win->meters = g_slist_append(meter_win->meters, meter); | |
| 205 | } | |
| 206 | ||
| 207 | gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(meter->progress), | |
| 208 | (float)step / (float)step_count); | |
| 209 | gtk_label_set_text(GTK_LABEL(meter->status), text); | |
| 210 | } | |
| 211 | ||
| 212 | static void gaim_gtk_connection_connected(GaimConnection *gc) | |
| 213 | { | |
| 214 | struct signon_meter *meter = find_signon_meter(gc); | |
| 215 | ||
| 216 | if(meter) | |
| 217 | kill_meter(meter, _("Done.")); | |
| 218 | } | |
| 219 | ||
| 220 | static void gaim_gtk_connection_request_pass(GaimConnection *gc) | |
| 221 | { | |
| 222 | } | |
| 223 | ||
| 224 | static void gaim_gtk_connection_disconnected(GaimConnection *gc, | |
| 225 | const char *reason) | |
| 226 | { | |
| 227 | struct signon_meter *meter = find_signon_meter(gc); | |
| 228 | if(meter) | |
| 229 | kill_meter(meter, _("Done.")); | |
| 230 | } | |
| 231 | ||
| 232 | static void gaim_gtk_connection_notice(GaimConnection *gc, | |
| 233 | const char *text) | |
| 234 | { | |
| 235 | } | |
| 236 | ||
| 237 | static GaimConnectionUiOps conn_ui_ops = | |
| 238 | { | |
| 239 | gaim_gtk_connection_connect_progress, | |
| 240 | gaim_gtk_connection_connected, | |
| 241 | gaim_gtk_connection_request_pass, | |
| 242 | gaim_gtk_connection_disconnected, | |
| 243 | gaim_gtk_connection_notice | |
| 244 | }; | |
| 245 | ||
| 246 | GaimConnectionUiOps *gaim_get_gtk_connection_ui_ops(void) | |
| 247 | { | |
| 248 | return &conn_ui_ops; | |
| 249 | } | |
| 250 | ||
| 251 | ||
| 252 | static void away_on_login(char *mesg) | |
| 253 | { | |
| 254 | GSList *awy = away_messages; | |
| 255 | struct away_message *a, *message = NULL; | |
| 256 | struct gaim_gtk_buddy_list *gtkblist; | |
| 257 | ||
| 258 | gtkblist = GAIM_GTK_BLIST(gaim_get_blist()); | |
| 259 | ||
| 260 | if (!gtkblist->window) { | |
| 261 | return; | |
| 262 | } | |
| 263 | ||
| 264 | if (mesg == NULL) { | |
| 265 | /* Use default message */ | |
| 266 | do_away_message(NULL, default_away); | |
| 267 | } else { | |
| 268 | /* Use argument */ | |
| 269 | while (awy) { | |
| 270 | a = (struct away_message *)awy->data; | |
| 271 | if (strcmp(a->name, mesg) == 0) { | |
| 272 | message = a; | |
| 273 | break; | |
| 274 | } | |
| 275 | awy = awy->next; | |
| 276 | } | |
| 277 | if (message == NULL) | |
| 278 | message = default_away; | |
| 279 | do_away_message(NULL, message); | |
| 280 | } | |
| 281 | return; | |
| 282 | } | |
| 283 | ||
| 284 | ||
| 285 | struct kick_dlg { | |
| 286 | GaimAccount *account; | |
| 287 | GtkWidget *dlg; | |
| 288 | }; | |
| 289 | static GSList *kicks = NULL; | |
| 290 | ||
| 291 | static struct kick_dlg *find_kick_dlg(GaimAccount *account) | |
| 292 | { | |
| 293 | GSList *k = kicks; | |
| 294 | while (k) { | |
| 295 | struct kick_dlg *d = k->data; | |
| 296 | if (d->account == account) | |
| 297 | return d; | |
| 298 | k = k->next; | |
| 299 | } | |
| 300 | return NULL; | |
| 301 | } | |
| 302 | ||
| 303 | static void set_kick_null(struct kick_dlg *k) | |
| 304 | { | |
| 305 | kicks = g_slist_remove(kicks, k); | |
| 306 | g_free(k); | |
| 307 | } | |
| 308 | ||
| 309 | /* | |
| 310 | * Common code for hide_login_progress(), and hide_login_progress_info() | |
| 311 | */ | |
| 312 | static void hide_login_progress_common(GaimConnection *gc, | |
| 313 | char *details, | |
| 314 | char *title, | |
| 315 | char *prologue) | |
| 316 | { | |
| 317 | gchar *buf; | |
| 318 | struct kick_dlg *k = find_kick_dlg(gc->account); | |
| 319 | struct signon_meter *meter = find_signon_meter(gc); | |
| 320 | buf = g_strdup_printf(_("%s\n%s: %s"), full_date(), prologue, details); | |
| 321 | if (k) | |
| 322 | gtk_widget_destroy(k->dlg); | |
| 323 | k = g_new0(struct kick_dlg, 1); | |
| 324 | k->account = gc->account; | |
| 325 | k->dlg = gaim_notify_message(NULL, GAIM_NOTIFY_MSG_ERROR, NULL, | |
| 326 | title, buf, G_CALLBACK(set_kick_null), k); | |
| 327 | kicks = g_slist_append(kicks, k); | |
| 328 | if (meter) { | |
| 329 | kill_meter(meter, _("Done.")); | |
| 330 | meter_win->meters = g_slist_remove(meter_win->meters, meter); | |
| 331 | g_free(meter); | |
| 332 | } | |
| 333 | g_free(buf); | |
| 334 | } | |
| 335 | ||
| 336 | static void hide_login_progress(GaimConnection *gc, char *why) | |
| 337 | { | |
| 338 | GaimAccount *account = gaim_connection_get_account(gc); | |
| 339 | gchar *buf; | |
| 340 | ||
| 341 | gaim_event_broadcast(event_error, gc, why); | |
| 342 | buf = g_strdup_printf(_("%s was unable to sign on"), | |
| 343 | gaim_account_get_username(account)); | |
| 344 | hide_login_progress_common(gc, why, _("Signon Error"), buf); | |
| 345 | g_free(buf); | |
| 346 | } | |
| 347 | ||
| 348 | /* | |
| 349 | * Like hide_login_progress(), but for informational, not error/warning, | |
| 350 | * messages. | |
| 351 | * | |
| 352 | */ | |
| 353 | static void hide_login_progress_notice(GaimConnection *gc, char *why) | |
| 354 | { | |
| 355 | GaimAccount *account = gaim_connection_get_account(gc); | |
| 356 | ||
| 357 | hide_login_progress_common(gc, why, _("Notice"), | |
| 358 | (char *)gaim_account_get_username(account)); | |
| 359 | } | |
| 360 | ||
| 361 | /* | |
| 362 | * Like hide_login_progress(), but for non-signon error messages. | |
| 363 | * | |
| 364 | */ | |
| 365 | static void hide_login_progress_error(GaimConnection *gc, char *why) | |
| 366 | { | |
| 367 | char buf[2048]; | |
| 368 | GaimAccount *account = gaim_connection_get_account(gc); | |
| 369 | ||
| 370 | gaim_event_broadcast(event_error, gc, why); | |
| 371 | g_snprintf(buf, sizeof(buf), _("%s has been signed off"), | |
| 372 | gaim_account_get_username(account)); | |
| 373 | hide_login_progress_common(gc, why, _("Connection Error"), buf); | |
| 374 | } | |
| 375 |