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 2 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, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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 *entry_quotemark;
52 GtkWidget *text_quotefmt;
53 GtkWidget *entry_fw_quotemark;
54 GtkWidget *text_fw_quotefmt;
55 GtkWidget *entry_quote_chars;
56 GtkWidget *label_quote_chars;
57 GtkWidget *btn_quotedesc;
58 GtkWidget *checkbtn_reply_with_quote;
61 static void prefs_quote_create_widget(PrefsPage *_page, GtkWindow *window,
64 QuotePage *prefs_quote = (QuotePage *) _page;
67 GtkWidget *frame_quote;
68 GtkWidget *vbox_quote;
71 GtkWidget *label_quotemark;
72 GtkWidget *entry_quotemark;
73 GtkWidget *scrolledwin_quotefmt;
74 GtkWidget *text_quotefmt;
76 GtkWidget *entry_fw_quotemark;
77 GtkWidget *text_fw_quotefmt;
79 GtkWidget *entry_quote_chars;
80 GtkWidget *label_quote_chars;
82 GtkWidget *btn_quotedesc;
84 GtkWidget *checkbtn_reply_with_quote;
86 vbox1 = gtk_vbox_new (FALSE, VSPACING);
87 gtk_widget_show (vbox1);
88 gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
92 PACK_CHECK_BUTTON (vbox1, checkbtn_reply_with_quote, _("Reply will quote by default"));
94 PACK_FRAME (vbox1, frame_quote, _("Reply format"));
96 vbox_quote = gtk_vbox_new (FALSE, VSPACING_NARROW);
97 gtk_widget_show (vbox_quote);
98 gtk_container_add (GTK_CONTAINER (frame_quote), vbox_quote);
99 gtk_container_set_border_width (GTK_CONTAINER (vbox_quote), 8);
101 hbox1 = gtk_hbox_new (FALSE, 32);
102 gtk_widget_show (hbox1);
103 gtk_box_pack_start (GTK_BOX (vbox_quote), hbox1, FALSE, FALSE, 0);
105 hbox2 = gtk_hbox_new (FALSE, 8);
106 gtk_widget_show (hbox2);
107 gtk_box_pack_start (GTK_BOX (hbox1), hbox2, FALSE, FALSE, 0);
109 label_quotemark = gtk_label_new (_("Quotation mark"));
110 gtk_widget_show (label_quotemark);
111 gtk_box_pack_start (GTK_BOX (hbox2), label_quotemark, FALSE, FALSE, 0);
113 entry_quotemark = gtk_entry_new ();
114 gtk_widget_show (entry_quotemark);
115 gtk_box_pack_start (GTK_BOX (hbox2), entry_quotemark, FALSE, FALSE, 0);
116 gtk_widget_set_size_request (entry_quotemark, 64, -1);
118 scrolledwin_quotefmt = gtk_scrolled_window_new (NULL, NULL);
119 gtk_widget_show (scrolledwin_quotefmt);
120 gtk_box_pack_start (GTK_BOX (vbox_quote), scrolledwin_quotefmt,
122 gtk_scrolled_window_set_policy
123 (GTK_SCROLLED_WINDOW (scrolledwin_quotefmt),
124 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
125 gtk_scrolled_window_set_shadow_type
126 (GTK_SCROLLED_WINDOW (scrolledwin_quotefmt), GTK_SHADOW_IN);
128 text_quotefmt = gtk_text_view_new ();
129 if (prefs_common.textfont) {
130 PangoFontDescription *font_desc;
132 font_desc = pango_font_description_from_string
133 (prefs_common.textfont);
135 gtk_widget_modify_font(text_quotefmt, font_desc);
136 pango_font_description_free(font_desc);
139 gtk_widget_show (text_quotefmt);
140 gtk_container_add(GTK_CONTAINER(scrolledwin_quotefmt), text_quotefmt);
141 gtk_text_view_set_editable (GTK_TEXT_VIEW (text_quotefmt), TRUE);
142 gtk_widget_set_size_request(text_quotefmt, -1, 100);
146 PACK_FRAME (vbox1, frame_quote, _("Forward format"));
148 vbox_quote = gtk_vbox_new (FALSE, VSPACING_NARROW);
149 gtk_widget_show (vbox_quote);
150 gtk_container_add (GTK_CONTAINER (frame_quote), vbox_quote);
151 gtk_container_set_border_width (GTK_CONTAINER (vbox_quote), 8);
153 hbox1 = gtk_hbox_new (FALSE, 32);
154 gtk_widget_show (hbox1);
155 gtk_box_pack_start (GTK_BOX (vbox_quote), hbox1, FALSE, FALSE, 0);
157 hbox2 = gtk_hbox_new (FALSE, 8);
158 gtk_widget_show (hbox2);
159 gtk_box_pack_start (GTK_BOX (hbox1), hbox2, FALSE, FALSE, 0);
161 label_quotemark = gtk_label_new (_("Quotation mark"));
162 gtk_widget_show (label_quotemark);
163 gtk_box_pack_start (GTK_BOX (hbox2), label_quotemark, FALSE, FALSE, 0);
165 entry_fw_quotemark = gtk_entry_new ();
166 gtk_widget_show (entry_fw_quotemark);
167 gtk_box_pack_start (GTK_BOX (hbox2), entry_fw_quotemark,
169 gtk_widget_set_size_request (entry_fw_quotemark, 64, -1);
171 scrolledwin_quotefmt = gtk_scrolled_window_new (NULL, NULL);
172 gtk_widget_show (scrolledwin_quotefmt);
173 gtk_box_pack_start (GTK_BOX (vbox_quote), scrolledwin_quotefmt,
175 gtk_scrolled_window_set_policy
176 (GTK_SCROLLED_WINDOW (scrolledwin_quotefmt),
177 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
178 gtk_scrolled_window_set_shadow_type
179 (GTK_SCROLLED_WINDOW (scrolledwin_quotefmt), GTK_SHADOW_IN);
181 text_fw_quotefmt = gtk_text_view_new ();
182 if (prefs_common.textfont) {
183 PangoFontDescription *font_desc;
185 font_desc = pango_font_description_from_string
186 (prefs_common.textfont);
188 gtk_widget_modify_font(text_fw_quotefmt, font_desc);
189 pango_font_description_free(font_desc);
192 gtk_widget_show (text_fw_quotefmt);
193 gtk_container_add(GTK_CONTAINER(scrolledwin_quotefmt),
195 gtk_text_view_set_editable (GTK_TEXT_VIEW (text_fw_quotefmt), TRUE);
196 gtk_widget_set_size_request (text_fw_quotefmt, -1, 100);
198 hbox1 = gtk_hbox_new (FALSE, 32);
199 gtk_widget_show (hbox1);
200 gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, FALSE, 0);
202 #if GTK_CHECK_VERSION(2, 8, 0)
203 btn_quotedesc = gtk_button_new_from_stock(GTK_STOCK_INFO);
206 gtk_button_new_with_label (_(" Description of symbols... "));
208 gtk_widget_show (btn_quotedesc);
209 gtk_box_pack_start (GTK_BOX (hbox1), btn_quotedesc, FALSE, FALSE, 0);
210 g_signal_connect(G_OBJECT(btn_quotedesc), "clicked",
211 G_CALLBACK(quote_fmt_quote_description), GTK_WIDGET(window));
215 PACK_FRAME (vbox1, frame_quote, _("Quotation characters"));
217 vbox_quote = gtk_vbox_new (FALSE, VSPACING_NARROW);
218 gtk_widget_show (vbox_quote);
219 gtk_container_add (GTK_CONTAINER (frame_quote), vbox_quote);
220 gtk_container_set_border_width (GTK_CONTAINER (vbox_quote), 8);
222 hbox1 = gtk_hbox_new (FALSE, 32);
223 gtk_widget_show (hbox1);
224 gtk_box_pack_start (GTK_BOX (vbox_quote), hbox1, FALSE, FALSE, 0);
226 hbox2 = gtk_hbox_new (FALSE, 8);
227 gtk_widget_show (hbox2);
228 gtk_box_pack_start (GTK_BOX (hbox1), hbox2, FALSE, FALSE, 0);
230 label_quote_chars = gtk_label_new (_("Treat these characters as quotation marks: "));
231 gtk_widget_show (label_quote_chars);
232 gtk_box_pack_start (GTK_BOX (hbox2), label_quote_chars, FALSE, FALSE, 0);
234 entry_quote_chars = gtk_entry_new ();
235 gtk_widget_show (entry_quote_chars);
236 gtk_box_pack_start (GTK_BOX (hbox2), entry_quote_chars,
238 gtk_widget_set_size_request (entry_quote_chars, 64, -1);
240 pref_set_textview_from_pref(GTK_TEXT_VIEW(text_quotefmt), prefs_common.quotefmt);
241 pref_set_textview_from_pref(GTK_TEXT_VIEW(text_fw_quotefmt), prefs_common.fw_quotefmt);
243 gtk_entry_set_text(GTK_ENTRY(entry_quotemark),
244 prefs_common.quotemark?prefs_common.quotemark:"");
245 gtk_entry_set_text(GTK_ENTRY(entry_fw_quotemark),
246 prefs_common.fw_quotemark?prefs_common.fw_quotemark:"");
247 gtk_entry_set_text(GTK_ENTRY(entry_quote_chars),
248 prefs_common.quote_chars?prefs_common.quote_chars:"");
249 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_reply_with_quote),
250 prefs_common.reply_with_quote);
252 prefs_quote->window = GTK_WIDGET(window);
253 prefs_quote->text_quotefmt = text_quotefmt;
254 prefs_quote->text_fw_quotefmt = text_fw_quotefmt;
255 prefs_quote->entry_quotemark = entry_quotemark;
256 prefs_quote->entry_fw_quotemark = entry_fw_quotemark;
257 prefs_quote->entry_quote_chars = entry_quote_chars;
258 prefs_quote->checkbtn_reply_with_quote
259 = checkbtn_reply_with_quote;
260 prefs_quote->page.widget = vbox1;
263 static void prefs_quote_save(PrefsPage *_page)
265 QuotePage *page = (QuotePage *) _page;
268 g_free(prefs_common.quotefmt);
269 prefs_common.quotefmt = NULL;
270 g_free(prefs_common.fw_quotefmt);
271 prefs_common.fw_quotefmt = NULL;
272 g_free(prefs_common.quotemark);
273 prefs_common.quotemark = NULL;
274 g_free(prefs_common.fw_quotemark);
275 prefs_common.fw_quotemark = NULL;
276 g_free(prefs_common.quote_chars);
277 prefs_common.quote_chars = NULL;
279 prefs_common.quotefmt = pref_get_pref_from_textview(
280 GTK_TEXT_VIEW(page->text_quotefmt));
281 if (!prefs_template_string_is_valid(prefs_common.quotefmt, &line)) {
282 gchar *msg = g_strdup_printf(_("Message reply format error at line %d."), line);
283 alertpanel_error(msg);
287 prefs_common.fw_quotefmt = pref_get_pref_from_textview(
288 GTK_TEXT_VIEW(page->text_fw_quotefmt));
289 if (!prefs_template_string_is_valid(prefs_common.fw_quotefmt, &line)) {
290 gchar *msg = g_strdup_printf(_("Message forward format error at line %d."), line);
291 alertpanel_error(msg);
295 prefs_common.quotemark = gtk_editable_get_chars(
296 GTK_EDITABLE(page->entry_quotemark), 0, -1);
297 prefs_common.fw_quotemark = gtk_editable_get_chars(
298 GTK_EDITABLE(page->entry_fw_quotemark), 0, -1);
299 prefs_common.quote_chars = gtk_editable_get_chars(
300 GTK_EDITABLE(page->entry_quote_chars), 0, -1);
301 prefs_common.reply_with_quote = gtk_toggle_button_get_active(
302 GTK_TOGGLE_BUTTON(page->checkbtn_reply_with_quote));
304 remove_space(prefs_common.quote_chars);
307 static void prefs_quote_destroy_widget(PrefsPage *_page)
311 QuotePage *prefs_quote;
313 void prefs_quote_init(void)
316 static gchar *path[3];
318 path[0] = _("Compose");
319 path[1] = _("Quoting");
322 page = g_new0(QuotePage, 1);
323 page->page.path = path;
324 page->page.create_widget = prefs_quote_create_widget;
325 page->page.destroy_widget = prefs_quote_destroy_widget;
326 page->page.save_page = prefs_quote_save;
327 page->page.weight = 185.0;
328 prefs_gtk_register_page((PrefsPage *) page);
332 void prefs_quote_done(void)
334 prefs_gtk_unregister_page((PrefsPage *) prefs_quote);