static void on_selection_changed (GtkTreeSelection *sel, gpointer data);
-static void on_account_update (TnyAccountStore *account_store,
- const gchar *account,
- gpointer user_data);
-
static void on_account_removed (TnyAccountStore *self,
TnyAccount *account,
gpointer user_data);
-static void on_accounts_reloaded (TnyAccountStore *store,
+static void on_account_inserted (TnyAccountStore *self,
+ TnyAccount *account,
gpointer user_data);
static gint cmp_rows (GtkTreeModel *tree_model,
GdkEventKey *event,
gpointer user_data);
-static void on_configuration_key_changed (ModestConf* conf,
- const gchar *key,
- ModestConfEvent event,
- ModestFolderView *self);
+static void on_configuration_key_changed (ModestConf* conf,
+ const gchar *key,
+ ModestConfEvent event,
+ ModestConfNotificationId notification_id,
+ ModestFolderView *self);
/* DnD functions */
static void on_drag_data_get (GtkWidget *widget,
static void setup_drag_and_drop (GtkTreeView *self);
-static gboolean _clipboard_set_selected_data (ModestFolderView *folder_view, gboolean delete);
+static gboolean _clipboard_set_selected_data (ModestFolderView *folder_view,
+ gboolean delete);
static void _clear_hidding_filter (ModestFolderView *folder_view);
-static void on_row_changed_maybe_select_folder (GtkTreeModel *tree_model, GtkTreePath *path, GtkTreeIter *iter,
+static void on_row_changed_maybe_select_folder (GtkTreeModel *tree_model,
+ GtkTreePath *path,
+ GtkTreeIter *iter,
ModestFolderView *self);
enum {
TnyFolder *folder_to_select; /* folder to select after the next update */
- gulong account_update_signal;
+ ModestConfNotificationId notification_id;
+
gulong changed_signal;
- gulong accounts_reloaded_signal;
+ gulong account_inserted_signal;
gulong account_removed_signal;
gulong conf_key_signal;
gchar *visible_account_id;
ModestFolderViewStyle style;
- gboolean reselect; /* we use this to force a reselection of the INBOX */
- gboolean show_non_move;
+ gboolean reselect; /* we use this to force a reselection of the INBOX */
+ gboolean show_non_move;
};
#define MODEST_FOLDER_VIEW_GET_PRIVATE(o) \
(G_TYPE_INSTANCE_GET_PRIVATE((o), \
/* printf ("DEBU1G: %s: account name=%s\n", __FUNCTION__, tny_account_get_name (TNY_ACCOUNT(account))); */
GetMmcAccountNameData *data = (GetMmcAccountNameData*)user_data;
-
+
if (!strings_are_equal (
tny_account_get_name(TNY_ACCOUNT(account)),
data->previous_name)) {
if (type != TNY_FOLDER_TYPE_ROOT) {
gint number = 0;
- if (modest_tny_folder_is_local_folder (TNY_FOLDER (instance))) {
- type = modest_tny_folder_get_local_folder_type (TNY_FOLDER (instance));
+ if (modest_tny_folder_is_local_folder (TNY_FOLDER (instance)) ||
+ modest_tny_folder_is_memory_card_folder (TNY_FOLDER (instance))) {
+ type = modest_tny_folder_get_local_or_mmc_folder_type (TNY_FOLDER (instance));
if (type != TNY_FOLDER_TYPE_UNKNOWN) {
g_free (fname);
fname = g_strdup(modest_local_folder_info_get_type_display_name (type));
signals[FOLDER_DISPLAY_NAME_CHANGED_SIGNAL], 0,
item_name);
}
-
g_free (item_name);
}
g_free (fname);
}
-
-
static void
icon_cell_data (GtkTreeViewColumn *column, GtkCellRenderer *renderer,
GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data)
* Track changes in the local account name (in the device it
* will be the device name)
*/
- priv->conf_key_signal =
- g_signal_connect (G_OBJECT(conf),
- "key_changed",
- G_CALLBACK(on_configuration_key_changed), obj);
+ priv->notification_id = modest_conf_listen_to_namespace (conf,
+ MODEST_CONF_NAMESPACE);
+ priv->conf_key_signal = g_signal_connect (G_OBJECT(conf),
+ "key_changed",
+ G_CALLBACK(on_configuration_key_changed),
+ obj);
}
static void
priv = MODEST_FOLDER_VIEW_GET_PRIVATE(obj);
+ if (priv->notification_id) {
+ modest_conf_forget_namespace (modest_runtime_get_conf (),
+ MODEST_CONF_NAMESPACE,
+ priv->notification_id);
+ }
+
if (priv->timer_expander != 0) {
g_source_remove (priv->timer_expander);
priv->timer_expander = 0;
if (priv->account_store) {
g_signal_handler_disconnect (G_OBJECT(priv->account_store),
- priv->account_update_signal);
- g_signal_handler_disconnect (G_OBJECT(priv->account_store),
- priv->accounts_reloaded_signal);
+ priv->account_inserted_signal);
g_signal_handler_disconnect (G_OBJECT(priv->account_store),
priv->account_removed_signal);
g_object_unref (G_OBJECT(priv->account_store));
if (G_UNLIKELY (priv->account_store)) {
- if (g_signal_handler_is_connected (G_OBJECT (priv->account_store),
- priv->account_update_signal))
- g_signal_handler_disconnect (G_OBJECT (priv->account_store),
- priv->account_update_signal);
- if (g_signal_handler_is_connected (G_OBJECT (priv->account_store),
- priv->accounts_reloaded_signal))
- g_signal_handler_disconnect (G_OBJECT (priv->account_store),
- priv->accounts_reloaded_signal);
+ if (g_signal_handler_is_connected (G_OBJECT (priv->account_store),
+ priv->account_inserted_signal))
+ g_signal_handler_disconnect (G_OBJECT (priv->account_store),
+ priv->account_inserted_signal);
if (g_signal_handler_is_connected (G_OBJECT (priv->account_store),
priv->account_removed_signal))
g_signal_handler_disconnect (G_OBJECT (priv->account_store),
priv->account_store = g_object_ref (G_OBJECT (account_store));
- priv->account_update_signal =
- g_signal_connect (G_OBJECT(account_store), "account_update",
- G_CALLBACK (on_account_update), self);
-
priv->account_removed_signal =
g_signal_connect (G_OBJECT(account_store), "account_removed",
G_CALLBACK (on_account_removed), self);
- priv->accounts_reloaded_signal =
- g_signal_connect (G_OBJECT(account_store), "accounts_reloaded",
- G_CALLBACK (on_accounts_reloaded), self);
+ priv->account_inserted_signal =
+ g_signal_connect (G_OBJECT(account_store), "account_inserted",
+ G_CALLBACK (on_account_inserted), self);
- g_signal_connect (G_OBJECT(account_store), "connecting_finished",
- G_CALLBACK (on_accounts_reloaded), self);
- on_accounts_reloaded (account_store, (gpointer ) self);
+/* g_signal_connect (G_OBJECT(account_store), "connecting_finished", */
+/* G_CALLBACK (on_accounts_reloaded), self); */
+
+/* on_accounts_reloaded (account_store, (gpointer ) self); */
+
+ modest_folder_view_update_model (MODEST_FOLDER_VIEW (self), account_store);
g_object_unref (G_OBJECT (device));
}
static void
-on_account_removed (TnyAccountStore *account_store,
- TnyAccount *account,
- gpointer user_data)
+on_account_inserted (TnyAccountStore *account_store,
+ TnyAccount *account,
+ gpointer user_data)
{
- ModestFolderView *self = MODEST_FOLDER_VIEW (user_data);
ModestFolderViewPrivate *priv;
+ GtkTreeModel *sort_model, *filter_model;
- priv = MODEST_FOLDER_VIEW_GET_PRIVATE (self);
+ /* Ignore transport account insertions, we're not showing them
+ in the folder view */
+ if (TNY_IS_TRANSPORT_ACCOUNT (account))
+ return;
- /* If the removed account is the currently viewed one then
- clear the configuration value. The new visible account will be the default account */
- if (!strcmp (priv->visible_account_id, tny_account_get_id (account))) {
- modest_folder_view_set_account_id_of_visible_server_account (self, NULL);
- }
+ priv = MODEST_FOLDER_VIEW_GET_PRIVATE (user_data);
+
+ /* If we're adding a new account, and there is no previous
+ one, we need to select the visible server account */
+ if (priv->style == MODEST_FOLDER_VIEW_STYLE_SHOW_ONE &&
+ !priv->visible_account_id)
+ modest_widget_memory_restore (modest_runtime_get_conf(),
+ G_OBJECT (user_data),
+ MODEST_CONF_FOLDER_VIEW_KEY);
+
+ /* Get the inner model */
+ filter_model = gtk_tree_view_get_model (GTK_TREE_VIEW (user_data));
+ sort_model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (filter_model));
+
+ /* Insert the account in the model */
+ tny_list_append (TNY_LIST (gtk_tree_model_sort_get_model (GTK_TREE_MODEL_SORT (sort_model))),
+ G_OBJECT (account));
}
static void
-on_account_update (TnyAccountStore *account_store,
- const gchar *account,
- gpointer user_data)
+on_account_removed (TnyAccountStore *account_store,
+ TnyAccount *account,
+ gpointer user_data)
{
ModestFolderView *self = NULL;
ModestFolderViewPrivate *priv;
+ GtkTreeModel *sort_model, *filter_model;
+
+ /* Ignore transport account removals, we're not showing them
+ in the folder view */
+ if (TNY_IS_TRANSPORT_ACCOUNT (account))
+ return;
+
+ g_print ("--------------------- FOLDER ---------------\n");
- g_return_if_fail (MODEST_IS_FOLDER_VIEW (user_data));
self = MODEST_FOLDER_VIEW (user_data);
priv = MODEST_FOLDER_VIEW_GET_PRIVATE (self);
- if (!priv->visible_account_id)
+ /* TODO: invalidate the cur_folder_* and folder_to_select things */
+
+ /* Remove the account from the model */
+ filter_model = gtk_tree_view_get_model (GTK_TREE_VIEW (self));
+ sort_model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (filter_model));
+ tny_list_remove (TNY_LIST (gtk_tree_model_sort_get_model (GTK_TREE_MODEL_SORT (sort_model))),
+ G_OBJECT (account));
+
+ /* If the removed account is the currently viewed one then
+ clear the configuration value. The new visible account will be the default account */
+ if (priv->visible_account_id &&
+ !strcmp (priv->visible_account_id, tny_account_get_id (account))) {
+
+ /* Clear the current visible account_id */
+ modest_folder_view_set_account_id_of_visible_server_account (self, NULL);
+
+ /* Call the restore method, this will set the new visible account */
modest_widget_memory_restore (modest_runtime_get_conf(), G_OBJECT(self),
MODEST_CONF_FOLDER_VIEW_KEY);
+ }
- if (!modest_folder_view_update_model (self, account_store))
- g_printerr ("modest: failed to update model for changes in '%s'",
- account);
-}
-
-static void
-on_accounts_reloaded (TnyAccountStore *account_store,
- gpointer user_data)
-{
- g_return_if_fail (MODEST_IS_FOLDER_VIEW (user_data));
- modest_folder_view_update_model (MODEST_FOLDER_VIEW (user_data), account_store);
+ /* Select the INBOX */
+ modest_folder_view_select_first_inbox_or_local (self);
}
void
need to rewrite some parts of Modest to avoid the
deathlock situation */
/* TODO: check if this is still the case */
- modest_folder_view_select_first_inbox_or_local (self);
priv->reselect = FALSE;
+ modest_folder_view_select_first_inbox_or_local (self);
+ /* Notify the display name observers */
+ g_signal_emit (G_OBJECT(self),
+ signals[FOLDER_DISPLAY_NAME_CHANGED_SIGNAL], 0,
+ NULL);
}
return FALSE;
}
guint i;
gboolean found = FALSE;
gboolean cleared = FALSE;
-
+
g_return_val_if_fail (MODEST_IS_FOLDER_VIEW (data), FALSE);
priv = MODEST_FOLDER_VIEW_GET_PRIVATE (data);
/* If it isn't a special folder,
* don't show it unless it is the visible account: */
- if (!modest_tny_account_is_virtual_local_folders (acc) &&
- strcmp (account_id, MODEST_MMC_ACCOUNT_ID)) {
+ if (priv->style == MODEST_FOLDER_VIEW_STYLE_SHOW_ONE &&
+ !modest_tny_account_is_virtual_local_folders (acc) &&
+ strcmp (account_id, MODEST_MMC_ACCOUNT_ID)) {
+
/* Show only the visible account id */
- if (priv->visible_account_id && strcmp (account_id, priv->visible_account_id))
+ if (priv->visible_account_id) {
+ if (strcmp (account_id, priv->visible_account_id))
+ retval = FALSE;
+ } else {
retval = FALSE;
+ }
}
/* Never show these to the user. They are merged into one folder
retval = FALSE;
}
}
-
- /* The virtual local-folders folder store is also shown by default. */
/* Check hiding (if necessary) */
cleared = modest_email_clipboard_cleared (priv->clipboard);
/* FIXME: the local accounts are not shown when the query
selects only the subscribed folders. */
/* model = tny_gtk_folder_store_tree_model_new (TRUE, priv->query); */
- model = tny_gtk_folder_store_tree_model_new (TRUE, NULL);
+ model = tny_gtk_folder_store_tree_model_new (NULL);
/* Deal with the model via its TnyList Interface,
* filling the TnyList via a get_accounts() call: */
GTK_SORT_ASCENDING);
gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (sortable),
TNY_GTK_FOLDER_STORE_TREE_MODEL_NAME_COLUMN,
- cmp_rows, NULL, NULL);
+ cmp_rows, NULL, NULL);
/* Create filter model */
filter_model = gtk_tree_model_filter_new (sortable, NULL);
filter_row,
self,
NULL);
-/* if (priv->style == MODEST_FOLDER_VIEW_STYLE_SHOW_ONE) { */
-/* filter_model = gtk_tree_model_filter_new (sortable, NULL); */
-/* gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (filter_model), */
-/* filter_row, */
-/* self, */
-/* NULL); */
-/* } */
/* Set new model */
gtk_tree_view_set_model (GTK_TREE_VIEW(self), filter_model);
g_signal_connect (G_OBJECT(filter_model), "row-inserted",
(GCallback)on_row_changed_maybe_select_folder, self);
-
-
-/* gtk_tree_view_set_model (GTK_TREE_VIEW(self), */
-/* (filter_model) ? filter_model : sortable); */
g_object_unref (model);
- g_object_unref (filter_model);
-/* if (filter_model) */
-/* g_object_unref (filter_model); */
-
+ g_object_unref (filter_model);
g_object_unref (sortable);
/* Force a reselection of the INBOX next time the widget is shown */
if ((parent_type == TNY_FOLDER_TYPE_ROOT) &&
TNY_IS_ACCOUNT (parent_folder) &&
modest_tny_account_is_virtual_local_folders (TNY_ACCOUNT (parent_folder))) {
- cmp1 = get_cmp_subfolder_type_pos (modest_tny_folder_get_local_folder_type (TNY_FOLDER (folder1)));
- cmp2 = get_cmp_subfolder_type_pos (modest_tny_folder_get_local_folder_type (TNY_FOLDER (folder2)));
+ cmp1 = get_cmp_subfolder_type_pos (modest_tny_folder_get_local_or_mmc_folder_type (TNY_FOLDER (folder1)));
+ cmp2 = get_cmp_subfolder_type_pos (modest_tny_folder_get_local_or_mmc_folder_type (TNY_FOLDER (folder2)));
}
g_object_unref (parent_folder);
}
helper->delete_source,
NULL,
NULL);
+
+ g_object_unref (G_OBJECT (mail_op));
}
/* Frees */
g_object_unref (G_OBJECT (parent_folder));
g_object_unref (G_OBJECT (folder));
- g_object_unref (G_OBJECT (mail_op));
}
/*
static void
on_configuration_key_changed (ModestConf* conf,
const gchar *key,
- ModestConfEvent event,
+ ModestConfEvent event,
+ ModestConfNotificationId id,
ModestFolderView *self)
{
ModestFolderViewPrivate *priv;
- if (!key)
- return;
g_return_if_fail (MODEST_IS_FOLDER_VIEW (self));
priv = MODEST_FOLDER_VIEW_GET_PRIVATE(self);
+ /* Do not listen for changes in other namespaces */
+ if (priv->notification_id != id)
+ return;
+
if (!strcmp (key, MODEST_CONF_DEVICE_NAME)) {
g_free (priv->local_account_name);
}
}
-void
+void
modest_folder_view_set_style (ModestFolderView *self,
ModestFolderViewStyle style)
{
do {
GtkTreeIter child;
TnyFolderType type = TNY_FOLDER_TYPE_UNKNOWN;
- gchar *name = NULL;
gtk_tree_model_get (model, iter,
- TNY_GTK_FOLDER_STORE_TREE_MODEL_NAME_COLUMN, &name,
TNY_GTK_FOLDER_STORE_TREE_MODEL_TYPE_COLUMN,
&type, -1);
-
- /*
- printf ("DEBUG: %s: name=%s, type=%d, TNY_FOLDER_TYPE_INBOX=%d\n",
- __FUNCTION__, name, type, TNY_FOLDER_TYPE_INBOX);
- */
gboolean result = FALSE;
if (type == TNY_FOLDER_TYPE_INBOX) {
result = TRUE;
- } else if (type == TNY_FOLDER_TYPE_NORMAL) {
- /* tinymail's camel implementation only provides TNY_FOLDER_TYPE_NORMAL
- * when getting folders from the cache, before connectin, so we do
- * an extra check. We could fix this in tinymail, but it's easier
- * to do here.
- */
- if (strcmp (name, "Inbox") == 0)
- result = TRUE;
- }
-
- g_free (name);
-
+ }
if (result) {
*inbox_iter = *iter;
return TRUE;
GtkTreeModel *model;
GtkTreeIter iter, inbox_iter;
GtkTreeSelection *sel;
-
-/* /\* Do not set it if the folder view was not painted *\/ */
-/* if (!GTK_WIDGET_MAPPED (self)) */
-/* return; */
+ GtkTreePath *path = NULL;
model = gtk_tree_view_get_model (GTK_TREE_VIEW (self));
if (!model)
sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (self));
gtk_tree_model_get_iter_first (model, &iter);
- gtk_tree_selection_unselect_all (sel);
- if (find_inbox_iter (model, &iter, &inbox_iter)) {
- gtk_tree_selection_select_iter (sel, &inbox_iter);
- }
- else {
- gtk_tree_model_get_iter_first (model, &iter);
- gtk_tree_selection_select_iter (sel, &iter);
- }
+ if (find_inbox_iter (model, &iter, &inbox_iter))
+ path = gtk_tree_model_get_path (model, &inbox_iter);
+ else
+ path = gtk_tree_path_new_first ();
+
+ /* Select the row and free */
+ gtk_tree_view_set_cursor (GTK_TREE_VIEW (self), path, NULL, FALSE);
+ gtk_tree_path_free (path);
}
if (!MODEST_IS_FOLDER_VIEW(self))
return;
- g_return_if_fail (MODEST_IS_FOLDER_VIEW (self));
priv = MODEST_FOLDER_VIEW_GET_PRIVATE (self);
-
if (priv->folder_to_select) {
if (!modest_folder_view_select_folder (self, priv->folder_to_select,
gtk_tree_path_free (path);
- }
+ }
g_object_unref (priv->folder_to_select);
priv->folder_to_select = NULL;
- }
+ }
}
priv = MODEST_FOLDER_VIEW_GET_PRIVATE (self);
if (after_change) {
+
+ sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (self));
+ gtk_tree_selection_unselect_all (sel);
+
if (priv->folder_to_select)
g_object_unref(priv->folder_to_select);
priv->folder_to_select = TNY_FOLDER(g_object_ref(folder));