Add preference to allow disabling automatic drafting of encrypted
[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
120         vbox1 = gtk_vbox_new (FALSE, VSPACING);
121         gtk_widget_show (vbox1);
122         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
123
124         /* Account autoselection */
125         PACK_FRAME(vbox1, frame, _("Automatic account selection"));
126
127         hbox_autosel = gtk_hbox_new (TRUE, VSPACING_NARROW);
128         gtk_widget_show (hbox_autosel);
129         gtk_container_add (GTK_CONTAINER (frame), hbox_autosel);
130         gtk_container_set_border_width (GTK_CONTAINER (hbox_autosel), 8);
131
132         PACK_CHECK_BUTTON (hbox_autosel, checkbtn_reply_account_autosel,
133                            _("when replying"));
134         PACK_CHECK_BUTTON (hbox_autosel, checkbtn_forward_account_autosel,
135                            _("when forwarding"));
136         PACK_CHECK_BUTTON (hbox_autosel, checkbtn_reedit_account_autosel,
137                            _("when re-editing"));
138
139         /* Editing */
140         vbox2 = gtkut_get_options_frame(vbox1, &frame, _("Editing"));
141
142         /* Editing: automatically start the text editor */
143         PACK_CHECK_BUTTON (vbox2, checkbtn_autoextedit,
144                            _("Automatically launch the external editor"));
145
146         /* Editing: automatically save draft */
147         hbox_autosave = gtk_hbox_new (FALSE, 8);
148         gtk_widget_show (hbox_autosave);
149         gtk_box_pack_start (GTK_BOX (vbox2), hbox_autosave, FALSE, FALSE, 0);
150
151         PACK_CHECK_BUTTON (hbox_autosave, checkbtn_autosave,
152                            _("Automatically save message to Drafts folder every"));
153
154         spinbtn_autosave_adj = GTK_ADJUSTMENT(gtk_adjustment_new (50, 0, 1000, 1, 10, 0));
155         spinbtn_autosave_length = gtk_spin_button_new
156                 (GTK_ADJUSTMENT (spinbtn_autosave_adj), 1, 0);
157         gtk_widget_set_size_request (spinbtn_autosave_length, 64, -1);  
158         gtk_widget_show (spinbtn_autosave_length);
159         gtk_box_pack_start (GTK_BOX (hbox_autosave), spinbtn_autosave_length, FALSE, FALSE, 0);
160         gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_autosave_length), TRUE);
161
162         label_autosave_length = gtk_label_new(_("characters"));
163         gtk_widget_show (label_autosave_length);
164         gtk_box_pack_start (GTK_BOX (hbox_autosave), label_autosave_length, FALSE, FALSE, 0);
165
166         /* Editing: automatically save draft when encrypted */
167         hbox_autosave_encrypted = gtk_hbox_new (FALSE, 8);
168         gtk_box_pack_start(GTK_BOX(hbox_autosave_encrypted), gtk_label_new("   "), FALSE, FALSE, 0);
169         gtk_widget_show_all (hbox_autosave_encrypted);
170         gtk_box_pack_start (GTK_BOX (vbox2), hbox_autosave_encrypted, FALSE, FALSE, 0);
171
172         PACK_CHECK_BUTTON (hbox_autosave_encrypted, checkbtn_autosave_encrypted,
173                            _("Even if message is to be encrypted"));
174
175         /* Editing: undo level */
176         hbox_undolevel = gtk_hbox_new (FALSE, 8);
177         gtk_widget_show (hbox_undolevel);
178         gtk_box_pack_start (GTK_BOX (vbox2), hbox_undolevel, FALSE, FALSE, 0);
179
180         label_undolevel = gtk_label_new (_("Undo level"));
181         gtk_widget_show (label_undolevel);
182         gtk_box_pack_start (GTK_BOX (hbox_undolevel), label_undolevel, FALSE, FALSE, 0);
183
184         spinbtn_undolevel_adj = GTK_ADJUSTMENT(gtk_adjustment_new (50, 0, 100, 1, 10, 0));
185         spinbtn_undolevel = gtk_spin_button_new
186                 (GTK_ADJUSTMENT (spinbtn_undolevel_adj), 1, 0);
187         gtk_widget_show (spinbtn_undolevel);
188         gtk_box_pack_start (GTK_BOX (hbox_undolevel), spinbtn_undolevel, FALSE, FALSE, 0);
189         gtk_widget_set_size_request (spinbtn_undolevel, 64, -1);
190         gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_undolevel), TRUE);
191
192         /* Editing: warn when inserting large files in message body */
193         hbox_warn_large_insert = gtk_hbox_new (FALSE, 8);
194         gtk_widget_show (hbox_warn_large_insert);
195         gtk_box_pack_start (GTK_BOX (vbox2), hbox_warn_large_insert, FALSE, FALSE, 0);
196
197         PACK_CHECK_BUTTON (hbox_warn_large_insert, checkbtn_warn_large_insert,
198                            _("Warn when inserting a file larger than"));
199
200         spinbtn_warn_large_insert_adj = GTK_ADJUSTMENT(gtk_adjustment_new (50, 0, 10000, 1, 10, 0));
201         spinbtn_warn_large_insert_size = gtk_spin_button_new
202                 (GTK_ADJUSTMENT (spinbtn_warn_large_insert_adj), 1, 0);
203         gtk_widget_set_size_request (spinbtn_warn_large_insert_size, 64, -1);   
204         gtk_widget_show (spinbtn_warn_large_insert_size);
205         gtk_box_pack_start (GTK_BOX (hbox_warn_large_insert),
206                         spinbtn_warn_large_insert_size, FALSE, FALSE, 0);
207         gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_warn_large_insert_size),
208                         TRUE);
209
210         label_warn_large_insert_size = gtk_label_new(_("KB into message body "));
211         gtk_widget_show (label_warn_large_insert_size);
212         gtk_box_pack_start (GTK_BOX (hbox_warn_large_insert),
213                         label_warn_large_insert_size, FALSE, FALSE, 0);
214
215         /* Replying */
216         vbox2 = gtkut_get_options_frame(vbox1, &frame, _("Replying"));
217
218         PACK_CHECK_BUTTON (vbox2, checkbtn_reply_with_quote,
219                            _("Reply will quote by default"));
220
221         PACK_CHECK_BUTTON (vbox2, checkbtn_default_reply_list,
222                            _("Reply button invokes mailing list reply"));
223
224         vbox2 = gtkut_get_options_frame(vbox1, &frame, _("Forwarding"));
225
226         PACK_CHECK_BUTTON (vbox2, checkbtn_forward_as_attachment,
227                            _("Forward as attachment"));
228
229         PACK_CHECK_BUTTON (vbox2, checkbtn_redirect_keep_from,
230                            _("Keep the original 'From' header when redirecting"));
231
232         /* dnd insert or attach */
233         label_dnd_insert_or_attach = gtk_label_new (_("When dropping files into the Compose window"));
234         gtk_misc_set_alignment(GTK_MISC(label_dnd_insert_or_attach), 0, 0.5);
235         gtk_widget_show (label_dnd_insert_or_attach);
236
237         optmenu_dnd_insert_or_attach = gtkut_sc_combobox_create(NULL, FALSE);
238         gtk_widget_show (optmenu_dnd_insert_or_attach);
239
240         menu = GTK_LIST_STORE(gtk_combo_box_get_model(
241                                 GTK_COMBO_BOX(optmenu_dnd_insert_or_attach)));
242         COMBOBOX_ADD (menu, _("Ask"), COMPOSE_DND_ASK);
243         COMBOBOX_ADD (menu, _("Insert"), COMPOSE_DND_INSERT);
244         COMBOBOX_ADD (menu, _("Attach"), COMPOSE_DND_ATTACH);
245
246         hbox_dnd_insert_or_attach = gtk_hbox_new(FALSE, 20);
247         gtk_widget_show(hbox_dnd_insert_or_attach);
248         gtk_box_pack_start(GTK_BOX(vbox1), hbox_dnd_insert_or_attach, FALSE, FALSE, 0);
249         gtk_box_pack_start(GTK_BOX(hbox_dnd_insert_or_attach),
250                         label_dnd_insert_or_attach, FALSE, FALSE, 0);
251         gtk_box_pack_start(GTK_BOX(hbox_dnd_insert_or_attach),
252                         optmenu_dnd_insert_or_attach, FALSE, FALSE, 0);
253         
254         SET_TOGGLE_SENSITIVITY (checkbtn_autosave, spinbtn_autosave_length);
255         SET_TOGGLE_SENSITIVITY (checkbtn_autosave, label_autosave_length);
256         SET_TOGGLE_SENSITIVITY (checkbtn_autosave, checkbtn_autosave_encrypted);
257
258         SET_TOGGLE_SENSITIVITY (checkbtn_warn_large_insert, spinbtn_warn_large_insert_size);
259         SET_TOGGLE_SENSITIVITY (checkbtn_warn_large_insert, label_warn_large_insert_size);
260
261
262         prefs_writing->checkbtn_autoextedit = checkbtn_autoextedit;
263
264         prefs_writing->checkbtn_reply_account_autosel   = checkbtn_reply_account_autosel;
265         prefs_writing->checkbtn_forward_account_autosel = checkbtn_forward_account_autosel;
266         prefs_writing->checkbtn_reedit_account_autosel  = checkbtn_reedit_account_autosel;
267
268         prefs_writing->spinbtn_undolevel     = spinbtn_undolevel;
269
270         prefs_writing->checkbtn_autosave     = checkbtn_autosave;
271         prefs_writing->spinbtn_autosave_length = spinbtn_autosave_length;
272
273         prefs_writing->checkbtn_autosave_encrypted     = checkbtn_autosave_encrypted;
274
275         prefs_writing->checkbtn_warn_large_insert = checkbtn_warn_large_insert;
276         prefs_writing->spinbtn_warn_large_insert_size = spinbtn_warn_large_insert_size;
277         
278         prefs_writing->checkbtn_forward_as_attachment =
279                 checkbtn_forward_as_attachment;
280         prefs_writing->checkbtn_redirect_keep_from = checkbtn_redirect_keep_from;
281         prefs_writing->checkbtn_reply_with_quote     = checkbtn_reply_with_quote;
282         prefs_writing->checkbtn_default_reply_list = checkbtn_default_reply_list;
283
284         prefs_writing->optmenu_dnd_insert_or_attach = optmenu_dnd_insert_or_attach;
285
286
287         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_writing->checkbtn_autoextedit),
288                 prefs_common.auto_exteditor);
289         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_writing->checkbtn_forward_as_attachment),
290                 prefs_common.forward_as_attachment);
291         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_writing->checkbtn_redirect_keep_from),
292                 prefs_common.redirect_keep_from);
293         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_writing->checkbtn_autosave),
294                 prefs_common.autosave);
295         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_writing->checkbtn_autosave_encrypted),
296                 prefs_common.autosave_encrypted);
297         gtk_spin_button_set_value(GTK_SPIN_BUTTON(prefs_writing->spinbtn_autosave_length),
298                 prefs_common.autosave_length);
299         gtk_spin_button_set_value(GTK_SPIN_BUTTON(prefs_writing->spinbtn_undolevel),
300                 prefs_common.undolevels);
301         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_writing->checkbtn_warn_large_insert),
302                 prefs_common.warn_large_insert);
303         gtk_spin_button_set_value(GTK_SPIN_BUTTON(prefs_writing->spinbtn_warn_large_insert_size),
304                 prefs_common.warn_large_insert_size);
305         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_writing->checkbtn_reply_account_autosel),
306                 prefs_common.reply_account_autosel);
307         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_writing->checkbtn_forward_account_autosel),
308                 prefs_common.forward_account_autosel);
309         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_writing->checkbtn_reedit_account_autosel),
310                 prefs_common.reedit_account_autosel);
311         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_writing->checkbtn_reply_with_quote),
312                         prefs_common.reply_with_quote);
313         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_writing->checkbtn_default_reply_list),
314                 prefs_common.default_reply_list);
315         combobox_select_by_data(GTK_COMBO_BOX(optmenu_dnd_insert_or_attach),
316                 prefs_common.compose_dnd_mode);
317
318         prefs_writing->page.widget = vbox1;
319 }
320
321 static void prefs_compose_writing_save(PrefsPage *_page)
322 {
323         WritingPage *page = (WritingPage *) _page;
324
325         prefs_common.auto_exteditor = 
326                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_autoextedit));
327         prefs_common.forward_as_attachment =
328                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_forward_as_attachment));
329         prefs_common.redirect_keep_from =
330                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_redirect_keep_from));
331         prefs_common.autosave = 
332                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_autosave));
333         prefs_common.autosave_encrypted = 
334                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_autosave_encrypted));
335         prefs_common.autosave_length =
336                 gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(page->spinbtn_autosave_length));
337         prefs_common.undolevels = 
338                 gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(page->spinbtn_undolevel));
339         prefs_common.warn_large_insert = 
340                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_warn_large_insert));
341         prefs_common.warn_large_insert_size =
342                 gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(page->spinbtn_warn_large_insert_size));
343                 
344         prefs_common.reply_account_autosel =
345                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_reply_account_autosel));
346         prefs_common.forward_account_autosel =
347                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_forward_account_autosel));
348         prefs_common.reedit_account_autosel =
349                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_reedit_account_autosel));
350         prefs_common.reply_with_quote = gtk_toggle_button_get_active(
351                         GTK_TOGGLE_BUTTON(page->checkbtn_reply_with_quote));
352         prefs_common.default_reply_list =
353                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_default_reply_list));
354         
355         prefs_common.compose_dnd_mode = combobox_get_active_data(
356                         GTK_COMBO_BOX(page->optmenu_dnd_insert_or_attach));
357 }
358
359 static void prefs_compose_writing_destroy_widget(PrefsPage *_page)
360 {
361 }
362
363 WritingPage *prefs_writing;
364
365 void prefs_compose_writing_init(void)
366 {
367         WritingPage *page;
368         static gchar *path[3];
369
370         path[0] = _("Compose");
371         path[1] = _("Writing");
372         path[2] = NULL;
373
374         page = g_new0(WritingPage, 1);
375         page->page.path = path;
376         page->page.create_widget = prefs_compose_writing_create_widget;
377         page->page.destroy_widget = prefs_compose_writing_destroy_widget;
378         page->page.save_page = prefs_compose_writing_save;
379         page->page.weight = 190.0;
380         prefs_gtk_register_page((PrefsPage *) page);
381         prefs_writing = page;
382 }
383
384 void prefs_compose_writing_done(void)
385 {
386         prefs_gtk_unregister_page((PrefsPage *) prefs_writing);
387         g_free(prefs_writing);
388 }