#include "modest-folder-view.h"
#include <modest-dnd.h>
#include <modest-platform.h>
+#include <modest-account-mgr-helpers.h>
+#include <modest-widget-memory.h>
/* 'private'/'protected' functions */
static void modest_folder_view_class_init (ModestFolderViewClass *klass);
guint timer_expander;
gchar *local_account_name;
+ gchar *visible_account_id;
ModestFolderViewStyle style;
};
#define MODEST_FOLDER_VIEW_GET_PRIVATE(o) \
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;
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();
/* 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",
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);
}
}
/*
- * 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;
-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);
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);
}
&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);
&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",
{
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
priv->style = style;
}
+
+void
+modest_folder_view_set_account_id_of_visible_server_account (ModestFolderView *self,
+ const gchar *account_id)
+{
+ ModestFolderViewPrivate *priv;
+ ModestConf *conf;
+
+ 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);
+}
+
+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;
+}