* Added "visible_server_account_id" persistent configuration key to the folder view
* Removed the double treemodel creation in the header view when refreshing
pmo-trunk-r1728
#include <modest-widget-memory.h>
#include <modest-widget-memory-priv.h>
-
+#include <modest-runtime.h>
+#include <modest-account-mgr-helpers.h>
#include <modest-tny-platform-factory.h>
#include <modest-tny-folder.h>
#include <widgets/modest-header-view.h>
save_settings_folder_view (ModestConf *conf, ModestFolderView *folder_view,
const gchar *name)
{
- return TRUE; /* FIXME: implement this */
+ gchar *key;
+ const gchar* account_id;
+
+ /* Restore the visible account */
+ key = _modest_widget_memory_get_keyname (name, "visible_server_account_id");
+
+ account_id = modest_folder_view_get_visible_server_account_id (folder_view);
+ if (account_id)
+ modest_conf_set_string (conf, key, account_id, NULL);
+
+ g_free (key);
+
+ return TRUE;
}
static gboolean
-restore_settings_folder_view (ModestConf *conf, ModestFolderView *folder_view,
+restore_settings_folder_view (ModestConf *conf,
+ ModestFolderView *folder_view,
const gchar *name)
{
- return TRUE; /* FIXME: implement this */
+ gchar *key, *account_id;
+
+ /* Restore the visible account */
+ key = _modest_widget_memory_get_keyname (name, "visible_server_account_id");
+
+ if (modest_conf_key_exists (conf, key, NULL)) {
+ account_id = modest_conf_get_string (conf, key, NULL);
+ modest_folder_view_set_visible_server_account_id (folder_view,
+ (const gchar *) account_id);
+ g_free (account_id);
+ } else {
+ ModestAccountMgr *mgr;
+ gchar *default_acc;
+
+ /* If there is no visible account id in the
+ configuration then pick the default account as
+ visible account */
+ mgr = modest_runtime_get_account_mgr ();
+ default_acc = modest_account_mgr_get_default_account (mgr);
+ if (default_acc) {
+ ModestAccountData *acc_data;
+ const gchar *server_acc_id;
+
+ acc_data = modest_account_mgr_get_account_data (mgr, (const gchar*) default_acc);
+ server_acc_id = (const gchar *) acc_data->store_account->account_name;
+
+ modest_conf_set_string (conf, key, server_acc_id, NULL);
+ modest_folder_view_set_visible_server_account_id (folder_view, server_acc_id);
+
+ g_free (default_acc);
+ }
+ }
+
+ g_free (key);
+
+ return TRUE;
}
static gboolean
-save_settings_msg_view (ModestConf *conf, ModestMsgView *msg_view,
- const gchar *name)
+save_settings_msg_view (ModestConf *conf,
+ ModestMsgView *msg_view,
+ const gchar *name)
{
return TRUE; /* FIXME: implement this */
}
#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) \
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), "folder-view");
+
/* 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);
}
-1);
if (type == TNY_FOLDER_TYPE_ROOT) {
- ModestAccountData *acc_data;
TnyAccount *acc;
const gchar *account_id;
- ModestAccountMgr *mgr;
acc = TNY_ACCOUNT (instance);
- account_id = tny_account_get_id (acc); /* Non human-readable name, not the title */
- mgr = modest_runtime_get_account_mgr ();
-
- /* TODO: This does not work because acc is the _server_account,
- * and this code assumes that it is the normal account, which uses a server account.
- * Maybe we need some way to get the parent account from the server account.
- */
- acc_data = modest_account_mgr_get_account_data (mgr, account_id);
- if (acc_data) {
- if (strcmp (account_id, MODEST_LOCAL_FOLDERS_ACCOUNT_ID) &&
- strcmp (account_id, MODEST_MMC_ACCOUNT_ID)) {
- /* Show only the default account */
- if (!acc_data->is_default)
- retval = FALSE;
- }
- modest_account_mgr_free_account_data (mgr, acc_data);
+ account_id = tny_account_get_id (acc);
+
+ 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;
}
}
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);
}
{
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_visible_server_account_id (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), "folder-view");
+}
+
+const gchar *
+modest_folder_view_get_visible_server_account_id (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;
+}
void modest_folder_view_set_style (ModestFolderView *self,
ModestFolderViewStyle style);
+/**
+ * modest_folder_view_set_visible_server_account_id:
+ * @self: a #ModestFolderView
+ * @account_id: the remote server account id
+ *
+ * sets the server account id (value returned by tny_account_get_id())
+ * to the string passed as argument. The remote server with the
+ * specified id will be the unique visible account if the folder view
+ * is configured in MODEST_FOLDER_VIEW_STYLE_SHOW_ONE
+ **/
+void modest_folder_view_set_visible_server_account_id (ModestFolderView *self,
+ const gchar *account_id);
+
+/**
+ * modest_folder_view_get_visible_server_account_id:
+ * @self: a #ModestFolderView
+ *
+ * gets the account id of the currently visible server account id
+ *
+ * Return value: the visible server account id or NULL if none set
+ **/
+const gchar* modest_folder_view_get_visible_server_account_id (ModestFolderView *self);
+
G_END_DECLS
#endif /* __MODEST_FOLDER_VIEW_H__ */
TnyFolderMonitor *monitor;
GMutex *monitor_lock;
- gint sort_colid[2][TNY_FOLDER_TYPE_NUM];
- gint sort_type[2][TNY_FOLDER_TYPE_NUM];
+
+ gint sort_colid[2][TNY_FOLDER_TYPE_NUM];
+ gint sort_type[2][TNY_FOLDER_TYPE_NUM];
+
+
};
#define MODEST_HEADER_VIEW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
remove_all_columns (ModestHeaderView *obj)
{
GList *columns, *cursor;
-
+
columns = gtk_tree_view_get_columns (GTK_TREE_VIEW(obj));
for (cursor = columns; cursor; cursor = cursor->next)
gtk_tree_view_append_column (GTK_TREE_VIEW(self), column);
}
-
return TRUE;
}
g_object_unref (G_OBJECT (priv->folder));
priv->folder = NULL;
}
-
+
G_OBJECT_CLASS(parent_class)->finalize (obj);
}
return;
}
-static void
-on_progress_changed (ModestMailOperation *mail_op,
- ModestHeaderView *self)
-{
- TnyFolderType type;
- GtkTreeModel *sortable;
- ModestHeaderViewPrivate *priv;
- GList *cols, *cursor;
- TnyList *headers;
- guint sort_colid;
- GtkSortType sort_type;
-
- if (!modest_mail_operation_is_finished (mail_op))
- return;
-
- if (modest_mail_operation_get_error (mail_op))
- return;
-
- priv = MODEST_HEADER_VIEW_GET_PRIVATE(self);
-
- headers = TNY_LIST (tny_gtk_header_list_model_new ());
-
- tny_gtk_header_list_model_set_folder (TNY_GTK_HEADER_LIST_MODEL(headers),
- priv->folder, TRUE);
-
- sortable = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL(headers));
- g_object_unref (G_OBJECT (headers));
-
- /* install our special sorting functions */
- cursor = cols = gtk_tree_view_get_columns (GTK_TREE_VIEW(self));
- while (cursor) {
- gint col_id = GPOINTER_TO_INT (g_object_get_data(G_OBJECT(cursor->data),
- MODEST_HEADER_VIEW_COLUMN));
- gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE(sortable),
- col_id,
- (GtkTreeIterCompareFunc) cmp_rows,
- cursor->data, NULL);
- cursor = g_list_next(cursor);
- }
- g_list_free (cols);
-
- /* Restore sort column id */
- type = modest_tny_folder_guess_folder_type (priv->folder);
- sort_colid = modest_header_view_get_sort_column_id (self, type);
- sort_type = modest_header_view_get_sort_type (self, type);
- gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE(sortable),
- sort_colid,
- sort_type);
-
- /* Set new model */
- modest_header_view_set_model (GTK_TREE_VIEW (self), sortable);
- g_object_unref (G_OBJECT (sortable));
-
- /* Add a folder observer */
- g_mutex_lock (priv->monitor_lock);
- priv->monitor = TNY_FOLDER_MONITOR (tny_folder_monitor_new (priv->folder));
- tny_folder_monitor_add_list (priv->monitor, TNY_LIST (headers));
- tny_folder_monitor_start (priv->monitor);
- g_mutex_unlock (priv->monitor_lock);
-
-}
-
TnyFolder*
modest_header_view_get_folder (ModestHeaderView *self)
{
cursor->data, NULL);
cursor = g_list_next(cursor);
}
- g_list_free (cols);
+ g_list_free (cols);
/* Restore sort column id */
type = modest_tny_folder_guess_folder_type (folder);
if (folder) {
ModestMailOperation *mail_op;
+ /* Set folder in the model */
modest_header_view_set_folder_intern (self, folder);
/* Pick my reference. Nothing to do with the mail operation */
modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
mail_op);
- /* Register a mail operation observer */
- g_signal_connect (mail_op, "progress-changed",
- G_CALLBACK (on_progress_changed), self);
-
/* Refresh the folder asynchronously */
modest_mail_operation_refresh_folder (mail_op, folder);
gint sort_colid;
static int counter = 0;
- g_return_val_if_fail (G_IS_OBJECT(user_data), 0);
+ g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN(user_data), 0);
col_id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(user_data), MODEST_HEADER_VIEW_COLUMN));
if (!(++counter % 100)) {