comparison src/multi.c @ 3060:4f2f12bf4408

[gaim-migrate @ 3074] Code cleanups by Robert McQueen. Michael Golden replaced the multiple per-account signon windows with a single signon window showing the status of all your accounts committer: Tailor Script <tailor@pidgin.im>
author Sean Egan <seanegan@gmail.com>
date Sat, 16 Mar 2002 00:32:53 +0000
parents 626729653436
children 3b1dc99ef79e
comparison
equal deleted inserted replaced
3059:966c4e460ebb 3060:4f2f12bf4408
35 #include "pixmaps/cancel.xpm" 35 #include "pixmaps/cancel.xpm"
36 #include "pixmaps/ok.xpm" 36 #include "pixmaps/ok.xpm"
37 #include "pixmaps/tb_redo.xpm" 37 #include "pixmaps/tb_redo.xpm"
38 #include "pixmaps/tb_undo.xpm" 38 #include "pixmaps/tb_undo.xpm"
39 #include "pixmaps/tb_refresh.xpm" 39 #include "pixmaps/tb_refresh.xpm"
40 #include "pixmaps/no_icon.xpm"
40 41
41 #define LOGIN_STEPS 5 42 #define LOGIN_STEPS 5
42 43
43 GSList *connections; 44 GSList *connections;
44 45
86 user->gc = gc; 87 user->gc = gc;
87 gc->user = user; 88 gc->user = user;
88 89
89 return gc; 90 return gc;
90 } 91 }
92
93 struct meter_window {
94 GtkWidget *window;
95 GtkTable *table;
96 gint rows;
97 gint active_count;
98 } *meter_win = NULL;
91 99
92 void destroy_gaim_conn(struct gaim_connection *gc) 100 void destroy_gaim_conn(struct gaim_connection *gc)
93 { 101 {
94 GSList *g = gc->groups; 102 GSList *g = gc->groups;
95 GSList *h; 103 GSList *h;
1030 gtk_widget_show_all(acctedit); 1038 gtk_widget_show_all(acctedit);
1031 } 1039 }
1032 1040
1033 struct signon_meter { 1041 struct signon_meter {
1034 struct gaim_connection *gc; 1042 struct gaim_connection *gc;
1035 GtkWidget *window; 1043 GtkWidget *button;
1036 GtkWidget *progress; 1044 GtkWidget *progress;
1037 GtkWidget *status; 1045 GtkWidget *status;
1038 }; 1046 };
1039 static GSList *meters = NULL; 1047 static GSList *meters = NULL;
1048
1049 GtkWidget* create_meter_pixmap (GtkWidget *widget, struct gaim_connection *gc)
1050 {
1051 GdkColormap *colormap;
1052 GdkPixmap *gdkpixmap;
1053 GdkBitmap *mask;
1054 GtkWidget *pixmap;
1055 GtkStyle *style;
1056 char **xpm;
1057
1058 style = gtk_widget_get_style( widget );
1059
1060 if (gc->prpl->list_icon)
1061 if (gc->prpl->protocol == PROTO_OSCAR)
1062 /* This is such a bad hack to get the right icon
1063 * for OSCAR. But it's pretty */
1064 if (isdigit(*gc->username))
1065 xpm = gc->prpl->list_icon(0);
1066 else
1067 xpm = gc->prpl->list_icon(0x10);
1068 else
1069 xpm = gc->prpl->list_icon (0);
1070 if (xpm == NULL)
1071 xpm = (char **)no_icon_xpm;
1072
1073 gdkpixmap = gdk_pixmap_create_from_xpm_d(widget->window, &mask, &style->bg[GTK_STATE_NORMAL], xpm);
1074
1075 pixmap = gtk_pixmap_new (gdkpixmap, mask);
1076 gdk_pixmap_unref (gdkpixmap);
1077 gdk_bitmap_unref (mask);
1078 return pixmap;
1079 }
1040 1080
1041 static struct signon_meter *find_signon_meter(struct gaim_connection *gc) 1081 static struct signon_meter *find_signon_meter(struct gaim_connection *gc)
1042 { 1082 {
1043 GSList *m = meters; 1083 GSList *m = meters;
1044 while (m) { 1084 while (m) {
1047 m = m->next; 1087 m = m->next;
1048 } 1088 }
1049 return NULL; 1089 return NULL;
1050 } 1090 }
1051 1091
1092 void kill_meter(struct signon_meter *meter) {
1093 gtk_widget_set_sensitive (meter->button, FALSE);
1094 gtk_progress_bar_update(GTK_PROGRESS_BAR(meter->progress), 1);
1095 gtk_statusbar_pop(GTK_STATUSBAR(meter->status), 1);
1096 gtk_statusbar_push(GTK_STATUSBAR(meter->status), 1, "Done.");
1097 meter_win->active_count--;
1098 if (meter_win->active_count == 0) {
1099 gtk_widget_destroy(meter_win->window);
1100 g_free (meter_win);
1101 meter_win = NULL;
1102 }
1103 }
1104
1052 void account_online(struct gaim_connection *gc) 1105 void account_online(struct gaim_connection *gc)
1053 { 1106 {
1054 int i; 1107 int i;
1055 struct signon_meter *meter = find_signon_meter(gc); 1108 struct signon_meter *meter = find_signon_meter(gc);
1056 1109
1057 /* first we hide the login progress meter */ 1110 /* first we hide the login progress meter */
1058 if (meter) { 1111 if (meter) {
1059 gtk_widget_destroy(meter->window); 1112 kill_meter(meter);
1060 meters = g_slist_remove(meters, meter); 1113 meters = g_slist_remove(meters, meter);
1061 g_free(meter); 1114 g_free(meter);
1062 } 1115 }
1063 1116
1064 /* then we do the buddy list stuff */ 1117 /* then we do the buddy list stuff */
1120 void account_offline(struct gaim_connection *gc) 1173 void account_offline(struct gaim_connection *gc)
1121 { 1174 {
1122 int i; 1175 int i;
1123 struct signon_meter *meter = find_signon_meter(gc); 1176 struct signon_meter *meter = find_signon_meter(gc);
1124 if (meter) { 1177 if (meter) {
1125 gtk_widget_destroy(meter->window); 1178 kill_meter(meter);
1126 meters = g_slist_remove(meters, meter); 1179 meters = g_slist_remove(meters, meter);
1127 g_free(meter); 1180 g_free(meter);
1128 } 1181 }
1129 gc->user->gc = NULL; /* wasn't that awkward? */ 1182 gc->user->gc = NULL; /* wasn't that awkward? */
1130 if (!acctedit) 1183 if (!acctedit)
1159 static gint meter_destroy(GtkWidget *window, GdkEvent *evt, struct signon_meter *meter) 1212 static gint meter_destroy(GtkWidget *window, GdkEvent *evt, struct signon_meter *meter)
1160 { 1213 {
1161 return TRUE; 1214 return TRUE;
1162 } 1215 }
1163 1216
1217 static struct signon_meter *register_meter(struct gaim_connection *gc, GtkWidget *widget, GtkTable *table, gint *rows)
1218 {
1219 GtkWidget *graphic;
1220 GtkWidget *label;
1221 GtkWidget *nest_vbox;
1222 GString *name_to_print;
1223 struct signon_meter *meter;
1224
1225 name_to_print = g_string_new(gc->username);
1226
1227 meter = g_new0(struct signon_meter, 1);
1228
1229 (*rows)++;
1230 gtk_table_resize (table, *rows, 4);
1231
1232 graphic = create_meter_pixmap( widget , gc);
1233
1234 nest_vbox = gtk_vbox_new (FALSE, 0);
1235
1236 name_to_print = g_string_prepend(name_to_print, "Signon: ");
1237 label = gtk_label_new (name_to_print->str);
1238 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
1239
1240 meter->status = gtk_statusbar_new();
1241 gtk_widget_set_usize(meter->status, 250, 0);
1242
1243 meter->progress = gtk_progress_bar_new ();
1244
1245 meter->button = gtk_button_new_with_label ("Cancel");
1246 gtk_signal_connect (GTK_OBJECT (meter->button), "clicked", GTK_SIGNAL_FUNC (cancel_signon), meter);
1247
1248 gtk_table_attach (GTK_TABLE (table), graphic, 0, 1, *rows, *rows+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0);
1249 gtk_table_attach (GTK_TABLE (table), nest_vbox, 1, 2, *rows, *rows+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0);
1250 gtk_box_pack_start (GTK_BOX (nest_vbox), GTK_WIDGET (label), FALSE, FALSE, 0);
1251 gtk_box_pack_start (GTK_BOX (nest_vbox), GTK_WIDGET (meter->status), FALSE, FALSE, 0);
1252 gtk_table_attach (GTK_TABLE (table), meter->progress, 2, 3, *rows, *rows+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0);
1253 gtk_table_attach (GTK_TABLE (table), meter->button, 3, 4, *rows, *rows+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0);
1254
1255 gtk_widget_show_all (GTK_WIDGET (meter_win->window));
1256
1257 meter_win->active_count++;
1258
1259 return meter;
1260 }
1261
1262 static void loop_cancel () {
1263 GSList *m = meters;
1264 struct signon_meter *meter = NULL;
1265
1266 while (m) {
1267 meter = (struct signon_meter *) (m->data);
1268 meter->gc->wants_to_die = TRUE;
1269 signoff((struct gaim_connection *) meter->gc);
1270 m = meters;
1271 }
1272 }
1273
1164 void set_login_progress(struct gaim_connection *gc, float howfar, char *message) 1274 void set_login_progress(struct gaim_connection *gc, float howfar, char *message)
1165 { 1275 {
1166 struct signon_meter *meter = find_signon_meter(gc); 1276 struct signon_meter *meter = find_signon_meter(gc);
1167 1277
1168 if (mainwindow) 1278 if (mainwindow)
1169 gtk_widget_hide(mainwindow); 1279 gtk_widget_hide(mainwindow);
1170 1280
1281 if (!meter_win) {
1282 GtkWidget *cancel_button;
1283 GtkWidget *vbox;
1284 GString *name;
1285
1286 meter_win = g_new0(struct meter_window, 1);
1287 meter_win->rows=0;
1288
1289 meter_win->window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
1290 GAIM_DIALOG(meter_win->window);
1291 gtk_window_set_policy(GTK_WINDOW(meter_win->window), 0, 0, 1);
1292 gtk_window_set_wmclass(GTK_WINDOW(meter_win->window), "signon", "Gaim");
1293 gtk_container_set_border_width(GTK_CONTAINER(meter_win->window), 5);
1294 gtk_window_set_title (GTK_WINDOW (meter_win->window), "Gaim Account Signon");
1295 gtk_widget_realize(meter_win->window);
1296 aol_icon(meter_win->window->window);
1297
1298 vbox = gtk_vbox_new (FALSE, 0);
1299 gtk_container_add (GTK_CONTAINER (meter_win->window), GTK_WIDGET (vbox));
1300
1301 meter_win->table = (GtkTable *) gtk_table_new (1 , 4, FALSE);
1302 gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (meter_win->table), FALSE, FALSE, 0);
1303 gtk_container_set_border_width (GTK_CONTAINER (meter_win->table), 5);
1304 gtk_table_set_row_spacings (GTK_TABLE (meter_win->table), 5);
1305 gtk_table_set_col_spacings (GTK_TABLE (meter_win->table), 10);
1306
1307 cancel_button = gtk_button_new_with_label ("Cancel All");
1308 gtk_signal_connect_object (GTK_OBJECT (cancel_button), "clicked", GTK_SIGNAL_FUNC (loop_cancel), NULL);
1309 gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (cancel_button), FALSE, FALSE, 0);
1310
1311 gtk_signal_connect (GTK_OBJECT (meter_win->window), "delete_event", GTK_SIGNAL_FUNC (meter_destroy), NULL);
1312 }
1313
1171 if (!meter) { 1314 if (!meter) {
1172 GtkWidget *box, *label, *button;
1173 char buf[256]; 1315 char buf[256];
1174 1316
1175 meter = g_new0(struct signon_meter, 1); 1317 meter = register_meter(gc, GTK_WIDGET (meter_win->window), GTK_TABLE (meter_win->table), (gint *) &meter_win->rows);
1176 meter->gc = gc; 1318 meter->gc = gc;
1177 meters = g_slist_append(meters, meter); 1319 meters = g_slist_append(meters, meter);
1178 1320
1179 GAIM_DIALOG(meter->window);
1180 gtk_window_set_policy(GTK_WINDOW(meter->window), 0, 0, 1);
1181 gtk_window_set_wmclass(GTK_WINDOW(meter->window), "signon", "Gaim");
1182 gtk_container_set_border_width(GTK_CONTAINER(meter->window), 5);
1183 g_snprintf(buf, sizeof(buf), "%s Signing On (using %s)", gc->username, gc->prpl->name()); 1321 g_snprintf(buf, sizeof(buf), "%s Signing On (using %s)", gc->username, gc->prpl->name());
1184 gtk_window_set_title(GTK_WINDOW(meter->window), buf);
1185 gtk_signal_connect(GTK_OBJECT(meter->window), "delete_event",
1186 GTK_SIGNAL_FUNC(meter_destroy), meter);
1187 gtk_widget_realize(meter->window);
1188 aol_icon(meter->window->window);
1189
1190 box = gtk_vbox_new(FALSE, 5);
1191 gtk_container_add(GTK_CONTAINER(meter->window), box);
1192 gtk_widget_show(box);
1193
1194 label = gtk_label_new(buf);
1195 gtk_box_pack_start(GTK_BOX(box), label, FALSE, FALSE, 0);
1196 gtk_widget_show(label);
1197
1198 meter->progress = gtk_progress_bar_new();
1199 gtk_widget_set_usize(meter->progress, 150, 0);
1200 gtk_box_pack_start(GTK_BOX(box), meter->progress, FALSE, FALSE, 0);
1201 gtk_widget_show(meter->progress);
1202
1203 meter->status = gtk_statusbar_new();
1204 gtk_widget_set_usize(meter->status, 150, 0);
1205 gtk_box_pack_start(GTK_BOX(box), meter->status, FALSE, FALSE, 0);
1206 gtk_widget_show(meter->status);
1207
1208 button = gtk_button_new_with_label(_("Cancel"));
1209 gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 0);
1210 gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(cancel_signon), meter);
1211 gtk_widget_show(button);
1212
1213 gtk_widget_show(meter->window);
1214 } 1322 }
1215 1323
1216 gtk_progress_bar_update(GTK_PROGRESS_BAR(meter->progress), howfar / LOGIN_STEPS); 1324 gtk_progress_bar_update(GTK_PROGRESS_BAR(meter->progress), howfar / LOGIN_STEPS);
1217 gtk_statusbar_pop(GTK_STATUSBAR(meter->status), 1); 1325 gtk_statusbar_pop(GTK_STATUSBAR(meter->status), 1);
1218 gtk_statusbar_push(GTK_STATUSBAR(meter->status), 1, message); 1326 gtk_statusbar_push(GTK_STATUSBAR(meter->status), 1, message);
1260 k->user = gc->user; 1368 k->user = gc->user;
1261 k->dlg = do_error_dialog(buf, title); 1369 k->dlg = do_error_dialog(buf, title);
1262 kicks = g_slist_append(kicks, k); 1370 kicks = g_slist_append(kicks, k);
1263 gtk_signal_connect(GTK_OBJECT(k->dlg), "destroy", GTK_SIGNAL_FUNC(set_kick_null), k); 1371 gtk_signal_connect(GTK_OBJECT(k->dlg), "destroy", GTK_SIGNAL_FUNC(set_kick_null), k);
1264 if (meter) { 1372 if (meter) {
1265 gtk_widget_destroy(meter->window); 1373 kill_meter(meter);
1266 meters = g_slist_remove(meters, meter); 1374 meters = g_slist_remove(meters, meter);
1267 g_free(meter); 1375 g_free(meter);
1268 } 1376 }
1269 } 1377 }
1270 1378