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