static void setup_drag_and_drop (GtkTreeView *self);
-static void _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 _clear_hidding_filter (ModestFolderView *folder_view);
G_TYPE_NONE, 1, G_TYPE_STRING);
}
+/* Simplify checks for NULLs: */
+static gboolean strings_are_equal (const gchar *a, const gchar *b)
+{
+ if (!a && !b)
+ return TRUE;
+ if (a && b)
+ {
+ return (strcmp (a, b) == 0);
+ }
+ else
+ return FALSE;
+}
+
static gboolean on_model_foreach_set_name(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data)
{
GObject *instance = NULL;
const gchar *this_account_id = tny_account_get_id(this_account);
const gchar *account_id = tny_account_get_id(account);
- if (this_account_id && account_id &&
- (strcmp (this_account_id, account_id) == 0)) {
-
+ g_object_unref (instance);
+ instance = NULL;
+
+ /* printf ("DEBUG: %s: this_account_id=%s, account_id=%s\n", __FUNCTION__, this_account_id, account_id); */
+ if (strings_are_equal(this_account_id, account_id)) {
/* Tell the model that the data has changed, so that
* it calls the cell_data_func callbacks again: */
+ /* TODO: This does not seem to actually cause the new string to be shown: */
gtk_tree_model_row_changed (model, path, iter);
- g_object_unref (instance);
return TRUE; /* stop walking */
}
- g_object_unref (instance);
return FALSE; /* keep walking */
}
-void on_get_mmc_account_name (TnyStoreAccount* account, gpointer user_data)
+typedef struct
{
- printf ("DEBUG: %s: account name=%s\n", __FUNCTION__, tny_account_get_name (TNY_ACCOUNT(account)));
+ ModestFolderView *self;
+ gchar *previous_name;
+} GetMmcAccountNameData;
- ModestFolderView *self = MODEST_FOLDER_VIEW (user_data);
+static void on_get_mmc_account_name (TnyStoreAccount* account, gpointer user_data)
+{
+ /* 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 this has been called then it means that the account name has
- * changed, so we tell the model that the data has changed, so that
- * it calls the cell_data_func callbacks again: */
- GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (self));
- if (!model)
- return;
-
- gtk_tree_model_foreach(model, on_model_foreach_set_name, self);
+ /* Tell the model that the data has changed, so that
+ * it calls the cell_data_func callbacks again: */
+ ModestFolderView *self = data->self;
+ GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (self));
+ if (model)
+ gtk_tree_model_foreach(model, on_model_foreach_set_name, account);
+ }
+
+ g_free (data->previous_name);
+ g_slice_free (GetMmcAccountNameData, data);
}
static void
TNY_GTK_FOLDER_STORE_TREE_MODEL_INSTANCE_COLUMN, &instance,
-1);
rendobj = G_OBJECT(renderer);
-
+
if (!fname)
return;
TNY_ACCOUNT (instance))) {
item_name = g_strdup (priv->local_account_name);
item_weight = 800;
+ } else if (modest_tny_account_is_memory_card_account (
+ TNY_ACCOUNT (instance))) {
+ /* fname is only correct when the items are first
+ * added to the model, not when the account is
+ * changed later, so get the name from the account
+ * instance: */
+ item_name = g_strdup (tny_account_get_name (
+ TNY_ACCOUNT (instance)));
+ item_weight = 800;
} else {
item_name = g_strdup (fname);
item_weight = 800;
g_object_set (rendobj,"text", item_name, "weight", item_weight, NULL);
/* Notify display name observers */
+ /* TODO: What listens for this signal, and how can it use only the new name? */
if (G_OBJECT (priv->cur_folder_store) == instance) {
- g_signal_emit (G_OBJECT(data),
+ g_signal_emit (G_OBJECT(self),
signals[FOLDER_DISPLAY_NAME_CHANGED_SIGNAL], 0,
item_name);
}
}
- /* If it is a Memory card account, make sure that we have the correct name: */
+ /* If it is a Memory card account, make sure that we have the correct name.
+ * This function will be trigerred again when the name has been retrieved: */
if (TNY_IS_STORE_ACCOUNT (instance) &&
modest_tny_account_is_memory_card_account (TNY_ACCOUNT (instance))) {
+
/* Get the account name asynchronously: */
+ GetMmcAccountNameData *callback_data =
+ g_slice_new0(GetMmcAccountNameData);
+ callback_data->self = self;
+
+ const gchar *name = tny_account_get_name (TNY_ACCOUNT(instance));
+ if (name)
+ callback_data->previous_name = g_strdup (name);
+
modest_tny_account_get_mmc_account_name (TNY_STORE_ACCOUNT (instance),
- on_get_mmc_account_name, self);
+ on_get_mmc_account_name, callback_data);
}
g_object_unref (G_OBJECT (instance));
if (priv->cur_folder_store) {
if (TNY_IS_FOLDER(priv->cur_folder_store))
- tny_folder_sync (TNY_FOLDER(priv->cur_folder_store), TRUE, NULL);
- /* expunge the message */
+ tny_folder_sync (TNY_FOLDER(priv->cur_folder_store), FALSE, NULL);
+ /* FALSE --> expunge the message */
g_object_unref (priv->cur_folder_store);
priv->cur_folder_store = NULL;
/* Current folder was unselected */
if (priv->cur_folder_store) {
if (TNY_IS_FOLDER(priv->cur_folder_store))
- tny_folder_sync (TNY_FOLDER(priv->cur_folder_store), TRUE, NULL);
- /* expunge the message */
+ tny_folder_sync (TNY_FOLDER(priv->cur_folder_store), FALSE, NULL);
+ /* FALSE --> don't expunge the messages */
g_signal_emit (G_OBJECT(tree_view), signals[FOLDER_SELECTION_CHANGED_SIGNAL], 0,
priv->cur_folder_store, FALSE);
TNY_GTK_FOLDER_STORE_TREE_MODEL_INSTANCE_COLUMN, &folder2,
-1);
+ /* Return if we get no folder. This could happen when folder
+ operations are happening. The model is updated after the
+ folder copy/move actually occurs, so there could be
+ situations where the model to be drawn is not correct */
+ if (!folder1 || !folder2)
+ return 0;
+
if (type == TNY_FOLDER_TYPE_ROOT) {
/* Compare the types, so that
* Remote accounts -> Local account -> MMC account .*/
priv = MODEST_FOLDER_VIEW_GET_PRIVATE (folder_view);
/* Copy selection */
- _clipboard_set_selected_data (folder_view, TRUE);
+ if (!_clipboard_set_selected_data (folder_view, TRUE))
+ return;
/* Get hidding ids */
hidding = modest_email_clipboard_get_hidding_ids (priv->clipboard, &n_selected);
gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (model));
}
-static void
+/* Returns FALSE if it did not selected anything */
+static gboolean
_clipboard_set_selected_data (ModestFolderView *folder_view,
gboolean delete)
{
ModestFolderViewPrivate *priv = NULL;
TnyFolderStore *folder = NULL;
+ gboolean retval = FALSE;
- g_return_if_fail (MODEST_IS_FOLDER_VIEW (folder_view));
+ g_return_val_if_fail (MODEST_IS_FOLDER_VIEW (folder_view), FALSE);
priv = MODEST_FOLDER_VIEW_GET_PRIVATE (folder_view);
/* Set selected data on clipboard */
- g_return_if_fail (MODEST_IS_EMAIL_CLIPBOARD (priv->clipboard));
+ g_return_val_if_fail (MODEST_IS_EMAIL_CLIPBOARD (priv->clipboard), FALSE);
folder = modest_folder_view_get_selected (folder_view);
- modest_email_clipboard_set_data (priv->clipboard, TNY_FOLDER(folder), NULL, delete);
+
+ /* Do not allow to select an account */
+ if (TNY_IS_FOLDER (folder)) {
+ modest_email_clipboard_set_data (priv->clipboard, TNY_FOLDER(folder), NULL, delete);
+ retval = TRUE;
+ }
/* Free */
g_object_unref (folder);
+
+ return retval;
}
static void