Fix memory leaks from results of gtk_tree_model_get().
[claws.git] / src / prefs_toolbar.c
index 24efd931fb035a8f24c61728f9f54737f91296fe..cc56483fd8c7bc87e569c6ace3355a1520add68b 100644 (file)
@@ -1,6 +1,6 @@
 /*
- * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 2002-2015 Hiroyuki Yamamoto & the Claws Mail team
+ * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 2002-2017 Hiroyuki Yamamoto & 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
@@ -14,7 +14,6 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
  */
 
 /*
@@ -92,7 +91,7 @@ static const gint ToolbarIcons[] =
        STOCK_PIXMAP_LDAP,
        STOCK_PIXMAP_LINEWRAP_CURRENT,
        STOCK_PIXMAP_LINEWRAP_ALL,
-       STOCK_PIXMAP_MAIL,
+       STOCK_PIXMAP_MAIL_DRAFT,
        STOCK_PIXMAP_MAIL_ATTACH,
        STOCK_PIXMAP_MAIL_COMPOSE,
        STOCK_PIXMAP_MAIL_FORWARD,
@@ -129,7 +128,7 @@ static const gint ToolbarIcons[] =
        STOCK_PIXMAP_MIME_PS,
        STOCK_PIXMAP_MIME_TEXT_CALENDAR,
        STOCK_PIXMAP_MIME_PGP_SIG,
-       STOCK_PIXMAP_PRINTER,
+       STOCK_PIXMAP_PRINTER_BTN,
        STOCK_PIXMAP_PRIVACY_SIGNED,
        STOCK_PIXMAP_PRIVACY_PASSED,
        STOCK_PIXMAP_PRIVACY_FAILED,
@@ -145,6 +144,7 @@ static const gint ToolbarIcons[] =
        STOCK_PIXMAP_HAM_BTN,
        STOCK_PIXMAP_TRASH,
        STOCK_PIXMAP_DELETE,
+       STOCK_PIXMAP_DELETE_DUP,
        STOCK_PIXMAP_CANCEL,
        STOCK_PIXMAP_MARK_IGNORETHREAD,
        STOCK_PIXMAP_MARK_WATCHTHREAD,
@@ -378,11 +378,7 @@ static void prefs_toolbar_set_displayed(ToolbarPage *prefs_toolbar)
 
 static void add_item_to_plugin_combo(gpointer key, gpointer data, gpointer combo_box)
 {
-#if !GTK_CHECK_VERSION(2, 24, 0)
-       gtk_combo_box_append_text(GTK_COMBO_BOX(combo_box), (const gchar*)key);
-#else
        gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo_box), (const gchar*)key);
-#endif
 }
 
 static void prefs_toolbar_populate(ToolbarPage *prefs_toolbar)
@@ -392,13 +388,8 @@ static void prefs_toolbar_populate(ToolbarPage *prefs_toolbar)
        GHashTable **hash;
 
        prefs_toolbar->combo_action_list = toolbar_get_action_items(prefs_toolbar->source);
-#if !GTK_CHECK_VERSION(2, 24, 0)
-       combobox_set_popdown_strings(GTK_COMBO_BOX(prefs_toolbar->item_func_combo),
-                                    prefs_toolbar->combo_action_list);
-#else
        combobox_set_popdown_strings(GTK_COMBO_BOX_TEXT(prefs_toolbar->item_func_combo),
                                     prefs_toolbar->combo_action_list);
-#endif
 
        /* get currently defined sylpheed actions */
        if (prefs_common.actions_list != NULL) {
@@ -406,13 +397,8 @@ static void prefs_toolbar_populate(ToolbarPage *prefs_toolbar)
                        act = (gchar *)cur->data;
                        get_action_name(act, &act_name);
 
-#if !GTK_CHECK_VERSION(2, 24, 0)
-                       gtk_combo_box_append_text(
-                               GTK_COMBO_BOX(prefs_toolbar->item_action_combo),
-#else
                        gtk_combo_box_text_append_text(
                                GTK_COMBO_BOX_TEXT(prefs_toolbar->item_action_combo),
-#endif
                                act_name);
 
                        g_free(act_name);
@@ -534,11 +520,7 @@ static void prefs_toolbar_register(GtkButton *button, ToolbarPage *prefs_toolbar
                }
 
                if (item_type == ITEM_FUNCTION) {
-#if !GTK_CHECK_VERSION(2, 24, 0)
-                       event = gtk_combo_box_get_active_text(GTK_COMBO_BOX(
-#else
                        event = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(
-#endif
                                                prefs_toolbar->item_func_combo));
 
                        if (is_duplicate(prefs_toolbar, event)) {
@@ -624,11 +606,7 @@ static void prefs_toolbar_substitute(GtkButton *button, ToolbarPage *prefs_toolb
                                                  -1);
 
                if (item_type == ITEM_FUNCTION) {
-#if !GTK_CHECK_VERSION(2, 24, 0)
-                       icon_event = gtk_combo_box_get_active_text(GTK_COMBO_BOX(
-#else
                        icon_event = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(
-#endif
                                                prefs_toolbar->item_func_combo));
 
                        if (is_duplicate(prefs_toolbar, icon_event)
@@ -822,11 +800,7 @@ static void item_type_changed(GtkComboBox *item_type_combo,
 static void action_selection_changed(GtkComboBox *action_combo,
                                ToolbarPage *prefs_toolbar)
 {
-#if !GTK_CHECK_VERSION(2, 24, 0)
-       gchar *text = gtk_combo_box_get_active_text(GTK_COMBO_BOX(
-#else
        gchar *text = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(
-#endif
                           prefs_toolbar->item_action_combo));
 
        if(text != NULL) { /* action */
@@ -838,11 +812,7 @@ static void action_selection_changed(GtkComboBox *action_combo,
 static void plugin_selection_changed(GtkComboBox *action_combo,
                 ToolbarPage *prefs_toolbar)
 {
-#if !GTK_CHECK_VERSION(2, 24, 0)
-       gchar *text = gtk_combo_box_get_active_text(GTK_COMBO_BOX(prefs_toolbar->item_plugin_combo));
-#else
        gchar *text = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(prefs_toolbar->item_plugin_combo));
-#endif
 
        if (text != NULL) { /* action */
                gtk_entry_set_text(GTK_ENTRY(prefs_toolbar->item_text_entry), text);
@@ -853,23 +823,22 @@ static void plugin_selection_changed(GtkComboBox *action_combo,
 static void func_selection_changed(GtkComboBox *action_combo,
                                ToolbarPage *prefs_toolbar)
 {
-#if !GTK_CHECK_VERSION(2, 24, 0)
-       gchar *text = gtk_combo_box_get_active_text(GTK_COMBO_BOX(
-#else
        gchar *text = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(
-#endif
                           prefs_toolbar->item_func_combo));
 
        if(text != NULL) { /* action */
-               int action = -1;
+               int action;
+
                action = toolbar_ret_val_from_descr(text);
-               if (action >= 0)
+               g_free(text);
+               if (action > -1) {
+                       gint icon;
+
                        gtk_entry_set_text(GTK_ENTRY(prefs_toolbar->item_text_entry),
                                        toolbar_get_short_text(action));
-               g_free(text);
-               if (action >= 0) {
-                       StockPixmap stockp = toolbar_get_icon(action);
-                       if (stockp >= 0)  {
+                       icon = toolbar_get_icon(action);
+                       if (icon > -1)  {
+                               StockPixmap stockp = (StockPixmap)icon;
                                g_free(prefs_toolbar->item_icon_file);
                                prefs_toolbar->item_icon_file = g_strdup(stock_pixmap_get_name(stockp));
 
@@ -965,33 +934,21 @@ static void prefs_toolbar_create(ToolbarPage *prefs_toolbar)
                          (GtkAttachOptions) (GTK_FILL),
                          (GtkAttachOptions) (0), 0, 0);
 
-#if !GTK_CHECK_VERSION(2, 24, 0)
-       item_action_combo = gtk_combo_box_new_text();
-#else
        item_action_combo = gtk_combo_box_text_new();
-#endif
        gtk_widget_set_size_request(item_action_combo, 200, -1);
        gtk_table_attach (GTK_TABLE (table), item_action_combo, 1, 3, 1, 2,
                          (GtkAttachOptions) (GTK_FILL),
                          (GtkAttachOptions) (0), 0, 0);
 
        /* available internal functions */
-#if !GTK_CHECK_VERSION(2, 24, 0)
-       item_func_combo = gtk_combo_box_new_text();
-#else
        item_func_combo = gtk_combo_box_text_new();
-#endif
        gtk_widget_set_size_request(item_func_combo, 200, -1);
        gtk_table_attach (GTK_TABLE (table), item_func_combo, 1, 3, 1, 2,
                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
                          (GtkAttachOptions) (0), 0, 0);
 
        /* plugin-registered items */
-#if !GTK_CHECK_VERSION(2, 24, 0)
-       item_plugin_combo = gtk_combo_box_new_text();
-#else
        item_plugin_combo = gtk_combo_box_text_new();
-#endif
        gtk_widget_set_size_request(item_plugin_combo, 200, -1);
        gtk_table_attach(GTK_TABLE(table), item_plugin_combo, 1, 3, 1, 2,
                         (GtkAttachOptions) (GTK_FILL),
@@ -1362,7 +1319,8 @@ static void set_visible_if_not_text(GtkTreeViewColumn *col,
                                   -1);
                /* note getting a pixbuf from a tree model increases
                 * its refcount ... */
-               g_object_unref(pixbuf);
+               if (pixbuf != NULL)
+                       g_object_unref(pixbuf);
 
                g_object_set(renderer, "visible", TRUE, NULL);
                g_object_set(renderer, "pixbuf",  pixbuf, NULL);
@@ -1480,6 +1438,8 @@ static gboolean set_list_selected(GtkTreeSelection *selector,
                                        ITEM_SEPARATOR);
                g_free(icon_text);
                g_free(descr);
+               if (pix != NULL)
+                       g_object_unref(pix);
 
                return TRUE;
        }
@@ -1516,6 +1476,8 @@ static gboolean set_list_selected(GtkTreeSelection *selector,
 
                g_free(icon_text);
                g_free(descr);
+               if (pix != NULL)
+                       g_object_unref(pix);
 
                return TRUE;
        }
@@ -1531,6 +1493,8 @@ static gboolean set_list_selected(GtkTreeSelection *selector,
 
                g_free(descr);
                g_free(icon_text);
+               if (pix != NULL)
+                       g_object_unref(pix);
                return TRUE;
        }
 
@@ -1556,6 +1520,8 @@ static gboolean set_list_selected(GtkTreeSelection *selector,
 
        g_free(icon_text);
        g_free(descr);
+       if (pix != NULL)
+               g_object_unref(pix);
 
        return TRUE;
 }
@@ -1591,6 +1557,8 @@ static void icon_chooser_ok_clicked(GtkButton *button,
        prefs_toolbar->item_icon_file = icon_file;
        gtk_button_set_image(GTK_BUTTON(prefs_toolbar->icon_button),
                             gtk_image_new_from_pixbuf(pix));
+       if (pix != NULL)
+               g_object_unref(pix);
 
        gtk_widget_destroy(prefs_toolbar->icon_chooser_win);
        prefs_toolbar->icon_chooser_win = NULL;