Mercurial > pidgin
comparison src/dialogs.c @ 8502:48112dfe1179
[gaim-migrate @ 9238]
-Don't let people create "empty" away messages containing only html
-Fix a 20 byte memleak when closing a Create Away Message dialog
with cancel or the window manager "X"
committer: Tailor Script <tailor@pidgin.im>
| author | Mark Doliner <mark@kingant.net> |
|---|---|
| date | Thu, 25 Mar 2004 06:44:52 +0000 |
| parents | 6d0869404696 |
| children | cc2ce209cc46 |
comparison
equal
deleted
inserted
replaced
| 8501:9f1678878dc8 | 8502:48112dfe1179 |
|---|---|
| 115 dest = w2; | 115 dest = w2; |
| 116 | 116 |
| 117 dialogwindows = g_list_remove(dialogwindows, dest); | 117 dialogwindows = g_list_remove(dialogwindows, dest); |
| 118 gtk_widget_destroy(dest); | 118 gtk_widget_destroy(dest); |
| 119 } | 119 } |
| 120 | |
| 121 | 120 |
| 122 void destroy_all_dialogs() | 121 void destroy_all_dialogs() |
| 123 { | 122 { |
| 124 while (dialogwindows) | 123 while (dialogwindows) |
| 125 destroy_dialog(NULL, dialogwindows->data); | 124 destroy_dialog(NULL, dialogwindows->data); |
| 645 | 644 |
| 646 /*------------------------------------------------------------------------*/ | 645 /*------------------------------------------------------------------------*/ |
| 647 /* The dialog for new away messages */ | 646 /* The dialog for new away messages */ |
| 648 /*------------------------------------------------------------------------*/ | 647 /*------------------------------------------------------------------------*/ |
| 649 | 648 |
| 649 static void away_mess_destroy(GtkWidget *widget, struct create_away *ca) | |
| 650 { | |
| 651 destroy_dialog(NULL, ca->window); | |
| 652 g_free(ca); | |
| 653 } | |
| 654 | |
| 655 static void away_mess_destroy_ca(GtkWidget *widget, GdkEvent *event, struct create_away *ca) | |
| 656 { | |
| 657 away_mess_destroy(NULL, ca); | |
| 658 } | |
| 659 | |
| 650 static struct away_message *save_away_message(struct create_away *ca) | 660 static struct away_message *save_away_message(struct create_away *ca) |
| 651 { | 661 { |
| 652 struct away_message *am; | 662 struct away_message *am; |
| 653 gchar *away_message; | 663 gchar *away_message; |
| 654 | 664 |
| 673 return am; | 683 return am; |
| 674 } | 684 } |
| 675 | 685 |
| 676 int check_away_mess(struct create_away *ca, int type) | 686 int check_away_mess(struct create_away *ca, int type) |
| 677 { | 687 { |
| 678 char *msg; | 688 gchar *msg; |
| 679 if ((strlen(gtk_entry_get_text(GTK_ENTRY(ca->entry))) == 0) && (type == 1)) { | 689 if ((strlen(gtk_entry_get_text(GTK_ENTRY(ca->entry))) == 0) && (type == 1)) { |
| 680 /* We shouldn't allow a blank title */ | 690 /* We shouldn't allow a blank title */ |
| 681 gaim_notify_error(NULL, NULL, | 691 gaim_notify_error(NULL, NULL, |
| 682 _("You cannot save an away message with a " | 692 _("You cannot save an away message with a " |
| 683 "blank title"), | 693 "blank title"), |
| 684 _("Please give the message a title, or choose " | 694 _("Please give the message a title, or choose " |
| 685 "\"Use\" to use without saving.")); | 695 "\"Use\" to use without saving.")); |
| 686 return 0; | 696 return 0; |
| 687 } | 697 } |
| 688 | 698 |
| 689 msg = gtk_imhtml_get_markup(GTK_IMHTML(ca->text)); | 699 msg = gtk_imhtml_get_text(GTK_IMHTML(ca->text)); |
| 690 | 700 |
| 691 if (!msg && (type <= 1)) { | 701 if ((type <= 1) && ((msg == NULL) || (*msg == '\0'))) { |
| 692 /* We shouldn't allow a blank message */ | 702 /* We shouldn't allow a blank message */ |
| 693 gaim_notify_error(NULL, NULL, | 703 gaim_notify_error(NULL, NULL, |
| 694 _("You cannot create an empty away message"), NULL); | 704 _("You cannot create an empty away message"), NULL); |
| 695 return 0; | 705 return 0; |
| 696 } | 706 } |
| 704 { | 714 { |
| 705 if (!check_away_mess(ca, 1)) | 715 if (!check_away_mess(ca, 1)) |
| 706 return; | 716 return; |
| 707 | 717 |
| 708 save_away_message(ca); | 718 save_away_message(ca); |
| 709 destroy_dialog(NULL, ca->window); | 719 |
| 710 g_free(ca); | 720 away_mess_destroy(NULL, ca); |
| 711 } | 721 } |
| 712 | 722 |
| 713 void use_away_mess(GtkWidget *widget, struct create_away *ca) | 723 void use_away_mess(GtkWidget *widget, struct create_away *ca) |
| 714 { | 724 { |
| 715 static struct away_message am; | 725 static struct away_message am; |
| 724 g_snprintf(am.message, sizeof(am.message), "%s", away_message); | 734 g_snprintf(am.message, sizeof(am.message), "%s", away_message); |
| 725 g_free(away_message); | 735 g_free(away_message); |
| 726 | 736 |
| 727 do_away_message(NULL, &am); | 737 do_away_message(NULL, &am); |
| 728 | 738 |
| 729 destroy_dialog(NULL, ca->window); | 739 away_mess_destroy(NULL, ca); |
| 730 g_free(ca); | |
| 731 } | 740 } |
| 732 | 741 |
| 733 void su_away_mess(GtkWidget *widget, struct create_away *ca) | 742 void su_away_mess(GtkWidget *widget, struct create_away *ca) |
| 734 { | 743 { |
| 735 if (!check_away_mess(ca, 1)) | 744 if (!check_away_mess(ca, 1)) |
| 736 return; | 745 return; |
| 746 | |
| 737 do_away_message(NULL, save_away_message(ca)); | 747 do_away_message(NULL, save_away_message(ca)); |
| 738 destroy_dialog(NULL, ca->window); | 748 |
| 739 g_free(ca); | 749 away_mess_destroy(NULL, ca); |
| 740 } | 750 } |
| 741 | 751 |
| 742 void create_away_mess(GtkWidget *widget, void *dummy) | 752 void create_away_mess(GtkWidget *widget, void *dummy) |
| 743 { | 753 { |
| 744 GtkWidget *vbox, *hbox; | 754 GtkWidget *vbox, *hbox; |
| 753 gtk_widget_set_size_request(ca->window, -1, 250); | 763 gtk_widget_set_size_request(ca->window, -1, 250); |
| 754 gtk_container_set_border_width(GTK_CONTAINER(ca->window), 6); | 764 gtk_container_set_border_width(GTK_CONTAINER(ca->window), 6); |
| 755 gtk_window_set_role(GTK_WINDOW(ca->window), "away_mess"); | 765 gtk_window_set_role(GTK_WINDOW(ca->window), "away_mess"); |
| 756 gtk_window_set_title(GTK_WINDOW(ca->window), _("New away message")); | 766 gtk_window_set_title(GTK_WINDOW(ca->window), _("New away message")); |
| 757 g_signal_connect(G_OBJECT(ca->window), "delete_event", | 767 g_signal_connect(G_OBJECT(ca->window), "delete_event", |
| 758 G_CALLBACK(destroy_dialog), ca->window); | 768 G_CALLBACK(away_mess_destroy_ca), ca); |
| 759 | 769 |
| 760 /* | 770 /* |
| 761 * This would be higgy... but I think it's pretty ugly --Mark | 771 * This would be higgy... but I think it's pretty ugly --Mark |
| 762 * If you want to use this, make sure you add the vbox to the hbox below | 772 * If you want to use this, make sure you add the vbox to the hbox below |
| 763 */ | 773 */ |
| 837 button = gaim_pixbuf_button_from_stock(_("Use"), GTK_STOCK_EXECUTE, GAIM_BUTTON_HORIZONTAL); | 847 button = gaim_pixbuf_button_from_stock(_("Use"), GTK_STOCK_EXECUTE, GAIM_BUTTON_HORIZONTAL); |
| 838 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(use_away_mess), ca); | 848 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(use_away_mess), ca); |
| 839 gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 0); | 849 gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 0); |
| 840 | 850 |
| 841 button = gaim_pixbuf_button_from_stock(_("Cancel"), GTK_STOCK_CANCEL, GAIM_BUTTON_HORIZONTAL); | 851 button = gaim_pixbuf_button_from_stock(_("Cancel"), GTK_STOCK_CANCEL, GAIM_BUTTON_HORIZONTAL); |
| 842 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(destroy_dialog), ca->window); | 852 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(away_mess_destroy), ca); |
| 843 gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 0); | 853 gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 0); |
| 844 | 854 |
| 845 gtk_widget_show_all(ca->window); | 855 gtk_widget_show_all(ca->window); |
| 846 } | 856 } |
| 847 | 857 |
