modify label to give more clarity
[claws.git] / src / prefs_send.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 2005-2012 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 #include "claws-features.h"
23 #endif
24
25 #include "defs.h"
26
27 #include <stdio.h>
28 #include <stdlib.h>
29
30 #include <glib.h>
31 #include <glib/gi18n.h>
32 #include <gtk/gtk.h>
33 #include <gdk/gdkkeysyms.h>
34
35 #include "prefs_common.h"
36 #include "prefs_gtk.h"
37 #include "gtk/menu.h"
38
39 #include "gtk/gtkutils.h"
40 #include "gtk/prefswindow.h"
41 #include "gtk/combobox.h"
42
43 #include "manage_window.h"
44
45 typedef struct _SendPage
46 {
47         PrefsPage page;
48
49         GtkWidget *window;
50
51         GtkWidget *checkbtn_savemsg;
52         GtkWidget *checkbtn_confirm_send_queued_messages;
53         GtkWidget *checkbtn_never_send_retrcpt;
54         GtkWidget *checkbtn_senddialog;
55         GtkWidget *checkbtn_warn_empty_subj;
56         GtkWidget *combobox_charset;
57         GtkWidget *combobox_encoding_method;
58 } SendPage;
59
60 static gchar * prefs_common_charset_set_data_from_optmenu(GtkWidget *widget)
61 {
62         GtkTreeModel *model;
63         GtkTreeIter iter;
64         gchar *data = NULL;
65
66         cm_return_val_if_fail(widget != NULL, NULL);
67
68         cm_return_val_if_fail(gtk_combo_box_get_active_iter(
69                                 GTK_COMBO_BOX(widget), &iter), NULL);
70
71         model = gtk_combo_box_get_model(GTK_COMBO_BOX(widget));
72
73         gtk_tree_model_get(model, &iter, COMBOBOX_DATA, &data, -1);
74
75         return data;
76 }
77
78 typedef struct _combobox_sel_by_data_ctx {
79         GtkComboBox *combobox;
80         gchar *data;
81 } ComboboxSelCtx;
82
83 static gboolean _select_by_data_func(GtkTreeModel *model, GtkTreePath *path,
84                 GtkTreeIter *iter, ComboboxSelCtx *ctx)
85 {
86         GtkComboBox *combobox = ctx->combobox;
87         gchar *data = ctx->data;
88         gchar *curdata; 
89
90         gtk_tree_model_get(GTK_TREE_MODEL(model), iter, COMBOBOX_DATA, &curdata, -1);
91         if ( data != NULL && curdata != NULL && !strcmp(data, curdata) ) {
92                 gtk_combo_box_set_active_iter(combobox, iter);
93                 return TRUE;
94         }
95
96         return FALSE;
97 }
98
99 static void prefs_common_charset_set_optmenu(GtkWidget *widget, gchar *data)
100 {
101         GtkComboBox *combobox = GTK_COMBO_BOX(widget);
102         GtkTreeModel *model;
103         ComboboxSelCtx *ctx = NULL;
104         cm_return_if_fail(combobox != NULL);
105
106         model = gtk_combo_box_get_model(combobox);
107
108         ctx = g_new(ComboboxSelCtx,
109                         sizeof(ComboboxSelCtx));
110         ctx->combobox = combobox;
111         ctx->data = data;
112
113         gtk_tree_model_foreach(model, (GtkTreeModelForeachFunc)_select_by_data_func, ctx);
114         g_free(ctx);
115 }
116
117 static gboolean _combobox_separator_func(GtkTreeModel *model,
118                 GtkTreeIter *iter, gpointer data)
119 {
120         gchar *txt = NULL;
121
122         cm_return_val_if_fail(model != NULL, FALSE);
123
124         gtk_tree_model_get(model, iter, COMBOBOX_TEXT, &txt, -1);
125
126         if( txt == NULL )
127                 return TRUE;
128         return FALSE;
129 }
130
131 static void prefs_send_create_widget(PrefsPage *_page, GtkWindow *window, 
132                                   gpointer data)
133 {
134         SendPage *prefs_send = (SendPage *) _page;
135         
136         GtkWidget *vbox1;
137         GtkWidget *vbox2;
138         GtkWidget *checkbtn_savemsg;
139         GtkWidget *label_outcharset;
140         GtkWidget *combobox_charset;
141         GtkListStore *optmenu;
142         GtkTreeIter iter;
143         GtkCellRenderer *rend;
144         GtkWidget *combobox_encoding;
145         GtkWidget *label_encoding;
146         GtkWidget *checkbtn_senddialog;
147         GtkWidget *checkbtn_confirm_send_queued_messages;
148         GtkWidget *checkbtn_never_send_retrcpt;
149         GtkWidget *checkbtn_warn_empty_subj;
150         GtkWidget *table;
151
152         vbox1 = gtk_vbox_new (FALSE, VSPACING);
153         gtk_widget_show (vbox1);
154         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
155
156         vbox2 = gtk_vbox_new (FALSE, 0);
157         gtk_widget_show (vbox2);
158         gtk_box_pack_start (GTK_BOX (vbox1), vbox2, FALSE, FALSE, 0);
159
160         PACK_CHECK_BUTTON(vbox2, checkbtn_savemsg,
161                         _("Save sent messages"));
162
163         PACK_CHECK_BUTTON(vbox2, checkbtn_confirm_send_queued_messages,
164                         _("Confirm before sending queued messages"));
165
166         PACK_CHECK_BUTTON(vbox2, checkbtn_never_send_retrcpt,
167                         _("Never send Return Receipts"));
168
169         PACK_CHECK_BUTTON(vbox2, checkbtn_senddialog,
170                         _("Show send dialog"));
171         PACK_CHECK_BUTTON(vbox2, checkbtn_warn_empty_subj,
172                         _("Warn when Subject is empty"));
173
174         table = gtk_table_new(2, 2, FALSE);
175         gtk_widget_show(table);
176         gtk_container_add (GTK_CONTAINER (vbox1), table);
177         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
178         gtk_table_set_col_spacings(GTK_TABLE(table), 8);
179
180         label_outcharset = gtk_label_new (_("Outgoing encoding"));
181         gtk_widget_show (label_outcharset);
182         gtk_table_attach(GTK_TABLE(table), label_outcharset, 0, 1, 1, 2,
183                         (GtkAttachOptions) (GTK_FILL),
184                         (GtkAttachOptions) (0), 0, 0);
185         gtk_label_set_justify(GTK_LABEL(label_outcharset), GTK_JUSTIFY_RIGHT);
186         gtk_misc_set_alignment(GTK_MISC(label_outcharset), 1, 0.5);
187
188         optmenu = gtk_list_store_new(2,
189                         G_TYPE_STRING,          /* Menu label */
190                         G_TYPE_STRING);         /* Actual charset data string */
191
192         combobox_charset = gtk_combo_box_new_with_model(
193                         GTK_TREE_MODEL(optmenu));
194         rend = gtk_cell_renderer_text_new();
195         gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combobox_charset), rend, TRUE);
196         gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combobox_charset), rend,
197                         "text", COMBOBOX_TEXT,
198                         NULL);
199
200         gtk_combo_box_set_row_separator_func(GTK_COMBO_BOX(combobox_charset),
201                         (GtkTreeViewRowSeparatorFunc)_combobox_separator_func, NULL, NULL);
202
203         gtk_widget_show (combobox_charset);
204         CLAWS_SET_TIP(combobox_charset,
205                              _("If 'Automatic' is selected, the optimal encoding"
206                                " for the current locale will be used"));
207         gtk_table_attach(GTK_TABLE(table), combobox_charset, 1, 2, 1, 2,
208                         (GtkAttachOptions) (GTK_FILL),
209                         (GtkAttachOptions) (0), 0, 0);
210
211 #define SET_MENUITEM(str, data) \
212 { \
213         gtk_list_store_append(optmenu, &iter); \
214         gtk_list_store_set(optmenu, &iter, \
215                         COMBOBOX_TEXT, str, \
216                         COMBOBOX_DATA, data, \
217                         -1); \
218 }
219
220         SET_MENUITEM(_("Automatic (Recommended)"),       CS_AUTO);
221         SET_MENUITEM(NULL, NULL);
222         SET_MENUITEM(_("7bit ASCII (US-ASCII)"),         CS_US_ASCII);
223         SET_MENUITEM(_("Unicode (UTF-8)"),               CS_UTF_8);
224         SET_MENUITEM(NULL, NULL);
225         SET_MENUITEM(_("Western European (ISO-8859-1)"),  CS_ISO_8859_1);
226         SET_MENUITEM(_("Western European (ISO-8859-15)"), CS_ISO_8859_15);
227         SET_MENUITEM(NULL, NULL);
228         SET_MENUITEM(_("Central European (ISO-8859-2)"), CS_ISO_8859_2);
229         SET_MENUITEM(NULL, NULL);
230         SET_MENUITEM(_("Baltic (ISO-8859-13)"),          CS_ISO_8859_13);
231         SET_MENUITEM(_("Baltic (ISO-8859-4)"),           CS_ISO_8859_4);
232         SET_MENUITEM(NULL, NULL);
233         SET_MENUITEM(_("Greek (ISO-8859-7)"),            CS_ISO_8859_7);
234         SET_MENUITEM(NULL, NULL);
235         SET_MENUITEM(_("Hebrew (ISO-8859-8)"),           CS_ISO_8859_8);
236         SET_MENUITEM(_("Hebrew (Windows-1255)"),         CS_WINDOWS_1255);
237         SET_MENUITEM(NULL, NULL);
238         SET_MENUITEM(_("Arabic (ISO-8859-6)"),           CS_ISO_8859_6);
239         SET_MENUITEM(_("Arabic (Windows-1256)"),         CS_WINDOWS_1256);
240         SET_MENUITEM(NULL, NULL);
241         SET_MENUITEM(_("Turkish (ISO-8859-9)"),          CS_ISO_8859_9);
242         SET_MENUITEM(NULL, NULL);
243         SET_MENUITEM(_("Cyrillic (ISO-8859-5)"),         CS_ISO_8859_5);
244         SET_MENUITEM(_("Cyrillic (KOI8-R)"),             CS_KOI8_R);
245         SET_MENUITEM(_("Cyrillic (X-MAC-CYRILLIC)"),             CS_MACCYR);
246         SET_MENUITEM(_("Cyrillic (KOI8-U)"),             CS_KOI8_U);
247         SET_MENUITEM(_("Cyrillic (Windows-1251)"),       CS_WINDOWS_1251);
248         SET_MENUITEM(NULL, NULL);
249         SET_MENUITEM(_("Japanese (ISO-2022-JP)"),        CS_ISO_2022_JP);
250 #if 0
251         SET_MENUITEM(_("Japanese (EUC-JP)"),             CS_EUC_JP);
252         SET_MENUITEM(_("Japanese (Shift_JIS)"),          CS_SHIFT_JIS);
253 #endif /* 0 */
254         SET_MENUITEM(NULL, NULL);
255         SET_MENUITEM(_("Simplified Chinese (GB18030)"),  CS_GB18030);
256         SET_MENUITEM(_("Simplified Chinese (GB2312)"),   CS_GB2312);
257         SET_MENUITEM(_("Simplified Chinese (GBK)"),      CS_GBK);
258         SET_MENUITEM(_("Traditional Chinese (Big5)"),    CS_BIG5);
259 #if 0
260         SET_MENUITEM(_("Traditional Chinese (EUC-TW)"),  CS_EUC_TW);
261         SET_MENUITEM(_("Chinese (ISO-2022-CN)"),         CS_ISO_2022_CN);
262 #endif /* 0 */
263         SET_MENUITEM(NULL, NULL);
264         SET_MENUITEM(_("Korean (EUC-KR)"),               CS_EUC_KR);
265         SET_MENUITEM(NULL, NULL);
266         SET_MENUITEM(_("Thai (TIS-620)"),                CS_TIS_620);
267         SET_MENUITEM(_("Thai (Windows-874)"),            CS_WINDOWS_874);
268
269 #undef SET_MENUITEM
270
271         label_encoding = gtk_label_new (_("Transfer encoding"));
272         gtk_widget_show (label_encoding);
273         gtk_table_attach(GTK_TABLE(table), label_encoding, 0, 1, 2, 3,
274                         (GtkAttachOptions) (GTK_FILL),
275                         (GtkAttachOptions) (0), 0, 0);
276         gtk_label_set_justify(GTK_LABEL(label_encoding), GTK_JUSTIFY_RIGHT);
277         gtk_misc_set_alignment(GTK_MISC(label_encoding), 1, 0.5);
278
279         combobox_encoding = gtkut_sc_combobox_create(NULL, FALSE);
280         gtk_widget_show (combobox_encoding);
281         CLAWS_SET_TIP(combobox_encoding,
282                              _("Specify Content-Transfer-Encoding used when"
283                                " message body contains non-ASCII characters"));
284         gtk_table_attach(GTK_TABLE(table), combobox_encoding, 1, 2, 2, 3,
285                         (GtkAttachOptions) (GTK_FILL),
286                         (GtkAttachOptions) (0), 0, 0);
287
288         optmenu = GTK_LIST_STORE(gtk_combo_box_get_model(
289                                 GTK_COMBO_BOX(combobox_encoding)));
290
291         COMBOBOX_ADD(optmenu, _("Automatic"),    CTE_AUTO);
292         COMBOBOX_ADD(optmenu, NULL, 0);
293         COMBOBOX_ADD(optmenu, "base64",          CTE_BASE64);
294         COMBOBOX_ADD(optmenu, "quoted-printable", CTE_QUOTED_PRINTABLE);
295         COMBOBOX_ADD(optmenu, "8bit",            CTE_8BIT);
296
297         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_savemsg),
298                 prefs_common.savemsg);
299         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_confirm_send_queued_messages),
300                 prefs_common.confirm_send_queued_messages);
301         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_never_send_retrcpt),
302                 prefs_common.never_send_retrcpt);
303         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_senddialog),
304                 !prefs_common.send_dialog_invisible);
305         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_warn_empty_subj),
306                 prefs_common.warn_empty_subj);
307         prefs_common_charset_set_optmenu(combobox_charset, 
308                 prefs_common.outgoing_charset);
309         combobox_select_by_data(GTK_COMBO_BOX(combobox_encoding),
310                 prefs_common.encoding_method);
311         
312         prefs_send->window                      = GTK_WIDGET(window);
313         
314         prefs_send->checkbtn_savemsg = checkbtn_savemsg;
315         prefs_send->checkbtn_confirm_send_queued_messages = checkbtn_confirm_send_queued_messages;
316         prefs_send->checkbtn_never_send_retrcpt = checkbtn_never_send_retrcpt;
317         prefs_send->checkbtn_senddialog = checkbtn_senddialog;
318         prefs_send->checkbtn_warn_empty_subj = checkbtn_warn_empty_subj;
319         prefs_send->combobox_charset = combobox_charset;
320         prefs_send->combobox_encoding_method = combobox_encoding;
321
322         prefs_send->page.widget = vbox1;
323 }
324
325 static void prefs_send_save(PrefsPage *_page)
326 {
327         SendPage *page = (SendPage *) _page;
328
329         prefs_common.savemsg = gtk_toggle_button_get_active(
330                 GTK_TOGGLE_BUTTON(page->checkbtn_savemsg));
331         prefs_common.confirm_send_queued_messages = gtk_toggle_button_get_active(
332                 GTK_TOGGLE_BUTTON(page->checkbtn_confirm_send_queued_messages));
333         prefs_common.never_send_retrcpt = gtk_toggle_button_get_active(
334                 GTK_TOGGLE_BUTTON(page->checkbtn_never_send_retrcpt));
335         prefs_common.send_dialog_invisible = !gtk_toggle_button_get_active(
336                 GTK_TOGGLE_BUTTON(page->checkbtn_senddialog));
337         prefs_common.warn_empty_subj = gtk_toggle_button_get_active(
338                 GTK_TOGGLE_BUTTON(page->checkbtn_warn_empty_subj));
339
340         g_free(prefs_common.outgoing_charset);
341         prefs_common.outgoing_charset = prefs_common_charset_set_data_from_optmenu(
342                 page->combobox_charset);
343         prefs_common.encoding_method =
344                 combobox_get_active_data(GTK_COMBO_BOX(page->combobox_encoding_method));
345 }
346
347 static void prefs_send_destroy_widget(PrefsPage *_page)
348 {
349 }
350
351 SendPage *prefs_send;
352
353 void prefs_send_init(void)
354 {
355         SendPage *page;
356         static gchar *path[3];
357
358         path[0] = _("Mail Handling");
359         path[1] = _("Sending");
360         path[2] = NULL;
361
362         page = g_new0(SendPage, 1);
363         page->page.path = path;
364         page->page.create_widget = prefs_send_create_widget;
365         page->page.destroy_widget = prefs_send_destroy_widget;
366         page->page.save_page = prefs_send_save;
367         page->page.weight = 195.0;
368         prefs_gtk_register_page((PrefsPage *) page);
369         prefs_send = page;
370 }
371
372 void prefs_send_done(void)
373 {
374         prefs_gtk_unregister_page((PrefsPage *) prefs_send);
375         g_free(prefs_send);
376 }