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