X-Git-Url: http://git.maemo.org/git/?p=modest;a=blobdiff_plain;f=src%2Fwidgets%2Fmodest-folder-view.c;h=ff7fc28a1cee802dc4992825c0adb36501113ffc;hp=4eaf923daa21aa89c0223e7c6fce2f324ea17009;hb=39d728083bfd2a0e31ea7a69f0278c79a755f41e;hpb=efb61a9683b6bed0a9444ad8a9dc4de552a00cb9 diff --git a/src/widgets/modest-folder-view.c b/src/widgets/modest-folder-view.c index 4eaf923..ff7fc28 100644 --- a/src/widgets/modest-folder-view.c +++ b/src/widgets/modest-folder-view.c @@ -49,6 +49,8 @@ #include "modest-folder-view.h" #include #include +#include +#include /* 'private'/'protected' functions */ static void modest_folder_view_class_init (ModestFolderViewClass *klass); @@ -139,6 +141,7 @@ struct _ModestFolderViewPrivate { guint timer_expander; gchar *local_account_name; + gchar *visible_account_id; ModestFolderViewStyle style; }; #define MODEST_FOLDER_VIEW_GET_PRIVATE(o) \ @@ -333,8 +336,8 @@ static void icon_cell_data (GtkTreeViewColumn *column, GtkCellRenderer *renderer, GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data) { - GObject *rendobj, *instance; - GdkPixbuf *pixbuf; + GObject *rendobj = NULL, *instance = NULL; + GdkPixbuf *pixbuf = NULL; TnyFolderType type; gchar *fname = NULL; const gchar *account_id = NULL; @@ -448,9 +451,10 @@ modest_folder_view_init (ModestFolderView *obj) priv->timer_expander = 0; priv->account_store = NULL; - priv->cur_folder_store = NULL; priv->query = NULL; priv->style = MODEST_FOLDER_VIEW_STYLE_SHOW_ALL; + priv->cur_folder_store = NULL; + priv->visible_account_id = NULL; /* Initialize the local account name */ conf = modest_runtime_get_conf(); @@ -462,6 +466,9 @@ modest_folder_view_init (ModestFolderView *obj) /* Setup drag and drop */ setup_drag_and_drop (GTK_TREE_VIEW(obj)); + /* Restore conf */ + modest_widget_memory_restore (conf, G_OBJECT (obj), MODEST_CONF_FOLDER_VIEW_KEY); + /* Connect signals */ g_signal_connect (G_OBJECT (obj), "key-press-event", @@ -521,6 +528,7 @@ modest_folder_view_finalize (GObject *obj) g_signal_handler_disconnect (G_OBJECT(sel), priv->changed_signal); g_free (priv->local_account_name); + g_free (priv->visible_account_id); G_OBJECT_CLASS(parent_class)->finalize (obj); } @@ -640,24 +648,16 @@ expand_root_items (ModestFolderView *self) } /* - * HACK: we use this function to implement the - * MODEST_FOLDER_VIEW_STYLE_SHOW_ONE style. This implementation - * assumes that the model has the following order (which is currently - * true) Remote folders->Local folders->MMC folders, so the rows of - * the first level (that represent the accounts) are received in the - * same order. So basically it uses a static variable to register that - * a remote account has already being shown to hide the others - * (returning NULL). When the function evaluates the local or the MMC - * accounts is time to reset the static variable in order to get it - * ready for the next time the tree model needs to be shown. + * We use this function to implement the + * MODEST_FOLDER_VIEW_STYLE_SHOW_ONE style. We only show the default + * account in this case */ static gboolean filter_row (GtkTreeModel *model, GtkTreeIter *iter, gpointer data) { - static gboolean found = FALSE; - gboolean retval; + gboolean retval = TRUE; gint type; GObject *instance = NULL; @@ -667,22 +667,22 @@ filter_row (GtkTreeModel *model, -1); if (type == TNY_FOLDER_TYPE_ROOT) { - const gchar *account_id = tny_account_get_id (TNY_ACCOUNT (instance)); + TnyAccount *acc; + const gchar *account_id; - if (strcmp (account_id, MODEST_LOCAL_FOLDERS_ACCOUNT_ID) && - strcmp (account_id, MODEST_MMC_ACCOUNT_ID)) { + acc = TNY_ACCOUNT (instance); + account_id = tny_account_get_id (acc); - if (!found) { - found = TRUE; - retval = TRUE; - } else + if (strcmp (account_id, MODEST_LOCAL_FOLDERS_ACCOUNT_ID) && + strcmp (account_id, MODEST_MMC_ACCOUNT_ID)) { + ModestFolderViewPrivate *priv; + + /* Show only the visible account id */ + priv = MODEST_FOLDER_VIEW_GET_PRIVATE (data); + if (priv->visible_account_id && strcmp (account_id, priv->visible_account_id)) retval = FALSE; - } else { - found = FALSE; - retval = TRUE; } - } else - retval = TRUE; + } g_object_unref (instance); @@ -730,7 +730,7 @@ update_model (ModestFolderView *self, ModestTnyAccountStore *account_store) filter_model = gtk_tree_model_filter_new (sortable, NULL); gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (filter_model), filter_row, - NULL, + self, NULL); } @@ -991,7 +991,7 @@ drag_and_drop_from_header_view (GtkTreeModel *source_model, &folder, -1); /* Transfer message */ - mail_op = modest_mail_operation_new_with_id (MODEST_MAIL_OPERATION_ID_RECEIVE); + mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE, NULL); modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op); @@ -1051,7 +1051,7 @@ drag_and_drop_from_folder_view (GtkTreeModel *source_model, &folder, -1); /* Do the mail operation */ - mail_op = modest_mail_operation_new_with_id (MODEST_MAIL_OPERATION_ID_RECEIVE); + mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE, NULL); modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op); g_signal_connect (G_OBJECT (mail_op), "progress-changed", @@ -1402,25 +1402,27 @@ on_configuration_key_changed (ModestConf* conf, { ModestFolderViewPrivate *priv; - if (!key || strcmp (key, MODEST_CONF_DEVICE_NAME)) + if (!key) return; priv = MODEST_FOLDER_VIEW_GET_PRIVATE(self); - g_free (priv->local_account_name); + if (!strcmp (key, MODEST_CONF_DEVICE_NAME)) { + g_free (priv->local_account_name); - if (event == MODEST_CONF_EVENT_KEY_UNSET) - priv->local_account_name = g_strdup (MODEST_LOCAL_FOLDERS_DEFAULT_DISPLAY_NAME); - else - priv->local_account_name = modest_conf_get_string (modest_runtime_get_conf(), - MODEST_CONF_DEVICE_NAME, NULL); + if (event == MODEST_CONF_EVENT_KEY_UNSET) + priv->local_account_name = g_strdup (MODEST_LOCAL_FOLDERS_DEFAULT_DISPLAY_NAME); + else + priv->local_account_name = modest_conf_get_string (modest_runtime_get_conf(), + MODEST_CONF_DEVICE_NAME, NULL); - /* Force a redraw */ + /* Force a redraw */ #if GTK_CHECK_VERSION(2, 8, 0) /* gtk_tree_view_column_queue_resize is only available in GTK+ 2.8 */ - GtkTreeViewColumn * tree_column = gtk_tree_view_get_column (GTK_TREE_VIEW (self), - TNY_GTK_FOLDER_STORE_TREE_MODEL_NAME_COLUMN); - gtk_tree_view_column_queue_resize (tree_column); + GtkTreeViewColumn * tree_column = gtk_tree_view_get_column (GTK_TREE_VIEW (self), + TNY_GTK_FOLDER_STORE_TREE_MODEL_NAME_COLUMN); + gtk_tree_view_column_queue_resize (tree_column); #endif + } } void @@ -1435,3 +1437,41 @@ modest_folder_view_set_style (ModestFolderView *self, priv->style = style; } + +void +modest_folder_view_set_account_id_of_visible_server_account (ModestFolderView *self, + const gchar *account_id) +{ + ModestFolderViewPrivate *priv; + ModestConf *conf; + GtkTreeModel *model; + + g_return_if_fail (self); + + priv = MODEST_FOLDER_VIEW_GET_PRIVATE(self); + + if (priv->visible_account_id) + g_free (priv->visible_account_id); + priv->visible_account_id = g_strdup (account_id); + + /* Save preferences */ + conf = modest_runtime_get_conf (); + modest_widget_memory_save (conf, G_OBJECT (self), MODEST_CONF_FOLDER_VIEW_KEY); + + /* Refilter */ + 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)); +} + +const gchar * +modest_folder_view_get_account_id_of_visible_server_account (ModestFolderView *self) +{ + ModestFolderViewPrivate *priv; + + g_return_val_if_fail (self, NULL); + + priv = MODEST_FOLDER_VIEW_GET_PRIVATE(self); + + return (const gchar *) priv->visible_account_id; +}