Mercurial > pidgin
annotate src/gtkconn.c @ 6138:1894de5f7fbd
[gaim-migrate @ 6612]
make the docklet do the right thing when the accounts menu item is clicked
thanks chickenboycole
committer: Tailor Script <tailor@pidgin.im>
| author | Nathan Walp <nwalp@pidgin.im> |
|---|---|
| date | Tue, 15 Jul 2003 14:20:13 +0000 |
| parents | 3c70f8be8558 |
| children | dc42b27101c0 |
| rev | line source |
|---|---|
| 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
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5746
diff
changeset
|
21 #include "internal.h" |
| 5717 | 22 |
| 23 #include "account.h" | |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5746
diff
changeset
|
24 #include "debug.h" |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5746
diff
changeset
|
25 #include "util.h" |
| 5717 | 26 |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5746
diff
changeset
|
27 #include "gtkblist.h" |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5746
diff
changeset
|
28 #include "gtkutils.h" |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5746
diff
changeset
|
29 |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5746
diff
changeset
|
30 #include "ui.h" |
| 5717 | 31 |
| 32 struct signon_meter { | |
| 33 GaimAccount *account; | |
| 34 GtkWidget *button; | |
| 35 GtkWidget *progress; | |
| 36 GtkWidget *status; | |
| 37 }; | |
| 38 | |
| 39 struct meter_window { | |
| 40 GtkWidget *window; | |
| 41 GtkWidget *table; | |
| 42 gint rows; | |
| 43 gint active_count; | |
| 44 GSList *meters; | |
| 45 } *meter_win = NULL; | |
| 46 | |
|
5991
5d5bad909bc4
[gaim-migrate @ 6439]
Christian Hammond <chipx86@chipx86.com>
parents:
5989
diff
changeset
|
47 static void kill_meter(struct signon_meter *meter, const char *text); |
|
5d5bad909bc4
[gaim-migrate @ 6439]
Christian Hammond <chipx86@chipx86.com>
parents:
5989
diff
changeset
|
48 |
| 5717 | 49 static void cancel_signon(GtkWidget *button, struct signon_meter *meter) |
| 50 { | |
|
5991
5d5bad909bc4
[gaim-migrate @ 6439]
Christian Hammond <chipx86@chipx86.com>
parents:
5989
diff
changeset
|
51 if (meter->account->gc != NULL) { |
|
5d5bad909bc4
[gaim-migrate @ 6439]
Christian Hammond <chipx86@chipx86.com>
parents:
5989
diff
changeset
|
52 meter->account->gc->wants_to_die = TRUE; |
|
5d5bad909bc4
[gaim-migrate @ 6439]
Christian Hammond <chipx86@chipx86.com>
parents:
5989
diff
changeset
|
53 gaim_connection_destroy(meter->account->gc); |
|
5d5bad909bc4
[gaim-migrate @ 6439]
Christian Hammond <chipx86@chipx86.com>
parents:
5989
diff
changeset
|
54 } |
|
5d5bad909bc4
[gaim-migrate @ 6439]
Christian Hammond <chipx86@chipx86.com>
parents:
5989
diff
changeset
|
55 else { |
|
5d5bad909bc4
[gaim-migrate @ 6439]
Christian Hammond <chipx86@chipx86.com>
parents:
5989
diff
changeset
|
56 kill_meter(meter, _("Done.")); |
|
5987
6e19ad2ef712
[gaim-migrate @ 6435]
Christian Hammond <chipx86@chipx86.com>
parents:
5936
diff
changeset
|
57 |
|
5991
5d5bad909bc4
[gaim-migrate @ 6439]
Christian Hammond <chipx86@chipx86.com>
parents:
5989
diff
changeset
|
58 if (gaim_connections_get_all() == NULL) { |
|
5d5bad909bc4
[gaim-migrate @ 6439]
Christian Hammond <chipx86@chipx86.com>
parents:
5989
diff
changeset
|
59 destroy_all_dialogs(); |
|
5d5bad909bc4
[gaim-migrate @ 6439]
Christian Hammond <chipx86@chipx86.com>
parents:
5989
diff
changeset
|
60 |
|
5d5bad909bc4
[gaim-migrate @ 6439]
Christian Hammond <chipx86@chipx86.com>
parents:
5989
diff
changeset
|
61 gaim_blist_destroy(); |
|
5d5bad909bc4
[gaim-migrate @ 6439]
Christian Hammond <chipx86@chipx86.com>
parents:
5989
diff
changeset
|
62 |
|
5d5bad909bc4
[gaim-migrate @ 6439]
Christian Hammond <chipx86@chipx86.com>
parents:
5989
diff
changeset
|
63 show_login(); |
|
5d5bad909bc4
[gaim-migrate @ 6439]
Christian Hammond <chipx86@chipx86.com>
parents:
5989
diff
changeset
|
64 } |
|
5d5bad909bc4
[gaim-migrate @ 6439]
Christian Hammond <chipx86@chipx86.com>
parents:
5989
diff
changeset
|
65 } |
| 5717 | 66 } |
| 67 | |
| 68 static void cancel_all () { | |
| 69 GSList *m = meter_win ? meter_win->meters : NULL; | |
| 6114 | 70 struct signon_meter *meter; |
| 5717 | 71 |
| 72 while (m) { | |
| 6114 | 73 meter = m->data; |
| 74 cancel_signon(NULL, meter); | |
| 75 m = m->next; | |
| 5717 | 76 } |
| 77 } | |
| 78 | |
| 79 static gint meter_destroy(GtkWidget *window, GdkEvent *evt, struct signon_meter *meter) | |
| 80 { | |
| 81 return TRUE; | |
| 82 } | |
| 83 | |
| 84 static struct signon_meter *find_signon_meter(GaimConnection *gc) | |
| 85 { | |
| 86 GSList *m = meter_win ? meter_win->meters : NULL; | |
| 6114 | 87 struct signon_meter *meter; |
| 5717 | 88 |
| 89 while (m) { | |
| 6114 | 90 meter = m->data; |
| 91 if (meter->account == gaim_connection_get_account(gc)) | |
| 5717 | 92 return m->data; |
| 93 m = m->next; | |
| 94 } | |
| 95 | |
| 96 return NULL; | |
| 97 } | |
| 98 | |
| 99 static GtkWidget* create_meter_pixmap (GaimConnection *gc) | |
| 100 { | |
| 101 GdkPixbuf *pb = create_prpl_icon(gc->account); | |
| 102 GdkPixbuf *scale = gdk_pixbuf_scale_simple(pb, 30,30,GDK_INTERP_BILINEAR); | |
| 103 GtkWidget *image = | |
| 104 gtk_image_new_from_pixbuf(scale); | |
| 105 g_object_unref(G_OBJECT(pb)); | |
| 106 g_object_unref(G_OBJECT(scale)); | |
| 107 return image; | |
| 108 } | |
| 109 | |
| 110 | |
| 111 | |
| 112 static struct signon_meter * | |
| 113 new_meter(GaimConnection *gc, GtkWidget *widget, | |
| 114 GtkWidget *table, gint *rows) | |
| 115 { | |
| 116 GtkWidget *graphic; | |
| 117 GtkWidget *label; | |
| 118 GtkWidget *nest_vbox; | |
| 119 GString *name_to_print; | |
| 120 struct signon_meter *meter; | |
| 121 | |
| 122 | |
| 123 meter = g_new0(struct signon_meter, 1); | |
| 124 | |
| 125 meter->account = gaim_connection_get_account(gc); | |
| 126 name_to_print = g_string_new(gaim_account_get_username(meter->account)); | |
| 127 | |
| 128 (*rows)++; | |
| 129 gtk_table_resize (GTK_TABLE(table), *rows, 4); | |
| 130 | |
| 131 graphic = create_meter_pixmap(gc); | |
| 132 | |
| 133 nest_vbox = gtk_vbox_new (FALSE, 0); | |
| 134 | |
| 135 g_string_prepend(name_to_print, _("Signon: ")); | |
| 136 label = gtk_label_new (name_to_print->str); | |
| 137 g_string_free(name_to_print, TRUE); | |
| 138 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); | |
| 139 | |
| 140 meter->status = gtk_label_new(""); | |
| 141 gtk_misc_set_alignment(GTK_MISC(meter->status), 0, 0.5); | |
| 142 gtk_widget_set_size_request(meter->status, 250, -1); | |
| 143 | |
| 144 meter->progress = gtk_progress_bar_new (); | |
| 145 | |
| 146 meter->button = gaim_pixbuf_button_from_stock (_("Cancel"), GTK_STOCK_CANCEL, GAIM_BUTTON_HORIZONTAL); | |
| 147 g_signal_connect(G_OBJECT (meter->button), "clicked", | |
| 148 G_CALLBACK (cancel_signon), meter); | |
| 149 | |
| 150 gtk_table_attach (GTK_TABLE (table), graphic, 0, 1, *rows, *rows+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); | |
| 151 gtk_table_attach (GTK_TABLE (table), nest_vbox, 1, 2, *rows, *rows+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); | |
| 152 gtk_box_pack_start (GTK_BOX (nest_vbox), GTK_WIDGET (label), FALSE, FALSE, 0); | |
| 153 gtk_box_pack_start (GTK_BOX (nest_vbox), GTK_WIDGET (meter->status), FALSE, FALSE, 0); | |
| 154 gtk_table_attach (GTK_TABLE (table), meter->progress, 2, 3, *rows, *rows+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); | |
| 155 gtk_table_attach (GTK_TABLE (table), meter->button, 3, 4, *rows, *rows+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); | |
| 156 | |
| 157 gtk_widget_show_all (GTK_WIDGET (meter_win->window)); | |
| 158 | |
| 159 meter_win->active_count++; | |
| 160 | |
| 161 return meter; | |
| 162 } | |
| 163 | |
| 164 static void kill_meter(struct signon_meter *meter, const char *text) { | |
| 165 gtk_widget_set_sensitive (meter->button, FALSE); | |
| 166 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(meter->progress), 1); | |
| 167 gtk_label_set_text(GTK_LABEL(meter->status), text); | |
| 168 meter_win->active_count--; | |
| 169 if (meter_win->active_count == 0) { | |
| 170 gtk_widget_destroy(meter_win->window); | |
| 171 g_free (meter_win); | |
| 172 meter_win = NULL; | |
| 173 } | |
| 174 } | |
| 175 | |
| 176 static void gaim_gtk_connection_connect_progress(GaimConnection *gc, | |
| 177 const char *text, size_t step, size_t step_count) | |
| 178 { | |
| 179 struct signon_meter *meter; | |
| 180 | |
| 181 if(!meter_win) { | |
| 182 GtkWidget *vbox; | |
| 183 GtkWidget *cancel_button; | |
| 184 | |
| 185 if(mainwindow) | |
| 186 gtk_widget_hide(mainwindow); | |
| 187 | |
| 188 meter_win = g_new0(struct meter_window, 1); | |
| 189 meter_win->window = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
| 190 gtk_window_set_resizable(GTK_WINDOW(meter_win->window), FALSE); | |
| 191 gtk_window_set_role(GTK_WINDOW(meter_win->window), "signon"); | |
| 192 gtk_container_set_border_width(GTK_CONTAINER(meter_win->window), 5); | |
| 193 gtk_window_set_title(GTK_WINDOW(meter_win->window), _("Signon")); | |
| 194 gtk_widget_realize(meter_win->window); | |
| 195 | |
| 196 vbox = gtk_vbox_new (FALSE, 0); | |
| 197 gtk_container_add(GTK_CONTAINER(meter_win->window), vbox); | |
| 198 | |
| 199 meter_win->table = gtk_table_new(1, 4, FALSE); | |
| 200 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(meter_win->table), | |
| 201 FALSE, FALSE, 0); | |
| 202 gtk_container_set_border_width(GTK_CONTAINER(meter_win->table), 5); | |
| 203 gtk_table_set_row_spacings(GTK_TABLE(meter_win->table), 5); | |
| 204 gtk_table_set_col_spacings(GTK_TABLE(meter_win->table), 10); | |
| 205 | |
| 206 cancel_button = gaim_pixbuf_button_from_stock(_("Cancel All"), | |
| 207 GTK_STOCK_QUIT, GAIM_BUTTON_HORIZONTAL); | |
| 208 g_signal_connect_swapped(G_OBJECT(cancel_button), "clicked", | |
| 209 G_CALLBACK(cancel_all), NULL); | |
| 210 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(cancel_button), | |
| 211 FALSE, FALSE, 0); | |
| 212 | |
| 213 g_signal_connect(G_OBJECT(meter_win->window), "delete_event", | |
| 214 G_CALLBACK(meter_destroy), NULL); | |
| 215 } | |
| 216 | |
| 217 meter = find_signon_meter(gc); | |
| 218 if(!meter) { | |
| 219 meter = new_meter(gc, meter_win->window, meter_win->table, | |
| 220 &meter_win->rows); | |
| 221 | |
| 222 meter_win->meters = g_slist_append(meter_win->meters, meter); | |
| 223 } | |
| 224 | |
| 225 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(meter->progress), | |
| 226 (float)step / (float)step_count); | |
| 227 gtk_label_set_text(GTK_LABEL(meter->status), text); | |
| 228 } | |
| 229 | |
| 230 static void gaim_gtk_connection_connected(GaimConnection *gc) | |
| 231 { | |
| 232 struct signon_meter *meter = find_signon_meter(gc); | |
| 233 | |
|
5885
02569519d0cc
[gaim-migrate @ 6317]
Christian Hammond <chipx86@chipx86.com>
parents:
5883
diff
changeset
|
234 gaim_setup(gc); |
|
02569519d0cc
[gaim-migrate @ 6317]
Christian Hammond <chipx86@chipx86.com>
parents:
5883
diff
changeset
|
235 |
| 6021 | 236 update_privacy_connections(); |
|
5885
02569519d0cc
[gaim-migrate @ 6317]
Christian Hammond <chipx86@chipx86.com>
parents:
5883
diff
changeset
|
237 do_away_menu(); |
|
5936
1b56a833d665
[gaim-migrate @ 6376]
Christian Hammond <chipx86@chipx86.com>
parents:
5885
diff
changeset
|
238 gaim_gtk_blist_update_protocol_actions(); |
|
5885
02569519d0cc
[gaim-migrate @ 6317]
Christian Hammond <chipx86@chipx86.com>
parents:
5883
diff
changeset
|
239 |
| 5717 | 240 if(meter) |
| 241 kill_meter(meter, _("Done.")); | |
| 242 } | |
| 243 | |
| 244 static void gaim_gtk_connection_disconnected(GaimConnection *gc, | |
| 245 const char *reason) | |
| 246 { | |
| 247 struct signon_meter *meter = find_signon_meter(gc); | |
|
5883
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
248 |
|
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
249 update_privacy_connections(); |
|
5885
02569519d0cc
[gaim-migrate @ 6317]
Christian Hammond <chipx86@chipx86.com>
parents:
5883
diff
changeset
|
250 do_away_menu(); |
|
5936
1b56a833d665
[gaim-migrate @ 6376]
Christian Hammond <chipx86@chipx86.com>
parents:
5885
diff
changeset
|
251 gaim_gtk_blist_update_protocol_actions(); |
|
5883
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
252 |
| 5717 | 253 if(meter) |
| 254 kill_meter(meter, _("Done.")); | |
|
5883
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
255 |
|
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
256 if (gaim_connections_get_all() != NULL) |
|
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
257 return; |
|
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
258 |
|
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
259 destroy_all_dialogs(); |
|
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
260 |
|
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
261 gaim_blist_destroy(); |
|
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
262 |
|
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
263 show_login(); |
| 5717 | 264 } |
| 265 | |
| 266 static void gaim_gtk_connection_notice(GaimConnection *gc, | |
| 267 const char *text) | |
| 268 { | |
| 269 } | |
| 270 | |
| 271 static GaimConnectionUiOps conn_ui_ops = | |
| 272 { | |
| 273 gaim_gtk_connection_connect_progress, | |
| 274 gaim_gtk_connection_connected, | |
| 275 gaim_gtk_connection_disconnected, | |
| 276 gaim_gtk_connection_notice | |
| 277 }; | |
| 278 | |
| 279 GaimConnectionUiOps *gaim_get_gtk_connection_ui_ops(void) | |
| 280 { | |
| 281 return &conn_ui_ops; | |
| 282 } | |
| 283 | |
| 284 | |
|
5746
2c04c55222b7
[gaim-migrate @ 6171]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5717
diff
changeset
|
285 void away_on_login(char *mesg) |
| 5717 | 286 { |
| 287 GSList *awy = away_messages; | |
| 288 struct away_message *a, *message = NULL; | |
| 289 struct gaim_gtk_buddy_list *gtkblist; | |
| 290 | |
| 291 gtkblist = GAIM_GTK_BLIST(gaim_get_blist()); | |
| 292 | |
| 293 if (!gtkblist->window) { | |
| 294 return; | |
| 295 } | |
| 296 | |
| 297 if (mesg == NULL) { | |
| 298 /* Use default message */ | |
| 299 do_away_message(NULL, default_away); | |
| 300 } else { | |
| 301 /* Use argument */ | |
| 302 while (awy) { | |
| 303 a = (struct away_message *)awy->data; | |
| 304 if (strcmp(a->name, mesg) == 0) { | |
| 305 message = a; | |
| 306 break; | |
| 307 } | |
| 308 awy = awy->next; | |
| 309 } | |
| 310 if (message == NULL) | |
| 311 message = default_away; | |
| 312 do_away_message(NULL, message); | |
| 313 } | |
| 314 return; | |
| 315 } |
