2d1b8147c712e4449945305c285e939be2bfcc6e
[claws.git] / src / prefs_quote.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 2005-2007 Colin Leroy <colin@colino.net> & The Claws Mail Team
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  * 
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #  include "config.h"
22 #endif
23
24 #include "defs.h"
25
26 #include <stdio.h>
27 #include <stdlib.h>
28
29 #include <glib.h>
30 #include <glib/gi18n.h>
31 #include <gtk/gtk.h>
32 #include <gdk/gdkkeysyms.h>
33
34 #include "prefs_common.h"
35 #include "prefs_gtk.h"
36 #include "prefs_template.h"
37 #include "alertpanel.h"
38
39 #include "gtk/gtkutils.h"
40 #include "gtk/prefswindow.h"
41
42 #include "manage_window.h"
43 #include "quote_fmt.h"
44
45 typedef struct _QuotePage
46 {
47         PrefsPage page;
48
49         GtkWidget *window;
50
51         GtkWidget *checkbtn_compose_with_format;
52         GtkWidget *entry_subject;
53         GtkWidget *text_format;
54         GtkWidget *entry_quotemark;
55         GtkWidget *text_quotefmt;
56         GtkWidget *entry_fw_quotemark;
57         GtkWidget *text_fw_quotefmt;
58         GtkWidget *btn_quotedesc;
59 } QuotePage;
60
61 static void prefs_quote_create_widget(PrefsPage *_page, GtkWindow *window, 
62                                   gpointer data)
63 {
64         QuotePage *prefs_quote = (QuotePage *) _page;
65         
66         GtkWidget *vbox;
67         GtkWidget *vbox2;
68         GtkWidget *notebook;
69
70         vbox = gtk_vbox_new (FALSE, 0);
71         gtk_widget_show (vbox);
72
73         notebook = gtk_notebook_new();
74         gtk_widget_show(notebook);
75         gtk_notebook_set_homogeneous_tabs(GTK_NOTEBOOK(notebook), TRUE);
76         gtk_box_pack_start(GTK_BOX(vbox), notebook, TRUE, TRUE, 0);
77
78         /* new message */
79         vbox2 = gtk_vbox_new (FALSE, VSPACING);
80         gtk_widget_show (vbox2);
81         gtk_container_set_border_width (GTK_CONTAINER (vbox2), VBOX_BORDER);
82         
83         quotefmt_create_new_msg_fmt_widgets(
84                                 window,
85                                 vbox2,
86                                 &prefs_quote->checkbtn_compose_with_format,
87                                 _("New message format"),
88                                 &prefs_quote->entry_subject,
89                                 &prefs_quote->text_format,
90                                 FALSE);
91         gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox2, gtk_label_new(_("Compose")));
92
93         /* reply */
94         vbox2 = gtk_vbox_new (FALSE, VSPACING);
95         gtk_widget_show (vbox2);
96         gtk_container_set_border_width (GTK_CONTAINER (vbox2), VBOX_BORDER);
97         
98         quotefmt_create_reply_fmt_widgets(
99                                 window,
100                                 vbox2,
101                                 NULL,
102                                 NULL,
103                                 &prefs_quote->entry_quotemark,
104                                 &prefs_quote->text_quotefmt,
105                                 FALSE);
106         gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox2, gtk_label_new(_("Reply")));
107
108         /* forward */
109         vbox2 = gtk_vbox_new (FALSE, VSPACING);
110         gtk_widget_show (vbox2);
111         gtk_container_set_border_width (GTK_CONTAINER (vbox2), VBOX_BORDER);
112         
113         quotefmt_create_forward_fmt_widgets(
114                                 window,
115                                 vbox2,
116                                 NULL,
117                                 NULL,
118                                 &prefs_quote->entry_fw_quotemark,
119                                 &prefs_quote->text_fw_quotefmt,
120                                 FALSE);
121         gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox2, gtk_label_new(_("Forward")));
122
123         /* info button */
124
125         quotefmt_add_info_button(window, vbox);
126
127         gtk_entry_set_text(GTK_ENTRY(prefs_quote->entry_quotemark), 
128                         prefs_common.quotemark?prefs_common.quotemark:"");
129         pref_set_textview_from_pref(GTK_TEXT_VIEW(prefs_quote->text_quotefmt),
130                         prefs_common.quotefmt);
131
132         pref_set_textview_from_pref(GTK_TEXT_VIEW(prefs_quote->text_fw_quotefmt),
133                         prefs_common.fw_quotefmt);
134         gtk_entry_set_text(GTK_ENTRY(prefs_quote->entry_fw_quotemark), 
135                         prefs_common.fw_quotemark?prefs_common.fw_quotemark:"");
136
137         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_quote->checkbtn_compose_with_format),
138                         prefs_common.compose_with_format);
139         pref_set_entry_from_pref(GTK_ENTRY(prefs_quote->entry_subject), prefs_common.compose_subject_format);
140         pref_set_textview_from_pref(GTK_TEXT_VIEW(prefs_quote->text_format), prefs_common.compose_body_format);
141
142         prefs_quote->window             = GTK_WIDGET(window);
143         prefs_quote->page.widget = vbox;
144 }
145
146 static void prefs_quote_save(PrefsPage *_page)
147 {
148         QuotePage *page = (QuotePage *) _page;
149         
150         g_free(prefs_common.compose_subject_format); 
151         prefs_common.compose_subject_format = NULL;
152         g_free(prefs_common.compose_body_format); 
153         prefs_common.compose_body_format = NULL;
154         g_free(prefs_common.quotefmt); 
155         prefs_common.quotefmt = NULL;
156         g_free(prefs_common.fw_quotefmt); 
157         prefs_common.fw_quotefmt = NULL;
158         g_free(prefs_common.quotemark); 
159         prefs_common.quotemark = NULL;
160         g_free(prefs_common.fw_quotemark); 
161         prefs_common.fw_quotemark = NULL;
162         
163         prefs_common.compose_with_format =
164                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_compose_with_format));
165         prefs_common.compose_subject_format = pref_get_pref_from_entry(
166                         GTK_ENTRY(page->entry_subject));
167         prefs_common.compose_body_format = pref_get_pref_from_textview(
168                         GTK_TEXT_VIEW(page->text_format));
169         quotefmt_check_new_msg_formats(prefs_common.compose_with_format,
170                                                                         prefs_common.compose_subject_format,
171                                                                         prefs_common.compose_body_format);
172
173         prefs_common.quotemark = gtk_editable_get_chars(
174                         GTK_EDITABLE(page->entry_quotemark), 0, -1);
175         prefs_common.quotefmt = pref_get_pref_from_textview(
176                         GTK_TEXT_VIEW(page->text_quotefmt));
177         quotefmt_check_reply_formats(TRUE, prefs_common.quotemark, prefs_common.quotefmt);
178
179         prefs_common.fw_quotemark = gtk_editable_get_chars(
180                         GTK_EDITABLE(page->entry_fw_quotemark), 0, -1);
181         prefs_common.fw_quotefmt = pref_get_pref_from_textview(
182                         GTK_TEXT_VIEW(page->text_fw_quotefmt));
183         quotefmt_check_forward_formats(TRUE, prefs_common.fw_quotemark, prefs_common.fw_quotefmt);
184 }
185
186 static void prefs_quote_destroy_widget(PrefsPage *_page)
187 {
188 }
189
190 QuotePage *prefs_quote;
191
192 void prefs_quote_init(void)
193 {
194         QuotePage *page;
195         static gchar *path[3];
196
197         path[0] = _("Compose");
198         path[1] = _("Templates");
199         path[2] = NULL;
200
201         page = g_new0(QuotePage, 1);
202         page->page.path = path;
203         page->page.create_widget = prefs_quote_create_widget;
204         page->page.destroy_widget = prefs_quote_destroy_widget;
205         page->page.save_page = prefs_quote_save;
206         page->page.weight = 185.0;
207         prefs_gtk_register_page((PrefsPage *) page);
208         prefs_quote = page;
209 }
210
211 void prefs_quote_done(void)
212 {
213         prefs_gtk_unregister_page((PrefsPage *) prefs_quote);
214         g_free(prefs_quote);
215 }