2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 2005 Colin Leroy <colin@colino.net> & The Sylpheed-Claws 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 2 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, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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"
41 #include "manage_window.h"
43 typedef struct _SendPage
49 GtkWidget *checkbtn_savemsg;
50 GtkWidget *checkbtn_confirm_send_queued_messages;
51 GtkWidget *optmenu_senddialog;
52 GtkWidget *optmenu_charset;
53 GtkWidget *optmenu_encoding_method;
56 static gchar * prefs_common_charset_set_data_from_optmenu(GtkWidget *widget)
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);
68 static void prefs_common_charset_set_optmenu(GtkWidget *widget, gchar *data)
70 GtkOptionMenu *optmenu = GTK_OPTION_MENU(widget);
73 g_return_if_fail(optmenu != NULL);
74 g_return_if_fail(data != NULL);
76 index = menu_find_option_menu_index(optmenu, data,
77 (GCompareFunc)strcmp2);
79 gtk_option_menu_set_history(optmenu, index);
81 gtk_option_menu_set_history(optmenu, 0);
84 static TransferEncodingMethod prefs_common_encoding_set_data_from_optmenu(GtkWidget *widget)
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));
95 static void prefs_common_encoding_set_optmenu(GtkWidget *widget, TransferEncodingMethod method)
97 GtkOptionMenu *optmenu = GTK_OPTION_MENU(widget);
100 g_return_if_fail(optmenu != NULL);
102 index = menu_find_option_menu_index(optmenu, GINT_TO_POINTER(method),
105 gtk_option_menu_set_history(optmenu, index);
107 gtk_option_menu_set_history(optmenu, 0);
111 void prefs_send_create_widget(PrefsPage *_page, GtkWindow *window,
114 SendPage *prefs_send = (SendPage *) _page;
118 GtkWidget *checkbtn_savemsg;
119 GtkWidget *label_outcharset;
120 GtkWidget *optmenu_charset;
121 GtkWidget *optmenu_menu;
123 GtkTooltips *charset_tooltip;
124 GtkWidget *optmenu_encoding;
125 GtkWidget *label_encoding;
126 GtkTooltips *encoding_tooltip;
127 GtkWidget *label_senddialog;
129 GtkWidget *optmenu_senddialog;
130 GtkWidget *checkbtn_confirm_send_queued_messages;
133 vbox1 = gtk_vbox_new (FALSE, VSPACING);
134 gtk_widget_show (vbox1);
135 gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
137 vbox2 = gtk_vbox_new (FALSE, 0);
138 gtk_widget_show (vbox2);
139 gtk_box_pack_start (GTK_BOX (vbox1), vbox2, FALSE, FALSE, 0);
141 PACK_CHECK_BUTTON (vbox2, checkbtn_savemsg,
142 _("Save sent messages to Sent folder"));
144 PACK_CHECK_BUTTON (vbox2, checkbtn_confirm_send_queued_messages,
145 _("Confirm before sending queued messages"));
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);
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);
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);
168 menu = gtk_menu_new ();
169 MENUITEM_ADD (menu, menuitem, _("Always"), SEND_DIALOG_ALWAYS);
170 MENUITEM_ADD (menu, menuitem, _("Never"), SEND_DIALOG_NEVER);
172 gtk_option_menu_set_menu (GTK_OPTION_MENU (optmenu_senddialog), menu);
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);
182 charset_tooltip = gtk_tooltips_new();
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"),
190 gtk_table_attach(GTK_TABLE(table), optmenu_charset, 1, 2, 1, 2,
191 (GtkAttachOptions) (GTK_FILL),
192 (GtkAttachOptions) (0), 0, 0);
194 optmenu_menu = gtk_menu_new ();
196 #define SET_MENUITEM(str, data) \
198 MENUITEM_ADD(optmenu_menu, menuitem, str, data); \
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(NULL, NULL);
205 SET_MENUITEM(_("Unicode (UTF-8)"), CS_UTF_8);
206 SET_MENUITEM(NULL, NULL);
207 SET_MENUITEM(_("Western European (ISO-8859-1)"), CS_ISO_8859_1);
208 SET_MENUITEM(_("Western European (ISO-8859-15)"), CS_ISO_8859_15);
209 SET_MENUITEM(NULL, NULL);
210 SET_MENUITEM(_("Central European (ISO-8859-2)"), CS_ISO_8859_2);
211 SET_MENUITEM(NULL, NULL);
212 SET_MENUITEM(_("Baltic (ISO-8859-13)"), CS_ISO_8859_13);
213 SET_MENUITEM(_("Baltic (ISO-8859-4)"), CS_ISO_8859_4);
214 SET_MENUITEM(NULL, NULL);
215 SET_MENUITEM(_("Greek (ISO-8859-7)"), CS_ISO_8859_7);
216 SET_MENUITEM(NULL, NULL);
217 SET_MENUITEM(_("Hebrew (ISO-8859-8)"), CS_ISO_8859_8);
218 SET_MENUITEM(_("Hebrew (Windows-1255)"), CS_WINDOWS_1255);
219 SET_MENUITEM(NULL, NULL);
220 SET_MENUITEM(_("Turkish (ISO-8859-9)"), CS_ISO_8859_9);
221 SET_MENUITEM(NULL, NULL);
222 SET_MENUITEM(_("Cyrillic (ISO-8859-5)"), CS_ISO_8859_5);
223 SET_MENUITEM(_("Cyrillic (KOI8-R)"), CS_KOI8_R);
224 SET_MENUITEM(_("Cyrillic (KOI8-U)"), CS_KOI8_U);
225 SET_MENUITEM(_("Cyrillic (Windows-1251)"), CS_WINDOWS_1251);
226 SET_MENUITEM(NULL, NULL);
227 SET_MENUITEM(_("Japanese (ISO-2022-JP)"), CS_ISO_2022_JP);
229 SET_MENUITEM(_("Japanese (EUC-JP)"), CS_EUC_JP);
230 SET_MENUITEM(_("Japanese (Shift_JIS)"), CS_SHIFT_JIS);
232 SET_MENUITEM(NULL, NULL);
233 SET_MENUITEM(_("Simplified Chinese (GB2312)"), CS_GB2312);
234 SET_MENUITEM(_("Simplified Chinese (GBK)"), CS_GBK);
235 SET_MENUITEM(_("Traditional Chinese (Big5)"), CS_BIG5);
237 SET_MENUITEM(_("Traditional Chinese (EUC-TW)"), CS_EUC_TW);
238 SET_MENUITEM(_("Chinese (ISO-2022-CN)"), CS_ISO_2022_CN);
240 SET_MENUITEM(NULL, NULL);
241 SET_MENUITEM(_("Korean (EUC-KR)"), CS_EUC_KR);
242 SET_MENUITEM(NULL, NULL);
243 SET_MENUITEM(_("Thai (TIS-620)"), CS_TIS_620);
244 SET_MENUITEM(_("Thai (Windows-874)"), CS_WINDOWS_874);
246 gtk_option_menu_set_menu (GTK_OPTION_MENU (optmenu_charset),
249 label_encoding = gtk_label_new (_("Transfer encoding"));
250 gtk_widget_show (label_encoding);
251 gtk_table_attach(GTK_TABLE(table), label_encoding, 0, 1, 2, 3,
252 (GtkAttachOptions) (GTK_FILL),
253 (GtkAttachOptions) (0), 0, 0);
254 gtk_label_set_justify(GTK_LABEL(label_encoding), GTK_JUSTIFY_RIGHT);
255 gtk_misc_set_alignment(GTK_MISC(label_encoding), 1, 0.5);
257 encoding_tooltip = gtk_tooltips_new();
259 optmenu_encoding = gtk_option_menu_new ();
260 gtk_widget_show (optmenu_encoding);
261 gtk_tooltips_set_tip(GTK_TOOLTIPS(encoding_tooltip), optmenu_encoding,
262 _("Specify Content-Transfer-Encoding used when"
263 " message body contains non-ASCII characters"),
265 gtk_table_attach(GTK_TABLE(table), optmenu_encoding, 1, 2, 2, 3,
266 (GtkAttachOptions) (GTK_FILL),
267 (GtkAttachOptions) (0), 0, 0);
269 optmenu_menu = gtk_menu_new ();
271 SET_MENUITEM(_("Automatic"), CTE_AUTO);
272 SET_MENUITEM("base64", CTE_BASE64);
273 SET_MENUITEM("quoted-printable", CTE_QUOTED_PRINTABLE);
274 SET_MENUITEM("8bit", CTE_8BIT);
276 gtk_option_menu_set_menu (GTK_OPTION_MENU (optmenu_encoding),
279 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_savemsg),
280 prefs_common.savemsg);
281 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_confirm_send_queued_messages),
282 prefs_common.confirm_send_queued_messages);
283 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu_senddialog),
284 prefs_common.send_dialog_mode);
285 prefs_common_charset_set_optmenu(optmenu_charset,
286 prefs_common.outgoing_charset);
287 prefs_common_encoding_set_optmenu(optmenu_encoding,
288 prefs_common.encoding_method);
290 prefs_send->window = GTK_WIDGET(window);
292 prefs_send->checkbtn_savemsg = checkbtn_savemsg;
293 prefs_send->checkbtn_confirm_send_queued_messages = checkbtn_confirm_send_queued_messages;
294 prefs_send->optmenu_senddialog = optmenu_senddialog;
295 prefs_send->optmenu_charset = optmenu_charset;
296 prefs_send->optmenu_encoding_method = optmenu_encoding;
298 prefs_send->page.widget = vbox1;
301 void prefs_send_save(PrefsPage *_page)
303 SendPage *page = (SendPage *) _page;
307 prefs_common.savemsg = gtk_toggle_button_get_active(
308 GTK_TOGGLE_BUTTON(page->checkbtn_savemsg));
309 prefs_common.confirm_send_queued_messages = gtk_toggle_button_get_active(
310 GTK_TOGGLE_BUTTON(page->checkbtn_confirm_send_queued_messages));
312 menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(page->optmenu_senddialog));
313 menuitem = gtk_menu_get_active(GTK_MENU(menu));
314 prefs_common.send_dialog_mode = GPOINTER_TO_INT
315 (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
317 g_free(prefs_common.outgoing_charset);
318 prefs_common.outgoing_charset = prefs_common_charset_set_data_from_optmenu(
319 page->optmenu_charset);
320 prefs_common.encoding_method = prefs_common_encoding_set_data_from_optmenu(
321 page->optmenu_encoding_method);
324 static void prefs_send_destroy_widget(PrefsPage *_page)
328 SendPage *prefs_send;
330 void prefs_send_init(void)
333 static gchar *path[3];
335 path[0] = _("Mail Handling");
339 page = g_new0(SendPage, 1);
340 page->page.path = path;
341 page->page.create_widget = prefs_send_create_widget;
342 page->page.destroy_widget = prefs_send_destroy_widget;
343 page->page.save_page = prefs_send_save;
344 page->page.weight = 195.0;
345 prefs_gtk_register_page((PrefsPage *) page);
349 void prefs_send_done(void)
351 prefs_gtk_unregister_page((PrefsPage *) prefs_send);