1b24b056a54f4b75bb02316786a501285f6ee83b
[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 *checkbtn_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 *checkbtn_senddialog;
129         GtkWidget *checkbtn_confirm_send_queued_messages;
130         GtkWidget *checkbtn_never_send_retrcpt;
131         GtkWidget *table;
132
133         vbox1 = gtk_vbox_new (FALSE, VSPACING);
134         gtk_widget_show (vbox1);
135         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
136
137         vbox2 = gtk_vbox_new (FALSE, 0);
138         gtk_widget_show (vbox2);
139         gtk_box_pack_start (GTK_BOX (vbox1), vbox2, FALSE, FALSE, 0);
140
141         PACK_CHECK_BUTTON(vbox2, checkbtn_savemsg,
142                         _("Save sent messages to Sent folder"));
143
144         PACK_CHECK_BUTTON(vbox2, checkbtn_confirm_send_queued_messages,
145                         _("Confirm before sending queued messages"));
146
147         PACK_CHECK_BUTTON(vbox2, checkbtn_never_send_retrcpt,
148                         _("Never send Return Receipts"));
149
150         PACK_CHECK_BUTTON(vbox2, checkbtn_senddialog,
151                         _("Show send dialog"));
152
153         table = gtk_table_new(2, 2, FALSE);
154         gtk_widget_show(table);
155         gtk_container_add (GTK_CONTAINER (vbox1), table);
156         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
157         gtk_table_set_col_spacings(GTK_TABLE(table), 8);
158
159         label_outcharset = gtk_label_new (_("Outgoing encoding"));
160         gtk_widget_show (label_outcharset);
161         gtk_table_attach(GTK_TABLE(table), label_outcharset, 0, 1, 1, 2,
162                         (GtkAttachOptions) (GTK_FILL),
163                         (GtkAttachOptions) (0), 0, 0);
164         gtk_label_set_justify(GTK_LABEL(label_outcharset), GTK_JUSTIFY_RIGHT);
165         gtk_misc_set_alignment(GTK_MISC(label_outcharset), 1, 0.5);
166
167         charset_tooltip = gtk_tooltips_new();
168
169         optmenu_charset = gtk_option_menu_new ();
170         gtk_widget_show (optmenu_charset);
171         gtk_tooltips_set_tip(GTK_TOOLTIPS(charset_tooltip), optmenu_charset,
172                              _("If 'Automatic' is selected, the optimal encoding"
173                                " for the current locale will be used"),
174                              NULL);
175         gtk_table_attach(GTK_TABLE(table), optmenu_charset, 1, 2, 1, 2,
176                         (GtkAttachOptions) (GTK_FILL),
177                         (GtkAttachOptions) (0), 0, 0);
178
179         optmenu_menu = gtk_menu_new ();
180
181 #define SET_MENUITEM(str, data) \
182 { \
183         MENUITEM_ADD(optmenu_menu, menuitem, str, data); \
184 }
185
186         SET_MENUITEM(_("Automatic (Recommended)"),       CS_AUTO);
187         SET_MENUITEM(NULL, NULL);
188         SET_MENUITEM(_("7bit ascii (US-ASCII)"),         CS_US_ASCII);
189         SET_MENUITEM(_("Unicode (UTF-8)"),               CS_UTF_8);
190         SET_MENUITEM(NULL, NULL);
191         SET_MENUITEM(_("Western European (ISO-8859-1)"),  CS_ISO_8859_1);
192         SET_MENUITEM(_("Western European (ISO-8859-15)"), CS_ISO_8859_15);
193         SET_MENUITEM(NULL, NULL);
194         SET_MENUITEM(_("Central European (ISO-8859-2)"), CS_ISO_8859_2);
195         SET_MENUITEM(NULL, NULL);
196         SET_MENUITEM(_("Baltic (ISO-8859-13)"),          CS_ISO_8859_13);
197         SET_MENUITEM(_("Baltic (ISO-8859-4)"),           CS_ISO_8859_4);
198         SET_MENUITEM(NULL, NULL);
199         SET_MENUITEM(_("Greek (ISO-8859-7)"),            CS_ISO_8859_7);
200         SET_MENUITEM(NULL, NULL);
201         SET_MENUITEM(_("Hebrew (ISO-8859-8)"),           CS_ISO_8859_8);
202         SET_MENUITEM(_("Hebrew (Windows-1255)"),         CS_WINDOWS_1255);
203         SET_MENUITEM(NULL, NULL);
204         SET_MENUITEM(_("Arabic (ISO-8859-6)"),           CS_ISO_8859_6);
205         SET_MENUITEM(_("Arabic (Windows-1256)"),         CS_WINDOWS_1256);
206         SET_MENUITEM(NULL, NULL);
207         SET_MENUITEM(_("Turkish (ISO-8859-9)"),          CS_ISO_8859_9);
208         SET_MENUITEM(NULL, NULL);
209         SET_MENUITEM(_("Cyrillic (ISO-8859-5)"),         CS_ISO_8859_5);
210         SET_MENUITEM(_("Cyrillic (KOI8-R)"),             CS_KOI8_R);
211         SET_MENUITEM(_("Cyrillic (KOI8-U)"),             CS_KOI8_U);
212         SET_MENUITEM(_("Cyrillic (Windows-1251)"),       CS_WINDOWS_1251);
213         SET_MENUITEM(NULL, NULL);
214         SET_MENUITEM(_("Japanese (ISO-2022-JP)"),        CS_ISO_2022_JP);
215 #if 0
216         SET_MENUITEM(_("Japanese (EUC-JP)"),             CS_EUC_JP);
217         SET_MENUITEM(_("Japanese (Shift_JIS)"),          CS_SHIFT_JIS);
218 #endif /* 0 */
219         SET_MENUITEM(NULL, NULL);
220         SET_MENUITEM(_("Simplified Chinese (GB2312)"),   CS_GB2312);
221         SET_MENUITEM(_("Simplified Chinese (GBK)"),      CS_GBK);
222         SET_MENUITEM(_("Traditional Chinese (Big5)"),    CS_BIG5);
223 #if 0
224         SET_MENUITEM(_("Traditional Chinese (EUC-TW)"),  CS_EUC_TW);
225         SET_MENUITEM(_("Chinese (ISO-2022-CN)"),         CS_ISO_2022_CN);
226 #endif /* 0 */
227         SET_MENUITEM(NULL, NULL);
228         SET_MENUITEM(_("Korean (EUC-KR)"),               CS_EUC_KR);
229         SET_MENUITEM(NULL, NULL);
230         SET_MENUITEM(_("Thai (TIS-620)"),                CS_TIS_620);
231         SET_MENUITEM(_("Thai (Windows-874)"),            CS_WINDOWS_874);
232
233         gtk_option_menu_set_menu (GTK_OPTION_MENU (optmenu_charset),
234                                   optmenu_menu);
235
236         label_encoding = gtk_label_new (_("Transfer encoding"));
237         gtk_widget_show (label_encoding);
238         gtk_table_attach(GTK_TABLE(table), label_encoding, 0, 1, 2, 3,
239                         (GtkAttachOptions) (GTK_FILL),
240                         (GtkAttachOptions) (0), 0, 0);
241         gtk_label_set_justify(GTK_LABEL(label_encoding), GTK_JUSTIFY_RIGHT);
242         gtk_misc_set_alignment(GTK_MISC(label_encoding), 1, 0.5);
243
244         encoding_tooltip = gtk_tooltips_new();
245
246         optmenu_encoding = gtk_option_menu_new ();
247         gtk_widget_show (optmenu_encoding);
248         gtk_tooltips_set_tip(GTK_TOOLTIPS(encoding_tooltip), optmenu_encoding,
249                              _("Specify Content-Transfer-Encoding used when"
250                                " message body contains non-ASCII characters"),
251                              NULL);
252         gtk_table_attach(GTK_TABLE(table), optmenu_encoding, 1, 2, 2, 3,
253                         (GtkAttachOptions) (GTK_FILL),
254                         (GtkAttachOptions) (0), 0, 0);
255
256         optmenu_menu = gtk_menu_new ();
257
258         SET_MENUITEM(_("Automatic"),     CTE_AUTO);
259         SET_MENUITEM("base64",           CTE_BASE64);
260         SET_MENUITEM("quoted-printable", CTE_QUOTED_PRINTABLE);
261         SET_MENUITEM("8bit",             CTE_8BIT);
262
263         gtk_option_menu_set_menu (GTK_OPTION_MENU (optmenu_encoding),
264                                   optmenu_menu);
265
266         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_savemsg),
267                 prefs_common.savemsg);
268         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_confirm_send_queued_messages),
269                 prefs_common.confirm_send_queued_messages);
270         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_never_send_retrcpt),
271                 prefs_common.never_send_retrcpt);
272         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_senddialog),
273                 prefs_common.send_dialog_mode);
274         prefs_common_charset_set_optmenu(optmenu_charset, 
275                 prefs_common.outgoing_charset);
276         prefs_common_encoding_set_optmenu(optmenu_encoding,
277                 prefs_common.encoding_method);
278         
279         prefs_send->window                      = GTK_WIDGET(window);
280         
281         prefs_send->checkbtn_savemsg = checkbtn_savemsg;
282         prefs_send->checkbtn_confirm_send_queued_messages = checkbtn_confirm_send_queued_messages;
283         prefs_send->checkbtn_never_send_retrcpt = checkbtn_never_send_retrcpt;
284         prefs_send->checkbtn_senddialog = checkbtn_senddialog;
285         prefs_send->optmenu_charset = optmenu_charset;
286         prefs_send->optmenu_encoding_method = optmenu_encoding;
287
288         prefs_send->page.widget = vbox1;
289 }
290
291 static void prefs_send_save(PrefsPage *_page)
292 {
293         SendPage *page = (SendPage *) _page;
294
295         prefs_common.savemsg = gtk_toggle_button_get_active(
296                 GTK_TOGGLE_BUTTON(page->checkbtn_savemsg));
297         prefs_common.confirm_send_queued_messages = gtk_toggle_button_get_active(
298                 GTK_TOGGLE_BUTTON(page->checkbtn_confirm_send_queued_messages));
299         prefs_common.never_send_retrcpt = gtk_toggle_button_get_active(
300                 GTK_TOGGLE_BUTTON(page->checkbtn_never_send_retrcpt));
301         prefs_common.send_dialog_mode = gtk_toggle_button_get_active(
302                 GTK_TOGGLE_BUTTON(page->checkbtn_senddialog));
303
304         g_free(prefs_common.outgoing_charset);
305         prefs_common.outgoing_charset = prefs_common_charset_set_data_from_optmenu(
306                 page->optmenu_charset);
307         prefs_common.encoding_method = prefs_common_encoding_set_data_from_optmenu(
308                 page->optmenu_encoding_method);
309 }
310
311 static void prefs_send_destroy_widget(PrefsPage *_page)
312 {
313 }
314
315 SendPage *prefs_send;
316
317 void prefs_send_init(void)
318 {
319         SendPage *page;
320         static gchar *path[3];
321
322         path[0] = _("Mail Handling");
323         path[1] = _("Sending");
324         path[2] = NULL;
325
326         page = g_new0(SendPage, 1);
327         page->page.path = path;
328         page->page.create_widget = prefs_send_create_widget;
329         page->page.destroy_widget = prefs_send_destroy_widget;
330         page->page.save_page = prefs_send_save;
331         page->page.weight = 195.0;
332         prefs_gtk_register_page((PrefsPage *) page);
333         prefs_send = page;
334 }
335
336 void prefs_send_done(void)
337 {
338         prefs_gtk_unregister_page((PrefsPage *) prefs_send);
339         g_free(prefs_send);
340 }