better fix for bug 4819
[claws.git] / src / quote_fmt.c
blob9d610e99db34de86cf5d744befb40eef018c32e7
1 /*
2 * Claws Mail -- a GTK based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2021 the Claws Mail team and Hiroyuki Yamamoto
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/>.
19 #ifdef HAVE_CONFIG_H
20 # include "config.h"
21 #include "claws-features.h"
22 #endif
24 #include <glib.h>
25 #include <glib/gi18n.h>
26 #include <gtk/gtk.h>
27 #include <gdk/gdkkeysyms.h>
29 #include "manage_window.h"
30 #include "description_window.h"
31 #include "gtkutils.h"
33 #include "prefs_gtk.h"
34 #include "prefs_common.h"
35 #include "quote_fmt.h"
36 #include "alertpanel.h"
37 #include "prefs_template.h"
41 * Strings describing quote format strings
43 * When adding new lines, remember to put 2 strings for each line
45 static gchar *quote_desc_strings[] = {
46 N_("<span weight=\"bold\">symbols:</span>"), NULL,
47 "%date_fmt{<span style=\"oblique\">fmt</span>} (%D{<span style=\"oblique\">fmt</span>})", N_("customized date format (see 'man strftime')"), /* date expression */
48 "%date (%d)", N_("Date"), /* date */
49 "%from (%f)", N_("From"), /* from */
50 "%email (%A)", N_("email address of sender"), /* email address */
51 "%fullname (%N)", N_("full name of sender"), /* full name */
52 "%firstname (%F)", N_("first name of sender"), /* first name */
53 "%lastname (%L)", N_("last name of sender"), /* last name */
54 "%initials (%I)", N_("initials of sender"), /* initial of sender */
55 "%subject (%s)", N_("Subject"), /* subject */
56 "%to (%t)", N_("To"), /* to */
57 "%cc (%c)", N_("Cc"), /* cc */
58 "%newsgroups (%n)", N_("Newsgroups"), /* newsgroups */
59 "%references (%r)", N_("References"), /* references */
60 "%messageid (%i)", N_("Message-ID"), /* message-id */
61 "%msg (%M)", N_("message body"), /* message */
62 "%quoted_msg (%Q)", N_("quoted message body"), /* quoted message */
63 "%msg_no_sig (%m)", N_("message body without signature"), /* message with no signature */
64 "%quoted_msg_no_sig (%q)", N_("quoted message body without signature"), /* quoted message with no signature */
65 "%tags", N_("message tags"), /* message tags */
66 "%dict (%T)", N_("current dictionary"), /* current dictionary */
67 "%cursor (%X)", N_("cursor position"), /* X marks the cursor spot */
68 "%account_fullname (%af)", N_("account property: your name"), /* full name in compose account */
69 "%account_email (%am)", N_("account property: your email address"), /* mail address in compose account */
70 "%account_name (%an)", N_("account property: account name"), /* compose account name itself */
71 "%account_org (%ao)", N_("account property: organization"), /* organization in compose account */
72 "%account_sig (%as)", N_("account property: signature"), /* signature set in account prefs */
73 "%account_sigpath (%asp)", N_("account property: signature path"), /* signature path set in account prefs */
74 "%account_dict (%aT)", N_("account property: default dictionary"), /* main dict (if enabled) in account */
75 "%addrbook_cc (%ABc)", N_("address book <span style=\"oblique\">completion</span>: Cc"), /* completion of 'Cc' from address book */
76 "%addrbook_from (%ABf)", N_("address book <span style=\"oblique\">completion</span>: From"), /* completion of 'From' from address book */
77 "%addrbook_to (%ABt)", N_("address book <span style=\"oblique\">completion</span>: To"), /* completion of 'To' from address book */
78 "\\%", N_("literal %"),
79 "\\\\", N_("literal backslash"),
80 "\\?", N_("literal question mark"),
81 "\\!", N_("literal exclamation mark"),
82 "\\|", N_("literal pipe"),
83 "\\{", N_("literal opening curly brace"),
84 "\\}", N_("literal closing curly brace"),
85 "\\t", N_("tab"),
86 "\\n", N_("new line"),
87 "", NULL,
88 N_("<span weight=\"bold\">commands:</span>"), NULL,
89 "?x{<span style=\"oblique\">expr</span>}\n\n", N_("insert <span style=\"oblique\">expr</span> if x is set, where x is one of\nthe [dfNFLIstcnriT, ad, af, ao, as, asp, aT, ABc, ABf, ABt]\nsymbols (or their long equivalent)"),
90 "!x{<span style=\"oblique\">expr</span>}\n\n", N_("insert <span style=\"oblique\">expr</span> if x is not set, where x is one of\nthe [dfNFLIstcnriT, ad, af, ao, as, asp, aT, ABc, ABf, ABt]\nsymbols (or their long equivalent)"),
91 "|file{<span style=\"oblique\">sub_expr</span>}\n(|f{<span style=\"oblique\">sub_expr</span>})", N_("insert file:\n<span style=\"oblique\">sub_expr</span> is evaluated as the path of the file to insert"), /* insert file */
92 "|program{<span style=\"oblique\">sub_expr</span>}\n(|p{<span style=\"oblique\">sub_expr</span>})\n", N_("insert program output:\n<span style=\"oblique\">sub_expr</span> is evaluated as a command-line to get\nthe output from"), /* insert program output */
93 "|input{<span style=\"oblique\">sub_expr</span>}\n(|i{<span style=\"oblique\">sub_expr</span>})\n", N_("insert user input:\n<span style=\"oblique\">sub_expr</span> is a variable to be replaced by\nuser-entered text"), /* insert user input */
94 "|attach{<span style=\"oblique\">sub_expr</span>}\n(|a{<span style=\"oblique\">sub_expr</span>})", N_("attach file:\n<span style=\"oblique\">sub_expr</span> is evaluated as the path of the file to attach"), /* attach file */
95 "|attach_program{<span style=\"oblique\">sub_expr</span>}\n(|A{<span style=\"oblique\">sub_expr</span>})", N_("attach file:\n<span style=\"oblique\">sub_expr</span> is evaluated as a command-line to get\nthe filename from"), /* attach file whose name's got from program output */
96 "", NULL,
97 N_("<span weight=\"bold\">definition of terms:</span>"), NULL,
98 "<span style=\"oblique\">expr</span>\n", N_("text that can contain any of the symbols or\ncommands above"),
99 "<span style=\"oblique\">sub_expr</span>\n", N_("text that can contain any of the symbols (no\ncommands) above"),
100 "<span style=\"oblique\">completion</span>\n\n\n", N_("completion from address book only works with the first\naddress of the header, it outputs the full name\nof the contact if that address matches exactly\none contact in the address book"),
101 NULL,NULL
104 static DescriptionWindow quote_desc_win = {
105 NULL,
106 NULL,
107 TRUE,
109 N_("Description of symbols"),
110 N_("The following symbols and commands can be used:"),
111 quote_desc_strings
115 void quote_fmt_quote_description(GtkWidget *widget, GtkWidget *pref_window)
117 quote_desc_win.parent = pref_window;
118 description_window_create(&quote_desc_win);
121 static void quote_fmt_add_buttons(GtkWindow* parent_window, GtkWidget *parent_box,
122 gboolean add_info_button, void(*set_defaults_func)(void)) {
123 GtkWidget *hbox_btns;
125 if (!add_info_button && !set_defaults_func)
126 return;
128 hbox_btns = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
129 gtk_box_pack_end (GTK_BOX(parent_box), hbox_btns, FALSE, TRUE, 0);
131 if (add_info_button)
132 quotefmt_add_info_button(parent_window, hbox_btns);
133 if (set_defaults_func)
134 quotefmt_add_defaults_button(parent_window, hbox_btns, set_defaults_func);
136 gtk_widget_show(GTK_WIDGET(hbox_btns));
139 void quotefmt_create_new_msg_fmt_widgets(GtkWindow *parent_window,
140 GtkWidget *parent_box,
141 GtkWidget **checkbtn_compose_with_format,
142 GtkWidget **override_from_format,
143 GtkWidget **edit_subject_format,
144 GtkWidget **edit_body_format,
145 gboolean add_info_button,
146 void(*set_defaults_func)(void))
148 GtkWidget *checkbtn_use_format = NULL;
149 GtkWidget *vbox_format;
150 GtkWidget *hbox_format;
151 GtkWidget *hbox2_format;
152 GtkWidget *label_from = NULL;
153 GtkWidget *entry_from = NULL;
154 GtkWidget *label_subject;
155 GtkWidget *entry_subject;
156 GtkWidget *scrolledwin_format;
157 GtkWidget *text_format;
158 GtkSizeGroup *size_group;
160 if (add_info_button)
161 cm_return_if_fail(parent_window != NULL);
162 cm_return_if_fail(parent_box != NULL);
163 if (checkbtn_compose_with_format)
164 cm_return_if_fail(checkbtn_compose_with_format != NULL);
166 cm_return_if_fail(edit_subject_format != NULL);
167 cm_return_if_fail(edit_body_format != NULL);
169 size_group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
171 if (checkbtn_compose_with_format)
172 PACK_CHECK_BUTTON (parent_box, checkbtn_use_format,
173 _("Use template when composing new messages"));
175 vbox_format = gtk_box_new(GTK_ORIENTATION_VERTICAL, 4);
176 gtk_widget_show(vbox_format);
177 gtk_container_add(GTK_CONTAINER (parent_box), vbox_format);
178 gtk_container_set_border_width (GTK_CONTAINER (vbox_format), 8);
180 if (override_from_format) {
181 hbox2_format = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
182 gtk_widget_show (hbox2_format);
183 gtk_box_pack_start (GTK_BOX (vbox_format), hbox2_format, FALSE, FALSE, 0);
185 label_from = gtk_label_new (prefs_common_translated_header_name("From"));
186 gtk_label_set_xalign(GTK_LABEL(label_from), 1.0);
187 gtk_widget_show (label_from);
188 gtk_box_pack_start (GTK_BOX (hbox2_format), label_from, FALSE, FALSE, 0);
189 gtk_size_group_add_widget(size_group, label_from);
191 entry_from = gtk_entry_new ();
192 gtk_widget_show (entry_from);
193 gtk_box_pack_start (GTK_BOX (hbox2_format), entry_from, TRUE, TRUE, 0);
195 CLAWS_SET_TIP(entry_from,
196 _("Override From header. This doesn't change the account used to compose the new message."));
199 hbox_format = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
200 gtk_widget_show (hbox_format);
201 gtk_box_pack_start (GTK_BOX (vbox_format), hbox_format, FALSE, FALSE, 0);
203 label_subject = gtk_label_new (prefs_common_translated_header_name("Subject"));
204 gtk_label_set_xalign(GTK_LABEL(label_subject), 1.0);
205 gtk_widget_show (label_subject);
206 gtk_box_pack_start (GTK_BOX (hbox_format), label_subject, FALSE, FALSE, 0);
207 gtk_size_group_add_widget(size_group, label_subject);
209 entry_subject = gtk_entry_new ();
210 gtk_widget_show (entry_subject);
211 gtk_box_pack_start (GTK_BOX (hbox_format), entry_subject, TRUE, TRUE, 0);
213 scrolledwin_format = gtk_scrolled_window_new (NULL, NULL);
214 gtk_widget_show (scrolledwin_format);
215 gtk_box_pack_start (GTK_BOX (vbox_format), scrolledwin_format,
216 TRUE, TRUE, 0);
217 gtk_scrolled_window_set_policy
218 (GTK_SCROLLED_WINDOW (scrolledwin_format),
219 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
220 gtk_scrolled_window_set_shadow_type
221 (GTK_SCROLLED_WINDOW (scrolledwin_format), GTK_SHADOW_IN);
222 gtk_scrolled_window_set_min_content_height(GTK_SCROLLED_WINDOW(scrolledwin_format), 260);
224 text_format = gtk_text_view_new ();
225 if (prefs_common.textfont) {
226 PangoFontDescription *font_desc;
228 font_desc = pango_font_description_from_string
229 (prefs_common.textfont);
230 if (font_desc) {
231 gtk_widget_override_font(text_format, font_desc);
232 pango_font_description_free(font_desc);
235 gtk_widget_show(text_format);
236 gtk_container_add(GTK_CONTAINER(scrolledwin_format), text_format);
237 gtk_text_view_set_editable (GTK_TEXT_VIEW (text_format), TRUE);
239 if (checkbtn_compose_with_format) {
240 SET_TOGGLE_SENSITIVITY(checkbtn_use_format, label_subject);
241 if (override_from_format) {
242 SET_TOGGLE_SENSITIVITY(checkbtn_use_format, entry_from);
243 SET_TOGGLE_SENSITIVITY(checkbtn_use_format, label_from);
245 SET_TOGGLE_SENSITIVITY(checkbtn_use_format, entry_subject);
246 SET_TOGGLE_SENSITIVITY(checkbtn_use_format, text_format);
249 quote_fmt_add_buttons(parent_window, vbox_format,
250 add_info_button, set_defaults_func);
252 if (checkbtn_compose_with_format)
253 *checkbtn_compose_with_format = checkbtn_use_format;
254 if (override_from_format)
255 *override_from_format = entry_from;
256 *edit_subject_format = entry_subject;
257 *edit_body_format = text_format;
259 g_object_unref(G_OBJECT(size_group));
262 void quotefmt_create_reply_fmt_widgets(GtkWindow *parent_window,
263 GtkWidget *parent_box,
264 GtkWidget **checkbtn_reply_with_format,
265 GtkWidget **override_from_format,
266 GtkWidget **edit_reply_quotemark,
267 GtkWidget **edit_reply_format,
268 gboolean add_info_button,
269 void(*set_defaults_func)(void))
271 GtkWidget *checkbtn_use_format = NULL;
272 GtkWidget *vbox_quote;
273 GtkWidget *hbox1;
274 GtkWidget *hbox2;
275 GtkWidget *hbox3;
276 GtkWidget *label_quotemark;
277 GtkWidget *entry_quotemark;
278 GtkWidget *label_from = NULL;
279 GtkWidget *entry_from = NULL;
280 GtkWidget *scrolledwin_quotefmt;
281 GtkWidget *text_quotefmt;
282 GtkSizeGroup *size_group;
284 if (add_info_button)
285 cm_return_if_fail(parent_window != NULL);
286 cm_return_if_fail(parent_box != NULL);
287 if (checkbtn_reply_with_format)
288 cm_return_if_fail(checkbtn_reply_with_format != NULL);
290 cm_return_if_fail(edit_reply_quotemark != NULL);
291 cm_return_if_fail(edit_reply_format != NULL);
293 size_group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
295 if (checkbtn_reply_with_format)
296 PACK_CHECK_BUTTON (parent_box, checkbtn_use_format,
297 _("Use template when replying to messages"));
299 vbox_quote = gtk_box_new(GTK_ORIENTATION_VERTICAL, 4);
300 gtk_widget_show(vbox_quote);
301 gtk_container_add(GTK_CONTAINER (parent_box), vbox_quote);
302 gtk_container_set_border_width (GTK_CONTAINER (vbox_quote), 8);
304 if (override_from_format) {
305 hbox3 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
306 gtk_widget_show (hbox3);
307 gtk_box_pack_start (GTK_BOX (vbox_quote), hbox3, FALSE, FALSE, 0);
309 label_from = gtk_label_new (prefs_common_translated_header_name("From:"));
310 gtk_label_set_xalign(GTK_LABEL(label_from), 1.0);
311 gtk_widget_show (label_from);
312 gtk_box_pack_start (GTK_BOX (hbox3), label_from, FALSE, FALSE, 0);
313 gtk_size_group_add_widget(size_group, label_from);
315 entry_from = gtk_entry_new ();
316 gtk_widget_show (entry_from);
317 gtk_box_pack_start (GTK_BOX (hbox3), entry_from, TRUE, TRUE, 0);
319 CLAWS_SET_TIP(entry_from,
320 _("Override From header. This doesn't change the account used to reply."));
323 hbox1 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 32);
324 gtk_widget_show (hbox1);
325 gtk_box_pack_start (GTK_BOX (vbox_quote), hbox1, FALSE, FALSE, 0);
327 hbox2 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
328 gtk_widget_show (hbox2);
329 gtk_box_pack_start (GTK_BOX (hbox1), hbox2, FALSE, FALSE, 0);
331 label_quotemark = gtk_label_new (_("Quotation mark"));
332 gtk_label_set_xalign(GTK_LABEL(label_quotemark), 1.0);
333 gtk_widget_show (label_quotemark);
334 gtk_box_pack_start (GTK_BOX (hbox2), label_quotemark, FALSE, FALSE, 0);
335 gtk_size_group_add_widget(size_group, label_quotemark);
337 entry_quotemark = gtk_entry_new ();
338 gtk_widget_show (entry_quotemark);
339 gtk_box_pack_start (GTK_BOX (hbox2), entry_quotemark, FALSE, FALSE, 0);
340 gtk_widget_set_size_request (entry_quotemark, 64, -1);
342 scrolledwin_quotefmt = gtk_scrolled_window_new (NULL, NULL);
343 gtk_widget_show (scrolledwin_quotefmt);
344 gtk_box_pack_start (GTK_BOX (vbox_quote), scrolledwin_quotefmt,
345 TRUE, TRUE, 0);
346 gtk_scrolled_window_set_policy
347 (GTK_SCROLLED_WINDOW (scrolledwin_quotefmt),
348 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
349 gtk_scrolled_window_set_shadow_type
350 (GTK_SCROLLED_WINDOW (scrolledwin_quotefmt), GTK_SHADOW_IN);
351 gtk_scrolled_window_set_min_content_height(GTK_SCROLLED_WINDOW(scrolledwin_quotefmt), 260);
353 text_quotefmt = gtk_text_view_new ();
354 if (prefs_common.textfont) {
355 PangoFontDescription *font_desc;
357 font_desc = pango_font_description_from_string
358 (prefs_common.textfont);
359 if (font_desc) {
360 gtk_widget_override_font(text_quotefmt, font_desc);
361 pango_font_description_free(font_desc);
364 gtk_widget_show(text_quotefmt);
365 gtk_container_add(GTK_CONTAINER(scrolledwin_quotefmt), text_quotefmt);
366 gtk_text_view_set_editable (GTK_TEXT_VIEW (text_quotefmt), TRUE);
368 if (checkbtn_reply_with_format) {
369 SET_TOGGLE_SENSITIVITY(checkbtn_use_format, label_quotemark);
370 SET_TOGGLE_SENSITIVITY(checkbtn_use_format, entry_quotemark);
371 if (override_from_format) {
372 SET_TOGGLE_SENSITIVITY(checkbtn_use_format, entry_from);
373 SET_TOGGLE_SENSITIVITY(checkbtn_use_format, label_from);
375 SET_TOGGLE_SENSITIVITY(checkbtn_use_format, text_quotefmt);
378 quote_fmt_add_buttons(parent_window, vbox_quote,
379 add_info_button, set_defaults_func);
381 if (checkbtn_reply_with_format)
382 *checkbtn_reply_with_format = checkbtn_use_format;
383 *edit_reply_quotemark = entry_quotemark;
384 if (override_from_format)
385 *override_from_format = entry_from;
386 *edit_reply_format = text_quotefmt;
388 g_object_unref(G_OBJECT(size_group));
391 void quotefmt_create_forward_fmt_widgets(GtkWindow *parent_window,
392 GtkWidget *parent_box,
393 GtkWidget **checkbtn_forward_with_format,
394 GtkWidget **override_from_format,
395 GtkWidget **edit_fw_quotemark,
396 GtkWidget **edit_fw_format,
397 gboolean add_info_button,
398 void(*set_defaults_func)(void))
400 GtkWidget *checkbtn_use_format = NULL;
401 GtkWidget *vbox_quote;
402 GtkWidget *hbox1;
403 GtkWidget *hbox2;
404 GtkWidget *hbox3;
405 GtkWidget *label_quotemark;
406 GtkWidget *entry_fw_quotemark;
407 GtkWidget *label_from = NULL;
408 GtkWidget *entry_from = NULL;
409 GtkWidget *scrolledwin_quotefmt;
410 GtkWidget *text_fw_quotefmt;
411 GtkSizeGroup *size_group;
413 if (add_info_button)
414 cm_return_if_fail(parent_window != NULL);
415 cm_return_if_fail(parent_box != NULL);
416 if (checkbtn_forward_with_format) {
417 cm_return_if_fail(checkbtn_forward_with_format != NULL);
419 cm_return_if_fail(edit_fw_quotemark != NULL);
420 cm_return_if_fail(edit_fw_format != NULL);
422 size_group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
424 if (checkbtn_forward_with_format)
425 PACK_CHECK_BUTTON (parent_box, checkbtn_use_format,
426 _("Use template when forwarding messages"));
428 vbox_quote = gtk_box_new(GTK_ORIENTATION_VERTICAL, 4);
429 gtk_widget_show(vbox_quote);
430 gtk_container_add(GTK_CONTAINER (parent_box), vbox_quote);
431 gtk_container_set_border_width (GTK_CONTAINER (vbox_quote), 8);
433 if (override_from_format) {
434 hbox3 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
435 gtk_widget_show (hbox3);
436 gtk_box_pack_start (GTK_BOX (vbox_quote), hbox3, FALSE, FALSE, 0);
438 label_from = gtk_label_new (prefs_common_translated_header_name("From:"));
439 gtk_label_set_xalign(GTK_LABEL(label_from), 1.0);
440 gtk_widget_show (label_from);
441 gtk_box_pack_start (GTK_BOX (hbox3), label_from, FALSE, FALSE, 0);
442 gtk_size_group_add_widget(size_group, label_from);
444 entry_from = gtk_entry_new ();
445 gtk_widget_show (entry_from);
446 gtk_box_pack_start (GTK_BOX (hbox3), entry_from, TRUE, TRUE, 0);
448 CLAWS_SET_TIP(entry_from,
449 _("Override From header. This doesn't change the account used to forward."));
452 hbox1 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 32);
453 gtk_widget_show (hbox1);
454 gtk_box_pack_start (GTK_BOX (vbox_quote), hbox1, FALSE, FALSE, 0);
456 hbox2 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
457 gtk_widget_show (hbox2);
458 gtk_box_pack_start (GTK_BOX (hbox1), hbox2, FALSE, FALSE, 0);
460 label_quotemark = gtk_label_new (_("Quotation mark"));
461 gtk_label_set_xalign(GTK_LABEL(label_quotemark), 1.0);
462 gtk_widget_show (label_quotemark);
463 gtk_box_pack_start (GTK_BOX (hbox2), label_quotemark, FALSE, FALSE, 0);
464 gtk_size_group_add_widget(size_group, label_quotemark);
466 entry_fw_quotemark = gtk_entry_new ();
467 gtk_widget_show (entry_fw_quotemark);
468 gtk_box_pack_start (GTK_BOX (hbox2), entry_fw_quotemark,
469 FALSE, FALSE, 0);
470 gtk_widget_set_size_request (entry_fw_quotemark, 64, -1);
472 scrolledwin_quotefmt = gtk_scrolled_window_new (NULL, NULL);
473 gtk_widget_show (scrolledwin_quotefmt);
474 gtk_box_pack_start (GTK_BOX (vbox_quote), scrolledwin_quotefmt,
475 TRUE, TRUE, 0);
476 gtk_scrolled_window_set_policy
477 (GTK_SCROLLED_WINDOW (scrolledwin_quotefmt),
478 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
479 gtk_scrolled_window_set_shadow_type
480 (GTK_SCROLLED_WINDOW (scrolledwin_quotefmt), GTK_SHADOW_IN);
481 gtk_scrolled_window_set_min_content_height(GTK_SCROLLED_WINDOW(scrolledwin_quotefmt), 260);
483 text_fw_quotefmt = gtk_text_view_new ();
484 if (prefs_common.textfont) {
485 PangoFontDescription *font_desc;
487 font_desc = pango_font_description_from_string
488 (prefs_common.textfont);
489 if (font_desc) {
490 gtk_widget_override_font(text_fw_quotefmt, font_desc);
491 pango_font_description_free(font_desc);
494 gtk_widget_show(text_fw_quotefmt);
495 gtk_container_add(GTK_CONTAINER(scrolledwin_quotefmt),
496 text_fw_quotefmt);
497 gtk_text_view_set_editable (GTK_TEXT_VIEW (text_fw_quotefmt), TRUE);
499 if (checkbtn_forward_with_format) {
500 SET_TOGGLE_SENSITIVITY(checkbtn_use_format, label_quotemark);
501 SET_TOGGLE_SENSITIVITY(checkbtn_use_format, entry_fw_quotemark);
502 if (override_from_format) {
503 SET_TOGGLE_SENSITIVITY(checkbtn_use_format, entry_from);
504 SET_TOGGLE_SENSITIVITY(checkbtn_use_format, label_from);
506 SET_TOGGLE_SENSITIVITY(checkbtn_use_format, text_fw_quotefmt);
509 quote_fmt_add_buttons(parent_window, vbox_quote,
510 add_info_button, set_defaults_func);
512 if (checkbtn_forward_with_format)
513 *checkbtn_forward_with_format = checkbtn_use_format;
514 *edit_fw_quotemark = entry_fw_quotemark;
515 if (override_from_format)
516 *override_from_format = entry_from;
517 *edit_fw_format = text_fw_quotefmt;
519 g_object_unref(G_OBJECT(size_group));
522 void quotefmt_add_info_button(GtkWindow *parent_window, GtkWidget *parent_box)
524 GtkWidget *btn_formatdesc;
526 btn_formatdesc = gtkut_stock_button("dialog-information", _("_Information"));
527 gtk_widget_show (btn_formatdesc);
528 gtk_box_pack_start (GTK_BOX (parent_box), btn_formatdesc, FALSE, FALSE, 0);
529 g_signal_connect(G_OBJECT(btn_formatdesc), "clicked",
530 G_CALLBACK(quote_fmt_quote_description), GTK_WIDGET(parent_window));
533 void quotefmt_add_defaults_button(GtkWindow *parent_window,
534 GtkWidget *parent_box,
535 void(*set_defaults_func)(void))
537 GtkWidget *btn_formatdesc;
539 cm_return_if_fail(set_defaults_func != NULL);
541 btn_formatdesc = gtk_button_new_with_mnemonic (_("Defaults"));
542 gtk_button_set_image (GTK_BUTTON(btn_formatdesc),
543 gtk_image_new_from_icon_name("edit-undo", GTK_ICON_SIZE_BUTTON));
544 gtk_widget_show (btn_formatdesc);
545 gtk_box_pack_end (GTK_BOX (parent_box), btn_formatdesc, FALSE, FALSE, 0);
546 g_signal_connect(G_OBJECT(btn_formatdesc), "clicked",
547 G_CALLBACK(set_defaults_func), GTK_WIDGET(parent_window));
550 void quotefmt_check_new_msg_formats(gboolean use_format,
551 gchar *override_from_fmt,
552 gchar *subject_fmt,
553 gchar *body_fmt)
555 if (use_format) {
556 gint line;
558 if (override_from_fmt && !prefs_template_string_is_valid(override_from_fmt, NULL, TRUE, TRUE))
559 alertpanel_error(_("The \"From\" field of the \"New message\" template contains an invalid email address."));
561 if (!prefs_template_string_is_valid(subject_fmt, NULL, TRUE, FALSE))
562 alertpanel_error(_("The \"Subject\" field of the \"New message\" template is invalid."));
564 if (!prefs_template_string_is_valid(body_fmt, &line, TRUE, FALSE)) {
565 alertpanel_error(_("The body of the \"New message\" template has an error at line %d."), line);
570 void quotefmt_check_reply_formats(gboolean use_format,
571 gchar *override_from_fmt,
572 gchar *quotation_mark,
573 gchar *body_fmt)
575 if (use_format) {
576 gint line;
578 if (!prefs_template_string_is_valid(quotation_mark, NULL, TRUE, FALSE))
579 alertpanel_error(_("The \"Quotation mark\" field of the \"Reply\" template is invalid."));
581 if (override_from_fmt && !prefs_template_string_is_valid(override_from_fmt, NULL, TRUE, TRUE))
582 alertpanel_error(_("The \"From\" field of the \"Reply\" template contains an invalid email address."));
584 if (!prefs_template_string_is_valid(body_fmt, &line, TRUE, FALSE)) {
585 alertpanel_error(_("The body of the \"Reply\" template has an error at line %d."), line);
590 void quotefmt_check_forward_formats(gboolean use_format,
591 gchar *override_from_fmt,
592 gchar *quotation_mark,
593 gchar *body_fmt)
595 if (use_format) {
596 gint line;
598 if (!prefs_template_string_is_valid(quotation_mark, NULL, TRUE, FALSE))
599 alertpanel_error(_("The \"Quotation mark\" field of the \"Forward\" template is invalid."));
601 if (override_from_fmt && !prefs_template_string_is_valid(override_from_fmt, NULL, TRUE, TRUE))
602 alertpanel_error(_("The \"From\" field of the \"Forward\" template contains an invalid email address."));
604 if (!prefs_template_string_is_valid(body_fmt, &line, TRUE, FALSE)) {
605 alertpanel_error(_("The body of the \"Forward\" template has an error at line %d."), line);