Move modest folder window to widgets
[modest] / src / widgets / modest-folder-view.c
index 770fb2a..7ef3c74 100644 (file)
@@ -144,6 +144,7 @@ static void         on_configuration_key_changed  (ModestConf* conf,
                                                   ModestConfNotificationId notification_id,
                                                   ModestFolderView *self);
 
+#ifndef MODEST_TOOLKIT_HILDON2
 /* DnD functions */
 static void         on_drag_data_get       (GtkWidget *widget,
                                            GdkDragContext *context,
@@ -168,24 +169,23 @@ static gboolean     on_drag_motion         (GtkWidget      *widget,
                                            guint           time,
                                            gpointer        user_data);
 
-static void         expand_root_items (ModestFolderView *self);
+static void         setup_drag_and_drop    (GtkTreeView *self);
+
+static void         on_row_inserted_maybe_select_folder (GtkTreeModel     *tree_model,
+                                                        GtkTreePath      *path,
+                                                        GtkTreeIter      *iter,
+                                                        ModestFolderView *self);
 
 static gint         expand_row_timeout     (gpointer data);
+#endif
 
-static void         setup_drag_and_drop    (GtkTreeView *self);
+static void         expand_root_items (ModestFolderView *self);
 
 static gboolean     _clipboard_set_selected_data (ModestFolderView *folder_view,
                                                  gboolean delete);
 
 static void         _clear_hidding_filter (ModestFolderView *folder_view);
 
-#ifndef MODEST_TOOLKIT_HILDON2
-static void         on_row_inserted_maybe_select_folder (GtkTreeModel     *tree_model,
-                                                        GtkTreePath      *path,
-                                                        GtkTreeIter      *iter,
-                                                        ModestFolderView *self);
-#endif
-
 static void         on_display_name_changed (ModestAccountMgr *self,
                                             const gchar *account,
                                             gpointer user_data);
@@ -1325,8 +1325,10 @@ modest_folder_view_init (ModestFolderView *obj)
        /* Build treeview */
        add_columns (GTK_WIDGET (obj));
 
+#ifndef MODEST_TOOLKIT_HILDON2
        /* Setup drag and drop */
        setup_drag_and_drop (GTK_TREE_VIEW(obj));
+#endif
 
        /* Connect signals */
        g_signal_connect (G_OBJECT (obj),
@@ -1513,7 +1515,9 @@ modest_folder_view_set_account_store (TnyAccountStoreView *self, TnyAccountStore
 
        modest_folder_view_update_model (MODEST_FOLDER_VIEW (self), account_store);
        priv->reselect = FALSE;
+#ifndef MODEST_TOOLKIT_HILDON2
        modest_folder_view_select_first_inbox_or_local (MODEST_FOLDER_VIEW (self));
+#endif
 
        g_object_unref (G_OBJECT (device));
 }
@@ -1621,6 +1625,7 @@ same_account_selected (ModestFolderView *self,
        return same_account;
 }
 
+#ifndef MODEST_TOOLKIT_HILDON2
 /**
  *
  * Selects the first inbox or the local account in an idle
@@ -1636,6 +1641,7 @@ on_idle_select_first_inbox_or_local (gpointer user_data)
 
        return FALSE;
 }
+#endif
 
 static void
 on_account_changed (TnyAccountStore *account_store,
@@ -1680,10 +1686,12 @@ on_account_changed (TnyAccountStore *account_store,
        /* Refilter the model */
        gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (filter_model));
 
+#ifndef MODEST_TOOLKIT_HILDON2
        /* Select the first INBOX if the currently selected folder
           belongs to the account that is being deleted */
        if (same_account && !MODEST_IS_TNY_LOCAL_FOLDERS_ACCOUNT (tny_account))
                g_idle_add (on_idle_select_first_inbox_or_local, self);
+#endif
 }
 
 static void
@@ -1765,10 +1773,12 @@ on_account_removed (TnyAccountStore *account_store,
        /* Refilter the model */
        gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (filter_model));
 
+#ifndef MODEST_TOOLKIT_HILDON2
        /* Select the first INBOX if the currently selected folder
           belongs to the account that is being deleted */
        if (same_account)
                g_idle_add (on_idle_select_first_inbox_or_local, self);
+#endif
 }
 
 void
@@ -1809,7 +1819,9 @@ modest_folder_view_on_map (ModestFolderView *self,
                   deathlock situation */
                /* TODO: check if this is still the case */
                priv->reselect = FALSE;
+#ifndef MODEST_TOOLKIT_HILDON2
                modest_folder_view_select_first_inbox_or_local (self);
+#endif
                /* Notify the display name observers */
                g_signal_emit (G_OBJECT(self),
                               signals[FOLDER_DISPLAY_NAME_CHANGED_SIGNAL], 0,
@@ -2354,10 +2366,48 @@ modest_folder_view_update_model (ModestFolderView *self,
                g_object_unref (account);
        }
 
-       /* Get the accounts: */
-       tny_account_store_get_accounts (TNY_ACCOUNT_STORE(account_store),
-                                       TNY_LIST (model),
-                                       TNY_ACCOUNT_STORE_STORE_ACCOUNTS);
+       if (priv->style == MODEST_FOLDER_VIEW_STYLE_SHOW_ALL) {
+               /* Get the accounts */
+               tny_account_store_get_accounts (TNY_ACCOUNT_STORE(account_store),
+                                               TNY_LIST (model),
+                                               TNY_ACCOUNT_STORE_STORE_ACCOUNTS);
+       } else {
+               if (priv->visible_account_id) {
+                       TnyAccount *account;
+
+                       /* Add local folders account */
+                      account = modest_tny_account_store_get_local_folders_account ((ModestTnyAccountStore *) account_store);
+
+                       if (account) {
+                               tny_list_append (TNY_LIST (model), (GObject *) account);
+                               g_object_unref (account);
+                       }
+
+                      account = modest_tny_account_store_get_mmc_folders_account ((ModestTnyAccountStore *) account_store);
+
+                       if (account) {
+                               tny_list_append (TNY_LIST (model), (GObject *) account);
+                               g_object_unref (account);
+                       }
+
+                       /* Add visible account */
+                      account = modest_tny_account_store_get_tny_account_by ((ModestTnyAccountStore *) account_store,
+                                                                             MODEST_TNY_ACCOUNT_STORE_QUERY_ID,
+                                                                              priv->visible_account_id);
+                       if (account) {
+                               tny_list_append (TNY_LIST (model), (GObject *) account);
+                               g_object_unref (account);
+                       } else {
+                               g_warning ("You need to set an account first");
+                               g_object_unref (model);
+                               return FALSE;
+                       }
+               } else {
+                       g_warning ("You need to set an account first");
+                       g_object_unref (model);
+                       return FALSE;
+               }
+       }
 
        sortable = gtk_tree_model_sort_new_with_model (model);
        gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE(sortable),
@@ -2813,6 +2863,7 @@ cmp_rows (GtkTreeModel *tree_model, GtkTreeIter *iter1, GtkTreeIter *iter2,
        return cmp;
 }
 
+#ifndef MODEST_TOOLKIT_HILDON2
 /*****************************************************************************/
 /*                        DRAG and DROP stuff                                */
 /*****************************************************************************/
@@ -2884,7 +2935,6 @@ tree_path_to_folder (GtkTreeModel *model, GtkTreePath *path)
        return folder;
 }
 
-
 /*
  * This function is used by drag_data_received_cb to manage drag and
  * drop of a header, i.e, and drag from the header view to the folder
@@ -3223,7 +3273,11 @@ on_drag_data_received (GtkWidget *widget,
        }
 
        /* Check if the get_data failed */
+#if GTK_CHECK_VERSION (2,14,0)
+       if ((selection_data == NULL) || (gtk_selection_data_get_length (selection_data) < 0))
+#else
        if (selection_data == NULL || selection_data->length < 0)
+#endif
                goto end;
 
        /* Select the destination model */
@@ -3446,9 +3500,6 @@ setup_drag_and_drop (GtkTreeView *self)
        /* Set up the folder view as a dnd destination. Set only the
           highlight flag, otherwise gtk will have a different
           behaviour */
-#ifdef MODEST_TOOLKIT_HILDON2
-       return;
-#endif
        gtk_drag_dest_set (GTK_WIDGET (self),
                           GTK_DEST_DEFAULT_HIGHLIGHT,
                           folder_view_drag_types,
@@ -3483,6 +3534,7 @@ setup_drag_and_drop (GtkTreeView *self)
                          G_CALLBACK (drag_drop_cb),
                          NULL);
 }
+#endif
 
 /*
  * This function manages the navigation through the folders using the
@@ -3603,6 +3655,9 @@ modest_folder_view_set_account_id_of_visible_server_account (ModestFolderView *s
        model = gtk_tree_view_get_model (GTK_TREE_VIEW (self));
        if (GTK_IS_TREE_MODEL_FILTER (model))
                gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (model));
+       else
+               modest_folder_view_update_model(self,
+                                               (TnyAccountStore *) modest_runtime_get_account_store());
 
        /* Save settings to gconf */
        modest_widget_memory_save (modest_runtime_get_conf (), G_OBJECT(self),
@@ -3656,13 +3711,10 @@ find_inbox_iter (GtkTreeModel *model, GtkTreeIter *iter, GtkTreeIter *inbox_iter
        return FALSE;
 }
 
-
-
-
+#ifndef MODEST_TOOLKIT_HILDON2
 void
 modest_folder_view_select_first_inbox_or_local (ModestFolderView *self)
 {
-#ifndef MODEST_TOOLKIT_HILDON2
        GtkTreeModel *model;
        GtkTreeIter iter, inbox_iter;
        GtkTreeSelection *sel;
@@ -3694,9 +3746,8 @@ modest_folder_view_select_first_inbox_or_local (ModestFolderView *self)
 
        /* set focus */
        gtk_widget_grab_focus (GTK_WIDGET(self));
-#endif
 }
-
+#endif
 
 /* recursive */
 static gboolean
@@ -4094,7 +4145,8 @@ update_style (ModestFolderView *self)
        /* Set color */
 
        attr_list = pango_attr_list_new ();
-       if (!gtk_style_lookup_color (GTK_WIDGET (self)->style, "SecondaryTextColor", &style_color)) {
+
+       if (!gtk_style_lookup_color (gtk_widget_get_style (GTK_WIDGET (self)), "SecondaryTextColor", &style_color)) {
                gdk_color_parse ("grey", &style_color);
        }
        attr = pango_attr_foreground_new (style_color.red, style_color.green, style_color.blue);
@@ -4118,7 +4170,7 @@ update_style (ModestFolderView *self)
                pango_attr_list_unref (attr_list);
        }
 
-       if (gtk_style_lookup_color (GTK_WIDGET (self)->style, "ActiveTextColor", &style_active_color)) {
+       if (gtk_style_lookup_color (gtk_widget_get_style (GTK_WIDGET (self)), "ActiveTextColor", &style_active_color)) {
                priv->active_color = style_active_color;
        } else {
                gdk_color_parse ("000", &(priv->active_color));
@@ -4284,3 +4336,21 @@ on_activity_changed (TnyGtkFolderListStore *store,
                       activity);
 }
 #endif
+
+TnyList *
+modest_folder_view_get_model_tny_list (ModestFolderView *self)
+{
+       GtkTreeModel *model;
+       TnyList *ret_value;
+
+       ret_value = NULL;
+       model = NULL;
+
+       if (get_inner_models (MODEST_FOLDER_VIEW (self), NULL, NULL, (GtkTreeModel **) &model)) {
+               ret_value = TNY_LIST (model);
+               g_object_ref (ret_value);
+       }
+
+       return ret_value;
+
+}