fd711b7de2e858d0d8055914b6c89daf53fb0f64
[claws.git] / src / prefs_send.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 #include "gtk/menu.h"
37
38 #include "gtk/gtkutils.h"
39 #include "gtk/prefswindow.h"
40
41 #include "manage_window.h"
42
43 typedef struct _SendPage
44 {
45         PrefsPage page;
46
47         GtkWidget *window;
48
49         GtkWidget *checkbtn_savemsg;
50         GtkWidget *checkbtn_confirm_send_queued_messages;
51         GtkWidget *checkbtn_never_send_retrcpt;
52         GtkWidget *optmenu_senddialog;
53         GtkWidget *optmenu_charset;
54         GtkWidget *optmenu_encoding_method;
55 } SendPage;
56
57 static gchar * prefs_common_charset_set_data_from_optmenu(GtkWidget *widget)
58 {
59         GtkWidget *menu;
60         GtkWidget *menuitem;
61         gchar *charset;
62
63         menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(widget));
64         menuitem = gtk_menu_get_active(GTK_MENU(menu));
65         charset = g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID);
66         return g_strdup(charset);
67 }
68
69 static void prefs_common_charset_set_optmenu(GtkWidget *widget, gchar *data)
70 {
71         GtkOptionMenu *optmenu = GTK_OPTION_MENU(widget);
72         gint index;
73
74         g_return_if_fail(optmenu != NULL);
75         g_return_if_fail(data != NULL);
76
77         index = menu_find_option_menu_index(optmenu, data,
78                                             (GCompareFunc)strcmp2);
79         if (index >= 0)
80                 gtk_option_menu_set_history(optmenu, index);
81         else
82                 gtk_option_menu_set_history(optmenu, 0);
83 }
84
85 static TransferEncodingMethod prefs_common_encoding_set_data_from_optmenu(GtkWidget *widget)
86 {
87         GtkWidget *menu;
88         GtkWidget *menuitem;
89
90         menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(widget));
91         menuitem = gtk_menu_get_active(GTK_MENU(menu));
92         return GPOINTER_TO_INT
93                 (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
94 }
95
96 static void prefs_common_encoding_set_optmenu(GtkWidget *widget, TransferEncodingMethod method)
97 {
98         GtkOptionMenu *optmenu = GTK_OPTION_MENU(widget);
99         gint index;
100
101         g_return_if_fail(optmenu != NULL);
102
103         index = menu_find_option_menu_index(optmenu, GINT_TO_POINTER(method),
104                                             NULL);
105         if (index >= 0)
106                 gtk_option_menu_set_history(optmenu, index);
107         else
108                 gtk_option_menu_set_history(optmenu, 0);
109 }
110
111
112 static void prefs_send_create_widget(PrefsPage *_page, GtkWindow *window, 
113                                   gpointer data)
114 {
115         SendPage *prefs_send = (SendPage *) _page;
116         
117         GtkWidget *vbox1;
118         GtkWidget *vbox2;
119         GtkWidget *checkbtn_savemsg;
120         GtkWidget *label_outcharset;
121         GtkWidget *optmenu_charset;
122         GtkWidget *optmenu_menu;
123         GtkWidget *menuitem;
124         GtkTooltips *charset_tooltip;
125         GtkWidget *optmenu_encoding;
126         GtkWidget *label_encoding;
127         GtkTooltips *encoding_tooltip;
128         GtkWidget *label_senddialog;
129         GtkWidget *menu;
130         GtkWidget *optmenu_senddialog;
131         GtkWidget *checkbtn_confirm_send_queued_messages;
132         GtkWidget *checkbtn_never_send_retrcpt;
133         GtkWidget *table;
134
135         vbox1 = gtk_vbox_new (FALSE, VSPACING);
136         gtk_widget_show (vbox1);
137         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
138
139         vbox2 = gtk_vbox_new (FALSE, 0);
140         gtk_widget_show (vbox2);
141         gtk_box_pack_start (GTK_BOX (vbox1), vbox2, FALSE, FALSE, 0);
142
143         PACK_CHECK_BUTTON (vbox2, checkbtn_savemsg,
144                         _("Save sent messages to Sent folder"));
145
146         PACK_CHECK_BUTTON (vbox2, checkbtn_confirm_send_queued_messages,
147                         _("Confirm before sending queued messages"));
148
149         PACK_CHECK_BUTTON(vbox2, checkbtn_never_send_retrcpt,
150                           _("Never send Return Receipts"));
151
152         table = gtk_table_new(3, 2, FALSE);
153         gtk_widget_show(table);
154         gtk_container_add (GTK_CONTAINER (vbox1), table);
155         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
156         gtk_table_set_col_spacings(GTK_TABLE(table), 8);
157
158         label_senddialog = gtk_label_new (_("Show send dialog"));
159         gtk_widget_show (label_senddialog);
160         gtk_table_attach(GTK_TABLE(table), label_senddialog, 0, 1, 0, 1,
161                         (GtkAttachOptions) (GTK_FILL),
162                         (GtkAttachOptions) (0), 0, 0);
163         gtk_label_set_justify(GTK_LABEL(label_senddialog), GTK_JUSTIFY_RIGHT);
164         gtk_misc_set_alignment(GTK_MISC(label_senddialog), 1, 0.5);
165
166         /* FIXME : Is it good to change this menu into a checkbtn ? */
167         optmenu_senddialog = gtk_option_menu_new ();
168         gtk_widget_show (optmenu_senddialog);
169         gtk_table_attach(GTK_TABLE(table), optmenu_senddialog, 1, 2, 0, 1,
170                         (GtkAttachOptions) (GTK_FILL),
171                         (GtkAttachOptions) (0), 0, 0);
172
173         menu = gtk_menu_new ();
174         MENUITEM_ADD (menu, menuitem, _("Always"), SEND_DIALOG_ALWAYS);
175         MENUITEM_ADD (menu, menuitem, _("Never"), SEND_DIALOG_NEVER);
176
177         gtk_option_menu_set_menu (GTK_OPTION_MENU (optmenu_senddialog), menu);
178
179         label_outcharset = gtk_label_new (_("Outgoing encoding"));
180         gtk_widget_show (label_outcharset);
181         gtk_table_attach(GTK_TABLE(table), label_outcharset, 0, 1, 1, 2,
182                         (GtkAttachOptions) (GTK_FILL),
183                         (GtkAttachOptions) (0), 0, 0);
184         gtk_label_set_justify(GTK_LABEL(label_outcharset), GTK_JUSTIFY_RIGHT);
185         gtk_misc_set_alignment(GTK_MISC(label_outcharset), 1, 0.5);
186
187         charset_tooltip = gtk_tooltips_new();
188
189         optmenu_charset = gtk_option_menu_new ();
190         gtk_widget_show (optmenu_charset);
191         gtk_tooltips_set_tip(GTK_TOOLTIPS(charset_tooltip), optmenu_charset,
192                              _("If 'Automatic' is selected, the optimal encoding"
193                                " for the current locale will be used"),
194                              NULL);
195         gtk_table_attach(GTK_TABLE(table), optmenu_charset, 1, 2, 1, 2,
196                         (GtkAttachOptions) (GTK_FILL),
197                         (GtkAttachOptions) (0), 0, 0);
198
199         optmenu_menu = gtk_menu_new ();
200
201 #define SET_MENUITEM(str, data) \
202 { \
203         MENUITEM_ADD(optmenu_menu, menuitem, str, data); \
204 }
205
206         SET_MENUITEM(_("Automatic (Recommended)"),       CS_AUTO);
207         SET_MENUITEM(NULL, NULL);
208         SET_MENUITEM(_("7bit ascii (US-ASCII)"),         CS_US_ASCII);
209         SET_MENUITEM(_("Unicode (UTF-8)"),               CS_UTF_8);
210         SET_MENUITEM(NULL, NULL);
211         SET_MENUITEM(_("Western European (ISO-8859-1)"),  CS_ISO_8859_1);
212         SET_MENUITEM(_("Western European (ISO-8859-15)"), CS_ISO_8859_15);
213         SET_MENUITEM(NULL, NULL);
214         SET_MENUITEM(_("Central European (ISO-8859-2)"), CS_ISO_8859_2);
215         SET_MENUITEM(NULL, NULL);
216         SET_MENUITEM(_("Baltic (ISO-8859-13)"),          CS_ISO_8859_13);
217         SET_MENUITEM(_("Baltic (ISO-8859-4)"),           CS_ISO_8859_4);
218         SET_MENUITEM(NULL, NULL);
219         SET_MENUITEM(_("Greek (ISO-8859-7)"),            CS_ISO_8859_7);
220         SET_MENUITEM(NULL, NULL);
221         SET_MENUITEM(_("Hebrew (ISO-8859-8)"),           CS_ISO_8859_8);
222         SET_MENUITEM(_("Hebrew (Windows-1255)"),         CS_WINDOWS_1255);
223         SET_MENUITEM(NULL, NULL);
224         SET_MENUITEM(_("Arabic (ISO-8859-6)"),           CS_ISO_8859_6);
225         SET_MENUITEM(_("Arabic (Windows-1256)"),         CS_WINDOWS_1256);
226         SET_MENUITEM(NULL, NULL);
227         SET_MENUITEM(_("Turkish (ISO-8859-9)"),          CS_ISO_8859_9);
228         SET_MENUITEM(NULL, NULL);
229         SET_MENUITEM(_("Cyrillic (ISO-8859-5)"),         CS_ISO_8859_5);
230         SET_MENUITEM(_("Cyrillic (KOI8-R)"),             CS_KOI8_R);
231         SET_MENUITEM(_("Cyrillic (KOI8-U)"),             CS_KOI8_U);
232         SET_MENUITEM(_("Cyrillic (Windows-1251)"),       CS_WINDOWS_1251);
233         SET_MENUITEM(NULL, NULL);
234         SET_MENUITEM(_("Japanese (ISO-2022-JP)"),        CS_ISO_2022_JP);
235 #if 0
236         SET_MENUITEM(_("Japanese (EUC-JP)"),             CS_EUC_JP);
237         SET_MENUITEM(_("Japanese (Shift_JIS)"),          CS_SHIFT_JIS);
238 #endif /* 0 */
239         SET_MENUITEM(NULL, NULL);
240         SET_MENUITEM(_("Simplified Chinese (GB2312)"),   CS_GB2312);
241         SET_MENUITEM(_("Simplified Chinese (GBK)"),      CS_GBK);
242         SET_MENUITEM(_("Traditional Chinese (Big5)"),    CS_BIG5);
243 #if 0
244         SET_MENUITEM(_("Traditional Chinese (EUC-TW)"),  CS_EUC_TW);
245         SET_MENUITEM(_("Chinese (ISO-2022-CN)"),         CS_ISO_2022_CN);
246 #endif /* 0 */
247         SET_MENUITEM(NULL, NULL);
248         SET_MENUITEM(_("Korean (EUC-KR)"),               CS_EUC_KR);
249         SET_MENUITEM(NULL, NULL);
250         SET_MENUITEM(_("Thai (TIS-620)"),                CS_TIS_620);
251         SET_MENUITEM(_("Thai (Windows-874)"),            CS_WINDOWS_874);
252
253         gtk_option_menu_set_menu (GTK_OPTION_MENU (optmenu_charset),
254                                   optmenu_menu);
255
256         label_encoding = gtk_label_new (_("Transfer encoding"));
257         gtk_widget_show (label_encoding);
258         gtk_table_attach(GTK_TABLE(table), label_encoding, 0, 1, 2, 3,
259                         (GtkAttachOptions) (GTK_FILL),
260                         (GtkAttachOptions) (0), 0, 0);
261         gtk_label_set_justify(GTK_LABEL(label_encoding), GTK_JUSTIFY_RIGHT);
262         gtk_misc_set_alignment(GTK_MISC(label_encoding), 1, 0.5);
263
264         encoding_tooltip = gtk_tooltips_new();
265
266         optmenu_encoding = gtk_option_menu_new ();
267         gtk_widget_show (optmenu_encoding);
268         gtk_tooltips_set_tip(GTK_TOOLTIPS(encoding_tooltip), optmenu_encoding,
269                              _("Specify Content-Transfer-Encoding used when"
270                                " message body contains non-ASCII characters"),
271                              NULL);
272         gtk_table_attach(GTK_TABLE(table), optmenu_encoding, 1, 2, 2, 3,
273                         (GtkAttachOptions) (GTK_FILL),
274                         (GtkAttachOptions) (0), 0, 0);
275
276         optmenu_menu = gtk_menu_new ();
277
278         SET_MENUITEM(_("Automatic"),     CTE_AUTO);
279         SET_MENUITEM("base64",           CTE_BASE64);
280         SET_MENUITEM("quoted-printable", CTE_QUOTED_PRINTABLE);
281         SET_MENUITEM("8bit",             CTE_8BIT);
282
283         gtk_option_menu_set_menu (GTK_OPTION_MENU (optmenu_encoding),
284                                   optmenu_menu);
285
286         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_savemsg),
287                 prefs_common.savemsg);
288         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_confirm_send_queued_messages),
289                 prefs_common.confirm_send_queued_messages);
290         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_never_send_retrcpt),
291                 prefs_common.never_send_retrcpt);
292         gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu_senddialog),
293                 prefs_common.send_dialog_mode);
294         prefs_common_charset_set_optmenu(optmenu_charset, 
295                 prefs_common.outgoing_charset);
296         prefs_common_encoding_set_optmenu(optmenu_encoding,
297                 prefs_common.encoding_method);
298         
299         prefs_send->window                      = GTK_WIDGET(window);
300         
301         prefs_send->checkbtn_savemsg = checkbtn_savemsg;
302         prefs_send->checkbtn_confirm_send_queued_messages = checkbtn_confirm_send_queued_messages;
303         prefs_send->checkbtn_never_send_retrcpt = checkbtn_never_send_retrcpt;
304         prefs_send->optmenu_senddialog = optmenu_senddialog;
305         prefs_send->optmenu_charset = optmenu_charset;
306         prefs_send->optmenu_encoding_method = optmenu_encoding;
307
308         prefs_send->page.widget = vbox1;
309 }
310
311 static void prefs_send_save(PrefsPage *_page)
312 {
313         SendPage *page = (SendPage *) _page;
314         GtkWidget *menu;
315         GtkWidget *menuitem;
316
317         prefs_common.savemsg = gtk_toggle_button_get_active(
318                 GTK_TOGGLE_BUTTON(page->checkbtn_savemsg));
319         prefs_common.confirm_send_queued_messages = gtk_toggle_button_get_active(
320                 GTK_TOGGLE_BUTTON(page->checkbtn_confirm_send_queued_messages));
321         prefs_common.never_send_retrcpt = gtk_toggle_button_get_active(
322                 GTK_TOGGLE_BUTTON(page->checkbtn_never_send_retrcpt));
323
324         menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(page->optmenu_senddialog));
325         menuitem = gtk_menu_get_active(GTK_MENU(menu));
326         prefs_common.send_dialog_mode = GPOINTER_TO_INT
327                 (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
328         
329         g_free(prefs_common.outgoing_charset);
330         prefs_common.outgoing_charset = prefs_common_charset_set_data_from_optmenu(
331                 page->optmenu_charset);
332         prefs_common.encoding_method = prefs_common_encoding_set_data_from_optmenu(
333                 page->optmenu_encoding_method);
334 }
335
336 static void prefs_send_destroy_widget(PrefsPage *_page)
337 {
338 }
339
340 SendPage *prefs_send;
341
342 void prefs_send_init(void)
343 {
344         SendPage *page;
345         static gchar *path[3];
346
347         path[0] = _("Mail Handling");
348         path[1] = _("Sending");
349         path[2] = NULL;
350
351         page = g_new0(SendPage, 1);
352         page->page.path = path;
353         page->page.create_widget = prefs_send_create_widget;
354         page->page.destroy_widget = prefs_send_destroy_widget;
355         page->page.save_page = prefs_send_save;
356         page->page.weight = 195.0;
357         prefs_gtk_register_page((PrefsPage *) page);
358         prefs_send = page;
359 }
360
361 void prefs_send_done(void)
362 {
363         prefs_gtk_unregister_page((PrefsPage *) prefs_send);
364         g_free(prefs_send);
365 }