2007-08-15 [ticho] 2.10.0cvs124
[claws.git] / src / prefs_compose_writing.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 2005-2007 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 *hbox_autosave;
64         GtkWidget *checkbtn_autosave;
65         GtkWidget *spinbtn_autosave_length;
66         GtkWidget *optmenu_dnd_insert_or_attach;
67         GtkWidget *entry_quote_chars;
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 *checkbtn_reply_with_quote;
92         GtkWidget *checkbtn_default_reply_list;
93
94         GtkWidget *checkbtn_forward_as_attachment;
95         GtkWidget *checkbtn_redirect_keep_from;
96
97         GtkWidget *hbox_autosave;
98         GtkWidget *checkbtn_autosave;
99         GtkObject *spinbtn_autosave_adj;
100         GtkWidget *spinbtn_autosave_length;
101         GtkWidget *label_autosave_length;
102         
103         GtkWidget *hbox_dnd_insert_or_attach;
104         GtkWidget *label_dnd_insert_or_attach;
105         GtkWidget *optmenu_dnd_insert_or_attach;
106         GtkListStore *menu;
107         GtkTreeIter iter;
108
109         GtkWidget *frame_quote;
110         GtkWidget *hbox1;
111         GtkWidget *hbox2;
112         GtkWidget *vbox_quote;
113         GtkWidget *entry_quote_chars;
114         GtkWidget *label_quote_chars;
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         vbox2 = gtkut_get_options_frame(vbox1, &frame, _("Editing"));
136
137         PACK_CHECK_BUTTON (vbox2, checkbtn_autoextedit,
138                            _("Automatically launch the external editor"));
139
140         hbox_autosave = gtk_hbox_new (FALSE, 8);
141         gtk_widget_show (hbox_autosave);
142         gtk_box_pack_start (GTK_BOX (vbox2), hbox_autosave, FALSE, FALSE, 0);
143
144         PACK_CHECK_BUTTON (hbox_autosave, checkbtn_autosave,
145                            _("Autosave message text to Drafts folder every"));
146
147         spinbtn_autosave_adj = gtk_adjustment_new (50, 0, 1000, 1, 10, 10);
148         spinbtn_autosave_length = gtk_spin_button_new
149                 (GTK_ADJUSTMENT (spinbtn_autosave_adj), 1, 0);
150         gtk_widget_set_size_request (spinbtn_autosave_length, 64, -1);  
151         gtk_widget_show (spinbtn_autosave_length);
152         gtk_box_pack_start (GTK_BOX (hbox_autosave), spinbtn_autosave_length, FALSE, FALSE, 0);
153         gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_autosave_length), TRUE);
154         
155         label_autosave_length = gtk_label_new(_("characters"));
156         gtk_widget_show (label_autosave_length);
157         gtk_box_pack_start (GTK_BOX (hbox_autosave), label_autosave_length, FALSE, FALSE, 0);
158         
159         hbox_undolevel = gtk_hbox_new (FALSE, 8);
160         gtk_widget_show (hbox_undolevel);
161         gtk_box_pack_start (GTK_BOX (vbox2), hbox_undolevel, FALSE, FALSE, 0);
162
163         label_undolevel = gtk_label_new (_("Undo level"));
164         gtk_widget_show (label_undolevel);
165         gtk_box_pack_start (GTK_BOX (hbox_undolevel), label_undolevel, FALSE, FALSE, 0);
166
167         spinbtn_undolevel_adj = gtk_adjustment_new (50, 0, 100, 1, 10, 10);
168         spinbtn_undolevel = gtk_spin_button_new
169                 (GTK_ADJUSTMENT (spinbtn_undolevel_adj), 1, 0);
170         gtk_widget_show (spinbtn_undolevel);
171         gtk_box_pack_start (GTK_BOX (hbox_undolevel), spinbtn_undolevel, FALSE, FALSE, 0);
172         gtk_widget_set_size_request (spinbtn_undolevel, 64, -1);
173         gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_undolevel), TRUE);
174         
175         vbox2 = gtkut_get_options_frame(vbox1, &frame, _("Replying"));
176
177         PACK_CHECK_BUTTON (vbox2, checkbtn_reply_with_quote,
178                            _("Reply will quote by default"));
179
180         PACK_CHECK_BUTTON (vbox2, checkbtn_default_reply_list,
181                            _("Reply button invokes mailing list reply"));
182
183         vbox2 = gtkut_get_options_frame(vbox1, &frame, _("Forwarding"));
184
185         PACK_CHECK_BUTTON (vbox2, checkbtn_forward_as_attachment,
186                            _("Forward as attachment"));
187
188         PACK_CHECK_BUTTON (vbox2, checkbtn_redirect_keep_from,
189                            _("Keep the original 'From' header when redirecting"));
190
191         /* dnd insert or attach */
192         label_dnd_insert_or_attach = gtk_label_new (_("When dropping files into the Compose window"));
193         gtk_misc_set_alignment(GTK_MISC(label_dnd_insert_or_attach), 0, 0.5);
194         gtk_widget_show (label_dnd_insert_or_attach);
195
196         optmenu_dnd_insert_or_attach = gtkut_sc_combobox_create(NULL, FALSE);
197         gtk_widget_show (optmenu_dnd_insert_or_attach);
198
199         menu = GTK_LIST_STORE(gtk_combo_box_get_model(
200                                 GTK_COMBO_BOX(optmenu_dnd_insert_or_attach)));
201         COMBOBOX_ADD (menu, _("Ask"), COMPOSE_DND_ASK);
202         COMBOBOX_ADD (menu, _("Insert"), COMPOSE_DND_INSERT);
203         COMBOBOX_ADD (menu, _("Attach"), COMPOSE_DND_ATTACH);
204
205         hbox_dnd_insert_or_attach = gtk_hbox_new(FALSE, 20);
206         gtk_widget_show(hbox_dnd_insert_or_attach);
207         gtk_box_pack_start(GTK_BOX(vbox1), hbox_dnd_insert_or_attach, FALSE, FALSE, 0);
208         gtk_box_pack_start(GTK_BOX(hbox_dnd_insert_or_attach),
209                         label_dnd_insert_or_attach, FALSE, FALSE, 0);
210         gtk_box_pack_start(GTK_BOX(hbox_dnd_insert_or_attach),
211                         optmenu_dnd_insert_or_attach, FALSE, FALSE, 0);
212         
213         SET_TOGGLE_SENSITIVITY (checkbtn_autosave, spinbtn_autosave_length);
214         SET_TOGGLE_SENSITIVITY (checkbtn_autosave, label_autosave_length);
215
216         /* quote chars */
217
218         PACK_FRAME (vbox1, frame_quote, _("Quotation characters"));
219
220         vbox_quote = gtk_vbox_new (FALSE, VSPACING_NARROW);
221         gtk_widget_show (vbox_quote);
222         gtk_container_add (GTK_CONTAINER (frame_quote), vbox_quote);
223         gtk_container_set_border_width (GTK_CONTAINER (vbox_quote), 8);
224
225         hbox1 = gtk_hbox_new (FALSE, 32);
226         gtk_widget_show (hbox1);
227         gtk_box_pack_start (GTK_BOX (vbox_quote), hbox1, FALSE, FALSE, 0);
228
229         hbox2 = gtk_hbox_new (FALSE, 8);
230         gtk_widget_show (hbox2);
231         gtk_box_pack_start (GTK_BOX (hbox1), hbox2, FALSE, FALSE, 0);
232
233         label_quote_chars = gtk_label_new (_("Treat these characters as quotation marks: "));
234         gtk_widget_show (label_quote_chars);
235         gtk_box_pack_start (GTK_BOX (hbox2), label_quote_chars, FALSE, FALSE, 0);
236
237         entry_quote_chars = gtk_entry_new ();
238         gtk_widget_show (entry_quote_chars);
239         gtk_box_pack_start (GTK_BOX (hbox2), entry_quote_chars,
240                             FALSE, FALSE, 0);
241         gtk_widget_set_size_request (entry_quote_chars, 64, -1);
242
243
244         prefs_writing->checkbtn_autoextedit = checkbtn_autoextedit;
245
246         prefs_writing->checkbtn_reply_account_autosel   = checkbtn_reply_account_autosel;
247         prefs_writing->checkbtn_forward_account_autosel = checkbtn_forward_account_autosel;
248         prefs_writing->checkbtn_reedit_account_autosel  = checkbtn_reedit_account_autosel;
249
250         prefs_writing->spinbtn_undolevel     = spinbtn_undolevel;
251
252         prefs_writing->checkbtn_autosave     = checkbtn_autosave;
253         prefs_writing->spinbtn_autosave_length = spinbtn_autosave_length;
254         
255         prefs_writing->checkbtn_forward_as_attachment =
256                 checkbtn_forward_as_attachment;
257         prefs_writing->checkbtn_redirect_keep_from = checkbtn_redirect_keep_from;
258         prefs_writing->checkbtn_reply_with_quote     = checkbtn_reply_with_quote;
259         prefs_writing->checkbtn_default_reply_list = checkbtn_default_reply_list;
260
261         prefs_writing->optmenu_dnd_insert_or_attach = optmenu_dnd_insert_or_attach;
262
263         prefs_writing->entry_quote_chars        = entry_quote_chars;
264
265         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_writing->checkbtn_autoextedit),
266                 prefs_common.auto_exteditor);
267         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_writing->checkbtn_forward_as_attachment),
268                 prefs_common.forward_as_attachment);
269         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_writing->checkbtn_redirect_keep_from),
270                 prefs_common.redirect_keep_from);
271         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_writing->checkbtn_autosave),
272                 prefs_common.autosave);
273         gtk_spin_button_set_value(GTK_SPIN_BUTTON(prefs_writing->spinbtn_autosave_length),
274                 prefs_common.autosave_length);
275         gtk_spin_button_set_value(GTK_SPIN_BUTTON(prefs_writing->spinbtn_undolevel),
276                 prefs_common.undolevels);
277         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_writing->checkbtn_reply_account_autosel),
278                 prefs_common.reply_account_autosel);
279         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_writing->checkbtn_forward_account_autosel),
280                 prefs_common.forward_account_autosel);
281         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_writing->checkbtn_reedit_account_autosel),
282                 prefs_common.reedit_account_autosel);
283         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_writing->checkbtn_reply_with_quote),
284                         prefs_common.reply_with_quote);
285         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_writing->checkbtn_default_reply_list),
286                 prefs_common.default_reply_list);
287         combobox_select_by_data(GTK_COMBO_BOX(optmenu_dnd_insert_or_attach),
288                 prefs_common.compose_dnd_mode);
289         gtk_entry_set_text(GTK_ENTRY(entry_quote_chars), 
290                         prefs_common.quote_chars?prefs_common.quote_chars:"");
291
292         prefs_writing->page.widget = vbox1;
293 }
294
295 static void prefs_compose_writing_save(PrefsPage *_page)
296 {
297         WritingPage *page = (WritingPage *) _page;
298
299         prefs_common.auto_exteditor = 
300                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_autoextedit));
301         prefs_common.forward_as_attachment =
302                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_forward_as_attachment));
303         prefs_common.redirect_keep_from =
304                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_redirect_keep_from));
305         prefs_common.autosave = 
306                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_autosave));
307         prefs_common.autosave_length =
308                 gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(page->spinbtn_autosave_length));
309         prefs_common.undolevels = 
310                 gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(page->spinbtn_undolevel));
311                 
312         prefs_common.reply_account_autosel =
313                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_reply_account_autosel));
314         prefs_common.forward_account_autosel =
315                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_forward_account_autosel));
316         prefs_common.reedit_account_autosel =
317                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_reedit_account_autosel));
318         prefs_common.reply_with_quote = gtk_toggle_button_get_active(
319                         GTK_TOGGLE_BUTTON(page->checkbtn_reply_with_quote));
320         prefs_common.default_reply_list =
321                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_default_reply_list));
322         
323         prefs_common.compose_dnd_mode = combobox_get_active_data(
324                         GTK_COMBO_BOX(page->optmenu_dnd_insert_or_attach));
325
326         g_free(prefs_common.quote_chars); 
327         prefs_common.quote_chars = gtk_editable_get_chars(
328                         GTK_EDITABLE(page->entry_quote_chars), 0, -1);
329         remove_space(prefs_common.quote_chars);
330 }
331
332 static void prefs_compose_writing_destroy_widget(PrefsPage *_page)
333 {
334 }
335
336 WritingPage *prefs_writing;
337
338 void prefs_compose_writing_init(void)
339 {
340         WritingPage *page;
341         static gchar *path[3];
342
343         path[0] = _("Compose");
344         path[1] = _("Writing");
345         path[2] = NULL;
346
347         page = g_new0(WritingPage, 1);
348         page->page.path = path;
349         page->page.create_widget = prefs_compose_writing_create_widget;
350         page->page.destroy_widget = prefs_compose_writing_destroy_widget;
351         page->page.save_page = prefs_compose_writing_save;
352         page->page.weight = 190.0;
353         prefs_gtk_register_page((PrefsPage *) page);
354         prefs_writing = page;
355 }
356
357 void prefs_compose_writing_done(void)
358 {
359         prefs_gtk_unregister_page((PrefsPage *) prefs_writing);
360         g_free(prefs_writing);
361 }