c6e36a70e465f44fa5afa413c057abb6befdbdcd
[claws.git] / src / prefs_compose_writing.c
1 /*
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
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 2 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, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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 typedef struct _WritingPage
44 {
45         PrefsPage page;
46
47         GtkWidget *window;
48
49         GtkWidget *checkbtn_autoextedit;
50         GtkWidget *checkbtn_reply_account_autosel;
51         GtkWidget *checkbtn_forward_account_autosel;
52         GtkWidget *checkbtn_reedit_account_autosel;
53         GtkWidget *spinbtn_undolevel;
54         GtkWidget *checkbtn_default_reply_list;
55         GtkWidget *checkbtn_forward_as_attachment;
56         GtkWidget *checkbtn_redirect_keep_from;
57         GtkWidget *hbox_autosave;
58         GtkWidget *checkbtn_autosave;
59         GtkWidget *spinbtn_autosave_length;
60         GtkWidget *optmenu_dnd_insert_or_attach;
61 } WritingPage;
62
63 void prefs_compose_writing_create_widget(PrefsPage *_page, GtkWindow *window, 
64                                   gpointer data)
65 {
66         WritingPage *prefs_writing = (WritingPage *) _page;
67         
68         GtkWidget *vbox1;
69         GtkWidget *vbox2;
70
71         GtkWidget *checkbtn_autoextedit;
72
73         GtkWidget *frame;
74         GtkWidget *hbox_autosel;
75         GtkWidget *checkbtn_reply_account_autosel;
76         GtkWidget *checkbtn_forward_account_autosel;
77         GtkWidget *checkbtn_reedit_account_autosel;
78
79         GtkWidget *hbox_undolevel;
80         GtkWidget *label_undolevel;
81         GtkObject *spinbtn_undolevel_adj;
82         GtkWidget *spinbtn_undolevel;
83
84         GtkWidget *checkbtn_default_reply_list;
85
86         GtkWidget *checkbtn_forward_as_attachment;
87         GtkWidget *checkbtn_redirect_keep_from;
88
89         GtkWidget *hbox_autosave;
90         GtkWidget *checkbtn_autosave;
91         GtkObject *spinbtn_autosave_adj;
92         GtkWidget *spinbtn_autosave_length;
93         GtkWidget *label_autosave_length;
94         
95         GtkWidget *hbox_dnd_insert_or_attach;
96         GtkWidget *label_dnd_insert_or_attach;
97         GtkWidget *optmenu_dnd_insert_or_attach;
98         GtkWidget *menu;
99         GtkWidget *menuitem;
100
101         vbox1 = gtk_vbox_new (FALSE, VSPACING);
102         gtk_widget_show (vbox1);
103         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
104
105         /* Account autoselection */
106         PACK_FRAME(vbox1, frame, _("Automatic account selection"));
107
108         hbox_autosel = gtk_hbox_new (TRUE, VSPACING_NARROW);
109         gtk_widget_show (hbox_autosel);
110         gtk_container_add (GTK_CONTAINER (frame), hbox_autosel);
111         gtk_container_set_border_width (GTK_CONTAINER (hbox_autosel), 8);
112
113         PACK_CHECK_BUTTON (hbox_autosel, checkbtn_reply_account_autosel,
114                            _("when replying"));
115         PACK_CHECK_BUTTON (hbox_autosel, checkbtn_forward_account_autosel,
116                            _("when forwarding"));
117         PACK_CHECK_BUTTON (hbox_autosel, checkbtn_reedit_account_autosel,
118                            _("when re-editing"));
119
120         PACK_FRAME(vbox1, frame, _("Forwarding"));
121         
122         vbox2 = gtk_vbox_new (FALSE, VSPACING_NARROW);
123         gtk_widget_show (vbox2);
124         gtk_container_add (GTK_CONTAINER (frame), vbox2);
125         gtk_container_set_border_width (GTK_CONTAINER (vbox2), 8);      
126
127         PACK_CHECK_BUTTON (vbox2, checkbtn_forward_as_attachment,
128                            _("Forward as attachment"));
129
130         PACK_CHECK_BUTTON (vbox2, checkbtn_redirect_keep_from,
131                            _("Keep the original 'From' header when redirecting"));
132
133         PACK_FRAME(vbox1, frame, _("Editing"));
134
135         vbox2 = gtk_vbox_new (FALSE, VSPACING_NARROW);
136         gtk_widget_show (vbox2);
137         gtk_container_add (GTK_CONTAINER (frame), vbox2);
138         gtk_container_set_border_width (GTK_CONTAINER (vbox2), 8);
139
140         PACK_CHECK_BUTTON (vbox2, checkbtn_autoextedit,
141                            _("Automatically launch the external editor"));
142
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                            _("Autosave message text to Drafts folder every"));
149
150         spinbtn_autosave_adj = gtk_adjustment_new (50, 0, 1000, 1, 10, 10);
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         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, 10);
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         PACK_CHECK_BUTTON (vbox1, checkbtn_default_reply_list,
179                            _("Reply button invokes mailing list reply"));
180
181         /* dnd insert or attach */
182         label_dnd_insert_or_attach = gtk_label_new (_("When dropping files into the Compose window"));
183         gtk_misc_set_alignment(GTK_MISC(label_dnd_insert_or_attach), 0, 0.5);
184         gtk_widget_show (label_dnd_insert_or_attach);
185
186         optmenu_dnd_insert_or_attach = gtk_option_menu_new ();
187         gtk_widget_show (optmenu_dnd_insert_or_attach);
188
189         menu = gtk_menu_new ();
190         MENUITEM_ADD (menu, menuitem, _("Ask"), COMPOSE_DND_ASK);
191         MENUITEM_ADD (menu, menuitem, _("Insert"), COMPOSE_DND_INSERT);
192         MENUITEM_ADD (menu, menuitem, _("Attach"), COMPOSE_DND_ATTACH);
193
194         gtk_option_menu_set_menu (GTK_OPTION_MENU (optmenu_dnd_insert_or_attach), menu);
195
196         hbox_dnd_insert_or_attach = gtk_hbox_new(FALSE, 20);
197         gtk_widget_show(hbox_dnd_insert_or_attach);
198         gtk_box_pack_start(GTK_BOX(vbox1), hbox_dnd_insert_or_attach, FALSE, FALSE, 0);
199         gtk_box_pack_start(GTK_BOX(hbox_dnd_insert_or_attach),
200                         label_dnd_insert_or_attach, FALSE, FALSE, 0);
201         gtk_box_pack_start(GTK_BOX(hbox_dnd_insert_or_attach),
202                         optmenu_dnd_insert_or_attach, FALSE, FALSE, 0);
203         
204         SET_TOGGLE_SENSITIVITY (checkbtn_autosave, spinbtn_autosave_length);
205         SET_TOGGLE_SENSITIVITY (checkbtn_autosave, label_autosave_length);
206
207         prefs_writing->checkbtn_autoextedit = checkbtn_autoextedit;
208
209         prefs_writing->checkbtn_reply_account_autosel   = checkbtn_reply_account_autosel;
210         prefs_writing->checkbtn_forward_account_autosel = checkbtn_forward_account_autosel;
211         prefs_writing->checkbtn_reedit_account_autosel  = checkbtn_reedit_account_autosel;
212
213         prefs_writing->spinbtn_undolevel     = spinbtn_undolevel;
214
215         prefs_writing->checkbtn_autosave     = checkbtn_autosave;
216         prefs_writing->spinbtn_autosave_length = spinbtn_autosave_length;
217         
218         prefs_writing->checkbtn_forward_as_attachment =
219                 checkbtn_forward_as_attachment;
220         prefs_writing->checkbtn_redirect_keep_from =
221                 checkbtn_redirect_keep_from;
222         prefs_writing->checkbtn_default_reply_list = checkbtn_default_reply_list;
223
224         prefs_writing->optmenu_dnd_insert_or_attach = optmenu_dnd_insert_or_attach;
225
226         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_writing->checkbtn_autoextedit),
227                 prefs_common.auto_exteditor);
228         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_writing->checkbtn_forward_as_attachment),
229                 prefs_common.forward_as_attachment);
230         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_writing->checkbtn_redirect_keep_from),
231                 prefs_common.redirect_keep_from);
232         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_writing->checkbtn_autosave),
233                 prefs_common.autosave);
234         gtk_spin_button_set_value(GTK_SPIN_BUTTON(prefs_writing->spinbtn_autosave_length),
235                 prefs_common.autosave_length);
236         gtk_spin_button_set_value(GTK_SPIN_BUTTON(prefs_writing->spinbtn_undolevel),
237                 prefs_common.undolevels);
238         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_writing->checkbtn_reply_account_autosel),
239                 prefs_common.reply_account_autosel);
240         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_writing->checkbtn_forward_account_autosel),
241                 prefs_common.forward_account_autosel);
242         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_writing->checkbtn_reedit_account_autosel),
243                 prefs_common.reedit_account_autosel);
244         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_writing->checkbtn_default_reply_list),
245                 prefs_common.default_reply_list);
246         gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu_dnd_insert_or_attach),
247                 prefs_common.compose_dnd_mode);
248
249         prefs_writing->page.widget = vbox1;
250 }
251
252 void prefs_compose_writing_save(PrefsPage *_page)
253 {
254         GtkWidget *menu;
255         GtkWidget *menuitem;
256
257         WritingPage *page = (WritingPage *) _page;
258         prefs_common.auto_exteditor = 
259                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_autoextedit));
260         prefs_common.forward_as_attachment =
261                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_forward_as_attachment));
262         prefs_common.redirect_keep_from =
263                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_redirect_keep_from));
264         prefs_common.autosave = 
265                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_autosave));
266         prefs_common.autosave_length =
267                 gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(page->spinbtn_autosave_length));
268         prefs_common.undolevels = 
269                 gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(page->spinbtn_undolevel));
270                 
271         prefs_common.reply_account_autosel =
272                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_reply_account_autosel));
273         prefs_common.forward_account_autosel =
274                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_forward_account_autosel));
275         prefs_common.reedit_account_autosel =
276                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_reedit_account_autosel));
277         prefs_common.default_reply_list =
278                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_default_reply_list));
279         
280         menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(page->optmenu_dnd_insert_or_attach));
281         menuitem = gtk_menu_get_active(GTK_MENU(menu));
282         prefs_common.compose_dnd_mode = GPOINTER_TO_INT
283                 (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
284 }
285
286 static void prefs_compose_writing_destroy_widget(PrefsPage *_page)
287 {
288 }
289
290 WritingPage *prefs_writing;
291
292 void prefs_compose_writing_init(void)
293 {
294         WritingPage *page;
295         static gchar *path[3];
296
297         path[0] = _("Compose");
298         path[1] = _("Writing");
299         path[2] = NULL;
300
301         page = g_new0(WritingPage, 1);
302         page->page.path = path;
303         page->page.create_widget = prefs_compose_writing_create_widget;
304         page->page.destroy_widget = prefs_compose_writing_destroy_widget;
305         page->page.save_page = prefs_compose_writing_save;
306         page->page.weight = 190.0;
307         prefs_gtk_register_page((PrefsPage *) page);
308         prefs_writing = page;
309 }
310
311 void prefs_compose_writing_done(void)
312 {
313         prefs_gtk_unregister_page((PrefsPage *) prefs_writing);
314         g_free(prefs_writing);
315 }