Mercurial > pidgin.yaz
comparison src/away.c @ 9730:c9ac1976ef01
[gaim-migrate @ 10591]
I shuffled lots of stuff around again.
See plugins/ChangeLog.API for the list of renamed functions.
I'm trying to clean up gtkdialogs.c/.h, so I moved the away stuff
into away.c/.h
I also reduced the minimum buddy list height from 200 pixels to
100 pixels. I just realized that that's also the default height
used when you don't have a prefs.xml, which is bad. I think I'm
going to set the default height to around 300 pixels.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Mon, 09 Aug 2004 03:49:46 +0000 |
parents | 4d05b6e9e9cd |
children | 4a15962c344a |
comparison
equal
deleted
inserted
replaced
9729:f44ae9331afc | 9730:c9ac1976ef01 |
---|---|
19 * along with this program; if not, write to the Free Software | 19 * along with this program; if not, write to the Free Software |
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
21 * | 21 * |
22 */ | 22 */ |
23 #include "internal.h" | 23 #include "internal.h" |
24 #include "gtkinternal.h" | |
24 | 25 |
25 #include "conversation.h" | 26 #include "conversation.h" |
26 #include "debug.h" | 27 #include "debug.h" |
28 #include "notify.h" | |
27 #include "plugin.h" | 29 #include "plugin.h" |
28 #include "prefs.h" | 30 #include "prefs.h" |
29 #include "prpl.h" | 31 #include "prpl.h" |
30 #include "status.h" | 32 #include "status.h" |
31 #include "util.h" | 33 #include "util.h" |
32 #include "request.h" | 34 #include "request.h" |
33 | 35 |
34 /* XXX CORE/UI: Until we can get rid of the message queue stuff... */ | 36 /* XXX CORE/UI: Until we can get rid of the message queue stuff... */ |
37 #include "away.h" | |
35 #include "gaim.h" | 38 #include "gaim.h" |
36 #include "gtkinternal.h" | |
37 #include "gtkblist.h" | 39 #include "gtkblist.h" |
38 #include "gtkdialogs.h" | 40 #include "gtkdialogs.h" |
39 #include "gtkimhtml.h" | 41 #include "gtkimhtml.h" |
42 #include "gtkimhtmltoolbar.h" | |
40 #include "gtkprefs.h" | 43 #include "gtkprefs.h" |
41 #include "gtkutils.h" | 44 #include "gtkutils.h" |
42 | 45 |
43 GtkWidget *imaway = NULL; | 46 GtkWidget *imaway = NULL; |
44 GtkWidget *awaymenu = NULL; | 47 GtkWidget *awaymenu = NULL; |
666 gtk_widget_hide(GTK_WIDGET(prefs_away_menu)); | 669 gtk_widget_hide(GTK_WIDGET(prefs_away_menu)); |
667 default_away_menu_init(GTK_WIDGET(prefs_away_menu)); | 670 default_away_menu_init(GTK_WIDGET(prefs_away_menu)); |
668 gtk_widget_show(prefs_away_menu); | 671 gtk_widget_show(prefs_away_menu); |
669 } | 672 } |
670 } | 673 } |
674 | |
675 /*------------------------------------------------------------------------*/ | |
676 /* The dialog for new away messages (from dialogs.c) */ | |
677 /*------------------------------------------------------------------------*/ | |
678 struct create_away { | |
679 GtkWidget *window; | |
680 GtkWidget *toolbar; | |
681 GtkWidget *entry; | |
682 GtkWidget *text; | |
683 struct away_message *mess; | |
684 }; | |
685 | |
686 static void | |
687 away_mess_destroy(GtkWidget *widget, struct create_away *ca) | |
688 { | |
689 gtk_widget_destroy(ca->window); | |
690 g_free(ca); | |
691 } | |
692 | |
693 static void | |
694 away_mess_destroy_ca(GtkWidget *widget, GdkEvent *event, struct create_away *ca) | |
695 { | |
696 away_mess_destroy(NULL, ca); | |
697 } | |
698 | |
699 static gint | |
700 sort_awaymsg_list(gconstpointer a, gconstpointer b) | |
701 { | |
702 struct away_message *msg_a; | |
703 struct away_message *msg_b; | |
704 | |
705 msg_a = (struct away_message *)a; | |
706 msg_b = (struct away_message *)b; | |
707 | |
708 return (strcmp(msg_a->name, msg_b->name)); | |
709 } | |
710 | |
711 static struct | |
712 away_message *save_away_message(struct create_away *ca) | |
713 { | |
714 struct away_message *am; | |
715 gchar *away_message; | |
716 | |
717 if (!ca->mess) | |
718 am = g_new0(struct away_message, 1); | |
719 else { | |
720 am = ca->mess; | |
721 } | |
722 | |
723 g_snprintf(am->name, sizeof(am->name), "%s", gtk_entry_get_text(GTK_ENTRY(ca->entry))); | |
724 away_message = gtk_imhtml_get_markup(GTK_IMHTML(ca->text)); | |
725 | |
726 g_snprintf(am->message, sizeof(am->message), "%s", away_message); | |
727 g_free(away_message); | |
728 | |
729 if (!ca->mess) | |
730 away_messages = g_slist_insert_sorted(away_messages, am, sort_awaymsg_list); | |
731 | |
732 do_away_menu(NULL); | |
733 gaim_status_sync(); | |
734 | |
735 return am; | |
736 } | |
737 | |
738 int | |
739 check_away_mess(struct create_away *ca, int type) | |
740 { | |
741 gchar *msg; | |
742 if ((strlen(gtk_entry_get_text(GTK_ENTRY(ca->entry))) == 0) && (type == 1)) { | |
743 /* We shouldn't allow a blank title */ | |
744 gaim_notify_error(NULL, NULL, | |
745 _("You cannot save an away message with a " | |
746 "blank title"), | |
747 _("Please give the message a title, or choose " | |
748 "\"Use\" to use without saving.")); | |
749 return 0; | |
750 } | |
751 | |
752 msg = gtk_imhtml_get_text(GTK_IMHTML(ca->text), NULL, NULL); | |
753 | |
754 if ((type <= 1) && ((msg == NULL) || (*msg == '\0'))) { | |
755 /* We shouldn't allow a blank message */ | |
756 gaim_notify_error(NULL, NULL, | |
757 _("You cannot create an empty away message"), NULL); | |
758 return 0; | |
759 } | |
760 | |
761 g_free(msg); | |
762 | |
763 return 1; | |
764 } | |
765 | |
766 void | |
767 save_away_mess(GtkWidget *widget, struct create_away *ca) | |
768 { | |
769 if (!check_away_mess(ca, 1)) | |
770 return; | |
771 | |
772 save_away_message(ca); | |
773 | |
774 away_mess_destroy(NULL, ca); | |
775 } | |
776 | |
777 void | |
778 use_away_mess(GtkWidget *widget, struct create_away *ca) | |
779 { | |
780 static struct away_message am; | |
781 gchar *away_message; | |
782 | |
783 if (!check_away_mess(ca, 0)) | |
784 return; | |
785 | |
786 g_snprintf(am.name, sizeof(am.name), "%s", gtk_entry_get_text(GTK_ENTRY(ca->entry))); | |
787 away_message = gtk_imhtml_get_markup(GTK_IMHTML(ca->text)); | |
788 | |
789 g_snprintf(am.message, sizeof(am.message), "%s", away_message); | |
790 g_free(away_message); | |
791 | |
792 do_away_message(NULL, &am); | |
793 | |
794 away_mess_destroy(NULL, ca); | |
795 } | |
796 | |
797 void | |
798 su_away_mess(GtkWidget *widget, struct create_away *ca) | |
799 { | |
800 if (!check_away_mess(ca, 1)) | |
801 return; | |
802 | |
803 do_away_message(NULL, save_away_message(ca)); | |
804 | |
805 away_mess_destroy(NULL, ca); | |
806 } | |
807 | |
808 void | |
809 create_away_mess(GtkWidget *widget, void *dummy) | |
810 { | |
811 GtkWidget *vbox, *hbox; | |
812 GtkWidget *label; | |
813 GtkWidget *sw; | |
814 GtkWidget *button; | |
815 GList *focus_chain = NULL; | |
816 struct create_away *ca = g_new0(struct create_away, 1); | |
817 | |
818 /* Set up window */ | |
819 GAIM_DIALOG(ca->window); | |
820 gtk_widget_set_size_request(ca->window, -1, 250); | |
821 gtk_window_set_role(GTK_WINDOW(ca->window), "away_mess"); | |
822 gtk_window_set_title(GTK_WINDOW(ca->window), _("New away message")); | |
823 g_signal_connect(G_OBJECT(ca->window), "delete_event", | |
824 G_CALLBACK(away_mess_destroy_ca), ca); | |
825 | |
826 hbox = gtk_hbox_new(FALSE, 12); | |
827 gtk_container_set_border_width(GTK_CONTAINER(hbox), 12); | |
828 gtk_container_add(GTK_CONTAINER(ca->window), hbox); | |
829 | |
830 vbox = gtk_vbox_new(FALSE, 12); | |
831 gtk_container_add(GTK_CONTAINER(hbox), vbox); | |
832 | |
833 /* Away message title */ | |
834 hbox = gtk_hbox_new(FALSE, 0); | |
835 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
836 | |
837 label = gtk_label_new(_("Away title: ")); | |
838 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
839 | |
840 ca->entry = gtk_entry_new(); | |
841 gtk_box_pack_start(GTK_BOX(hbox), ca->entry, TRUE, TRUE, 0); | |
842 gaim_set_accessible_label (ca->entry, label); | |
843 focus_chain = g_list_append(focus_chain, hbox); | |
844 | |
845 /* Toolbar */ | |
846 ca->toolbar = gtk_imhtmltoolbar_new(); | |
847 gtk_box_pack_start(GTK_BOX(vbox), ca->toolbar, FALSE, FALSE, 0); | |
848 | |
849 /* Away message text */ | |
850 sw = gtk_scrolled_window_new(NULL, NULL); | |
851 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), | |
852 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
853 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), GTK_SHADOW_IN); | |
854 gtk_box_pack_start(GTK_BOX(vbox), sw, TRUE, TRUE, 0); | |
855 | |
856 ca->text = gtk_imhtml_new(NULL, NULL); | |
857 gtk_imhtml_set_editable(GTK_IMHTML(ca->text), TRUE); | |
858 gtk_imhtml_set_format_functions(GTK_IMHTML(ca->text), GTK_IMHTML_ALL ^ GTK_IMHTML_IMAGE); | |
859 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(ca->text), GTK_WRAP_WORD_CHAR); | |
860 | |
861 gtk_imhtml_smiley_shortcuts(GTK_IMHTML(ca->text), | |
862 gaim_prefs_get_bool("/gaim/gtk/conversations/smiley_shortcuts")); | |
863 gtk_imhtml_html_shortcuts(GTK_IMHTML(ca->text), | |
864 gaim_prefs_get_bool("/gaim/gtk/conversations/html_shortcuts")); | |
865 if (gaim_prefs_get_bool("/gaim/gtk/conversations/spellcheck")) | |
866 gaim_gtk_setup_gtkspell(GTK_TEXT_VIEW(ca->text)); | |
867 gtk_imhtmltoolbar_attach(GTK_IMHTMLTOOLBAR(ca->toolbar), ca->text); | |
868 gtk_imhtmltoolbar_associate_smileys(GTK_IMHTMLTOOLBAR(ca->toolbar), "default"); | |
869 gaim_setup_imhtml(ca->text); | |
870 | |
871 gtk_container_add(GTK_CONTAINER(sw), ca->text); | |
872 focus_chain = g_list_append(focus_chain, sw); | |
873 | |
874 if (dummy) { | |
875 struct away_message *amt; | |
876 GtkTreeIter iter; | |
877 GtkListStore *ls = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dummy))); | |
878 GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(dummy)); | |
879 GValue val = { 0, }; | |
880 | |
881 if (! gtk_tree_selection_get_selected (sel, (GtkTreeModel**)&ls, &iter)) | |
882 return; | |
883 gtk_tree_model_get_value (GTK_TREE_MODEL(ls), &iter, 1, &val); | |
884 amt = g_value_get_pointer (&val); | |
885 gtk_entry_set_text(GTK_ENTRY(ca->entry), amt->name); | |
886 gtk_imhtml_append_text_with_images(GTK_IMHTML(ca->text), amt->message, 0, NULL); | |
887 ca->mess = amt; | |
888 } | |
889 | |
890 hbox = gtk_hbox_new(FALSE, 5); | |
891 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
892 | |
893 button = gaim_pixbuf_button_from_stock(_("_Save"), GTK_STOCK_SAVE, GAIM_BUTTON_HORIZONTAL); | |
894 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(save_away_mess), ca); | |
895 gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
896 | |
897 button = gaim_pixbuf_button_from_stock(_("Sa_ve & Use"), GTK_STOCK_OK, GAIM_BUTTON_HORIZONTAL); | |
898 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(su_away_mess), ca); | |
899 gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
900 | |
901 button = gaim_pixbuf_button_from_stock(_("_Use"), GTK_STOCK_EXECUTE, GAIM_BUTTON_HORIZONTAL); | |
902 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(use_away_mess), ca); | |
903 gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
904 | |
905 button = gaim_pixbuf_button_from_stock(_("_Cancel"), GTK_STOCK_CANCEL, GAIM_BUTTON_HORIZONTAL); | |
906 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(away_mess_destroy), ca); | |
907 gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
908 focus_chain = g_list_prepend(focus_chain, hbox); | |
909 | |
910 gtk_widget_show_all(ca->window); | |
911 gtk_container_set_focus_chain(GTK_CONTAINER(vbox), focus_chain); | |
912 } |