2 * Claws Mail -- a GTK based, lightweight, and fast e-mail client
3 * Copyright (C) 2005-2019 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/>.
21 #include "claws-features.h"
30 #include <glib/gi18n.h>
32 #include <gdk/gdkkeysyms.h>
34 #include "prefs_common.h"
35 #include "prefs_gtk.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
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
*checkbtn_warn_multiple_recipients
;
56 GtkWidget
*spinbtn_warn_multiple_recipients
;
57 GtkWidget
*combobox_charset
;
58 GtkWidget
*combobox_encoding_method
;
61 static gchar
* prefs_common_charset_set_data_from_optmenu(GtkWidget
*widget
)
67 cm_return_val_if_fail(widget
!= NULL
, NULL
);
69 cm_return_val_if_fail(gtk_combo_box_get_active_iter(
70 GTK_COMBO_BOX(widget
), &iter
), NULL
);
72 model
= gtk_combo_box_get_model(GTK_COMBO_BOX(widget
));
74 gtk_tree_model_get(model
, &iter
, COMBOBOX_DATA
, &data
, -1);
79 typedef struct _combobox_sel_by_data_ctx
{
80 GtkComboBox
*combobox
;
84 static gboolean
_select_by_data_func(GtkTreeModel
*model
, GtkTreePath
*path
,
85 GtkTreeIter
*iter
, ComboboxSelCtx
*ctx
)
87 GtkComboBox
*combobox
= ctx
->combobox
;
88 gchar
*data
= ctx
->data
;
91 gtk_tree_model_get(GTK_TREE_MODEL(model
), iter
, COMBOBOX_DATA
, &curdata
, -1);
92 if ( data
!= NULL
&& curdata
!= NULL
&& !strcmp(data
, curdata
) ) {
93 gtk_combo_box_set_active_iter(combobox
, iter
);
102 static void prefs_common_charset_set_optmenu(GtkWidget
*widget
, gchar
*data
)
104 GtkComboBox
*combobox
= GTK_COMBO_BOX(widget
);
106 ComboboxSelCtx
*ctx
= NULL
;
107 cm_return_if_fail(combobox
!= NULL
);
109 model
= gtk_combo_box_get_model(combobox
);
111 ctx
= g_new(ComboboxSelCtx
,
112 sizeof(ComboboxSelCtx
));
113 ctx
->combobox
= combobox
;
116 gtk_tree_model_foreach(model
, (GtkTreeModelForeachFunc
)_select_by_data_func
, ctx
);
120 static gboolean
_combobox_separator_func(GtkTreeModel
*model
,
121 GtkTreeIter
*iter
, gpointer data
)
125 cm_return_val_if_fail(model
!= NULL
, FALSE
);
127 gtk_tree_model_get(model
, iter
, COMBOBOX_TEXT
, &txt
, -1);
136 static void checkbtn_warn_multiple_recipients_toggled(GtkToggleButton
*button
,
139 gboolean active
= gtk_toggle_button_get_active(button
);
140 GtkWidget
*spin
= GTK_WIDGET(user_data
);
142 gtk_widget_set_sensitive(spin
, active
);
145 static void prefs_send_create_widget(PrefsPage
*_page
, GtkWindow
*window
,
148 SendPage
*prefs_send
= (SendPage
*) _page
;
150 GtkWidget
*vbox1
, *vbox2
, *hbox1
;
151 GtkWidget
*checkbtn_savemsg
;
152 GtkWidget
*label_outcharset
;
153 GtkWidget
*combobox_charset
;
154 GtkListStore
*optmenu
;
156 GtkCellRenderer
*rend
;
157 GtkWidget
*combobox_encoding
;
158 GtkWidget
*label_encoding
;
159 GtkWidget
*checkbtn_senddialog
;
160 GtkWidget
*checkbtn_confirm_send_queued_messages
;
161 GtkWidget
*checkbtn_never_send_retrcpt
;
162 GtkWidget
*checkbtn_warn_empty_subj
;
163 GtkWidget
*checkbtn_warn_multiple_recipients
;
164 GtkWidget
*spinbtn_warn_multiple_recipients
;
167 vbox1
= gtk_box_new(GTK_ORIENTATION_VERTICAL
, VSPACING
);
168 gtk_widget_show (vbox1
);
169 gtk_container_set_border_width (GTK_CONTAINER (vbox1
), VBOX_BORDER
);
172 vbox2
= gtk_box_new(GTK_ORIENTATION_VERTICAL
, 0);
173 gtk_widget_show (vbox2
);
175 PACK_CHECK_BUTTON(vbox2
, checkbtn_savemsg
,
176 _("Save sent messages"));
178 PACK_CHECK_BUTTON(vbox2
, checkbtn_never_send_retrcpt
,
179 _("Never send Return Receipts"));
182 table
= gtk_grid_new();
183 gtk_widget_show(table
);
184 gtk_container_add (GTK_CONTAINER (vbox2
), table
);
185 gtk_grid_set_row_spacing(GTK_GRID(table
), 4);
186 gtk_grid_set_column_spacing(GTK_GRID(table
), 8);
188 PACK_FRAME (vbox1
, frame
, _("Messages"))
189 gtk_container_set_border_width(GTK_CONTAINER(vbox2
), 8);
190 gtk_container_add(GTK_CONTAINER(frame
), vbox2
);
192 /* interface frame */
193 vbox2
= gtk_box_new(GTK_ORIENTATION_VERTICAL
, 0);
194 gtk_widget_show (vbox2
);
196 PACK_CHECK_BUTTON(vbox2
, checkbtn_confirm_send_queued_messages
,
197 _("Confirm before sending queued messages"));
199 PACK_CHECK_BUTTON(vbox2
, checkbtn_senddialog
,
200 _("Show send dialog"));
202 PACK_CHECK_BUTTON(vbox2
, checkbtn_warn_empty_subj
,
203 _("Warn when Subject is empty"));
205 hbox1
= gtk_box_new(GTK_ORIENTATION_HORIZONTAL
, 0);
206 gtk_widget_show (hbox1
);
208 PACK_CHECK_BUTTON(hbox1
, checkbtn_warn_multiple_recipients
,
209 _("Warn when sending to more recipients than"));
211 spinbtn_warn_multiple_recipients
= gtk_spin_button_new_with_range(2, 999, 1);
212 gtk_widget_show(spinbtn_warn_multiple_recipients
);
213 gtk_box_pack_start(GTK_BOX(hbox1
), spinbtn_warn_multiple_recipients
, FALSE
, FALSE
, 0);
214 g_signal_connect(G_OBJECT(checkbtn_warn_multiple_recipients
), "toggled",
215 G_CALLBACK(checkbtn_warn_multiple_recipients_toggled
),
216 spinbtn_warn_multiple_recipients
);
218 gtk_box_pack_start(GTK_BOX(vbox2
), hbox1
, FALSE
, FALSE
, 0);
220 PACK_FRAME (vbox1
, frame
, _("Interface"))
221 gtk_container_set_border_width(GTK_CONTAINER(vbox2
), 8);
222 gtk_container_add(GTK_CONTAINER(frame
), vbox2
);
224 /* populate table within encoding sub-frame */
225 label_outcharset
= gtk_label_new (_("Outgoing encoding"));
226 gtk_widget_show (label_outcharset
);
227 gtk_label_set_justify(GTK_LABEL(label_outcharset
), GTK_JUSTIFY_RIGHT
);
228 gtk_label_set_xalign(GTK_LABEL(label_outcharset
), 1.0);
229 gtk_grid_attach(GTK_GRID(table
), label_outcharset
, 0, 1, 1, 1);
231 optmenu
= gtk_list_store_new(2,
232 G_TYPE_STRING
, /* Menu label */
233 G_TYPE_STRING
); /* Actual charset data string */
235 combobox_charset
= gtk_combo_box_new_with_model(
236 GTK_TREE_MODEL(optmenu
));
237 rend
= gtk_cell_renderer_text_new();
238 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combobox_charset
), rend
, TRUE
);
239 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combobox_charset
), rend
,
240 "text", COMBOBOX_TEXT
,
243 gtk_combo_box_set_row_separator_func(GTK_COMBO_BOX(combobox_charset
),
244 (GtkTreeViewRowSeparatorFunc
)_combobox_separator_func
, NULL
, NULL
);
246 gtk_widget_show (combobox_charset
);
247 CLAWS_SET_TIP(combobox_charset
,
248 _("If 'Automatic' is selected, the optimal encoding"
249 " for the current locale will be used"));
250 gtk_grid_attach(GTK_GRID(table
), combobox_charset
, 1, 1, 1, 1);
252 #define SET_MENUITEM(str, data) \
254 gtk_list_store_append(optmenu, &iter); \
255 gtk_list_store_set(optmenu, &iter, \
256 COMBOBOX_TEXT, str, \
257 COMBOBOX_DATA, data, \
261 SET_MENUITEM(_("Automatic"), CS_AUTO
);
262 SET_MENUITEM(NULL
, NULL
);
263 SET_MENUITEM(_("7bit ASCII (US-ASCII)"), CS_US_ASCII
);
264 SET_MENUITEM(_("Unicode (UTF-8)"), CS_UTF_8
);
265 SET_MENUITEM(NULL
, NULL
);
266 SET_MENUITEM(_("Western European (ISO-8859-1)"), CS_ISO_8859_1
);
267 SET_MENUITEM(_("Western European (ISO-8859-15)"), CS_ISO_8859_15
);
268 SET_MENUITEM(NULL
, NULL
);
269 SET_MENUITEM(_("Central European (ISO-8859-2)"), CS_ISO_8859_2
);
270 SET_MENUITEM(NULL
, NULL
);
271 SET_MENUITEM(_("Baltic (ISO-8859-13)"), CS_ISO_8859_13
);
272 SET_MENUITEM(_("Baltic (ISO-8859-4)"), CS_ISO_8859_4
);
273 SET_MENUITEM(NULL
, NULL
);
274 SET_MENUITEM(_("Greek (ISO-8859-7)"), CS_ISO_8859_7
);
275 SET_MENUITEM(NULL
, NULL
);
276 SET_MENUITEM(_("Hebrew (ISO-8859-8)"), CS_ISO_8859_8
);
277 SET_MENUITEM(_("Hebrew (Windows-1255)"), CS_WINDOWS_1255
);
278 SET_MENUITEM(NULL
, NULL
);
279 SET_MENUITEM(_("Arabic (ISO-8859-6)"), CS_ISO_8859_6
);
280 SET_MENUITEM(_("Arabic (Windows-1256)"), CS_WINDOWS_1256
);
281 SET_MENUITEM(NULL
, NULL
);
282 SET_MENUITEM(_("Turkish (ISO-8859-9)"), CS_ISO_8859_9
);
283 SET_MENUITEM(NULL
, NULL
);
284 SET_MENUITEM(_("Cyrillic (ISO-8859-5)"), CS_ISO_8859_5
);
285 SET_MENUITEM(_("Cyrillic (KOI8-R)"), CS_KOI8_R
);
286 SET_MENUITEM(_("Cyrillic (X-MAC-CYRILLIC)"), CS_MACCYR
);
287 SET_MENUITEM(_("Cyrillic (KOI8-U)"), CS_KOI8_U
);
288 SET_MENUITEM(_("Cyrillic (Windows-1251)"), CS_WINDOWS_1251
);
289 SET_MENUITEM(NULL
, NULL
);
290 SET_MENUITEM(_("Japanese (ISO-2022-JP)"), CS_ISO_2022_JP
);
292 SET_MENUITEM(_("Japanese (EUC-JP)"), CS_EUC_JP
);
293 SET_MENUITEM(_("Japanese (Shift_JIS)"), CS_SHIFT_JIS
);
295 SET_MENUITEM(NULL
, NULL
);
296 SET_MENUITEM(_("Simplified Chinese (GB18030)"), CS_GB18030
);
297 SET_MENUITEM(_("Simplified Chinese (GB2312)"), CS_GB2312
);
298 SET_MENUITEM(_("Simplified Chinese (GBK)"), CS_GBK
);
299 SET_MENUITEM(_("Traditional Chinese (Big5)"), CS_BIG5
);
301 SET_MENUITEM(_("Traditional Chinese (EUC-TW)"), CS_EUC_TW
);
302 SET_MENUITEM(_("Chinese (ISO-2022-CN)"), CS_ISO_2022_CN
);
304 SET_MENUITEM(NULL
, NULL
);
305 SET_MENUITEM(_("Korean (EUC-KR)"), CS_EUC_KR
);
306 SET_MENUITEM(NULL
, NULL
);
307 SET_MENUITEM(_("Thai (TIS-620)"), CS_TIS_620
);
308 SET_MENUITEM(_("Thai (Windows-874)"), CS_WINDOWS_874
);
312 label_encoding
= gtk_label_new (_("Transfer encoding"));
313 gtk_widget_show (label_encoding
);
314 gtk_label_set_justify(GTK_LABEL(label_encoding
), GTK_JUSTIFY_RIGHT
);
315 gtk_label_set_xalign(GTK_LABEL(label_encoding
), 1.0);
316 gtk_grid_attach(GTK_GRID(table
), label_encoding
, 0, 2, 1, 1);
318 combobox_encoding
= gtkut_sc_combobox_create(NULL
, FALSE
);
319 gtk_widget_show (combobox_encoding
);
320 CLAWS_SET_TIP(combobox_encoding
,
321 _("Specify Content-Transfer-Encoding used when"
322 " message body contains non-ASCII characters"));
323 gtk_grid_attach(GTK_GRID(table
), combobox_encoding
, 1, 2, 1, 1);
325 optmenu
= GTK_LIST_STORE(gtk_combo_box_get_model(
326 GTK_COMBO_BOX(combobox_encoding
)));
328 COMBOBOX_ADD(optmenu
, _("Automatic"), CTE_AUTO
);
329 COMBOBOX_ADD(optmenu
, NULL
, 0);
330 COMBOBOX_ADD(optmenu
, "base64", CTE_BASE64
);
331 COMBOBOX_ADD(optmenu
, "quoted-printable", CTE_QUOTED_PRINTABLE
);
332 COMBOBOX_ADD(optmenu
, "8bit", CTE_8BIT
);
334 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_savemsg
),
335 prefs_common
.savemsg
);
336 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_confirm_send_queued_messages
),
337 prefs_common
.confirm_send_queued_messages
);
338 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_never_send_retrcpt
),
339 prefs_common
.never_send_retrcpt
);
340 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_senddialog
),
341 !prefs_common
.send_dialog_invisible
);
342 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_warn_empty_subj
),
343 prefs_common
.warn_empty_subj
);
344 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_warn_multiple_recipients
), prefs_common
.warn_sending_many_recipients_num
> 0);
346 if (prefs_common
.warn_sending_many_recipients_num
> 0)
347 gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinbtn_warn_multiple_recipients
),
348 prefs_common
.warn_sending_many_recipients_num
);
350 gtk_widget_set_sensitive(spinbtn_warn_multiple_recipients
, FALSE
);
352 prefs_common_charset_set_optmenu(combobox_charset
,
353 prefs_common
.outgoing_charset
);
354 combobox_select_by_data(GTK_COMBO_BOX(combobox_encoding
),
355 prefs_common
.encoding_method
);
357 prefs_send
->window
= GTK_WIDGET(window
);
359 prefs_send
->checkbtn_savemsg
= checkbtn_savemsg
;
360 prefs_send
->checkbtn_confirm_send_queued_messages
= checkbtn_confirm_send_queued_messages
;
361 prefs_send
->checkbtn_never_send_retrcpt
= checkbtn_never_send_retrcpt
;
362 prefs_send
->checkbtn_senddialog
= checkbtn_senddialog
;
363 prefs_send
->checkbtn_warn_empty_subj
= checkbtn_warn_empty_subj
;
364 prefs_send
->checkbtn_warn_multiple_recipients
= checkbtn_warn_multiple_recipients
;
365 prefs_send
->spinbtn_warn_multiple_recipients
= spinbtn_warn_multiple_recipients
;
366 prefs_send
->combobox_charset
= combobox_charset
;
367 prefs_send
->combobox_encoding_method
= combobox_encoding
;
369 prefs_send
->page
.widget
= vbox1
;
372 static void prefs_send_save(PrefsPage
*_page
)
374 SendPage
*page
= (SendPage
*) _page
;
376 prefs_common
.savemsg
= gtk_toggle_button_get_active(
377 GTK_TOGGLE_BUTTON(page
->checkbtn_savemsg
));
378 prefs_common
.confirm_send_queued_messages
= gtk_toggle_button_get_active(
379 GTK_TOGGLE_BUTTON(page
->checkbtn_confirm_send_queued_messages
));
380 prefs_common
.never_send_retrcpt
= gtk_toggle_button_get_active(
381 GTK_TOGGLE_BUTTON(page
->checkbtn_never_send_retrcpt
));
382 prefs_common
.send_dialog_invisible
= !gtk_toggle_button_get_active(
383 GTK_TOGGLE_BUTTON(page
->checkbtn_senddialog
));
384 prefs_common
.warn_empty_subj
= gtk_toggle_button_get_active(
385 GTK_TOGGLE_BUTTON(page
->checkbtn_warn_empty_subj
));
387 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page
->checkbtn_warn_multiple_recipients
)))
388 prefs_common
.warn_sending_many_recipients_num
=
389 gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(page
->spinbtn_warn_multiple_recipients
));
391 prefs_common
.warn_sending_many_recipients_num
= 0;
393 g_free(prefs_common
.outgoing_charset
);
394 prefs_common
.outgoing_charset
= prefs_common_charset_set_data_from_optmenu(
395 page
->combobox_charset
);
396 prefs_common
.encoding_method
=
397 combobox_get_active_data(GTK_COMBO_BOX(page
->combobox_encoding_method
));
400 static void prefs_send_destroy_widget(PrefsPage
*_page
)
404 SendPage
*prefs_send
;
406 void prefs_send_init(void)
409 static gchar
*path
[3];
411 path
[0] = _("Mail Handling");
412 path
[1] = _("Sending");
415 page
= g_new0(SendPage
, 1);
416 page
->page
.path
= path
;
417 page
->page
.create_widget
= prefs_send_create_widget
;
418 page
->page
.destroy_widget
= prefs_send_destroy_widget
;
419 page
->page
.save_page
= prefs_send_save
;
420 page
->page
.weight
= 195.0;
421 prefs_gtk_register_page((PrefsPage
*) page
);
425 void prefs_send_done(void)
427 prefs_gtk_unregister_page((PrefsPage
*) prefs_send
);