Fixes NB#139404, download remote message attachments and open them from modest
[modest] / src / widgets / modest-folder-view.c
index 56584af..b5ce7c8 100644 (file)
@@ -737,7 +737,7 @@ text_cell_data  (GtkTreeViewColumn *column,
 
        /* Convert INBOX */
        if (type == TNY_FOLDER_TYPE_INBOX &&
-           !g_ascii_strcasecmp (fname, "Inbox")) {
+           g_str_has_suffix (fname, "Inbox")) {
                g_free (item_name);
                item_name = g_strdup (_("mcen_me_folder_inbox"));
        }
@@ -928,7 +928,7 @@ get_composite_icons (const gchar *icon_code,
 {
        ThreePixbufs *retval;
 
-       if (!*pixbuf) {
+       if (pixbuf && !*pixbuf) {
                GdkPixbuf *icon;
                icon = modest_platform_get_icon (icon_code, FOLDER_ICON_SIZE);
                if (icon) {
@@ -938,23 +938,29 @@ get_composite_icons (const gchar *icon_code,
                }
        }
 
-       if (!*pixbuf_open && pixbuf && *pixbuf)
+       if (pixbuf_open && !*pixbuf_open && pixbuf && *pixbuf)
                *pixbuf_open = get_composite_pixbuf ("qgn_list_gene_fldr_exp",
                                                     FOLDER_ICON_SIZE,
                                                     *pixbuf);
 
-       if (!*pixbuf_close && pixbuf && *pixbuf)
+       if (pixbuf_close && !*pixbuf_close && pixbuf && *pixbuf)
                *pixbuf_close = get_composite_pixbuf ("qgn_list_gene_fldr_clp",
                                                      FOLDER_ICON_SIZE,
                                                      *pixbuf);
 
        retval = g_slice_new0 (ThreePixbufs);
-       if (*pixbuf)
+       if (pixbuf && *pixbuf)
                retval->pixbuf = g_object_ref (*pixbuf);
-       if (*pixbuf_open)
+       else
+               retval->pixbuf = NULL;
+       if (pixbuf_open && *pixbuf_open)
                retval->pixbuf_open = g_object_ref (*pixbuf_open);
-       if (*pixbuf_close)
+       else
+               retval->pixbuf_open = NULL;
+       if (pixbuf_close && *pixbuf_close)
                retval->pixbuf_close = g_object_ref (*pixbuf_close);
+       else
+               retval->pixbuf_close = NULL;
 
        return retval;
 }
@@ -1361,9 +1367,13 @@ static void
 modest_folder_view_dispose (GObject *obj)
 {
        ModestFolderViewPrivate *priv;
+       GtkTreeModel *model = NULL;
 
        priv =  MODEST_FOLDER_VIEW_GET_PRIVATE (obj);
 
+       get_inner_models (MODEST_FOLDER_VIEW (obj),
+                         NULL, NULL, &model);
+
 #ifdef MODEST_TOOLKIT_HILDON2
        if (priv->signal_handlers) {
                modest_signal_mgr_disconnect_all_and_destroy (priv->signal_handlers);
@@ -2348,10 +2358,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),
@@ -2368,7 +2416,7 @@ modest_folder_view_update_model (ModestFolderView *self,
                                                self,
                                                NULL);
 
-       GtkTreeModel *old_tny_model;
+       GtkTreeModel *old_tny_model = NULL;
        if (get_inner_models (self, NULL, NULL, &old_tny_model)) {
                if (priv->signal_handlers > 0) {
                        priv->signal_handlers = modest_signal_mgr_disconnect (priv->signal_handlers,
@@ -2388,7 +2436,7 @@ modest_folder_view_update_model (ModestFolderView *self,
        priv->signal_handlers = modest_signal_mgr_connect (priv->signal_handlers,
                                                           G_OBJECT (model),
                                                           "activity-changed",
-                                                          G_CALLBACK (on_activity_changed), 
+                                                          G_CALLBACK (on_activity_changed),
                                                           self);
 #endif
 
@@ -3597,6 +3645,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),
@@ -4278,3 +4329,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;
+
+}