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