More translatable header names in UI strings.
[claws.git] / src / prefs_compose_writing.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 2005-2012 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 3 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, see <http://www.gnu.org/licenses/>.
17  * 
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #  include "config.h"
22 #include "claws-features.h"
23 #endif
24
25 #include "defs.h"
26
27 #include <stdio.h>
28 #include <stdlib.h>
29
30 #include <glib.h>
31 #include <glib/gi18n.h>
32 #include <gtk/gtk.h>
33 #include <gdk/gdkkeysyms.h>
34
35 #include "prefs_common.h"
36 #include "prefs_gtk.h"
37
38 #include "gtk/gtkutils.h"
39 #include "gtk/prefswindow.h"
40 #include "gtk/menu.h"
41
42 #include "manage_window.h"
43
44 #include "quote_fmt.h"
45 #include "prefs_template.h"
46 #include "alertpanel.h"
47 #include "combobox.h"
48
49 typedef struct _WritingPage
50 {
51         PrefsPage page;
52
53         GtkWidget *window;
54
55         GtkWidget *checkbtn_autoextedit;
56         GtkWidget *checkbtn_reply_account_autosel;
57         GtkWidget *checkbtn_forward_account_autosel;
58         GtkWidget *checkbtn_reedit_account_autosel;
59         GtkWidget *spinbtn_undolevel;
60         GtkWidget *checkbtn_reply_with_quote;
61         GtkWidget *checkbtn_default_reply_list;
62         GtkWidget *checkbtn_forward_as_attachment;
63         GtkWidget *checkbtn_redirect_keep_from;
64         GtkWidget *checkbtn_autosave;
65         GtkWidget *spinbtn_autosave_length;
66         GtkWidget *checkbtn_autosave_encrypted;
67         GtkWidget *checkbtn_warn_large_insert;
68         GtkWidget *spinbtn_warn_large_insert_size;
69         GtkWidget *optmenu_dnd_insert_or_attach;
70 } WritingPage;
71
72 static void prefs_compose_writing_create_widget(PrefsPage *_page, GtkWindow *window, 
73                                   gpointer data)
74 {
75         WritingPage *prefs_writing = (WritingPage *) _page;
76         
77         GtkWidget *vbox1;
78         GtkWidget *vbox2;
79
80         GtkWidget *checkbtn_autoextedit;
81
82         GtkWidget *frame;
83         GtkWidget *hbox_autosel;
84         GtkWidget *checkbtn_reply_account_autosel;
85         GtkWidget *checkbtn_forward_account_autosel;
86         GtkWidget *checkbtn_reedit_account_autosel;
87
88         GtkWidget *hbox_undolevel;
89         GtkWidget *label_undolevel;
90         GtkAdjustment *spinbtn_undolevel_adj;
91         GtkWidget *spinbtn_undolevel;
92
93         GtkWidget *hbox_warn_large_insert;
94         GtkWidget *checkbtn_warn_large_insert;
95         GtkAdjustment *spinbtn_warn_large_insert_adj;
96         GtkWidget *spinbtn_warn_large_insert_size;
97         GtkWidget *label_warn_large_insert_size;
98
99         GtkWidget *checkbtn_reply_with_quote;
100         GtkWidget *checkbtn_default_reply_list;
101
102         GtkWidget *checkbtn_forward_as_attachment;
103         GtkWidget *checkbtn_redirect_keep_from;
104
105         GtkWidget *hbox_autosave;
106         GtkWidget *checkbtn_autosave;
107         GtkAdjustment *spinbtn_autosave_adj;
108         GtkWidget *spinbtn_autosave_length;
109         GtkWidget *label_autosave_length;
110
111         GtkWidget *hbox_autosave_encrypted;
112         GtkWidget *checkbtn_autosave_encrypted;
113
114         GtkWidget *hbox_dnd_insert_or_attach;
115         GtkWidget *label_dnd_insert_or_attach;
116         GtkWidget *optmenu_dnd_insert_or_attach;
117         GtkListStore *menu;
118         GtkTreeIter iter;
119         gchar *text;
120
121         vbox1 = gtk_vbox_new (FALSE, VSPACING);
122         gtk_widget_show (vbox1);
123         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
124
125         /* Account autoselection */
126         PACK_FRAME(vbox1, frame, _("Automatic account selection"));
127
128         hbox_autosel = gtk_hbox_new (TRUE, VSPACING_NARROW);
129         gtk_widget_show (hbox_autosel);
130         gtk_container_add (GTK_CONTAINER (frame), hbox_autosel);
131         gtk_container_set_border_width (GTK_CONTAINER (hbox_autosel), 8);
132
133         PACK_CHECK_BUTTON (hbox_autosel, checkbtn_reply_account_autosel,
134                            _("when replying"));
135         PACK_CHECK_BUTTON (hbox_autosel, checkbtn_forward_account_autosel,
136                            _("when forwarding"));
137         PACK_CHECK_BUTTON (hbox_autosel, checkbtn_reedit_account_autosel,
138                            _("when re-editing"));
139
140         /* Editing */
141         vbox2 = gtkut_get_options_frame(vbox1, &frame, _("Editing"));
142
143         /* Editing: automatically start the text editor */
144         PACK_CHECK_BUTTON (vbox2, checkbtn_autoextedit,
145                            _("Automatically launch the external editor"));
146
147         /* Editing: automatically save draft */
148         hbox_autosave = gtk_hbox_new (FALSE, 8);
149         gtk_widget_show (hbox_autosave);
150         gtk_box_pack_start (GTK_BOX (vbox2), hbox_autosave, FALSE, FALSE, 0);
151
152         PACK_CHECK_BUTTON (hbox_autosave, checkbtn_autosave,
153                            _("Automatically save message to Drafts folder every"));
154
155         spinbtn_autosave_adj = GTK_ADJUSTMENT(gtk_adjustment_new (50, 0, 1000, 1, 10, 0));
156         spinbtn_autosave_length = gtk_spin_button_new
157                 (GTK_ADJUSTMENT (spinbtn_autosave_adj), 1, 0);
158         gtk_widget_set_size_request (spinbtn_autosave_length, 64, -1);  
159         gtk_widget_show (spinbtn_autosave_length);
160         gtk_box_pack_start (GTK_BOX (hbox_autosave), spinbtn_autosave_length, FALSE, FALSE, 0);
161         gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_autosave_length), TRUE);
162
163         label_autosave_length = gtk_label_new(_("characters"));
164         gtk_widget_show (label_autosave_length);
165         gtk_box_pack_start (GTK_BOX (hbox_autosave), label_autosave_length, FALSE, FALSE, 0);
166
167         /* Editing: automatically save draft when encrypted */
168         hbox_autosave_encrypted = gtk_hbox_new (FALSE, 8);
169         gtk_box_pack_start(GTK_BOX(hbox_autosave_encrypted), gtk_label_new("   "), FALSE, FALSE, 0);
170         gtk_widget_show_all (hbox_autosave_encrypted);
171         gtk_box_pack_start (GTK_BOX (vbox2), hbox_autosave_encrypted, FALSE, FALSE, 0);
172
173         PACK_CHECK_BUTTON (hbox_autosave_encrypted, checkbtn_autosave_encrypted,
174                            _("Even if message is to be encrypted"));
175
176         /* Editing: undo level */
177         hbox_undolevel = gtk_hbox_new (FALSE, 8);
178         gtk_widget_show (hbox_undolevel);
179         gtk_box_pack_start (GTK_BOX (vbox2), hbox_undolevel, FALSE, FALSE, 0);
180
181         label_undolevel = gtk_label_new (_("Undo level"));
182         gtk_widget_show (label_undolevel);
183         gtk_box_pack_start (GTK_BOX (hbox_undolevel), label_undolevel, FALSE, FALSE, 0);
184
185         spinbtn_undolevel_adj = GTK_ADJUSTMENT(gtk_adjustment_new (50, 0, 100, 1, 10, 0));
186         spinbtn_undolevel = gtk_spin_button_new
187                 (GTK_ADJUSTMENT (spinbtn_undolevel_adj), 1, 0);
188         gtk_widget_show (spinbtn_undolevel);
189         gtk_box_pack_start (GTK_BOX (hbox_undolevel), spinbtn_undolevel, FALSE, FALSE, 0);
190         gtk_widget_set_size_request (spinbtn_undolevel, 64, -1);
191         gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_undolevel), TRUE);
192
193         /* Editing: warn when inserting large files in message body */
194         hbox_warn_large_insert = gtk_hbox_new (FALSE, 8);
195         gtk_widget_show (hbox_warn_large_insert);
196         gtk_box_pack_start (GTK_BOX (vbox2), hbox_warn_large_insert, FALSE, FALSE, 0);
197
198         PACK_CHECK_BUTTON (hbox_warn_large_insert, checkbtn_warn_large_insert,
199                            _("Warn when inserting a file larger than"));
200
201         spinbtn_warn_large_insert_adj = GTK_ADJUSTMENT(gtk_adjustment_new (50, 0, 10000, 1, 10, 0));
202         spinbtn_warn_large_insert_size = gtk_spin_button_new
203                 (GTK_ADJUSTMENT (spinbtn_warn_large_insert_adj), 1, 0);
204         gtk_widget_set_size_request (spinbtn_warn_large_insert_size, 64, -1);   
205         gtk_widget_show (spinbtn_warn_large_insert_size);
206         gtk_box_pack_start (GTK_BOX (hbox_warn_large_insert),
207                         spinbtn_warn_large_insert_size, FALSE, FALSE, 0);
208         gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_warn_large_insert_size),
209                         TRUE);
210
211         label_warn_large_insert_size = gtk_label_new(_("KB into message body "));
212         gtk_widget_show (label_warn_large_insert_size);
213         gtk_box_pack_start (GTK_BOX (hbox_warn_large_insert),
214                         label_warn_large_insert_size, FALSE, FALSE, 0);
215
216         /* Replying */
217         vbox2 = gtkut_get_options_frame(vbox1, &frame, _("Replying"));
218
219         PACK_CHECK_BUTTON (vbox2, checkbtn_reply_with_quote,
220                            _("Reply will quote by default"));
221
222         PACK_CHECK_BUTTON (vbox2, checkbtn_default_reply_list,
223                            _("Reply button invokes mailing list reply"));
224
225         vbox2 = gtkut_get_options_frame(vbox1, &frame, _("Forwarding"));
226
227         PACK_CHECK_BUTTON (vbox2, checkbtn_forward_as_attachment,
228                            _("Forward as attachment"));
229
230         text = g_strdup_printf(_("Keep the original '%s' header when redirecting"),
231                         prefs_common_translated_header_name("From"));
232         PACK_CHECK_BUTTON (vbox2, checkbtn_redirect_keep_from, text);
233         g_free(text);
234
235         /* dnd insert or attach */
236         label_dnd_insert_or_attach = gtk_label_new (_("When dropping files into the Compose window"));
237         gtk_misc_set_alignment(GTK_MISC(label_dnd_insert_or_attach), 0, 0.5);
238         gtk_widget_show (label_dnd_insert_or_attach);
239
240         optmenu_dnd_insert_or_attach = gtkut_sc_combobox_create(NULL, FALSE);
241         gtk_widget_show (optmenu_dnd_insert_or_attach);
242
243         menu = GTK_LIST_STORE(gtk_combo_box_get_model(
244                                 GTK_COMBO_BOX(optmenu_dnd_insert_or_attach)));
245         COMBOBOX_ADD (menu, _("Ask"), COMPOSE_DND_ASK);
246         COMBOBOX_ADD (menu, _("Insert"), COMPOSE_DND_INSERT);
247         COMBOBOX_ADD (menu, _("Attach"), COMPOSE_DND_ATTACH);
248
249         hbox_dnd_insert_or_attach = gtk_hbox_new(FALSE, 20);
250         gtk_widget_show(hbox_dnd_insert_or_attach);
251         gtk_box_pack_start(GTK_BOX(vbox1), hbox_dnd_insert_or_attach, FALSE, FALSE, 0);
252         gtk_box_pack_start(GTK_BOX(hbox_dnd_insert_or_attach),
253                         label_dnd_insert_or_attach, FALSE, FALSE, 0);
254         gtk_box_pack_start(GTK_BOX(hbox_dnd_insert_or_attach),
255                         optmenu_dnd_insert_or_attach, FALSE, FALSE, 0);
256         
257         SET_TOGGLE_SENSITIVITY (checkbtn_autosave, spinbtn_autosave_length);
258         SET_TOGGLE_SENSITIVITY (checkbtn_autosave, label_autosave_length);
259         SET_TOGGLE_SENSITIVITY (checkbtn_autosave, checkbtn_autosave_encrypted);
260
261         SET_TOGGLE_SENSITIVITY (checkbtn_warn_large_insert, spinbtn_warn_large_insert_size);
262         SET_TOGGLE_SENSITIVITY (checkbtn_warn_large_insert, label_warn_large_insert_size);
263
264
265         prefs_writing->checkbtn_autoextedit = checkbtn_autoextedit;
266
267         prefs_writing->checkbtn_reply_account_autosel   = checkbtn_reply_account_autosel;
268         prefs_writing->checkbtn_forward_account_autosel = checkbtn_forward_account_autosel;
269         prefs_writing->checkbtn_reedit_account_autosel  = checkbtn_reedit_account_autosel;
270
271         prefs_writing->spinbtn_undolevel     = spinbtn_undolevel;
272
273         prefs_writing->checkbtn_autosave     = checkbtn_autosave;
274         prefs_writing->spinbtn_autosave_length = spinbtn_autosave_length;
275
276         prefs_writing->checkbtn_autosave_encrypted     = checkbtn_autosave_encrypted;
277
278         prefs_writing->checkbtn_warn_large_insert = checkbtn_warn_large_insert;
279         prefs_writing->spinbtn_warn_large_insert_size = spinbtn_warn_large_insert_size;
280         
281         prefs_writing->checkbtn_forward_as_attachment =
282                 checkbtn_forward_as_attachment;
283         prefs_writing->checkbtn_redirect_keep_from = checkbtn_redirect_keep_from;
284         prefs_writing->checkbtn_reply_with_quote     = checkbtn_reply_with_quote;
285         prefs_writing->checkbtn_default_reply_list = checkbtn_default_reply_list;
286
287         prefs_writing->optmenu_dnd_insert_or_attach = optmenu_dnd_insert_or_attach;
288
289
290         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_writing->checkbtn_autoextedit),
291                 prefs_common.auto_exteditor);
292         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_writing->checkbtn_forward_as_attachment),
293                 prefs_common.forward_as_attachment);
294         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_writing->checkbtn_redirect_keep_from),
295                 prefs_common.redirect_keep_from);
296         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_writing->checkbtn_autosave),
297                 prefs_common.autosave);
298         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_writing->checkbtn_autosave_encrypted),
299                 prefs_common.autosave_encrypted);
300         gtk_spin_button_set_value(GTK_SPIN_BUTTON(prefs_writing->spinbtn_autosave_length),
301                 prefs_common.autosave_length);
302         gtk_spin_button_set_value(GTK_SPIN_BUTTON(prefs_writing->spinbtn_undolevel),
303                 prefs_common.undolevels);
304         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_writing->checkbtn_warn_large_insert),
305                 prefs_common.warn_large_insert);
306         gtk_spin_button_set_value(GTK_SPIN_BUTTON(prefs_writing->spinbtn_warn_large_insert_size),
307                 prefs_common.warn_large_insert_size);
308         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_writing->checkbtn_reply_account_autosel),
309                 prefs_common.reply_account_autosel);
310         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_writing->checkbtn_forward_account_autosel),
311                 prefs_common.forward_account_autosel);
312         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_writing->checkbtn_reedit_account_autosel),
313                 prefs_common.reedit_account_autosel);
314         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_writing->checkbtn_reply_with_quote),
315                         prefs_common.reply_with_quote);
316         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_writing->checkbtn_default_reply_list),
317                 prefs_common.default_reply_list);
318         combobox_select_by_data(GTK_COMBO_BOX(optmenu_dnd_insert_or_attach),
319                 prefs_common.compose_dnd_mode);
320
321         prefs_writing->page.widget = vbox1;
322 }
323
324 static void prefs_compose_writing_save(PrefsPage *_page)
325 {
326         WritingPage *page = (WritingPage *) _page;
327
328         prefs_common.auto_exteditor = 
329                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_autoextedit));
330         prefs_common.forward_as_attachment =
331                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_forward_as_attachment));
332         prefs_common.redirect_keep_from =
333                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_redirect_keep_from));
334         prefs_common.autosave = 
335                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_autosave));
336         prefs_common.autosave_encrypted = 
337                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_autosave_encrypted));
338         prefs_common.autosave_length =
339                 gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(page->spinbtn_autosave_length));
340         prefs_common.undolevels = 
341                 gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(page->spinbtn_undolevel));
342         prefs_common.warn_large_insert = 
343                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_warn_large_insert));
344         prefs_common.warn_large_insert_size =
345                 gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(page->spinbtn_warn_large_insert_size));
346                 
347         prefs_common.reply_account_autosel =
348                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_reply_account_autosel));
349         prefs_common.forward_account_autosel =
350                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_forward_account_autosel));
351         prefs_common.reedit_account_autosel =
352                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_reedit_account_autosel));
353         prefs_common.reply_with_quote = gtk_toggle_button_get_active(
354                         GTK_TOGGLE_BUTTON(page->checkbtn_reply_with_quote));
355         prefs_common.default_reply_list =
356                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_default_reply_list));
357         
358         prefs_common.compose_dnd_mode = combobox_get_active_data(
359                         GTK_COMBO_BOX(page->optmenu_dnd_insert_or_attach));
360 }
361
362 static void prefs_compose_writing_destroy_widget(PrefsPage *_page)
363 {
364 }
365
366 WritingPage *prefs_writing;
367
368 void prefs_compose_writing_init(void)
369 {
370         WritingPage *page;
371         static gchar *path[3];
372
373         path[0] = _("Compose");
374         path[1] = _("Writing");
375         path[2] = NULL;
376
377         page = g_new0(WritingPage, 1);
378         page->page.path = path;
379         page->page.create_widget = prefs_compose_writing_create_widget;
380         page->page.destroy_widget = prefs_compose_writing_destroy_widget;
381         page->page.save_page = prefs_compose_writing_save;
382         page->page.weight = 190.0;
383         prefs_gtk_register_page((PrefsPage *) page);
384         prefs_writing = page;
385 }
386
387 void prefs_compose_writing_done(void)
388 {
389         prefs_gtk_unregister_page((PrefsPage *) prefs_writing);
390         g_free(prefs_writing);
391 }