2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 2005-2006 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 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 gtk_widget_show (text_quotefmt
);
130 gtk_container_add(GTK_CONTAINER(scrolledwin_quotefmt
), text_quotefmt
);
131 gtk_text_view_set_editable (GTK_TEXT_VIEW (text_quotefmt
), TRUE
);
132 gtk_widget_set_size_request(text_quotefmt
, -1, 100);
136 PACK_FRAME (vbox1
, frame_quote
, _("Forward format"));
138 vbox_quote
= gtk_vbox_new (FALSE
, VSPACING_NARROW
);
139 gtk_widget_show (vbox_quote
);
140 gtk_container_add (GTK_CONTAINER (frame_quote
), vbox_quote
);
141 gtk_container_set_border_width (GTK_CONTAINER (vbox_quote
), 8);
143 hbox1
= gtk_hbox_new (FALSE
, 32);
144 gtk_widget_show (hbox1
);
145 gtk_box_pack_start (GTK_BOX (vbox_quote
), hbox1
, FALSE
, FALSE
, 0);
147 hbox2
= gtk_hbox_new (FALSE
, 8);
148 gtk_widget_show (hbox2
);
149 gtk_box_pack_start (GTK_BOX (hbox1
), hbox2
, FALSE
, FALSE
, 0);
151 label_quotemark
= gtk_label_new (_("Quotation mark"));
152 gtk_widget_show (label_quotemark
);
153 gtk_box_pack_start (GTK_BOX (hbox2
), label_quotemark
, FALSE
, FALSE
, 0);
155 entry_fw_quotemark
= gtk_entry_new ();
156 gtk_widget_show (entry_fw_quotemark
);
157 gtk_box_pack_start (GTK_BOX (hbox2
), entry_fw_quotemark
,
159 gtk_widget_set_size_request (entry_fw_quotemark
, 64, -1);
161 scrolledwin_quotefmt
= gtk_scrolled_window_new (NULL
, NULL
);
162 gtk_widget_show (scrolledwin_quotefmt
);
163 gtk_box_pack_start (GTK_BOX (vbox_quote
), scrolledwin_quotefmt
,
165 gtk_scrolled_window_set_policy
166 (GTK_SCROLLED_WINDOW (scrolledwin_quotefmt
),
167 GTK_POLICY_NEVER
, GTK_POLICY_AUTOMATIC
);
168 gtk_scrolled_window_set_shadow_type
169 (GTK_SCROLLED_WINDOW (scrolledwin_quotefmt
), GTK_SHADOW_IN
);
171 text_fw_quotefmt
= gtk_text_view_new ();
172 gtk_widget_show (text_fw_quotefmt
);
173 gtk_container_add(GTK_CONTAINER(scrolledwin_quotefmt
),
175 gtk_text_view_set_editable (GTK_TEXT_VIEW (text_fw_quotefmt
), TRUE
);
176 gtk_widget_set_size_request (text_fw_quotefmt
, -1, 100);
178 hbox1
= gtk_hbox_new (FALSE
, 32);
179 gtk_widget_show (hbox1
);
180 gtk_box_pack_start (GTK_BOX (vbox1
), hbox1
, FALSE
, FALSE
, 0);
182 #if GTK_CHECK_VERSION(2, 8, 0)
183 btn_quotedesc
= gtk_button_new_from_stock(GTK_STOCK_INFO
);
186 gtk_button_new_with_label (_(" Description of symbols... "));
188 gtk_widget_show (btn_quotedesc
);
189 gtk_box_pack_start (GTK_BOX (hbox1
), btn_quotedesc
, FALSE
, FALSE
, 0);
190 g_signal_connect(G_OBJECT(btn_quotedesc
), "clicked",
191 G_CALLBACK(quote_fmt_quote_description
), GTK_WIDGET(window
));
195 PACK_FRAME (vbox1
, frame_quote
, _("Quotation characters"));
197 vbox_quote
= gtk_vbox_new (FALSE
, VSPACING_NARROW
);
198 gtk_widget_show (vbox_quote
);
199 gtk_container_add (GTK_CONTAINER (frame_quote
), vbox_quote
);
200 gtk_container_set_border_width (GTK_CONTAINER (vbox_quote
), 8);
202 hbox1
= gtk_hbox_new (FALSE
, 32);
203 gtk_widget_show (hbox1
);
204 gtk_box_pack_start (GTK_BOX (vbox_quote
), hbox1
, FALSE
, FALSE
, 0);
206 hbox2
= gtk_hbox_new (FALSE
, 8);
207 gtk_widget_show (hbox2
);
208 gtk_box_pack_start (GTK_BOX (hbox1
), hbox2
, FALSE
, FALSE
, 0);
210 label_quote_chars
= gtk_label_new (_("Treat these characters as quotation marks: "));
211 gtk_widget_show (label_quote_chars
);
212 gtk_box_pack_start (GTK_BOX (hbox2
), label_quote_chars
, FALSE
, FALSE
, 0);
214 entry_quote_chars
= gtk_entry_new ();
215 gtk_widget_show (entry_quote_chars
);
216 gtk_box_pack_start (GTK_BOX (hbox2
), entry_quote_chars
,
218 gtk_widget_set_size_request (entry_quote_chars
, 64, -1);
220 pref_set_textview_from_pref(GTK_TEXT_VIEW(text_quotefmt
), prefs_common
.quotefmt
);
221 pref_set_textview_from_pref(GTK_TEXT_VIEW(text_fw_quotefmt
), prefs_common
.fw_quotefmt
);
223 gtk_entry_set_text(GTK_ENTRY(entry_quotemark
),
224 prefs_common
.quotemark
?prefs_common
.quotemark
:"");
225 gtk_entry_set_text(GTK_ENTRY(entry_fw_quotemark
),
226 prefs_common
.fw_quotemark
?prefs_common
.fw_quotemark
:"");
227 gtk_entry_set_text(GTK_ENTRY(entry_quote_chars
),
228 prefs_common
.quote_chars
?prefs_common
.quote_chars
:"");
229 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_reply_with_quote
),
230 prefs_common
.reply_with_quote
);
232 prefs_quote
->window
= GTK_WIDGET(window
);
233 prefs_quote
->text_quotefmt
= text_quotefmt
;
234 prefs_quote
->text_fw_quotefmt
= text_fw_quotefmt
;
235 prefs_quote
->entry_quotemark
= entry_quotemark
;
236 prefs_quote
->entry_fw_quotemark
= entry_fw_quotemark
;
237 prefs_quote
->entry_quote_chars
= entry_quote_chars
;
238 prefs_quote
->checkbtn_reply_with_quote
239 = checkbtn_reply_with_quote
;
240 prefs_quote
->page
.widget
= vbox1
;
243 void prefs_quote_save(PrefsPage
*_page
)
245 QuotePage
*page
= (QuotePage
*) _page
;
247 g_free(prefs_common
.quotefmt
);
248 prefs_common
.quotefmt
= NULL
;
249 g_free(prefs_common
.fw_quotefmt
);
250 prefs_common
.fw_quotefmt
= NULL
;
251 g_free(prefs_common
.quotemark
);
252 prefs_common
.quotemark
= NULL
;
253 g_free(prefs_common
.fw_quotemark
);
254 prefs_common
.fw_quotemark
= NULL
;
255 g_free(prefs_common
.quote_chars
);
256 prefs_common
.quote_chars
= NULL
;
258 prefs_common
.quotefmt
= pref_get_pref_from_textview(
259 GTK_TEXT_VIEW(page
->text_quotefmt
));
260 if (!prefs_template_string_is_valid(prefs_common
.quotefmt
))
261 alertpanel_error(_("Message reply quote format error."));
263 prefs_common
.fw_quotefmt
= pref_get_pref_from_textview(
264 GTK_TEXT_VIEW(page
->text_fw_quotefmt
));
265 if (!prefs_template_string_is_valid(prefs_common
.fw_quotefmt
))
266 alertpanel_error(_("Message forward quote format error."));
268 prefs_common
.quotemark
= gtk_editable_get_chars(
269 GTK_EDITABLE(page
->entry_quotemark
), 0, -1);
270 prefs_common
.fw_quotemark
= gtk_editable_get_chars(
271 GTK_EDITABLE(page
->entry_fw_quotemark
), 0, -1);
272 prefs_common
.quote_chars
= gtk_editable_get_chars(
273 GTK_EDITABLE(page
->entry_quote_chars
), 0, -1);
274 prefs_common
.reply_with_quote
= gtk_toggle_button_get_active(
275 GTK_TOGGLE_BUTTON(page
->checkbtn_reply_with_quote
));
277 remove_space(prefs_common
.quote_chars
);
280 static void prefs_quote_destroy_widget(PrefsPage
*_page
)
284 QuotePage
*prefs_quote
;
286 void prefs_quote_init(void)
289 static gchar
*path
[3];
291 path
[0] = _("Compose");
292 path
[1] = _("Quoting");
295 page
= g_new0(QuotePage
, 1);
296 page
->page
.path
= path
;
297 page
->page
.create_widget
= prefs_quote_create_widget
;
298 page
->page
.destroy_widget
= prefs_quote_destroy_widget
;
299 page
->page
.save_page
= prefs_quote_save
;
300 page
->page
.weight
= 185.0;
301 prefs_gtk_register_page((PrefsPage
*) page
);
305 void prefs_quote_done(void)
307 prefs_gtk_unregister_page((PrefsPage
*) prefs_quote
);