2006-06-25 [ticho] 2.3.1cvs19
authorAndrej Kacian <ticho@claws-mail.org>
Sun, 25 Jun 2006 09:54:36 +0000 (09:54 +0000)
committerAndrej Kacian <ticho@claws-mail.org>
Sun, 25 Jun 2006 09:54:36 +0000 (09:54 +0000)
* src/compose.c
* src/gtk/Makefile.am
* src/gtk/combobox.c
* src/gtk/combobox.h
* src/gtk/gtkutils.c
* src/gtk/gtkutils.h
Use GtkComboBox instead of deprecated GtkOptionMenu
for account selector in compose window and for encoding
selector in attachment properties.
Also factorise working with the new GtkComboBox somewhat.

ChangeLog
PATCHSETS
configure.ac
src/compose.c
src/gtk/Makefile.am
src/gtk/combobox.c [new file with mode: 0644]
src/gtk/combobox.h [new file with mode: 0644]
src/gtk/gtkutils.c
src/gtk/gtkutils.h

index 186d0fe44839011c6ec8331ac9258aaa0ecf10dd..fc3c26bbc8b5cf91df677d2231d74874c4306ae1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2006-06-25 [ticho]     2.3.1cvs19
+
+       * src/compose.c
+       * src/gtk/Makefile.am
+       * src/gtk/combobox.c
+       * src/gtk/combobox.h
+       * src/gtk/gtkutils.c
+       * src/gtk/gtkutils.h
+               Use GtkComboBox instead of deprecated GtkOptionMenu
+               for account selector in compose window and for encoding
+               selector in attachment properties.
+               Also factorise working with the new GtkComboBox somewhat.
+
 2006-06-24 [paul]      2.3.1cvs18
 
        * src/prefs_common.c
index d2ccae3f2ee716af174cbccc217018456180ffef..b0a9fd07e6c36ee88a6aac5c6d1da53eb8fa29ff 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
 ( cvs diff -u -r 1.382.2.283 -r 1.382.2.284 src/compose.c;  ) > 2.3.1cvs16.patchset
 ( cvs diff -u -r 1.382.2.284 -r 1.382.2.285 src/compose.c;  cvs diff -u -r 1.204.2.89 -r 1.204.2.90 src/prefs_common.c;  cvs diff -u -r 1.103.2.52 -r 1.103.2.53 src/prefs_common.h;  cvs diff -u -r 1.1.2.8 -r 1.1.2.9 src/prefs_compose_writing.c;  ) > 2.3.1cvs17.patchset
 ( cvs diff -u -r 1.204.2.90 -r 1.204.2.91 src/prefs_common.c;  ) > 2.3.1cvs18.patchset
+( cvs diff -u -r 1.382.2.285 -r 1.382.2.286 src/compose.c;  cvs diff -u -r 1.20.2.8 -r 1.20.2.9 src/gtk/Makefile.am;  diff -u /dev/null src/gtk/combobox.c;  diff -u /dev/null src/gtk/combobox.h;  cvs diff -u -r 1.5.2.28 -r 1.5.2.29 src/gtk/gtkutils.c;  cvs diff -u -r 1.4.2.20 -r 1.4.2.21 src/gtk/gtkutils.h;  ) > 2.3.1cvs19.patchset
index 5e6a5189cfc9a96aa2734d98ae91ffc09de028de..46f33581feae1a72feceee04828187d989ee6ddb 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=3
 MICRO_VERSION=1
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=18
+EXTRA_VERSION=19
 EXTRA_RELEASE=
 EXTRA_GTK2_VERSION=
 
index b91b9521c14f56523ae007366b229c008890d40a..adf85707705f44c7d63cf5e318874a4ca72cc5dd 100644 (file)
 #include "toolbar.h"
 #include "inc.h"
 #include "message_search.h"
+#include "combobox.h"
 
 enum
 {
@@ -333,7 +334,7 @@ static void compose_add_field_list  ( Compose *compose,
 static gboolean compose_edit_size_alloc (GtkEditable   *widget,
                                         GtkAllocation  *allocation,
                                         GtkSHRuler     *shruler);
-static void account_activated          (GtkMenuItem    *menuitem,
+static void account_activated          (GtkComboBox *optmenu,
                                         gpointer        data);
 static void attach_selected            (GtkTreeView    *tree_view, 
                                         GtkTreePath    *tree_path,
@@ -6146,7 +6147,9 @@ static GtkWidget *compose_account_option_menu_create(Compose *compose)
        GList *accounts;
        GtkWidget *hbox;
        GtkWidget *optmenu;
-       GtkWidget *menu;
+       GtkWidget *optmenubox;
+       GtkListStore *menu;
+       GtkTreeIter iter;
        GtkWidget *from_name = NULL;
 
        gint num = 0, def_menu = 0;
@@ -6154,8 +6157,9 @@ static GtkWidget *compose_account_option_menu_create(Compose *compose)
        accounts = account_get_list();
        g_return_val_if_fail(accounts != NULL, NULL);
 
-       optmenu = gtk_option_menu_new();
-       menu = gtk_menu_new();
+       optmenubox = gtk_event_box_new();
+       optmenu = gtkut_sc_combobox_create(optmenubox);
+       menu = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(optmenu)));
 
        hbox = gtk_hbox_new(FALSE, 6);
        from_name = gtk_entry_new();
@@ -6165,7 +6169,6 @@ static GtkWidget *compose_account_option_menu_create(Compose *compose)
 
        for (; accounts != NULL; accounts = accounts->next, num++) {
                PrefsAccount *ac = (PrefsAccount *)accounts->data;
-               GtkWidget *menuitem;
                gchar *name, *from = NULL;
 
                if (ac == compose->account) def_menu = num;
@@ -6186,24 +6189,21 @@ static GtkWidget *compose_account_option_menu_create(Compose *compose)
                                gtk_entry_set_text(GTK_ENTRY(from_name), from);
                        }
                }
-               MENUITEM_ADD(menu, menuitem, name, ac->account_id);
-               gtk_label_set_use_markup (
-                               GTK_LABEL (gtk_bin_get_child (GTK_BIN (menuitem))),
-                               TRUE);
+               COMBOBOX_ADD(menu, name, ac->account_id);
                g_free(name);
                g_free(from);
-               g_signal_connect(G_OBJECT(menuitem), "activate",
-                                G_CALLBACK(account_activated),
-                                compose);
        }
 
-       gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
-       gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), def_menu);
+       gtk_combo_box_set_active(GTK_COMBO_BOX(optmenu), def_menu);
+
+       g_signal_connect(G_OBJECT(optmenu), "changed",
+                       G_CALLBACK(account_activated),
+                       compose);
 
-       gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
+       gtk_box_pack_start(GTK_BOX(hbox), optmenubox, FALSE, FALSE, 0);
        gtk_box_pack_start(GTK_BOX(hbox), from_name, TRUE, TRUE, 0);
        
-       gtk_tooltips_set_tip(compose->tooltips, optmenu,
+       gtk_tooltips_set_tip(compose->tooltips, optmenubox,
                _("Account to use for this email"), NULL);
        gtk_tooltips_set_tip(compose->tooltips, from_name,
                _("Sender address to be used"), NULL);
@@ -6753,7 +6753,7 @@ static void compose_attach_property(Compose *compose)
 {
        GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
        AttachInfo *ainfo;
-       GtkOptionMenu *optmenu;
+       GtkComboBox *optmenu;
        GtkTreeSelection *selection;
        GList *sel;
        GtkTreeModel *model;
@@ -6787,13 +6787,11 @@ static void compose_attach_property(Compose *compose)
        gtk_widget_show(attach_prop.window);
        manage_window_set_transient(GTK_WINDOW(attach_prop.window));
 
-       optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
+       optmenu = GTK_COMBO_BOX(attach_prop.encoding_optmenu);
        if (ainfo->encoding == ENC_UNKNOWN)
-               menu_select_by_data(GTK_MENU(gtk_option_menu_get_menu(optmenu)),
-                                   GINT_TO_POINTER(ENC_BASE64));
+               combobox_select_by_data(optmenu, ENC_BASE64);
        else
-               menu_select_by_data(GTK_MENU(gtk_option_menu_get_menu(optmenu)),
-                                   GINT_TO_POINTER(ainfo->encoding));
+               combobox_select_by_data(optmenu, ainfo->encoding);
 
        gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
                           ainfo->content_type ? ainfo->content_type : "");
@@ -6808,8 +6806,6 @@ static void compose_attach_property(Compose *compose)
                gchar *cnttype = NULL;
                gchar *file = NULL;
                off_t size = 0;
-               GtkWidget *menu;
-               GtkWidget *menuitem;
 
                cancelled = FALSE;
                gtk_main();
@@ -6834,10 +6830,7 @@ static void compose_attach_property(Compose *compose)
                        }
                }
 
-               menu = gtk_option_menu_get_menu(optmenu);
-               menuitem = gtk_menu_get_active(GTK_MENU(menu));
-               ainfo->encoding = GPOINTER_TO_INT
-                       (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
+               ainfo->encoding = combobox_get_active_data(optmenu);
 
                entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
                if (*entry_text != '\0') {
@@ -6905,14 +6898,14 @@ static void compose_attach_property_create(gboolean *cancelled)
        GtkWidget *mimetype_entry;
        GtkWidget *hbox;
        GtkWidget *optmenu;
-       GtkWidget *optmenu_menu;
-       GtkWidget *menuitem;
+       GtkListStore *optmenu_menu;
        GtkWidget *path_entry;
        GtkWidget *filename_entry;
        GtkWidget *hbbox;
        GtkWidget *ok_btn;
        GtkWidget *cancel_btn;
        GList     *mime_type_list, *strlist;
+       GtkTreeIter iter;
 
        debug_print("Creating attach_property window...\n");
 
@@ -6979,21 +6972,16 @@ static void compose_attach_property_create(gboolean *cancelled)
        gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
                         GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
 
-       optmenu = gtk_option_menu_new();
-       gtk_box_pack_start(GTK_BOX(hbox), optmenu, TRUE, TRUE, 0);
-
-       optmenu_menu = gtk_menu_new();
-       MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
-       gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
-       MENUITEM_ADD(optmenu_menu, menuitem, "8bit", ENC_8BIT);
-       gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
-       MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable",
-                    ENC_QUOTED_PRINTABLE);
-       gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
+       optmenu = gtkut_sc_combobox_create(NULL);
+       optmenu_menu = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(optmenu)));
 
-       MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
+       COMBOBOX_ADD(optmenu_menu, "7bit", ENC_7BIT);
+       COMBOBOX_ADD(optmenu_menu, "8bit", ENC_8BIT);
+       COMBOBOX_ADD(optmenu_menu, "quoted-printable",  ENC_QUOTED_PRINTABLE);
+       COMBOBOX_ADD(optmenu_menu, "base64", ENC_BASE64);
+       gtk_combo_box_set_active(GTK_COMBO_BOX(optmenu), 0);
 
-       gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
+       gtk_box_pack_start(GTK_BOX(hbox), optmenu, TRUE, TRUE, 0);
 
        SET_LABEL_AND_ENTRY(_("Path"),      path_entry,     2);
        SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
@@ -7389,15 +7377,22 @@ static gboolean compose_edit_size_alloc(GtkEditable *widget,
        return TRUE;
 }
 
-static void account_activated(GtkMenuItem *menuitem, gpointer data)
+static void account_activated(GtkComboBox *optmenu, gpointer data)
 {
        Compose *compose = (Compose *)data;
 
        PrefsAccount *ac;
        gchar *folderidentifier;
+       gint account_id = 0;
+       GtkTreeModel *menu;
+       GtkTreeIter iter;
+
+       /* Get ID of active account in the combo box */
+       menu = gtk_combo_box_get_model(optmenu);
+       gtk_combo_box_get_active_iter(optmenu, &iter);
+       gtk_tree_model_get(menu, &iter, 1, &account_id, -1);
 
-       ac = account_find_from_id(
-               GPOINTER_TO_INT(g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID)));
+       ac = account_find_from_id(account_id);
        g_return_if_fail(ac != NULL);
 
        if (ac != compose->account)
index 0337ac424f4ca6c197541fca0c7dbfe59622617a..ac3fede2ee15f3442ccbe9ff0b02c8a02df14438 100644 (file)
@@ -10,6 +10,7 @@ libsylpheedgtk_la_SOURCES = \
        about.c \
        colorlabel.c \
        colorsel.c \
+       combobox.c \
        description_window.c \
        filesel.c \
        foldersort.c \
@@ -37,6 +38,7 @@ sylpheedgtkinclude_HEADERS = \
        about.h \
        colorlabel.h \
        colorsel.h \
+       combobox.h \
        description_window.h \
        filesel.h \
        foldersort.h \
diff --git a/src/gtk/combobox.c b/src/gtk/combobox.c
new file mode 100644 (file)
index 0000000..91f32ae
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+ * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 2006 Andrej Kacian and the Sylpheed-Claws 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
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
+
+typedef struct _combobox_sel_by_data_ctx {
+       GtkComboBox *combobox;
+       gint data;
+} ComboboxSelCtx;
+
+static gboolean _select_by_data_func(GtkTreeModel *model,      GtkTreePath *path,
+               GtkTreeIter *iter, ComboboxSelCtx *ctx)
+{
+       GtkComboBox *combobox = ctx->combobox;
+       gint data = ctx->data;
+       gint curdata;
+
+       gtk_tree_model_get(model, iter, 1, &curdata, -1);
+       if (data == curdata) {
+               gtk_combo_box_set_active_iter(combobox, iter);
+               return TRUE;
+       }
+
+       return FALSE;
+}
+
+void combobox_select_by_data(GtkComboBox *combobox, gint data)
+{
+       GtkTreeModel *model;
+       ComboboxSelCtx *ctx = NULL;
+       g_return_if_fail(combobox != NULL);
+
+       model = gtk_combo_box_get_model(combobox);
+
+       ctx = g_new(ComboboxSelCtx,
+                       sizeof(ComboboxSelCtx));
+       ctx->combobox = combobox;
+       ctx->data = data;
+
+       gtk_tree_model_foreach(model, (GtkTreeModelForeachFunc)_select_by_data_func, ctx);
+       g_free(ctx);
+}
+
+gint combobox_get_active_data(GtkComboBox *combobox)
+{
+       GtkTreeModel *model;
+       GtkTreeIter iter;
+       gint data;
+
+       g_return_val_if_fail(combobox != NULL, -1);
+
+       gtk_combo_box_get_active_iter(combobox, &iter);
+
+       model = gtk_combo_box_get_model(combobox);
+
+       gtk_tree_model_get(model, &iter, 1, &data, -1);
+
+       return data;
+}
diff --git a/src/gtk/combobox.h b/src/gtk/combobox.h
new file mode 100644 (file)
index 0000000..198c6ce
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 1999-2006 Andrej Kacian and the Sylpheed-Claws 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
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * 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.
+ */
+
+#ifndef __COMBOBOX_H__
+#define __COMBOBOX_H__
+
+#include <glib.h>
+#include <gtk/gtkwidget.h>
+#include <gtk/gtkcombobox.h>
+
+#define COMBOBOX_ADD(menu, label, data)                 \
+{                                                               \
+       gtk_list_store_append(menu, &iter); \
+       gtk_list_store_set(menu, &iter, \
+                       0, (label ? label : ""), \
+                       1, data, \
+                       -1); \
+}
+
+void combobox_select_by_data   (GtkComboBox            *combobox,
+                                gint            data);
+
+gint combobox_get_active_data  (GtkComboBox            *combobox);
+
+#endif /* __COMBOBOX_H__ */
index cb8e87b022a72ea3aed92510c0d1cbe4c2cbbb98..288ae4569efb110e956dcdaf0fbd642c8ee025cb 100644 (file)
@@ -1280,3 +1280,27 @@ GtkWidget *gtkut_get_link_btn(GtkWidget *window, const gchar *url, const gchar *
                         G_CALLBACK(link_btn_unrealize), local_url);
        return btn;
 }
+
+GtkWidget *gtkut_sc_combobox_create(GtkWidget *eventbox)
+{
+       GtkWidget *combobox;
+       GtkListStore *menu;
+       GtkCellRenderer *rend;
+
+       menu = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_INT);
+
+       combobox = gtk_combo_box_new_with_model(GTK_TREE_MODEL(menu));
+
+       rend = gtk_cell_renderer_text_new();
+       gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combobox), rend, TRUE);
+       gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combobox), rend,
+                       "markup", 0,
+                       NULL);
+
+       if( eventbox != NULL )
+               gtk_container_add(GTK_CONTAINER(eventbox), combobox);
+
+       gtk_combo_box_set_focus_on_click(GTK_COMBO_BOX(combobox), FALSE);
+
+       return combobox;
+}
index 136f7f1733953f7b8bfa57421e38346cc827485e..6939df86be96ac88399760a60fd2d2f8b1d29c2c 100644 (file)
@@ -204,4 +204,6 @@ gboolean get_tag_range(GtkTextIter *iter,
 GtkWidget *face_get_from_header(const gchar *o_face);
 GtkWidget *gtkut_get_link_btn(GtkWidget *window, const gchar *url, const gchar *label);
 
+GtkWidget *gtkut_sc_combobox_create(GtkWidget *eventbox);
+
 #endif /* __GTKUTILS_H__ */