Wed, 02 Jul 2003 09:23:14 +0000
[gaim-migrate @ 6437]
Next time, I'll try compiling first.
| 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 | */ | |
|
5872
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5746
diff
changeset
|
21 | #include "internal.h" |
| 5717 | 22 | |
| 23 | #include "account.h" | |
|
5872
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5746
diff
changeset
|
24 | #include "debug.h" |
|
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5746
diff
changeset
|
25 | #include "notify.h" |
|
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5746
diff
changeset
|
26 | #include "util.h" |
| 5717 | 27 | |
|
5872
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5746
diff
changeset
|
28 | #include "gtkblist.h" |
|
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5746
diff
changeset
|
29 | #include "gtkutils.h" |
|
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5746
diff
changeset
|
30 | |
|
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5746
diff
changeset
|
31 | #include "ui.h" |
| 5717 | 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 | { | |
|
5989
e5fc43035608
[gaim-migrate @ 6437]
Christian Hammond <chipx86@chipx86.com>
parents:
5987
diff
changeset
|
50 | if (meter->account->gc == NULL) |
|
5987
1c35193f8dcb
[gaim-migrate @ 6435]
Christian Hammond <chipx86@chipx86.com>
parents:
5936
diff
changeset
|
51 | return; |
|
1c35193f8dcb
[gaim-migrate @ 6435]
Christian Hammond <chipx86@chipx86.com>
parents:
5936
diff
changeset
|
52 | |
| 5717 | 53 | meter->account->gc->wants_to_die = TRUE; |
| 54 | gaim_connection_destroy(meter->account->gc); | |
| 55 | } | |
| 56 | ||
| 57 | static void cancel_all () { | |
| 58 | GSList *m = meter_win ? meter_win->meters : NULL; | |
| 59 | ||
| 60 | while (m) { | |
| 61 | cancel_signon(NULL, m->data); | |
| 62 | m = meter_win ? meter_win->meters : NULL; | |
| 63 | } | |
| 64 | } | |
| 65 | ||
| 66 | static gint meter_destroy(GtkWidget *window, GdkEvent *evt, struct signon_meter *meter) | |
| 67 | { | |
| 68 | return TRUE; | |
| 69 | } | |
| 70 | ||
| 71 | static struct signon_meter *find_signon_meter(GaimConnection *gc) | |
| 72 | { | |
| 73 | GSList *m = meter_win ? meter_win->meters : NULL; | |
| 74 | ||
| 75 | while (m) { | |
| 76 | if (((struct signon_meter *)m->data)->account == gc->account) | |
| 77 | return m->data; | |
| 78 | m = m->next; | |
| 79 | } | |
| 80 | ||
| 81 | return NULL; | |
| 82 | } | |
| 83 | ||
| 84 | static GtkWidget* create_meter_pixmap (GaimConnection *gc) | |
| 85 | { | |
| 86 | GdkPixbuf *pb = create_prpl_icon(gc->account); | |
| 87 | GdkPixbuf *scale = gdk_pixbuf_scale_simple(pb, 30,30,GDK_INTERP_BILINEAR); | |
| 88 | GtkWidget *image = | |
| 89 | gtk_image_new_from_pixbuf(scale); | |
| 90 | g_object_unref(G_OBJECT(pb)); | |
| 91 | g_object_unref(G_OBJECT(scale)); | |
| 92 | return image; | |
| 93 | } | |
| 94 | ||
| 95 | ||
| 96 | ||
| 97 | static struct signon_meter * | |
| 98 | new_meter(GaimConnection *gc, GtkWidget *widget, | |
| 99 | GtkWidget *table, gint *rows) | |
| 100 | { | |
| 101 | GtkWidget *graphic; | |
| 102 | GtkWidget *label; | |
| 103 | GtkWidget *nest_vbox; | |
| 104 | GString *name_to_print; | |
| 105 | struct signon_meter *meter; | |
| 106 | ||
| 107 | ||
| 108 | meter = g_new0(struct signon_meter, 1); | |
| 109 | ||
| 110 | meter->account = gaim_connection_get_account(gc); | |
| 111 | name_to_print = g_string_new(gaim_account_get_username(meter->account)); | |
| 112 | ||
| 113 | (*rows)++; | |
| 114 | gtk_table_resize (GTK_TABLE(table), *rows, 4); | |
| 115 | ||
| 116 | graphic = create_meter_pixmap(gc); | |
| 117 | ||
| 118 | nest_vbox = gtk_vbox_new (FALSE, 0); | |
| 119 | ||
| 120 | g_string_prepend(name_to_print, _("Signon: ")); | |
| 121 | label = gtk_label_new (name_to_print->str); | |
| 122 | g_string_free(name_to_print, TRUE); | |
| 123 | gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); | |
| 124 | ||
| 125 | meter->status = gtk_label_new(""); | |
| 126 | gtk_misc_set_alignment(GTK_MISC(meter->status), 0, 0.5); | |
| 127 | gtk_widget_set_size_request(meter->status, 250, -1); | |
| 128 | ||
| 129 | meter->progress = gtk_progress_bar_new (); | |
| 130 | ||
| 131 | meter->button = gaim_pixbuf_button_from_stock (_("Cancel"), GTK_STOCK_CANCEL, GAIM_BUTTON_HORIZONTAL); | |
| 132 | g_signal_connect(G_OBJECT (meter->button), "clicked", | |
| 133 | G_CALLBACK (cancel_signon), meter); | |
| 134 | ||
| 135 | gtk_table_attach (GTK_TABLE (table), graphic, 0, 1, *rows, *rows+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); | |
| 136 | gtk_table_attach (GTK_TABLE (table), nest_vbox, 1, 2, *rows, *rows+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); | |
| 137 | gtk_box_pack_start (GTK_BOX (nest_vbox), GTK_WIDGET (label), FALSE, FALSE, 0); | |
| 138 | gtk_box_pack_start (GTK_BOX (nest_vbox), GTK_WIDGET (meter->status), FALSE, FALSE, 0); | |
| 139 | gtk_table_attach (GTK_TABLE (table), meter->progress, 2, 3, *rows, *rows+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); | |
| 140 | gtk_table_attach (GTK_TABLE (table), meter->button, 3, 4, *rows, *rows+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); | |
| 141 | ||
| 142 | gtk_widget_show_all (GTK_WIDGET (meter_win->window)); | |
| 143 | ||
| 144 | meter_win->active_count++; | |
| 145 | ||
| 146 | return meter; | |
| 147 | } | |
| 148 | ||
| 149 | static void kill_meter(struct signon_meter *meter, const char *text) { | |
| 150 | gtk_widget_set_sensitive (meter->button, FALSE); | |
| 151 | gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(meter->progress), 1); | |
| 152 | gtk_label_set_text(GTK_LABEL(meter->status), text); | |
| 153 | meter_win->active_count--; | |
| 154 | if (meter_win->active_count == 0) { | |
| 155 | gtk_widget_destroy(meter_win->window); | |
| 156 | g_free (meter_win); | |
| 157 | meter_win = NULL; | |
| 158 | } | |
| 159 | } | |
| 160 | ||
| 161 | static void gaim_gtk_connection_connect_progress(GaimConnection *gc, | |
| 162 | const char *text, size_t step, size_t step_count) | |
| 163 | { | |
| 164 | struct signon_meter *meter; | |
| 165 | ||
| 166 | if(!meter_win) { | |
| 167 | GtkWidget *vbox; | |
| 168 | GtkWidget *cancel_button; | |
| 169 | ||
| 170 | if(mainwindow) | |
| 171 | gtk_widget_hide(mainwindow); | |
| 172 | ||
| 173 | meter_win = g_new0(struct meter_window, 1); | |
| 174 | meter_win->window = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
| 175 | gtk_window_set_resizable(GTK_WINDOW(meter_win->window), FALSE); | |
| 176 | gtk_window_set_role(GTK_WINDOW(meter_win->window), "signon"); | |
| 177 | gtk_container_set_border_width(GTK_CONTAINER(meter_win->window), 5); | |
| 178 | gtk_window_set_title(GTK_WINDOW(meter_win->window), _("Signon")); | |
| 179 | gtk_widget_realize(meter_win->window); | |
| 180 | ||
| 181 | vbox = gtk_vbox_new (FALSE, 0); | |
| 182 | gtk_container_add(GTK_CONTAINER(meter_win->window), vbox); | |
| 183 | ||
| 184 | meter_win->table = gtk_table_new(1, 4, FALSE); | |
| 185 | gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(meter_win->table), | |
| 186 | FALSE, FALSE, 0); | |
| 187 | gtk_container_set_border_width(GTK_CONTAINER(meter_win->table), 5); | |
| 188 | gtk_table_set_row_spacings(GTK_TABLE(meter_win->table), 5); | |
| 189 | gtk_table_set_col_spacings(GTK_TABLE(meter_win->table), 10); | |
| 190 | ||
| 191 | cancel_button = gaim_pixbuf_button_from_stock(_("Cancel All"), | |
| 192 | GTK_STOCK_QUIT, GAIM_BUTTON_HORIZONTAL); | |
| 193 | g_signal_connect_swapped(G_OBJECT(cancel_button), "clicked", | |
| 194 | G_CALLBACK(cancel_all), NULL); | |
| 195 | gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(cancel_button), | |
| 196 | FALSE, FALSE, 0); | |
| 197 | ||
| 198 | g_signal_connect(G_OBJECT(meter_win->window), "delete_event", | |
| 199 | G_CALLBACK(meter_destroy), NULL); | |
| 200 | } | |
| 201 | ||
| 202 | meter = find_signon_meter(gc); | |
| 203 | if(!meter) { | |
| 204 | meter = new_meter(gc, meter_win->window, meter_win->table, | |
| 205 | &meter_win->rows); | |
| 206 | ||
| 207 | meter_win->meters = g_slist_append(meter_win->meters, meter); | |
| 208 | } | |
| 209 | ||
| 210 | gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(meter->progress), | |
| 211 | (float)step / (float)step_count); | |
| 212 | gtk_label_set_text(GTK_LABEL(meter->status), text); | |
| 213 | } | |
| 214 | ||
| 215 | static void gaim_gtk_connection_connected(GaimConnection *gc) | |
| 216 | { | |
| 217 | struct signon_meter *meter = find_signon_meter(gc); | |
| 218 | ||
|
5885
223ac977eed2
[gaim-migrate @ 6317]
Christian Hammond <chipx86@chipx86.com>
parents:
5883
diff
changeset
|
219 | gaim_setup(gc); |
|
223ac977eed2
[gaim-migrate @ 6317]
Christian Hammond <chipx86@chipx86.com>
parents:
5883
diff
changeset
|
220 | |
|
223ac977eed2
[gaim-migrate @ 6317]
Christian Hammond <chipx86@chipx86.com>
parents:
5883
diff
changeset
|
221 | do_away_menu(); |
|
5936
4bac764cc792
[gaim-migrate @ 6376]
Christian Hammond <chipx86@chipx86.com>
parents:
5885
diff
changeset
|
222 | gaim_gtk_blist_update_protocol_actions(); |
|
5885
223ac977eed2
[gaim-migrate @ 6317]
Christian Hammond <chipx86@chipx86.com>
parents:
5883
diff
changeset
|
223 | |
| 5717 | 224 | if(meter) |
| 225 | kill_meter(meter, _("Done.")); | |
| 226 | } | |
| 227 | ||
| 228 | static void gaim_gtk_connection_request_pass(GaimConnection *gc) | |
| 229 | { | |
| 230 | } | |
| 231 | ||
| 232 | static void gaim_gtk_connection_disconnected(GaimConnection *gc, | |
| 233 | const char *reason) | |
| 234 | { | |
| 235 | struct signon_meter *meter = find_signon_meter(gc); | |
|
5883
290fe1d16e60
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
236 | |
|
290fe1d16e60
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
237 | update_privacy_connections(); |
|
5885
223ac977eed2
[gaim-migrate @ 6317]
Christian Hammond <chipx86@chipx86.com>
parents:
5883
diff
changeset
|
238 | do_away_menu(); |
|
5936
4bac764cc792
[gaim-migrate @ 6376]
Christian Hammond <chipx86@chipx86.com>
parents:
5885
diff
changeset
|
239 | gaim_gtk_blist_update_protocol_actions(); |
|
5883
290fe1d16e60
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
240 | |
| 5717 | 241 | if(meter) |
| 242 | kill_meter(meter, _("Done.")); | |
|
5883
290fe1d16e60
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
243 | |
|
290fe1d16e60
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
244 | if (gaim_connections_get_all() != NULL) |
|
290fe1d16e60
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
245 | return; |
|
290fe1d16e60
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
246 | |
|
290fe1d16e60
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
247 | destroy_all_dialogs(); |
|
290fe1d16e60
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
248 | |
|
290fe1d16e60
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
249 | gaim_blist_destroy(); |
|
290fe1d16e60
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
250 | |
|
290fe1d16e60
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
251 | show_login(); |
| 5717 | 252 | } |
| 253 | ||
| 254 | static void gaim_gtk_connection_notice(GaimConnection *gc, | |
| 255 | const char *text) | |
| 256 | { | |
| 257 | } | |
| 258 | ||
| 259 | static GaimConnectionUiOps conn_ui_ops = | |
| 260 | { | |
| 261 | gaim_gtk_connection_connect_progress, | |
| 262 | gaim_gtk_connection_connected, | |
| 263 | gaim_gtk_connection_request_pass, | |
| 264 | gaim_gtk_connection_disconnected, | |
| 265 | gaim_gtk_connection_notice | |
| 266 | }; | |
| 267 | ||
| 268 | GaimConnectionUiOps *gaim_get_gtk_connection_ui_ops(void) | |
| 269 | { | |
| 270 | return &conn_ui_ops; | |
| 271 | } | |
| 272 | ||
| 273 | ||
|
5746
3603ba25c56d
[gaim-migrate @ 6171]
Herman Bloggs <herman@bluedigits.com>
parents:
5717
diff
changeset
|
274 | void away_on_login(char *mesg) |
| 5717 | 275 | { |
| 276 | GSList *awy = away_messages; | |
| 277 | struct away_message *a, *message = NULL; | |
| 278 | struct gaim_gtk_buddy_list *gtkblist; | |
| 279 | ||
| 280 | gtkblist = GAIM_GTK_BLIST(gaim_get_blist()); | |
| 281 | ||
| 282 | if (!gtkblist->window) { | |
| 283 | return; | |
| 284 | } | |
| 285 | ||
| 286 | if (mesg == NULL) { | |
| 287 | /* Use default message */ | |
| 288 | do_away_message(NULL, default_away); | |
| 289 | } else { | |
| 290 | /* Use argument */ | |
| 291 | while (awy) { | |
| 292 | a = (struct away_message *)awy->data; | |
| 293 | if (strcmp(a->name, mesg) == 0) { | |
| 294 | message = a; | |
| 295 | break; | |
| 296 | } | |
| 297 | awy = awy->next; | |
| 298 | } | |
| 299 | if (message == NULL) | |
| 300 | message = default_away; | |
| 301 | do_away_message(NULL, message); | |
| 302 | } | |
| 303 | return; | |
| 304 | } | |
| 305 | ||
|
5872
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5746
diff
changeset
|
306 | #if 0 |
| 5717 | 307 | struct kick_dlg { |
| 308 | GaimAccount *account; | |
| 309 | GtkWidget *dlg; | |
| 310 | }; | |
| 311 | static GSList *kicks = NULL; | |
| 312 | ||
| 313 | static struct kick_dlg *find_kick_dlg(GaimAccount *account) | |
| 314 | { | |
| 315 | GSList *k = kicks; | |
| 316 | while (k) { | |
| 317 | struct kick_dlg *d = k->data; | |
| 318 | if (d->account == account) | |
| 319 | return d; | |
| 320 | k = k->next; | |
| 321 | } | |
| 322 | return NULL; | |
| 323 | } | |
| 324 | ||
| 325 | static void set_kick_null(struct kick_dlg *k) | |
| 326 | { | |
| 327 | kicks = g_slist_remove(kicks, k); | |
| 328 | g_free(k); | |
| 329 | } | |
| 330 | ||
| 331 | /* | |
| 332 | * Common code for hide_login_progress(), and hide_login_progress_info() | |
| 333 | */ | |
| 334 | static void hide_login_progress_common(GaimConnection *gc, | |
| 335 | char *details, | |
| 336 | char *title, | |
| 337 | char *prologue) | |
| 338 | { | |
| 339 | gchar *buf; | |
| 340 | struct kick_dlg *k = find_kick_dlg(gc->account); | |
| 341 | struct signon_meter *meter = find_signon_meter(gc); | |
| 342 | buf = g_strdup_printf(_("%s\n%s: %s"), full_date(), prologue, details); | |
| 343 | if (k) | |
| 344 | gtk_widget_destroy(k->dlg); | |
| 345 | k = g_new0(struct kick_dlg, 1); | |
| 346 | k->account = gc->account; | |
| 347 | k->dlg = gaim_notify_message(NULL, GAIM_NOTIFY_MSG_ERROR, NULL, | |
| 348 | title, buf, G_CALLBACK(set_kick_null), k); | |
| 349 | kicks = g_slist_append(kicks, k); | |
| 350 | if (meter) { | |
| 351 | kill_meter(meter, _("Done.")); | |
| 352 | meter_win->meters = g_slist_remove(meter_win->meters, meter); | |
| 353 | g_free(meter); | |
| 354 | } | |
| 355 | g_free(buf); | |
| 356 | } | |
| 357 | ||
| 358 | static void hide_login_progress(GaimConnection *gc, char *why) | |
| 359 | { | |
| 360 | GaimAccount *account = gaim_connection_get_account(gc); | |
| 361 | gchar *buf; | |
| 362 | ||
| 363 | gaim_event_broadcast(event_error, gc, why); | |
| 364 | buf = g_strdup_printf(_("%s was unable to sign on"), | |
| 365 | gaim_account_get_username(account)); | |
| 366 | hide_login_progress_common(gc, why, _("Signon Error"), buf); | |
| 367 | g_free(buf); | |
| 368 | } | |
| 369 | ||
| 370 | /* | |
| 371 | * Like hide_login_progress(), but for informational, not error/warning, | |
| 372 | * messages. | |
| 373 | * | |
| 374 | */ | |
| 375 | static void hide_login_progress_notice(GaimConnection *gc, char *why) | |
| 376 | { | |
| 377 | GaimAccount *account = gaim_connection_get_account(gc); | |
| 378 | ||
| 379 | hide_login_progress_common(gc, why, _("Notice"), | |
| 380 | (char *)gaim_account_get_username(account)); | |
| 381 | } | |
| 382 | ||
| 383 | /* | |
| 384 | * Like hide_login_progress(), but for non-signon error messages. | |
| 385 | * | |
| 386 | */ | |
| 387 | static void hide_login_progress_error(GaimConnection *gc, char *why) | |
| 388 | { | |
| 389 | char buf[2048]; | |
| 390 | GaimAccount *account = gaim_connection_get_account(gc); | |
| 391 | ||
| 392 | gaim_event_broadcast(event_error, gc, why); | |
| 393 | g_snprintf(buf, sizeof(buf), _("%s has been signed off"), | |
| 394 | gaim_account_get_username(account)); | |
| 395 | hide_login_progress_common(gc, why, _("Connection Error"), buf); | |
| 396 | } | |
|
5872
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5746
diff
changeset
|
397 | #endif |