e6835aae6a59803f2d69151ac328791973cb56ec
[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 2 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, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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 *label_quote_chars;
59         GtkWidget *btn_quotedesc;
60 } QuotePage;
61
62 static void prefs_quote_create_widget(PrefsPage *_page, GtkWindow *window, 
63                                   gpointer data)
64 {
65         QuotePage *prefs_quote = (QuotePage *) _page;
66         
67         GtkWidget *vbox;
68
69         vbox = gtk_vbox_new (FALSE, VSPACING);
70         gtk_widget_show (vbox);
71         gtk_container_set_border_width (GTK_CONTAINER (vbox), VBOX_BORDER);
72
73         /* new message */
74
75         quotefmt_create_new_msg_fmt_widgets(
76                                 window,
77                                 vbox,
78                                 &prefs_quote->checkbtn_compose_with_format,
79                                 _("New message format"),
80                                 &prefs_quote->entry_subject,
81                                 &prefs_quote->text_format,
82                                 FALSE);
83
84         /* reply */
85
86         quotefmt_create_reply_fmt_widgets(
87                                 window,
88                                 vbox,
89                                 NULL,
90                                 NULL,
91                                 &prefs_quote->entry_quotemark,
92                                 &prefs_quote->text_quotefmt,
93                                 FALSE);
94
95         /* forward */
96
97         quotefmt_create_forward_fmt_widgets(
98                                 window,
99                                 vbox,
100                                 NULL,
101                                 NULL,
102                                 &prefs_quote->entry_fw_quotemark,
103                                 &prefs_quote->text_fw_quotefmt,
104                                 FALSE);
105
106         /* info button */
107
108         quotefmt_add_info_button(window, vbox);
109
110         gtk_entry_set_text(GTK_ENTRY(prefs_quote->entry_quotemark), 
111                         prefs_common.quotemark?prefs_common.quotemark:"");
112         pref_set_textview_from_pref(GTK_TEXT_VIEW(prefs_quote->text_quotefmt),
113                         prefs_common.quotefmt);
114
115         pref_set_textview_from_pref(GTK_TEXT_VIEW(prefs_quote->text_fw_quotefmt),
116                         prefs_common.fw_quotefmt);
117         gtk_entry_set_text(GTK_ENTRY(prefs_quote->entry_fw_quotemark), 
118                         prefs_common.fw_quotemark?prefs_common.fw_quotemark:"");
119
120         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_quote->checkbtn_compose_with_format),
121                         prefs_common.compose_with_format);
122         pref_set_entry_from_pref(GTK_ENTRY(prefs_quote->entry_subject), prefs_common.compose_subject_format);
123         pref_set_textview_from_pref(GTK_TEXT_VIEW(prefs_quote->text_format), prefs_common.compose_body_format);
124
125         prefs_quote->window             = GTK_WIDGET(window);
126         prefs_quote->page.widget = vbox;
127 }
128
129 static void prefs_quote_save(PrefsPage *_page)
130 {
131         QuotePage *page = (QuotePage *) _page;
132         
133         g_free(prefs_common.compose_subject_format); 
134         prefs_common.compose_subject_format = NULL;
135         g_free(prefs_common.compose_body_format); 
136         prefs_common.compose_body_format = NULL;
137         g_free(prefs_common.quotefmt); 
138         prefs_common.quotefmt = NULL;
139         g_free(prefs_common.fw_quotefmt); 
140         prefs_common.fw_quotefmt = NULL;
141         g_free(prefs_common.quotemark); 
142         prefs_common.quotemark = NULL;
143         g_free(prefs_common.fw_quotemark); 
144         prefs_common.fw_quotemark = NULL;
145         g_free(prefs_common.quote_chars); 
146         prefs_common.quote_chars = NULL;
147         
148         prefs_common.compose_with_format =
149                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_compose_with_format));
150         prefs_common.compose_subject_format = pref_get_pref_from_entry(
151                         GTK_ENTRY(page->entry_subject));
152         prefs_common.compose_body_format = pref_get_pref_from_textview(
153                         GTK_TEXT_VIEW(page->text_format));
154         quotefmt_check_new_msg_formats(prefs_common.compose_with_format,
155                                                                         prefs_common.compose_subject_format,
156                                                                         prefs_common.compose_body_format);
157
158         prefs_common.quotefmt = pref_get_pref_from_textview(
159                         GTK_TEXT_VIEW(page->text_quotefmt));
160         quotefmt_check_reply_formats(TRUE, prefs_common.quotefmt);
161
162         prefs_common.fw_quotefmt = pref_get_pref_from_textview(
163                         GTK_TEXT_VIEW(page->text_fw_quotefmt));
164         quotefmt_check_forward_formats(TRUE, prefs_common.fw_quotefmt);
165
166         prefs_common.quotemark = gtk_editable_get_chars(
167                         GTK_EDITABLE(page->entry_quotemark), 0, -1);
168         prefs_common.fw_quotemark = gtk_editable_get_chars(
169                         GTK_EDITABLE(page->entry_fw_quotemark), 0, -1);
170 }
171
172 static void prefs_quote_destroy_widget(PrefsPage *_page)
173 {
174 }
175
176 QuotePage *prefs_quote;
177
178 void prefs_quote_init(void)
179 {
180         QuotePage *page;
181         static gchar *path[3];
182
183         path[0] = _("Compose");
184         path[1] = _("Templates");
185         path[2] = NULL;
186
187         page = g_new0(QuotePage, 1);
188         page->page.path = path;
189         page->page.create_widget = prefs_quote_create_widget;
190         page->page.destroy_widget = prefs_quote_destroy_widget;
191         page->page.save_page = prefs_quote_save;
192         page->page.weight = 185.0;
193         prefs_gtk_register_page((PrefsPage *) page);
194         prefs_quote = page;
195 }
196
197 void prefs_quote_done(void)
198 {
199         prefs_gtk_unregister_page((PrefsPage *) prefs_quote);
200         g_free(prefs_quote);
201 }