modify label to give more clarity
[claws.git] / src / prefs_send.c
index ddb96cbd5228502b0baf4e9b4444adf05788e0b4..512bb8c1ceb8cf8bafcbbf692d5b08c0af0f5a2f 100644 (file)
@@ -1,10 +1,10 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 2005-2007 Colin Leroy <colin@colino.net> & The Claws Mail Team
+ * Copyright (C) 2005-2012 Colin Leroy <colin@colino.net> & The Claws Mail Team
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation; either version 3 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * 
  */
 
 #ifdef HAVE_CONFIG_H
 #  include "config.h"
+#include "claws-features.h"
 #endif
 
 #include "defs.h"
@@ -37,6 +38,7 @@
 
 #include "gtk/gtkutils.h"
 #include "gtk/prefswindow.h"
+#include "gtk/combobox.h"
 
 #include "manage_window.h"
 
@@ -48,65 +50,83 @@ typedef struct _SendPage
 
        GtkWidget *checkbtn_savemsg;
        GtkWidget *checkbtn_confirm_send_queued_messages;
-       GtkWidget *optmenu_senddialog;
-       GtkWidget *optmenu_charset;
-       GtkWidget *optmenu_encoding_method;
+       GtkWidget *checkbtn_never_send_retrcpt;
+       GtkWidget *checkbtn_senddialog;
+       GtkWidget *checkbtn_warn_empty_subj;
+       GtkWidget *combobox_charset;
+       GtkWidget *combobox_encoding_method;
 } SendPage;
 
 static gchar * prefs_common_charset_set_data_from_optmenu(GtkWidget *widget)
 {
-       GtkWidget *menu;
-       GtkWidget *menuitem;
-       gchar *charset;
-
-       menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(widget));
-       menuitem = gtk_menu_get_active(GTK_MENU(menu));
-       charset = g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID);
-       return g_strdup(charset);
+       GtkTreeModel *model;
+       GtkTreeIter iter;
+       gchar *data = NULL;
+
+       cm_return_val_if_fail(widget != NULL, NULL);
+
+       cm_return_val_if_fail(gtk_combo_box_get_active_iter(
+                               GTK_COMBO_BOX(widget), &iter), NULL);
+
+       model = gtk_combo_box_get_model(GTK_COMBO_BOX(widget));
+
+       gtk_tree_model_get(model, &iter, COMBOBOX_DATA, &data, -1);
+
+       return data;
 }
 
-static void prefs_common_charset_set_optmenu(GtkWidget *widget, gchar *data)
+typedef struct _combobox_sel_by_data_ctx {
+       GtkComboBox *combobox;
+       gchar *data;
+} ComboboxSelCtx;
+
+static gboolean _select_by_data_func(GtkTreeModel *model, GtkTreePath *path,
+               GtkTreeIter *iter, ComboboxSelCtx *ctx)
 {
-       GtkOptionMenu *optmenu = GTK_OPTION_MENU(widget);
-       gint index;
-
-       g_return_if_fail(optmenu != NULL);
-       g_return_if_fail(data != NULL);
-
-       index = menu_find_option_menu_index(optmenu, data,
-                                           (GCompareFunc)strcmp2);
-       if (index >= 0)
-               gtk_option_menu_set_history(optmenu, index);
-       else
-               gtk_option_menu_set_history(optmenu, 0);
+       GtkComboBox *combobox = ctx->combobox;
+       gchar *data = ctx->data;
+       gchar *curdata; 
+
+       gtk_tree_model_get(GTK_TREE_MODEL(model), iter, COMBOBOX_DATA, &curdata, -1);
+       if ( data != NULL && curdata != NULL && !strcmp(data, curdata) ) {
+               gtk_combo_box_set_active_iter(combobox, iter);
+               return TRUE;
+       }
+
+       return FALSE;
 }
 
-static TransferEncodingMethod prefs_common_encoding_set_data_from_optmenu(GtkWidget *widget)
+static void prefs_common_charset_set_optmenu(GtkWidget *widget, gchar *data)
 {
-       GtkWidget *menu;
-       GtkWidget *menuitem;
+       GtkComboBox *combobox = GTK_COMBO_BOX(widget);
+       GtkTreeModel *model;
+       ComboboxSelCtx *ctx = NULL;
+       cm_return_if_fail(combobox != NULL);
+
+       model = gtk_combo_box_get_model(combobox);
+
+       ctx = g_new(ComboboxSelCtx,
+                       sizeof(ComboboxSelCtx));
+       ctx->combobox = combobox;
+       ctx->data = data;
 
-       menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(widget));
-       menuitem = gtk_menu_get_active(GTK_MENU(menu));
-       return GPOINTER_TO_INT
-               (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
+       gtk_tree_model_foreach(model, (GtkTreeModelForeachFunc)_select_by_data_func, ctx);
+       g_free(ctx);
 }
 
-static void prefs_common_encoding_set_optmenu(GtkWidget *widget, TransferEncodingMethod method)
+static gboolean _combobox_separator_func(GtkTreeModel *model,
+               GtkTreeIter *iter, gpointer data)
 {
-       GtkOptionMenu *optmenu = GTK_OPTION_MENU(widget);
-       gint index;
+       gchar *txt = NULL;
 
-       g_return_if_fail(optmenu != NULL);
+       cm_return_val_if_fail(model != NULL, FALSE);
 
-       index = menu_find_option_menu_index(optmenu, GINT_TO_POINTER(method),
-                                           NULL);
-       if (index >= 0)
-               gtk_option_menu_set_history(optmenu, index);
-       else
-               gtk_option_menu_set_history(optmenu, 0);
-}
+       gtk_tree_model_get(model, iter, COMBOBOX_TEXT, &txt, -1);
 
+       if( txt == NULL )
+               return TRUE;
+       return FALSE;
+}
 
 static void prefs_send_create_widget(PrefsPage *_page, GtkWindow *window, 
                                  gpointer data)
@@ -117,17 +137,16 @@ static void prefs_send_create_widget(PrefsPage *_page, GtkWindow *window,
        GtkWidget *vbox2;
        GtkWidget *checkbtn_savemsg;
        GtkWidget *label_outcharset;
-       GtkWidget *optmenu_charset;
-       GtkWidget *optmenu_menu;
-       GtkWidget *menuitem;
-       GtkTooltips *charset_tooltip;
-       GtkWidget *optmenu_encoding;
+       GtkWidget *combobox_charset;
+       GtkListStore *optmenu;
+       GtkTreeIter iter;
+       GtkCellRenderer *rend;
+       GtkWidget *combobox_encoding;
        GtkWidget *label_encoding;
-       GtkTooltips *encoding_tooltip;
-       GtkWidget *label_senddialog;
-       GtkWidget *menu;
-       GtkWidget *optmenu_senddialog;
+       GtkWidget *checkbtn_senddialog;
        GtkWidget *checkbtn_confirm_send_queued_messages;
+       GtkWidget *checkbtn_never_send_retrcpt;
+       GtkWidget *checkbtn_warn_empty_subj;
        GtkWidget *table;
 
        vbox1 = gtk_vbox_new (FALSE, VSPACING);
@@ -138,39 +157,26 @@ static void prefs_send_create_widget(PrefsPage *_page, GtkWindow *window,
        gtk_widget_show (vbox2);
        gtk_box_pack_start (GTK_BOX (vbox1), vbox2, FALSE, FALSE, 0);
 
-       PACK_CHECK_BUTTON (vbox2, checkbtn_savemsg,
-                       _("Save sent messages to Sent folder"));
+       PACK_CHECK_BUTTON(vbox2, checkbtn_savemsg,
+                       _("Save sent messages"));
 
-       PACK_CHECK_BUTTON (vbox2, checkbtn_confirm_send_queued_messages,
+       PACK_CHECK_BUTTON(vbox2, checkbtn_confirm_send_queued_messages,
                        _("Confirm before sending queued messages"));
 
-       table = gtk_table_new(3, 2, FALSE);
+       PACK_CHECK_BUTTON(vbox2, checkbtn_never_send_retrcpt,
+                       _("Never send Return Receipts"));
+
+       PACK_CHECK_BUTTON(vbox2, checkbtn_senddialog,
+                       _("Show send dialog"));
+       PACK_CHECK_BUTTON(vbox2, checkbtn_warn_empty_subj,
+                       _("Warn when Subject is empty"));
+
+       table = gtk_table_new(2, 2, FALSE);
        gtk_widget_show(table);
        gtk_container_add (GTK_CONTAINER (vbox1), table);
        gtk_table_set_row_spacings(GTK_TABLE(table), 4);
        gtk_table_set_col_spacings(GTK_TABLE(table), 8);
 
-       label_senddialog = gtk_label_new (_("Show send dialog"));
-       gtk_widget_show (label_senddialog);
-       gtk_table_attach(GTK_TABLE(table), label_senddialog, 0, 1, 0, 1,
-                       (GtkAttachOptions) (GTK_FILL),
-                       (GtkAttachOptions) (0), 0, 0);
-       gtk_label_set_justify(GTK_LABEL(label_senddialog), GTK_JUSTIFY_RIGHT);
-       gtk_misc_set_alignment(GTK_MISC(label_senddialog), 1, 0.5);
-
-       /* FIXME : Is it good to change this menu into a checkbtn ? */
-       optmenu_senddialog = gtk_option_menu_new ();
-       gtk_widget_show (optmenu_senddialog);
-       gtk_table_attach(GTK_TABLE(table), optmenu_senddialog, 1, 2, 0, 1,
-                       (GtkAttachOptions) (GTK_FILL),
-                       (GtkAttachOptions) (0), 0, 0);
-
-       menu = gtk_menu_new ();
-       MENUITEM_ADD (menu, menuitem, _("Always"), SEND_DIALOG_ALWAYS);
-       MENUITEM_ADD (menu, menuitem, _("Never"), SEND_DIALOG_NEVER);
-
-       gtk_option_menu_set_menu (GTK_OPTION_MENU (optmenu_senddialog), menu);
-
        label_outcharset = gtk_label_new (_("Outgoing encoding"));
        gtk_widget_show (label_outcharset);
        gtk_table_attach(GTK_TABLE(table), label_outcharset, 0, 1, 1, 2,
@@ -179,28 +185,41 @@ static void prefs_send_create_widget(PrefsPage *_page, GtkWindow *window,
        gtk_label_set_justify(GTK_LABEL(label_outcharset), GTK_JUSTIFY_RIGHT);
        gtk_misc_set_alignment(GTK_MISC(label_outcharset), 1, 0.5);
 
-       charset_tooltip = gtk_tooltips_new();
+       optmenu = gtk_list_store_new(2,
+                       G_TYPE_STRING,          /* Menu label */
+                       G_TYPE_STRING);         /* Actual charset data string */
+
+       combobox_charset = gtk_combo_box_new_with_model(
+                       GTK_TREE_MODEL(optmenu));
+       rend = gtk_cell_renderer_text_new();
+       gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combobox_charset), rend, TRUE);
+       gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combobox_charset), rend,
+                       "text", COMBOBOX_TEXT,
+                       NULL);
 
-       optmenu_charset = gtk_option_menu_new ();
-       gtk_widget_show (optmenu_charset);
-       gtk_tooltips_set_tip(GTK_TOOLTIPS(charset_tooltip), optmenu_charset,
+       gtk_combo_box_set_row_separator_func(GTK_COMBO_BOX(combobox_charset),
+                       (GtkTreeViewRowSeparatorFunc)_combobox_separator_func, NULL, NULL);
+
+       gtk_widget_show (combobox_charset);
+       CLAWS_SET_TIP(combobox_charset,
                             _("If 'Automatic' is selected, the optimal encoding"
-                              " for the current locale will be used"),
-                            NULL);
-       gtk_table_attach(GTK_TABLE(table), optmenu_charset, 1, 2, 1, 2,
+                              " for the current locale will be used"));
+       gtk_table_attach(GTK_TABLE(table), combobox_charset, 1, 2, 1, 2,
                        (GtkAttachOptions) (GTK_FILL),
                        (GtkAttachOptions) (0), 0, 0);
 
-       optmenu_menu = gtk_menu_new ();
-
 #define SET_MENUITEM(str, data) \
 { \
-       MENUITEM_ADD(optmenu_menu, menuitem, str, data); \
+       gtk_list_store_append(optmenu, &iter); \
+       gtk_list_store_set(optmenu, &iter, \
+                       COMBOBOX_TEXT, str, \
+                       COMBOBOX_DATA, data, \
+                       -1); \
 }
 
        SET_MENUITEM(_("Automatic (Recommended)"),       CS_AUTO);
        SET_MENUITEM(NULL, NULL);
-       SET_MENUITEM(_("7bit ascii (US-ASCII)"),         CS_US_ASCII);
+       SET_MENUITEM(_("7bit ASCII (US-ASCII)"),         CS_US_ASCII);
        SET_MENUITEM(_("Unicode (UTF-8)"),               CS_UTF_8);
        SET_MENUITEM(NULL, NULL);
        SET_MENUITEM(_("Western European (ISO-8859-1)"),  CS_ISO_8859_1);
@@ -223,6 +242,7 @@ static void prefs_send_create_widget(PrefsPage *_page, GtkWindow *window,
        SET_MENUITEM(NULL, NULL);
        SET_MENUITEM(_("Cyrillic (ISO-8859-5)"),         CS_ISO_8859_5);
        SET_MENUITEM(_("Cyrillic (KOI8-R)"),             CS_KOI8_R);
+       SET_MENUITEM(_("Cyrillic (X-MAC-CYRILLIC)"),             CS_MACCYR);
        SET_MENUITEM(_("Cyrillic (KOI8-U)"),             CS_KOI8_U);
        SET_MENUITEM(_("Cyrillic (Windows-1251)"),       CS_WINDOWS_1251);
        SET_MENUITEM(NULL, NULL);
@@ -232,6 +252,7 @@ static void prefs_send_create_widget(PrefsPage *_page, GtkWindow *window,
        SET_MENUITEM(_("Japanese (Shift_JIS)"),          CS_SHIFT_JIS);
 #endif /* 0 */
        SET_MENUITEM(NULL, NULL);
+       SET_MENUITEM(_("Simplified Chinese (GB18030)"),  CS_GB18030);
        SET_MENUITEM(_("Simplified Chinese (GB2312)"),   CS_GB2312);
        SET_MENUITEM(_("Simplified Chinese (GBK)"),      CS_GBK);
        SET_MENUITEM(_("Traditional Chinese (Big5)"),    CS_BIG5);
@@ -245,8 +266,7 @@ static void prefs_send_create_widget(PrefsPage *_page, GtkWindow *window,
        SET_MENUITEM(_("Thai (TIS-620)"),                CS_TIS_620);
        SET_MENUITEM(_("Thai (Windows-874)"),            CS_WINDOWS_874);
 
-       gtk_option_menu_set_menu (GTK_OPTION_MENU (optmenu_charset),
-                                 optmenu_menu);
+#undef SET_MENUITEM
 
        label_encoding = gtk_label_new (_("Transfer encoding"));
        gtk_widget_show (label_encoding);
@@ -256,46 +276,48 @@ static void prefs_send_create_widget(PrefsPage *_page, GtkWindow *window,
        gtk_label_set_justify(GTK_LABEL(label_encoding), GTK_JUSTIFY_RIGHT);
        gtk_misc_set_alignment(GTK_MISC(label_encoding), 1, 0.5);
 
-       encoding_tooltip = gtk_tooltips_new();
-
-       optmenu_encoding = gtk_option_menu_new ();
-       gtk_widget_show (optmenu_encoding);
-       gtk_tooltips_set_tip(GTK_TOOLTIPS(encoding_tooltip), optmenu_encoding,
+       combobox_encoding = gtkut_sc_combobox_create(NULL, FALSE);
+       gtk_widget_show (combobox_encoding);
+       CLAWS_SET_TIP(combobox_encoding,
                             _("Specify Content-Transfer-Encoding used when"
-                              " message body contains non-ASCII characters"),
-                            NULL);
-       gtk_table_attach(GTK_TABLE(table), optmenu_encoding, 1, 2, 2, 3,
+                              " message body contains non-ASCII characters"));
+       gtk_table_attach(GTK_TABLE(table), combobox_encoding, 1, 2, 2, 3,
                        (GtkAttachOptions) (GTK_FILL),
                        (GtkAttachOptions) (0), 0, 0);
 
-       optmenu_menu = gtk_menu_new ();
-
-       SET_MENUITEM(_("Automatic"),     CTE_AUTO);
-       SET_MENUITEM("base64",           CTE_BASE64);
-       SET_MENUITEM("quoted-printable", CTE_QUOTED_PRINTABLE);
-       SET_MENUITEM("8bit",             CTE_8BIT);
+       optmenu = GTK_LIST_STORE(gtk_combo_box_get_model(
+                               GTK_COMBO_BOX(combobox_encoding)));
 
-       gtk_option_menu_set_menu (GTK_OPTION_MENU (optmenu_encoding),
-                                 optmenu_menu);
+       COMBOBOX_ADD(optmenu, _("Automatic"),    CTE_AUTO);
+       COMBOBOX_ADD(optmenu, NULL, 0);
+       COMBOBOX_ADD(optmenu, "base64",          CTE_BASE64);
+       COMBOBOX_ADD(optmenu, "quoted-printable", CTE_QUOTED_PRINTABLE);
+       COMBOBOX_ADD(optmenu, "8bit",            CTE_8BIT);
 
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_savemsg),
                prefs_common.savemsg);
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_confirm_send_queued_messages),
                prefs_common.confirm_send_queued_messages);
-       gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu_senddialog),
-               prefs_common.send_dialog_mode);
-       prefs_common_charset_set_optmenu(optmenu_charset, 
+       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_never_send_retrcpt),
+               prefs_common.never_send_retrcpt);
+       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_senddialog),
+               !prefs_common.send_dialog_invisible);
+       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_warn_empty_subj),
+               prefs_common.warn_empty_subj);
+       prefs_common_charset_set_optmenu(combobox_charset, 
                prefs_common.outgoing_charset);
-       prefs_common_encoding_set_optmenu(optmenu_encoding,
+       combobox_select_by_data(GTK_COMBO_BOX(combobox_encoding),
                prefs_common.encoding_method);
        
        prefs_send->window                      = GTK_WIDGET(window);
        
        prefs_send->checkbtn_savemsg = checkbtn_savemsg;
        prefs_send->checkbtn_confirm_send_queued_messages = checkbtn_confirm_send_queued_messages;
-       prefs_send->optmenu_senddialog = optmenu_senddialog;
-       prefs_send->optmenu_charset = optmenu_charset;
-       prefs_send->optmenu_encoding_method = optmenu_encoding;
+       prefs_send->checkbtn_never_send_retrcpt = checkbtn_never_send_retrcpt;
+       prefs_send->checkbtn_senddialog = checkbtn_senddialog;
+       prefs_send->checkbtn_warn_empty_subj = checkbtn_warn_empty_subj;
+       prefs_send->combobox_charset = combobox_charset;
+       prefs_send->combobox_encoding_method = combobox_encoding;
 
        prefs_send->page.widget = vbox1;
 }
@@ -303,24 +325,23 @@ static void prefs_send_create_widget(PrefsPage *_page, GtkWindow *window,
 static void prefs_send_save(PrefsPage *_page)
 {
        SendPage *page = (SendPage *) _page;
-       GtkWidget *menu;
-       GtkWidget *menuitem;
 
        prefs_common.savemsg = gtk_toggle_button_get_active(
                GTK_TOGGLE_BUTTON(page->checkbtn_savemsg));
        prefs_common.confirm_send_queued_messages = gtk_toggle_button_get_active(
                GTK_TOGGLE_BUTTON(page->checkbtn_confirm_send_queued_messages));
+       prefs_common.never_send_retrcpt = gtk_toggle_button_get_active(
+               GTK_TOGGLE_BUTTON(page->checkbtn_never_send_retrcpt));
+       prefs_common.send_dialog_invisible = !gtk_toggle_button_get_active(
+               GTK_TOGGLE_BUTTON(page->checkbtn_senddialog));
+       prefs_common.warn_empty_subj = gtk_toggle_button_get_active(
+               GTK_TOGGLE_BUTTON(page->checkbtn_warn_empty_subj));
 
-       menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(page->optmenu_senddialog));
-       menuitem = gtk_menu_get_active(GTK_MENU(menu));
-       prefs_common.send_dialog_mode = GPOINTER_TO_INT
-               (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
-       
        g_free(prefs_common.outgoing_charset);
        prefs_common.outgoing_charset = prefs_common_charset_set_data_from_optmenu(
-               page->optmenu_charset);
-       prefs_common.encoding_method = prefs_common_encoding_set_data_from_optmenu(
-               page->optmenu_encoding_method);
+               page->combobox_charset);
+       prefs_common.encoding_method =
+               combobox_get_active_data(GTK_COMBO_BOX(page->combobox_encoding_method));
 }
 
 static void prefs_send_destroy_widget(PrefsPage *_page)