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
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.
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.
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/>.
30 #include <glib/gi18n.h>
32 #include <gdk/gdkkeysyms.h>
34 #include "prefs_common.h"
35 #include "prefs_gtk.h"
36 #include "prefs_template.h"
37 #include "alertpanel.h"
39 #include "gtk/gtkutils.h"
40 #include "gtk/prefswindow.h"
42 #include "manage_window.h"
43 #include "quote_fmt.h"
45 typedef struct _QuotePage
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;
61 QuotePage *prefs_quote;
63 static void prefs_quote_set_default_new_msg_fmt(void)
65 g_return_if_fail(prefs_quote->text_format != NULL);
67 pref_set_textview_from_pref(GTK_TEXT_VIEW(prefs_quote->text_format),
71 static void prefs_quote_set_default_reply_fmt(void)
73 g_return_if_fail(prefs_quote->text_quotefmt != NULL);
75 pref_set_textview_from_pref(GTK_TEXT_VIEW(prefs_quote->text_quotefmt),
76 _("On %d\\n%f wrote:\\n\\n%q"));
79 static void prefs_quote_set_default_forward_fmt(void)
81 g_return_if_fail(prefs_quote->text_fw_quotefmt != NULL);
83 pref_set_textview_from_pref(GTK_TEXT_VIEW(prefs_quote->text_fw_quotefmt),
84 _("\\n\\nBegin forwarded message:\\n\\n"
85 "?d{Date: %d\\n}?f{From: %f\\n}?t{To: %t\\n}?c{Cc: %c\\n}"
86 "?n{Newsgroups: %n\\n}?s{Subject: %s\\n}\\n\\n%M"));
89 static void prefs_quote_create_widget(PrefsPage *_page, GtkWindow *window,
92 QuotePage *prefs_quote = (QuotePage *) _page;
98 vbox = gtk_vbox_new (FALSE, 0);
99 gtk_widget_show (vbox);
101 notebook = gtk_notebook_new();
102 gtk_widget_show(notebook);
103 gtk_notebook_set_homogeneous_tabs(GTK_NOTEBOOK(notebook), TRUE);
104 gtk_box_pack_start(GTK_BOX(vbox), notebook, TRUE, TRUE, 0);
107 vbox2 = gtk_vbox_new (FALSE, VSPACING);
108 gtk_widget_show (vbox2);
109 gtk_container_set_border_width (GTK_CONTAINER (vbox2), VBOX_BORDER);
111 quotefmt_create_new_msg_fmt_widgets(
114 &prefs_quote->checkbtn_compose_with_format,
116 &prefs_quote->entry_subject,
117 &prefs_quote->text_format,
118 FALSE, prefs_quote_set_default_new_msg_fmt);
119 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox2, gtk_label_new(_("Compose")));
122 vbox2 = gtk_vbox_new (FALSE, VSPACING);
123 gtk_widget_show (vbox2);
124 gtk_container_set_border_width (GTK_CONTAINER (vbox2), VBOX_BORDER);
126 quotefmt_create_reply_fmt_widgets(
131 &prefs_quote->entry_quotemark,
132 &prefs_quote->text_quotefmt,
133 FALSE, prefs_quote_set_default_reply_fmt);
134 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox2, gtk_label_new(_("Reply")));
137 vbox2 = gtk_vbox_new (FALSE, VSPACING);
138 gtk_widget_show (vbox2);
139 gtk_container_set_border_width (GTK_CONTAINER (vbox2), VBOX_BORDER);
141 quotefmt_create_forward_fmt_widgets(
146 &prefs_quote->entry_fw_quotemark,
147 &prefs_quote->text_fw_quotefmt,
148 FALSE, prefs_quote_set_default_forward_fmt);
149 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox2, gtk_label_new(_("Forward")));
152 quotefmt_add_info_button(window, vbox);
154 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_quote->checkbtn_compose_with_format),
155 prefs_common.compose_with_format);
156 pref_set_entry_from_pref(GTK_ENTRY(prefs_quote->entry_subject),
157 prefs_common.compose_subject_format);
158 if (prefs_common.compose_body_format)
159 pref_set_textview_from_pref(GTK_TEXT_VIEW(prefs_quote->text_format),
160 prefs_common.compose_body_format);
162 prefs_quote_set_default_new_msg_fmt();
164 gtk_entry_set_text(GTK_ENTRY(prefs_quote->entry_quotemark),
165 prefs_common.quotemark?prefs_common.quotemark:"");
166 if (prefs_common.quotefmt)
167 pref_set_textview_from_pref(GTK_TEXT_VIEW(prefs_quote->text_quotefmt),
168 prefs_common.quotefmt);
170 prefs_quote_set_default_reply_fmt();
172 gtk_entry_set_text(GTK_ENTRY(prefs_quote->entry_fw_quotemark),
173 prefs_common.fw_quotemark?prefs_common.fw_quotemark:"");
174 if (prefs_common.fw_quotefmt)
175 pref_set_textview_from_pref(GTK_TEXT_VIEW(prefs_quote->text_fw_quotefmt),
176 prefs_common.fw_quotefmt);
178 prefs_quote_set_default_forward_fmt();
180 prefs_quote->window = GTK_WIDGET(window);
181 prefs_quote->page.widget = vbox;
184 static void prefs_quote_save(PrefsPage *_page)
186 QuotePage *page = (QuotePage *) _page;
188 g_free(prefs_common.compose_subject_format);
189 prefs_common.compose_subject_format = NULL;
190 g_free(prefs_common.compose_body_format);
191 prefs_common.compose_body_format = NULL;
192 g_free(prefs_common.quotefmt);
193 prefs_common.quotefmt = NULL;
194 g_free(prefs_common.fw_quotefmt);
195 prefs_common.fw_quotefmt = NULL;
196 g_free(prefs_common.quotemark);
197 prefs_common.quotemark = NULL;
198 g_free(prefs_common.fw_quotemark);
199 prefs_common.fw_quotemark = NULL;
201 prefs_common.compose_with_format =
202 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_compose_with_format));
203 prefs_common.compose_subject_format = pref_get_pref_from_entry(
204 GTK_ENTRY(page->entry_subject));
205 prefs_common.compose_body_format = pref_get_pref_from_textview(
206 GTK_TEXT_VIEW(page->text_format));
207 quotefmt_check_new_msg_formats(prefs_common.compose_with_format,
209 prefs_common.compose_subject_format,
210 prefs_common.compose_body_format);
212 prefs_common.quotemark = gtk_editable_get_chars(
213 GTK_EDITABLE(page->entry_quotemark), 0, -1);
214 prefs_common.quotefmt = pref_get_pref_from_textview(
215 GTK_TEXT_VIEW(page->text_quotefmt));
216 quotefmt_check_reply_formats(TRUE,
218 prefs_common.quotemark,
219 prefs_common.quotefmt);
221 prefs_common.fw_quotemark = gtk_editable_get_chars(
222 GTK_EDITABLE(page->entry_fw_quotemark), 0, -1);
223 prefs_common.fw_quotefmt = pref_get_pref_from_textview(
224 GTK_TEXT_VIEW(page->text_fw_quotefmt));
225 quotefmt_check_forward_formats(TRUE,
227 prefs_common.fw_quotemark,
228 prefs_common.fw_quotefmt);
231 static void prefs_quote_destroy_widget(PrefsPage *_page)
235 void prefs_quote_init(void)
238 static gchar *path[3];
240 path[0] = _("Compose");
241 path[1] = _("Templates");
244 page = g_new0(QuotePage, 1);
245 page->page.path = path;
246 page->page.create_widget = prefs_quote_create_widget;
247 page->page.destroy_widget = prefs_quote_destroy_widget;
248 page->page.save_page = prefs_quote_save;
249 page->page.weight = 185.0;
250 prefs_gtk_register_page((PrefsPage *) page);
254 void prefs_quote_done(void)
256 prefs_gtk_unregister_page((PrefsPage *) prefs_quote);