In header view, don't use pointers for colors, as, when they're replaced
[modest] / src / widgets / modest-header-view.c
index 5a671fb..6a2c7ae 100644 (file)
@@ -33,6 +33,7 @@
 #include <tny-folder-monitor.h>
 #include <tny-folder-change.h>
 #include <tny-error.h>
+#include <tny-merge-folder.h>
 #include <string.h>
 
 #include <modest-header-view.h>
@@ -170,6 +171,9 @@ struct _ModestHeaderViewPrivate {
        GtkCellRenderer *renderer_subject;
        GtkCellRenderer *renderer_address;
        GtkCellRenderer *renderer_date_status;
+
+       GdkColor active_color;
+       GdkColor secondary_color;
 };
 
 typedef struct _HeadersCountChangedHelper HeadersCountChangedHelper;
@@ -1157,6 +1161,7 @@ modest_header_view_set_folder_intern (ModestHeaderView *self, TnyFolder *folder)
 
        /* Create sortable model */
        sortable = gtk_tree_model_sort_new_with_model (filter_model);
+       g_object_unref (filter_model);
 
        /* install our special sorting functions */
        cursor = cols = gtk_tree_view_get_columns (GTK_TREE_VIEW(self));
@@ -2232,10 +2237,19 @@ on_account_removed (TnyAccountStore *self,
        if (priv->folder) {
                TnyAccount *my_account;
 
-               my_account = tny_folder_get_account (priv->folder);
-               if (my_account == account)
-                       modest_header_view_clear (MODEST_HEADER_VIEW (user_data));
-               g_object_unref (my_account);
+               if (TNY_IS_MERGE_FOLDER (priv->folder) &&
+                   tny_folder_get_folder_type (priv->folder) == TNY_FOLDER_TYPE_OUTBOX) {
+                       ModestTnyAccountStore *acc_store = modest_runtime_get_account_store ();
+                       my_account = modest_tny_account_store_get_local_folders_account (acc_store);
+               } else {
+                       my_account = tny_folder_get_account (priv->folder);
+               }
+
+               if (my_account) {
+                       if (my_account == account)
+                               modest_header_view_clear (MODEST_HEADER_VIEW (user_data));
+                       g_object_unref (my_account);
+               }
        }
 }
 
@@ -2359,7 +2373,6 @@ update_style (ModestHeaderView *self)
        PangoAttrList *attr_list;
        GtkStyle *style;
        PangoAttribute *attr;
-       GdkColor *new_color;
 
        g_return_if_fail (MODEST_IS_HEADER_VIEW (self));
        priv = MODEST_HEADER_VIEW_GET_PRIVATE (self);
@@ -2370,6 +2383,7 @@ update_style (ModestHeaderView *self)
        if (!gtk_style_lookup_color (GTK_WIDGET (self)->style, "SecondaryTextColor", &style_color)) {
                gdk_color_parse ("grey", &style_color);
        }
+       priv->secondary_color = style_color;
        attr = pango_attr_foreground_new (style_color.red, style_color.green, style_color.blue);
        pango_attr_list_insert (attr_list, attr);
 
@@ -2384,25 +2398,25 @@ update_style (ModestHeaderView *self)
                pango_attr_list_insert (attr_list, attr);
 
                g_object_set (G_OBJECT (priv->renderer_address),
-                             "foreground-gdk", &style_color,
+                             "foreground-gdk", priv->secondary_color,
                              "foreground-set", TRUE,
                              "attributes", attr_list,
                              NULL);
                g_object_set (G_OBJECT (priv->renderer_date_status),
-                             "foreground-gdk", &style_color,
+                             "foreground-gdk", priv->secondary_color,
                              "foreground-set", TRUE,
                              "attributes", attr_list,
                              NULL);
                pango_attr_list_unref (attr_list);
        } else {
                g_object_set (G_OBJECT (priv->renderer_address),
-                             "foreground-gdk", &style_color,
+                             "foreground-gdk", priv->secondary_color,
                              "foreground-set", TRUE,
                              "scale", PANGO_SCALE_SMALL,
                              "scale-set", TRUE,
                              NULL);
                g_object_set (G_OBJECT (priv->renderer_date_status),
-                             "foreground-gdk", &style_color,
+                             "foreground-gdk", priv->secondary_color,
                              "foreground-set", TRUE,
                              "scale", PANGO_SCALE_SMALL,
                              "scale-set", TRUE,
@@ -2410,12 +2424,47 @@ update_style (ModestHeaderView *self)
        }
 
        if (gtk_style_lookup_color (GTK_WIDGET (self)->style, "ActiveTextColor", &style_active_color)) {
-               new_color = gdk_color_copy (&style_active_color);
+               priv->active_color = style_active_color;
+#ifdef MODEST_TOOLKIT_HILDON2
+               g_object_set_data (G_OBJECT (priv->renderer_subject), BOLD_IS_ACTIVE_COLOR, GINT_TO_POINTER (TRUE));
+               g_object_set_data_full (G_OBJECT (priv->renderer_subject), ACTIVE_COLOR, new_color, (GDestroyNotify) gdk_color_free);
+#endif
        } else {
-               new_color = NULL;
-       }
 #ifdef MODEST_TOOLKIT_HILDON2
-       g_object_set_data (G_OBJECT (priv->renderer_subject), BOLD_IS_ACTIVE_COLOR, GINT_TO_POINTER (new_color != NULL));
-       g_object_set_data_full (G_OBJECT (priv->renderer_subject), ACTIVE_COLOR, new_color, (GDestroyNotify) gdk_color_free);
+               g_object_set_data (G_OBJECT (priv->renderer_subject), BOLD_IS_ACTIVE_COLOR, GINT_TO_POINTER (FALSE));
 #endif
+       }
+}
+
+TnyHeader *
+modest_header_view_get_header_at_pos (ModestHeaderView *header_view,
+                                     gint initial_x,
+                                     gint initial_y)
+{
+       GtkTreePath *path;
+       GtkTreeModel *tree_model;
+       GtkTreeIter iter;
+       TnyHeader *header;
+
+       /* Get tree path */
+       if (!gtk_tree_view_get_dest_row_at_pos ((GtkTreeView *) header_view,
+                                               initial_x,
+                                               initial_y,
+                                               &path,
+                                               NULL))
+               return NULL;
+
+       g_debug ("located path: %s", gtk_tree_path_to_string (path));
+
+       /* Get model */
+       tree_model = gtk_tree_view_get_model ((GtkTreeView *) header_view);
+       if (!gtk_tree_model_get_iter (tree_model, &iter, path))
+               return NULL;
+
+       /* Get header */
+       gtk_tree_model_get (tree_model, &iter,
+                           TNY_GTK_HEADER_LIST_MODEL_INSTANCE_COLUMN,
+                           &header, -1);
+
+       return header;
 }