comparison src/dialogs.c @ 1729:251c19bf5763

[gaim-migrate @ 1739] nsanch's rename patch. slightly modified. committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Fri, 20 Apr 2001 07:39:09 +0000
parents 1edc8b545d6f
children e5ba877f51f2
comparison
equal deleted inserted replaced
1728:467a3b36623a 1729:251c19bf5763
88 static GList *dialogwindows = NULL; 88 static GList *dialogwindows = NULL;
89 static GtkWidget *exportdialog, *importdialog; 89 static GtkWidget *exportdialog, *importdialog;
90 static GtkWidget *aliasdlg = NULL; 90 static GtkWidget *aliasdlg = NULL;
91 static GtkWidget *aliasentry = NULL; 91 static GtkWidget *aliasentry = NULL;
92 static GtkWidget *aliasname = NULL; 92 static GtkWidget *aliasname = NULL;
93 static GtkWidget *rename_dialog = NULL;
94 static GtkWidget *rename_bud_dialog = NULL;
93 95
94 struct create_away { 96 struct create_away {
95 GtkWidget *window; 97 GtkWidget *window;
96 GtkWidget *entry; 98 GtkWidget *entry;
97 GtkWidget *text; 99 GtkWidget *text;
281 if (dest == aliasdlg) { 283 if (dest == aliasdlg) {
282 aliasdlg = NULL; 284 aliasdlg = NULL;
283 aliasentry = NULL; 285 aliasentry = NULL;
284 aliasname = NULL; 286 aliasname = NULL;
285 } 287 }
288
289 if (dest == rename_dialog)
290 rename_dialog = NULL;
291
292 if (dest == rename_bud_dialog)
293 rename_bud_dialog = NULL;
286 294
287 dialogwindows = g_list_remove(dialogwindows, dest); 295 dialogwindows = g_list_remove(dialogwindows, dest);
288 gtk_widget_destroy(dest); 296 gtk_widget_destroy(dest);
289 297
290 } 298 }
550 return; 558 return;
551 } 559 }
552 560
553 static void do_im(GtkWidget *widget, GtkWidget *imentry) 561 static void do_im(GtkWidget *widget, GtkWidget *imentry)
554 { 562 {
555 char *who; 563 char *who;
556 struct conversation *c; 564 struct conversation *c;
557 565
558 who = g_strdup(gtk_entry_get_text(GTK_ENTRY(imentry))); 566 who = g_strdup(gtk_entry_get_text(GTK_ENTRY(imentry)));
559 destroy_dialog(NULL, imdialog); 567 destroy_dialog(NULL, imdialog);
560 imdialog = NULL; 568 imdialog = NULL;
561 569
562 if (!strcasecmp(who, "")) { 570 if (!strcasecmp(who, "")) {
563 g_free(who); 571 g_free(who);
564 return; 572 return;
565 } 573 }
566 574
567 c = find_conversation(who); 575 c = find_conversation(who);
568 576
569 if (c == NULL) { 577 if (c == NULL) {
570 c = new_conversation(who); 578 c = new_conversation(who);
571 } else { 579 } else {
572 gdk_window_raise(c->window->window); 580 gdk_window_raise(c->window->window);
573 } 581 }
574 g_free(who); 582 g_free(who);
575 } 583 }
576 584
577 static void do_info(GtkWidget *widget, GtkWidget *infoentry) 585 static void do_info(GtkWidget *widget, GtkWidget *infoentry)
578 { 586 {
579 char *who; 587 char *who;
580 588
581 who = g_strdup(normalize(gtk_entry_get_text(GTK_ENTRY(infoentry)))); 589 who = g_strdup(normalize(gtk_entry_get_text(GTK_ENTRY(infoentry))));
582 destroy_dialog(NULL, infodialog); 590 destroy_dialog(NULL, infodialog);
583 infodialog = NULL; 591 infodialog = NULL;
584 592
585 if (!strcasecmp(who, "")) { 593 if (!strcasecmp(who, "")) {
586 g_free(who); 594 g_free(who);
587 return; 595 return;
588 } 596 }
589 597
590 /* what do we want to do about this case? */ 598 /* what do we want to do about this case? */
591 if (connections) 599 if (connections)
600 GtkWidget *label; 608 GtkWidget *label;
601 GtkWidget *box; 609 GtkWidget *box;
602 GtkWidget *eedialog; 610 GtkWidget *eedialog;
603 611
604 eedialog = gtk_window_new(GTK_WINDOW_DIALOG); 612 eedialog = gtk_window_new(GTK_WINDOW_DIALOG);
605 ok = gtk_button_new_with_label(_("OK")); 613 ok = gtk_button_new_with_label(_("OK"));
606 box = gtk_vbox_new(FALSE, 10); 614 box = gtk_vbox_new(FALSE, 10);
607 615
608 616
609 if (display_options & OPT_DISP_COOL_LOOK) 617 if (display_options & OPT_DISP_COOL_LOOK)
610 gtk_button_set_relief(GTK_BUTTON(ok), GTK_RELIEF_NONE); 618 gtk_button_set_relief(GTK_BUTTON(ok), GTK_RELIEF_NONE);
611 619
630 gtk_window_set_title(GTK_WINDOW(eedialog), "Gaim - SUPRISE!"); 638 gtk_window_set_title(GTK_WINDOW(eedialog), "Gaim - SUPRISE!");
631 639
632 gtk_signal_connect(GTK_OBJECT(ok), "clicked", 640 gtk_signal_connect(GTK_OBJECT(ok), "clicked",
633 GTK_SIGNAL_FUNC(destroy_dialog), eedialog); 641 GTK_SIGNAL_FUNC(destroy_dialog), eedialog);
634 gtk_widget_realize(eedialog); 642 gtk_widget_realize(eedialog);
635 aol_icon(eedialog->window); 643 aol_icon(eedialog->window);
636 644
637 gtk_widget_show(eedialog); 645 gtk_widget_show(eedialog);
638 } 646 }
639 647
640 char *gem() 648 char *gem()
3380 c->smiley_dialog = dialog; 3388 c->smiley_dialog = dialog;
3381 3389
3382 return; 3390 return;
3383 } 3391 }
3384 3392
3385 static void do_alias_bs(GtkWidget *w, struct buddy_show *b) 3393 static void do_alias_bud(GtkWidget *w, struct buddy *b)
3386 { 3394 {
3387 GSList *c = b->connlist; 3395 char *al = gtk_entry_get_text(GTK_ENTRY(aliasname));
3388 struct gaim_connection *g; 3396 g_snprintf(b->show, sizeof(b->show), "%s", (al && strlen(al)) ? al : b->name);
3389 struct buddy *n; 3397 handle_buddy_rename(b, b->name);
3390 g_free(b->show);
3391 b->show = g_strdup(gtk_entry_get_text(GTK_ENTRY(aliasname)));
3392 gtk_label_set(GTK_LABEL(b->label), b->show);
3393 while (c) {
3394 g = (struct gaim_connection *)c->data;
3395 n = find_buddy(g, b->name);
3396 if (n) g_snprintf(n->show, sizeof(n->show), "%s", b->show);
3397 c = c->next;
3398 }
3399 do_export(0, 0); 3398 do_export(0, 0);
3400 destroy_dialog(aliasdlg, aliasdlg); 3399 destroy_dialog(aliasdlg, aliasdlg);
3401 build_edit_tree();
3402 }
3403
3404 void alias_dialog_bs(struct buddy_show *b)
3405 {
3406 GtkWidget *frame;
3407 GtkWidget *vbox;
3408 GtkWidget *bbox;
3409 GtkWidget *cancel;
3410 static GtkWidget *add = NULL;
3411 GtkWidget *label;
3412 GtkWidget *topbox;
3413 static int a, c;
3414
3415 if (aliasdlg)
3416 gtk_widget_destroy(aliasdlg);
3417
3418 aliasdlg = gtk_window_new(GTK_WINDOW_DIALOG);
3419 gtk_window_set_policy(GTK_WINDOW(aliasdlg), FALSE, FALSE, TRUE);
3420 gtk_window_set_wmclass(GTK_WINDOW(aliasdlg), "alias_dialog", "Gaim");
3421 gtk_widget_realize(aliasdlg);
3422 dialogwindows = g_list_prepend(dialogwindows, aliasdlg);
3423
3424 bbox = gtk_hbox_new(TRUE, 10);
3425 topbox = gtk_hbox_new(FALSE, 5);
3426 vbox = gtk_vbox_new(FALSE, 5);
3427
3428 aliasentry = gtk_entry_new();
3429 aliasname = gtk_entry_new();
3430 /* Put the buttons in the box */
3431
3432 add = picture_button(aliasdlg, _("Alias"), add_xpm);
3433
3434 cancel = picture_button(aliasdlg, _("Cancel"), cancel_xpm);
3435
3436 gtk_box_pack_start(GTK_BOX(bbox), add, FALSE, FALSE, 5);
3437 gtk_box_pack_end(GTK_BOX(bbox), cancel, FALSE, FALSE, 5);
3438
3439 frame = gtk_frame_new(NULL);
3440 gtk_frame_set_label(GTK_FRAME(frame), _("Alias Buddy"));
3441
3442 label = gtk_label_new(_("Buddy"));
3443 gtk_widget_show(label);
3444 gtk_box_pack_start(GTK_BOX(topbox), label, FALSE, FALSE, 5);
3445 gtk_box_pack_start(GTK_BOX(topbox), aliasentry, FALSE, FALSE, 5);
3446 gtk_entry_set_editable(GTK_ENTRY(aliasentry), FALSE);
3447 label = gtk_label_new(_("Alias"));
3448 gtk_widget_show(label);
3449 gtk_box_pack_start(GTK_BOX(topbox), label, FALSE, FALSE, 5);
3450 gtk_box_pack_start(GTK_BOX(topbox), aliasname, FALSE, FALSE, 5);
3451
3452 gtk_entry_set_text(GTK_ENTRY(aliasentry), b->name);
3453 gtk_entry_set_text(GTK_ENTRY(aliasname), b->show);
3454
3455 /* And the boxes in the box */
3456 gtk_box_pack_start(GTK_BOX(vbox), topbox, TRUE, TRUE, 5);
3457 gtk_box_pack_start(GTK_BOX(vbox), bbox, TRUE, TRUE, 5);
3458
3459 /* Handle closes right */
3460 gtk_signal_connect(GTK_OBJECT(aliasdlg), "destroy",
3461 GTK_SIGNAL_FUNC(destroy_dialog), aliasdlg);
3462 gtk_signal_connect(GTK_OBJECT(cancel), "clicked",
3463 GTK_SIGNAL_FUNC(destroy_dialog), aliasdlg);
3464 a = gtk_signal_connect(GTK_OBJECT(add), "clicked",
3465 GTK_SIGNAL_FUNC(do_alias_bs), b);
3466 c = gtk_signal_connect(GTK_OBJECT(aliasname), "activate",
3467 GTK_SIGNAL_FUNC(do_alias_bs), b);
3468 /* Finish up */
3469 gtk_widget_show(add);
3470 gtk_widget_show(cancel);
3471 gtk_widget_show(aliasentry);
3472 gtk_widget_show(aliasname);
3473 gtk_widget_show(topbox);
3474 gtk_widget_show(bbox);
3475 gtk_widget_show(vbox);
3476 gtk_widget_show(frame);
3477 gtk_window_set_title(GTK_WINDOW(aliasdlg), _("Gaim - Alias Buddy"));
3478 gtk_window_set_focus(GTK_WINDOW(aliasdlg), aliasentry);
3479 gtk_container_add(GTK_CONTAINER(frame), vbox);
3480 gtk_container_add(GTK_CONTAINER(aliasdlg), frame);
3481 gtk_container_set_border_width(GTK_CONTAINER(aliasdlg), 5);
3482 gtk_widget_realize(aliasdlg);
3483 aol_icon(aliasdlg->window);
3484
3485 gtk_widget_show(aliasdlg);
3486 }
3487
3488 static void do_alias_bud(GtkWidget *w, struct buddy *b)
3489 {
3490 g_snprintf(b->show, sizeof(b->show), "%s", gtk_entry_get_text(GTK_ENTRY(aliasname)));
3491 do_export(0, 0);
3492 destroy_dialog(aliasdlg, aliasdlg);
3493 build_edit_tree();
3494 } 3400 }
3495 3401
3496 void alias_dialog_bud(struct buddy *b) 3402 void alias_dialog_bud(struct buddy *b)
3497 { 3403 {
3498 GtkWidget *frame; 3404 GtkWidget *frame;
3865 fclose(fp); 3771 fclose(fp);
3866 g_string_free (string, TRUE); 3772 g_string_free (string, TRUE);
3867 3773
3868 return; 3774 return;
3869 } 3775 }
3776
3777 /*------------------------------------------------------------------------*/
3778 /* The dialog for renaming groups */
3779 /*------------------------------------------------------------------------*/
3780
3781 static void do_rename_group(GtkObject *obj, GtkWidget *entry)
3782 {
3783 char *new_name;
3784 struct group *g;
3785
3786 new_name = gtk_entry_get_text(GTK_ENTRY(entry));
3787 g = gtk_object_get_user_data(obj);
3788
3789 if (new_name && (strlen(new_name) != 0) && strcmp(new_name, g->name)) {
3790 char *prevname = g_strdup(g->name);
3791 g_snprintf(g->name, sizeof(g->name), "%s", new_name);
3792 handle_group_rename(g, prevname);
3793 g_free(prevname);
3794 do_export(0, 0);
3795 }
3796
3797 destroy_dialog(rename_dialog, rename_dialog);
3798 }
3799
3800 void show_rename_group(GtkWidget *unused, struct group *g)
3801 {
3802 GtkWidget *mainbox;
3803 GtkWidget *frame;
3804 GtkWidget *fbox;
3805 GtkWidget *bbox;
3806 GtkWidget *button;
3807 GtkWidget *name_entry;
3808 GtkWidget *label;
3809
3810 if (!rename_dialog) {
3811 rename_dialog = gtk_window_new(GTK_WINDOW_DIALOG);
3812 gtk_window_set_wmclass(GTK_WINDOW(rename_dialog), "rename_dialog",
3813 "Gaim");
3814 gtk_window_set_policy(GTK_WINDOW(rename_dialog), FALSE, TRUE, TRUE);
3815 gtk_window_set_title(GTK_WINDOW(rename_dialog),
3816 _("Gaim - Rename Group"));
3817 gtk_signal_connect(GTK_OBJECT(rename_dialog), "destroy",
3818 GTK_SIGNAL_FUNC(destroy_dialog), rename_dialog);
3819 gtk_widget_realize(rename_dialog);
3820 aol_icon(rename_dialog->window);
3821
3822 mainbox = gtk_vbox_new(FALSE, 5);
3823 gtk_container_set_border_width(GTK_CONTAINER(mainbox), 5);
3824 gtk_container_add(GTK_CONTAINER(rename_dialog), mainbox);
3825
3826 frame = gtk_frame_new(_("Rename Group"));
3827 gtk_box_pack_start(GTK_BOX(mainbox), frame, TRUE, TRUE, 0);
3828
3829 fbox = gtk_hbox_new(FALSE, 5);
3830 gtk_container_set_border_width(GTK_CONTAINER(fbox), 5);
3831 gtk_container_add(GTK_CONTAINER(frame), fbox);
3832
3833 label = gtk_label_new(_("New name:"));
3834 gtk_box_pack_start(GTK_BOX(fbox), label, FALSE, FALSE, 0);
3835
3836 name_entry = gtk_entry_new();
3837 gtk_box_pack_start(GTK_BOX(fbox), name_entry, TRUE, TRUE, 0);
3838 gtk_object_set_user_data(GTK_OBJECT(name_entry), g);
3839 gtk_entry_set_text(GTK_ENTRY(name_entry), g->name);
3840 gtk_signal_connect(GTK_OBJECT(name_entry), "activate",
3841 GTK_SIGNAL_FUNC(do_rename_group), name_entry);
3842 gtk_widget_grab_focus(name_entry);
3843
3844 bbox = gtk_hbox_new(FALSE, 5);
3845 gtk_box_pack_start(GTK_BOX(mainbox), bbox, FALSE, FALSE, 0);
3846
3847 button = picture_button(rename_dialog, _("Cancel"), cancel_xpm);
3848 gtk_box_pack_end(GTK_BOX(bbox), button, FALSE, FALSE, 0);
3849 gtk_signal_connect(GTK_OBJECT(button), "clicked",
3850 GTK_SIGNAL_FUNC(destroy_dialog), rename_dialog);
3851
3852 button = picture_button(rename_dialog, _("OK"), ok_xpm);
3853 gtk_object_set_user_data(GTK_OBJECT(button), g);
3854 gtk_box_pack_end(GTK_BOX(bbox), button, FALSE, FALSE, 0);
3855 gtk_signal_connect(GTK_OBJECT(button), "clicked",
3856 GTK_SIGNAL_FUNC(do_rename_group), name_entry);
3857 }
3858
3859 gtk_widget_show_all(rename_dialog);
3860 }
3861
3862 /*------------------------------------------------------------------------*/
3863 /* The dialog for renaming buddies */
3864 /*------------------------------------------------------------------------*/
3865
3866 static void do_rename_buddy(GtkObject *obj, GtkWidget *entry)
3867 {
3868 char *new_name;
3869 struct buddy *b;
3870
3871 new_name = gtk_entry_get_text(GTK_ENTRY(entry));
3872 b = gtk_object_get_user_data(obj);
3873
3874 if (new_name && (strlen(new_name) != 0) && strcmp(new_name, b->name)) {
3875 char *prevname = g_strdup(b->name);
3876 serv_remove_buddy(b->gc, b->name);
3877 if (!strcmp(b->name, b->show))
3878 g_snprintf(b->show, sizeof(b->show), "%s", new_name);
3879 g_snprintf(b->name, sizeof(b->name), "%s", new_name);
3880 serv_add_buddy(b->gc, b->name);
3881 handle_buddy_rename(b, prevname);
3882 g_free(prevname);
3883 }
3884
3885 destroy_dialog(rename_bud_dialog, rename_bud_dialog);
3886 }
3887
3888 void show_rename_buddy(GtkWidget *unused, struct buddy *b)
3889 {
3890 GtkWidget *mainbox;
3891 GtkWidget *frame;
3892 GtkWidget *fbox;
3893 GtkWidget *bbox;
3894 GtkWidget *button;
3895 GtkWidget *name_entry;
3896 GtkWidget *label;
3897
3898 if (!rename_bud_dialog) {
3899 rename_bud_dialog = gtk_window_new(GTK_WINDOW_DIALOG);
3900 gtk_window_set_wmclass(GTK_WINDOW(rename_bud_dialog), "rename_bud_dialog",
3901 "Gaim");
3902 gtk_window_set_policy(GTK_WINDOW(rename_bud_dialog), FALSE, TRUE, TRUE);
3903 gtk_window_set_title(GTK_WINDOW(rename_bud_dialog),
3904 _("Gaim - Rename Buddy"));
3905 gtk_signal_connect(GTK_OBJECT(rename_bud_dialog), "destroy",
3906 GTK_SIGNAL_FUNC(destroy_dialog), rename_bud_dialog);
3907 gtk_widget_realize(rename_bud_dialog);
3908 aol_icon(rename_bud_dialog->window);
3909
3910 mainbox = gtk_vbox_new(FALSE, 5);
3911 gtk_container_set_border_width(GTK_CONTAINER(mainbox), 5);
3912 gtk_container_add(GTK_CONTAINER(rename_bud_dialog), mainbox);
3913
3914 frame = gtk_frame_new(_("Rename Buddy"));
3915 gtk_box_pack_start(GTK_BOX(mainbox), frame, TRUE, TRUE, 0);
3916
3917 fbox = gtk_hbox_new(FALSE, 5);
3918 gtk_container_set_border_width(GTK_CONTAINER(fbox), 5);
3919 gtk_container_add(GTK_CONTAINER(frame), fbox);
3920
3921 label = gtk_label_new(_("New name:"));
3922 gtk_box_pack_start(GTK_BOX(fbox), label, FALSE, FALSE, 0);
3923
3924 name_entry = gtk_entry_new();
3925 gtk_box_pack_start(GTK_BOX(fbox), name_entry, TRUE, TRUE, 0);
3926 gtk_object_set_user_data(GTK_OBJECT(name_entry), b);
3927 gtk_entry_set_text(GTK_ENTRY(name_entry), b->name);
3928 gtk_signal_connect(GTK_OBJECT(name_entry), "activate",
3929 GTK_SIGNAL_FUNC(do_rename_buddy), name_entry);
3930 gtk_widget_grab_focus(name_entry);
3931
3932 bbox = gtk_hbox_new(FALSE, 5);
3933 gtk_box_pack_start(GTK_BOX(mainbox), bbox, FALSE, FALSE, 0);
3934
3935 button = picture_button(rename_bud_dialog, _("Cancel"), cancel_xpm);
3936 gtk_box_pack_end(GTK_BOX(bbox), button, FALSE, FALSE, 0);
3937 gtk_signal_connect(GTK_OBJECT(button), "clicked",
3938 GTK_SIGNAL_FUNC(destroy_dialog), rename_bud_dialog);
3939
3940 button = picture_button(rename_bud_dialog, _("OK"), ok_xpm);
3941 gtk_object_set_user_data(GTK_OBJECT(button), b);
3942 gtk_box_pack_end(GTK_BOX(bbox), button, FALSE, FALSE, 0);
3943 gtk_signal_connect(GTK_OBJECT(button), "clicked",
3944 GTK_SIGNAL_FUNC(do_rename_buddy), name_entry);
3945 }
3946
3947 gtk_widget_show_all(rename_bud_dialog);
3948 }