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