+
+ /* Free */
+ frees:
+ g_list_foreach(rows,(GFunc) gtk_tree_path_free, NULL);
+ g_list_free(rows);
+
+ return path;
+}
+
+/*
+ * This function moves the tree view scroll to the current selected
+ * row when the widget grabs the focus
+ */
+static gboolean
+on_focus_in (GtkWidget *self,
+ GdkEventFocus *event,
+ gpointer user_data)
+{
+ GtkTreeSelection *selection;
+ GtkTreeModel *model;
+ GList *selected = NULL;
+ GtkTreePath *selected_path = NULL;
+
+ model = gtk_tree_view_get_model (GTK_TREE_VIEW (self));
+ if (!model)
+ return FALSE;
+
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (self));
+ /* If none selected yet, pick the first one */
+ if (gtk_tree_selection_count_selected_rows (selection) == 0) {
+ GtkTreeIter iter;
+ GtkTreePath *path;
+
+ /* Return if the model is empty */
+ if (!gtk_tree_model_get_iter_first (model, &iter))
+ return FALSE;
+
+ path = gtk_tree_model_get_path (model, &iter);
+ gtk_tree_selection_select_path (selection, path);
+ gtk_tree_path_free (path);
+ }
+
+ /* Need to get the all the rows because is selection multiple */
+ selected = gtk_tree_selection_get_selected_rows (selection, &model);
+ if (selected == NULL) return FALSE;
+ selected_path = (GtkTreePath *) selected->data;
+
+ /* Check if we need to scroll */
+ #if GTK_CHECK_VERSION(2, 8, 0) /* TODO: gtk_tree_view_get_visible_range() is only available in GTK+ 2.8 */
+ GtkTreePath *start_path = NULL;
+ GtkTreePath *end_path = NULL;
+ if (gtk_tree_view_get_visible_range (GTK_TREE_VIEW (self),
+ &start_path,
+ &end_path)) {
+
+ if ((gtk_tree_path_compare (start_path, selected_path) != -1) ||
+ (gtk_tree_path_compare (end_path, selected_path) != 1)) {
+
+ /* Scroll to first path */
+ gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (self),
+ selected_path,
+ NULL,
+ TRUE,
+ 0.5,
+ 0.0);
+ }
+ }
+ #endif /* GTK_CHECK_VERSION */
+
+ /* Frees */
+ g_list_foreach (selected, (GFunc) gtk_tree_path_free, NULL);
+ g_list_free (selected);
+
+ return FALSE;
+}
+
+static void
+folder_monitor_update (TnyFolderObserver *self,
+ TnyFolderChange *change)
+{
+ ModestHeaderViewPrivate *priv = MODEST_HEADER_VIEW_GET_PRIVATE (self);
+ TnyFolderChangeChanged changed;
+
+ g_mutex_lock (priv->observers_lock);
+
+ changed = tny_folder_change_get_changed (change);
+
+ if (changed & TNY_FOLDER_CHANGE_CHANGED_ADDED_HEADERS) {
+/* TnyIterator *iter; */
+/* TnyList *list; */
+/* /\* The added headers *\/ */
+/* list = tny_simple_list_new (); */
+/* tny_folder_change_get_added_headers (change, list); */
+/* iter = tny_list_create_iterator (list); */
+/* while (!tny_iterator_is_done (iter)) */
+/* { */
+/* TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter)); */
+/* g_object_unref (G_OBJECT (header)); */
+/* tny_iterator_next (iter); */
+/* } */
+/* g_object_unref (G_OBJECT (iter)); */
+/* g_object_unref (G_OBJECT (list)); */
+ modest_platform_on_new_msg ();
+ }
+
+ g_mutex_unlock (priv->observers_lock);
+}