comparison src/dialogs.c @ 5234:890b29f00b68

[gaim-migrate @ 5604] Chats in the buddy list! You can now put chat rooms in your buddy list, and double-click them to join them, instead of having to do all that typing. I'm eventually gonna add auto-join support, so that ugly hack involving pouncing can go away. Someone should make some new artwork so we don't have 2 + icons next to each other in the menus. This also has some fixes to let gaim compile again, after the renaming of the buddy list files. This also fixes the problem with offline buddies not showing up in the list sometimes for accounts that didn't log in at startup. This probably fixes other stuff, but I can't remember any of it off the top of my head. I'm going to stop typing and let people play with this now. committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Sat, 26 Apr 2003 20:30:43 +0000
parents 1a53330dfd34
children 0d4b8ca97c17
comparison
equal deleted inserted replaced
5233:202105dbed8f 5234:890b29f00b68
401 401
402 dialogwindows = g_list_prepend(dialogwindows, w->window); 402 dialogwindows = g_list_prepend(dialogwindows, w->window);
403 gtk_widget_show_all(w->window); 403 gtk_widget_show_all(w->window);
404 } 404 }
405 405
406 void do_remove_chat(struct chat *chat)
407 {
408 gaim_blist_remove_chat(chat);
409 gaim_blist_save();
410 }
411
406 void do_remove_buddy(struct buddy *b) 412 void do_remove_buddy(struct buddy *b)
407 { 413 {
408 struct group *g; 414 struct group *g;
409 struct gaim_conversation *c; 415 struct gaim_conversation *c;
410 gchar *name; 416 gchar *name;
431 437
432 void do_remove_group(struct group *g) 438 void do_remove_group(struct group *g)
433 { 439 {
434 GaimBlistNode *b = ((GaimBlistNode*)g)->child; 440 GaimBlistNode *b = ((GaimBlistNode*)g)->child;
435 while (b) { 441 while (b) {
436 struct buddy *bd = (struct buddy *)b; 442 if(GAIM_BLIST_NODE_IS_BUDDY(b)) {
437 struct gaim_conversation *c = gaim_find_conversation(bd->name); 443 struct buddy *bd = (struct buddy *)b;
438 if(bd->account->gc) { 444 struct gaim_conversation *c = gaim_find_conversation(bd->name);
439 serv_remove_buddy(bd->account->gc, bd->name, g->name); 445 if(bd->account->gc) {
440 gaim_blist_remove_buddy(bd); 446 serv_remove_buddy(bd->account->gc, bd->name, g->name);
441 447 gaim_blist_remove_buddy(bd);
442 if (c != NULL) 448
443 gaim_conversation_update(c, GAIM_CONV_UPDATE_REMOVE); 449 if (c != NULL)
450 gaim_conversation_update(c, GAIM_CONV_UPDATE_REMOVE);
451 }
444 } 452 }
445 b = b->next; 453 b = b->next;
446 } 454 }
447 gaim_blist_remove_group(g); 455 gaim_blist_remove_group(g);
448 gaim_blist_save(); 456 gaim_blist_save();
455 if (!bd) 463 if (!bd)
456 return; 464 return;
457 465
458 text = g_strdup_printf(_("You are about to remove %s from your buddy list. Do you want to continue?"), name); 466 text = g_strdup_printf(_("You are about to remove %s from your buddy list. Do you want to continue?"), name);
459 do_ask_dialog(_("Remove Buddy"), text, bd, _("Remove Buddy"), do_remove_buddy, _("Cancel"), NULL, NULL, FALSE); 467 do_ask_dialog(_("Remove Buddy"), text, bd, _("Remove Buddy"), do_remove_buddy, _("Cancel"), NULL, NULL, FALSE);
468 g_free(text);
469 }
470
471 void show_confirm_del_chat(struct chat *chat)
472 {
473 char *text = g_strdup_printf(_("You are about to remove the chat %s from your buddy list. Do you want to continue?"), chat->alias);
474 do_ask_dialog(_("Remove Chat"), text, chat, _("Remove Chat"), do_remove_chat, _("Cancel"), NULL, NULL, FALSE);
460 g_free(text); 475 g_free(text);
461 } 476 }
462 477
463 void show_confirm_del_group(struct group *g) 478 void show_confirm_del_group(struct group *g)
464 { 479 {
1160 1175
1161 a->account = gtk_option_menu_new(); 1176 a->account = gtk_option_menu_new();
1162 gtk_table_attach_defaults(GTK_TABLE(table), a->account, 1, 2, 3, 4); 1177 gtk_table_attach_defaults(GTK_TABLE(table), a->account, 1, 2, 3, 4);
1163 1178
1164 create_online_user_names(a); 1179 create_online_user_names(a);
1165 1180
1166 /* End of account box */ 1181 /* End of account box */
1167 1182
1168 g_signal_connect(G_OBJECT(a->window), "response", G_CALLBACK(do_add_buddy), a); 1183 g_signal_connect(G_OBJECT(a->window), "response", G_CALLBACK(do_add_buddy), a);
1169 1184
1170 gtk_widget_show_all(a->window); 1185 gtk_widget_show_all(a->window);
1171 1186
1172 if (group != NULL) 1187 if (group != NULL)
1173 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(a->combo)->entry), group); 1188 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(a->combo)->entry), group);
1174 } 1189 }
1190
1191 struct addchat {
1192 struct gaim_account *account;
1193 GtkWidget *window;
1194 GtkWidget *account_menu;
1195 GtkWidget *alias_entry;
1196 GtkWidget *group_combo;
1197 GtkWidget *entries_box;
1198 GtkSizeGroup *sg;
1199 GList *entries;
1200 };
1201
1202 static void do_add_chat(GtkWidget *w, struct addchat *ac) {
1203 GHashTable *components = g_hash_table_new_full(g_str_hash, g_str_equal,
1204 g_free, g_free);
1205 GList *tmp;
1206
1207 struct chat *chat;
1208 struct group *group;
1209 const char *group_name;
1210
1211 for(tmp = ac->entries; tmp; tmp = tmp->next) {
1212 if(g_object_get_data(tmp->data, "is_spin")) {
1213 g_hash_table_replace(components,
1214 g_strdup(g_object_get_data(tmp->data, "identifier")),
1215 g_strdup_printf("%d",
1216 gtk_spin_button_get_value_as_int(tmp->data)));
1217 } else {
1218 g_hash_table_replace(components,
1219 g_strdup(g_object_get_data(tmp->data, "identifier")),
1220 g_strdup(gtk_entry_get_text(tmp->data)));
1221 }
1222 }
1223
1224 chat = gaim_chat_new(ac->account, gtk_entry_get_text(GTK_ENTRY(ac->alias_entry)), components);
1225
1226 group_name = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(ac->group_combo)->entry));
1227 if (!(group = gaim_find_group(group_name))) {
1228 group = gaim_group_new(group_name);
1229 gaim_blist_add_group(group, NULL);
1230 }
1231
1232 gaim_blist_add_chat(chat, group, NULL);
1233 gaim_blist_save();
1234
1235 gtk_widget_destroy(ac->window);
1236 g_list_free(ac->entries);
1237
1238 g_free(ac);
1239 }
1240
1241 static void do_add_chat_resp(GtkWidget *w, int resp, struct addchat *ac) {
1242 if(resp == GTK_RESPONSE_OK) {
1243 do_add_chat(NULL, ac);
1244 } else {
1245 gtk_widget_destroy(ac->window);
1246 g_list_free(ac->entries);
1247 g_free(ac);
1248 }
1249 }
1250
1251
1252 static void rebuild_addchat_entries(struct addchat *ac) {
1253 GList *list, *tmp;
1254 struct proto_chat_entry *pce;
1255
1256 while(GTK_BOX(ac->entries_box)->children)
1257 gtk_container_remove(GTK_CONTAINER(ac->entries_box),
1258 ((GtkBoxChild *)GTK_BOX(ac->entries_box)->children->data)->widget);
1259
1260 if(ac->entries)
1261 g_list_free(ac->entries);
1262
1263 ac->entries = NULL;
1264
1265 list = GAIM_PLUGIN_PROTOCOL_INFO(ac->account->gc->prpl)->chat_info(ac->account->gc);
1266
1267 for(tmp = list; tmp; tmp = tmp->next) {
1268 GtkWidget *label;
1269 GtkWidget *rowbox;
1270 pce = tmp->data;
1271
1272 rowbox = gtk_hbox_new(FALSE, 5);
1273 gtk_box_pack_start(GTK_BOX(ac->entries_box), rowbox, FALSE, FALSE, 0);
1274
1275 label = gtk_label_new(pce->label);
1276 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
1277 gtk_size_group_add_widget(ac->sg, label);
1278 gtk_box_pack_start(GTK_BOX(rowbox), label, FALSE, FALSE, 0);
1279
1280 if(pce->is_int) {
1281 GtkObject *adjust;
1282 GtkWidget *spin;
1283 adjust = gtk_adjustment_new(pce->min, pce->min, pce->max,
1284 1, 10, 10);
1285 spin = gtk_spin_button_new(GTK_ADJUSTMENT(adjust), 1, 0);
1286 g_object_set_data(G_OBJECT(spin), "is_spin", GINT_TO_POINTER(TRUE));
1287 g_object_set_data(G_OBJECT(spin), "identifier", pce->identifier);
1288 ac->entries = g_list_append(ac->entries, spin);
1289 gtk_widget_set_size_request(spin, 50, -1);
1290 gtk_box_pack_end(GTK_BOX(rowbox), spin, FALSE, FALSE, 0);
1291 } else {
1292 GtkWidget *entry = gtk_entry_new();
1293 g_object_set_data(G_OBJECT(entry), "identifier", pce->identifier);
1294 ac->entries = g_list_append(ac->entries, entry);
1295
1296 if(pce->def)
1297 gtk_entry_set_text(GTK_ENTRY(entry), pce->def);
1298
1299 gtk_box_pack_end(GTK_BOX(rowbox), entry, TRUE, TRUE, 0);
1300
1301 g_signal_connect(G_OBJECT(entry), "activate",
1302 G_CALLBACK(do_add_chat), ac);
1303 }
1304 }
1305
1306 gtk_widget_show_all(ac->entries_box);
1307 }
1308
1309 static void addchat_select_account(GObject *w, struct gaim_connection *gc)
1310 {
1311 struct addchat *ac = g_object_get_data(w, "addchat");
1312
1313 if(ac->account->protocol == gc->account->protocol) {
1314 ac->account = gc->account;
1315 } else {
1316 ac->account = gc->account;
1317 rebuild_addchat_entries(ac);
1318 }
1319 }
1320
1321 static void create_online_account_menu_for_add_chat(struct addchat *ac)
1322 {
1323 char buf[2048]; /* Never hurts to be safe ;-) */
1324 GSList *g = connections;
1325 struct gaim_connection *c;
1326 GtkWidget *menu, *opt;
1327 int count = 0;
1328 int place = 0;
1329
1330 menu = gtk_menu_new();
1331
1332 while (g) {
1333 c = (struct gaim_connection *)g->data;
1334 g_snprintf(buf, sizeof(buf), "%s (%s)",
1335 c->username, c->prpl->info->name);
1336 opt = gtk_menu_item_new_with_label(buf);
1337 g_object_set_data(G_OBJECT(opt), "addchat", ac);
1338 g_signal_connect(GTK_OBJECT(opt), "activate",
1339 G_CALLBACK(addchat_select_account),
1340 c);
1341 gtk_widget_show(opt);
1342 gtk_menu_shell_append(GTK_MENU_SHELL(menu), opt);
1343
1344 /* Now check to see if it's our current menu */
1345 if (c->account == ac->account) {
1346 place = count;
1347 gtk_menu_item_activate(GTK_MENU_ITEM(opt));
1348 gtk_option_menu_set_history(GTK_OPTION_MENU(ac->account_menu), count);
1349
1350 /* Do the cha cha cha */
1351 }
1352
1353 count++;
1354
1355 g = g->next;
1356 }
1357
1358 gtk_option_menu_remove_menu(GTK_OPTION_MENU(ac->account_menu));
1359 gtk_option_menu_set_menu(GTK_OPTION_MENU(ac->account_menu), menu);
1360 gtk_option_menu_set_history(GTK_OPTION_MENU(ac->account_menu), place);
1361 }
1362
1363 void show_add_chat(struct gaim_account *account, struct group *group) {
1364 struct addchat *ac = g_new0(struct addchat, 1);
1365 struct gaim_gtk_buddy_list *gtkblist;
1366
1367 GtkWidget *label;
1368 GtkWidget *rowbox;
1369 GtkWidget *hbox;
1370 GtkWidget *vbox;
1371 GtkWidget *img = gtk_image_new_from_stock(GAIM_STOCK_DIALOG_QUESTION,
1372 GTK_ICON_SIZE_DIALOG);
1373
1374 gtkblist = GAIM_GTK_BLIST(gaim_get_blist());
1375
1376 ac->account = account ? account :
1377 ((struct gaim_connection *)connections->data)->account;
1378
1379 ac->sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
1380
1381 ac->window = gtk_dialog_new_with_buttons(_("Add Chat"),
1382 GTK_WINDOW(gtkblist->window), 0,
1383 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1384 GTK_STOCK_ADD, GTK_RESPONSE_OK,
1385 NULL);
1386
1387 gtk_dialog_set_default_response(GTK_DIALOG(ac->window), GTK_RESPONSE_OK);
1388 gtk_container_set_border_width(GTK_CONTAINER(ac->window), 6);
1389 gtk_window_set_resizable(GTK_WINDOW(ac->window), FALSE);
1390 gtk_dialog_set_has_separator(GTK_DIALOG(ac->window), FALSE);
1391 gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(ac->window)->vbox), 12);
1392 gtk_container_set_border_width(GTK_CONTAINER(GTK_DIALOG(ac->window)->vbox),
1393 6);
1394 gtk_window_set_role(GTK_WINDOW(ac->window), "add_chat");
1395
1396 hbox = gtk_hbox_new(FALSE, 12);
1397 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(ac->window)->vbox), hbox);
1398 gtk_box_pack_start(GTK_BOX(hbox), img, FALSE, FALSE, 0);
1399 gtk_misc_set_alignment(GTK_MISC(img), 0, 0);
1400
1401 vbox = gtk_vbox_new(FALSE, 5);
1402 gtk_container_add(GTK_CONTAINER(hbox), vbox);
1403
1404 label = gtk_label_new(_("Please enter an alias, and the appropriate information about the chat you would like to add to your buddy list.\n"));
1405 gtk_widget_set_size_request(label, 400, -1);
1406 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
1407 gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
1408 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
1409
1410 rowbox = gtk_hbox_new(FALSE, 5);
1411 gtk_box_pack_start(GTK_BOX(vbox), rowbox, FALSE, FALSE, 0);
1412
1413 label = gtk_label_new(_("Account:"));
1414 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
1415 gtk_size_group_add_widget(ac->sg, label);
1416 gtk_box_pack_start(GTK_BOX(rowbox), label, FALSE, FALSE, 0);
1417
1418 ac->account_menu = gtk_option_menu_new();
1419 gtk_box_pack_end(GTK_BOX(rowbox), ac->account_menu, TRUE, TRUE, 0);
1420
1421 create_online_account_menu_for_add_chat(ac);
1422
1423 rowbox = gtk_hbox_new(FALSE, 5);
1424 gtk_box_pack_start(GTK_BOX(vbox), rowbox, FALSE, FALSE, 0);
1425
1426 label = gtk_label_new(_("Alias:"));
1427 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
1428 gtk_size_group_add_widget(ac->sg, label);
1429 gtk_box_pack_start(GTK_BOX(rowbox), label, FALSE, FALSE, 0);
1430
1431 ac->alias_entry = gtk_entry_new();
1432 gtk_box_pack_end(GTK_BOX(rowbox), ac->alias_entry, TRUE, TRUE, 0);
1433
1434 ac->entries_box = gtk_vbox_new(FALSE, 5);
1435 gtk_container_set_border_width(GTK_CONTAINER(ac->entries_box), 0);
1436 gtk_box_pack_start(GTK_BOX(vbox), ac->entries_box, TRUE, TRUE, 0);
1437
1438 rebuild_addchat_entries(ac);
1439
1440 rowbox = gtk_hbox_new(FALSE, 5);
1441 gtk_box_pack_start(GTK_BOX(vbox), rowbox, FALSE, FALSE, 0);
1442
1443 label = gtk_label_new(_("Group:"));
1444 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
1445 gtk_size_group_add_widget(ac->sg, label);
1446 gtk_box_pack_start(GTK_BOX(rowbox), label, FALSE, FALSE, 0);
1447
1448 ac->group_combo = gtk_combo_new();
1449 gtk_combo_set_popdown_strings(GTK_COMBO(ac->group_combo), groups_tree());
1450 gtk_box_pack_end(GTK_BOX(rowbox), ac->group_combo, TRUE, TRUE, 0);
1451
1452 if (group)
1453 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(ac->group_combo)->entry), group->name);
1454
1455 g_signal_connect(G_OBJECT(ac->window), "response", G_CALLBACK(do_add_chat_resp), ac);
1456
1457 gtk_widget_grab_focus(ac->alias_entry);
1458
1459 gtk_widget_show_all(ac->window);
1460 }
1461
1175 1462
1176 1463
1177 /*------------------------------------------------------------------------* 1464 /*------------------------------------------------------------------------*
1178 * Privacy Settings * 1465 * Privacy Settings *
1179 *------------------------------------------------------------------------*/ 1466 *------------------------------------------------------------------------*/
3275 gtkconv->dialogs.smiley = dialog; 3562 gtkconv->dialogs.smiley = dialog;
3276 3563
3277 return; 3564 return;
3278 } 3565 }
3279 3566
3567 static void do_alias_chat(GtkWidget *w, int resp, struct chat *chat)
3568 {
3569 if(resp == GTK_RESPONSE_OK) {
3570 GtkWidget *entry = g_object_get_data(G_OBJECT(w), "alias_entry");
3571 const char *text = gtk_entry_get_text(GTK_ENTRY(entry));
3572 if(text && strlen(text)) {
3573 gaim_blist_alias_chat(chat, text);
3574 gaim_blist_save();
3575 }
3576 }
3577 gtk_widget_destroy(w);
3578 }
3579
3280 static void 3580 static void
3281 do_alias_buddy(GtkWidget *w, int resp, struct alias_dialog_info *info) 3581 do_alias_buddy(GtkWidget *w, int resp, struct alias_dialog_info *info)
3282 { 3582 {
3283 if (resp == GTK_RESPONSE_OK) { 3583 if (resp == GTK_RESPONSE_OK) {
3284 const char *alias; 3584 const char *alias;
3292 3592
3293 destroy_dialog(NULL, alias_dialog); 3593 destroy_dialog(NULL, alias_dialog);
3294 alias_dialog = NULL; 3594 alias_dialog = NULL;
3295 3595
3296 g_free(info); 3596 g_free(info);
3597 }
3598
3599 void alias_dialog_chat(struct chat *chat) {
3600 GtkWidget *dialog;
3601 GtkWidget *hbox;
3602 GtkWidget *img;
3603 GtkWidget *vbox;
3604 GtkWidget *label;
3605 GtkWidget *alias_entry;
3606
3607 dialog = gtk_dialog_new_with_buttons(_("Alias Buddy"), NULL,
3608 GTK_DIALOG_NO_SEPARATOR,
3609 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
3610 GTK_STOCK_OK, GTK_RESPONSE_OK,
3611 NULL);
3612 gtk_dialog_set_default_response(GTK_DIALOG(dialog),
3613 GTK_RESPONSE_OK);
3614
3615 gtk_container_set_border_width(GTK_CONTAINER(dialog), 6);
3616 gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE);
3617 gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(dialog)->vbox), 12);
3618 gtk_container_set_border_width(
3619 GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), 6);
3620
3621 /* The main hbox container. */
3622 hbox = gtk_hbox_new(FALSE, 12);
3623 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), hbox);
3624
3625 /* The dialog image. */
3626 img = gtk_image_new_from_stock(GAIM_STOCK_DIALOG_QUESTION,
3627 GTK_ICON_SIZE_DIALOG);
3628 gtk_box_pack_start(GTK_BOX(hbox), img, FALSE, FALSE, 0);
3629 gtk_misc_set_alignment(GTK_MISC(img), 0, 0);
3630
3631 /* The main vbox container. */
3632 vbox = gtk_vbox_new(FALSE, 0);
3633 gtk_container_add(GTK_CONTAINER(hbox), vbox);
3634
3635 /* Setup the label containing the description. */
3636 label = gtk_label_new(_("Please enter an aliased name for this chat.\n"));
3637 gtk_widget_set_size_request(GTK_WIDGET(label), 350, -1);
3638
3639 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
3640 gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
3641 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
3642
3643 hbox = gtk_hbox_new(FALSE, 6);
3644 gtk_container_add(GTK_CONTAINER(vbox), hbox);
3645
3646 /* The "Alias:" label. */
3647 label = gtk_label_new(NULL);
3648 gtk_label_set_markup_with_mnemonic(GTK_LABEL(label), _("_Alias:"));
3649 gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
3650 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
3651
3652 /* The alias entry field. */
3653 alias_entry = gtk_entry_new();
3654 gtk_box_pack_start(GTK_BOX(hbox), alias_entry, FALSE, FALSE, 0);
3655 gtk_entry_set_activates_default(GTK_ENTRY(alias_entry), TRUE);
3656 gtk_label_set_mnemonic_widget(GTK_LABEL(label), alias_entry);
3657
3658 gtk_entry_set_text(GTK_ENTRY(alias_entry), chat->alias);
3659
3660 g_object_set_data(G_OBJECT(dialog), "alias_entry", alias_entry);
3661
3662 g_signal_connect(G_OBJECT(dialog), "response",
3663 G_CALLBACK(do_alias_chat), chat);
3664
3665 gtk_widget_show_all(dialog);
3297 } 3666 }
3298 3667
3299 void 3668 void
3300 alias_dialog_bud(struct buddy *b) 3669 alias_dialog_bud(struct buddy *b)
3301 { 3670 {