gpointer user_data;
} GetMmcAccountNameData;
+
+
+
/* Gets the memory card name: */
static void
on_modest_file_system_info(HildonFileSystemInfoHandle *handle,
g_warning ("%s: error=%s", __FUNCTION__, error->message);
}
+ TnyAccount *account = TNY_ACCOUNT (callback_data->account);
+
+ const gchar *previous_display_name = NULL;
+
const gchar *display_name = NULL;
if (!error && info) {
display_name = hildon_file_system_info_get_display_name(info);
- printf ("DEBUG: %s: display name=%s\n", __FUNCTION__, display_name);
+ previous_display_name = tny_account_get_name (account);
}
-
- TnyAccount *account = TNY_ACCOUNT (callback_data->account);
-
- const gchar * previous_display_name = tny_account_get_name (account);
-
- /* Use the new name if it is different: */
- if (display_name &&
- (previous_display_name && (strcmp (display_name, previous_display_name) != 0))) {
- /* printf ("DEBUG: %s: display name=%s\n", __FUNCTION__, display_name); */
- tny_account_set_name (account, display_name);
+
+ /* printf ("DEBUG: %s: display name=%s\n", __FUNCTION__, display_name); */
+ tny_account_set_name (account, display_name);
- /* Inform the application that the name is now ready: */
- if (callback_data->callback)
- (*(callback_data->callback)) (callback_data->account,
- callback_data->user_data);
- }
+ /* Inform the application that the name is now ready: */
+ if (callback_data->callback)
+ (*(callback_data->callback)) (callback_data->account,
+ callback_data->user_data);
g_object_unref (callback_data->account);
g_slice_free (GetMmcAccountNameData, callback_data);
void modest_tny_account_get_mmc_account_name (TnyStoreAccount* self, ModestTnyAccountGetMmcAccountNameCallback callback, gpointer user_data)
{
+ /* Just use the hard-coded path for the single memory card,
+ * rather than try to figure out the path to the specific card by
+ * looking at the maildir URI:
+ */
+ const gchar *uri_real = MODEST_MCC1_VOLUMEPATH_URI;
+
+ /*
gchar* uri = tny_account_get_url_string (TNY_ACCOUNT (self));
if (!uri)
return;
+
+ TODO: This gets the name of the folder, but we want the name of the volume.
+ gchar *uri_real = NULL;
+ const gchar* prefix = "maildir://localhost/";
+ if ((strstr (uri, prefix) == uri) && (strlen(uri) > strlen(prefix)) )
+ uri_real = g_strconcat ("file:///", uri + strlen (prefix), NULL);
+ */
+
+ if (uri_real) {
+ //This is freed in the callback:
+ GetMmcAccountNameData * callback_data = g_slice_new0(GetMmcAccountNameData);
+ callback_data->account = self;
+ g_object_ref (callback_data->account); /* Unrefed when we destroy the struct. */
+ callback_data->callback = callback;
+ callback_data->user_data = user_data;
- //This is freed in the callback:
- GetMmcAccountNameData * callback_data = g_slice_new0(GetMmcAccountNameData);
- callback_data->account = self;
- g_object_ref (callback_data->account); /* Unrefed when we destroy the struct. */
- callback_data->user_data = user_data;
-
- /* TODO: gnome_vfs_volume_get_display_name() does not return
- * the same string. But why not? Why does hildon needs its own
- * function for this?
- */
- printf ("DEBUG: %s Calling hildon_file_system_info_async_new() with URI=%s\n", __FUNCTION__, uri);
- hildon_file_system_info_async_new(uri,
- on_modest_file_system_info, callback_data /* user_data */);
+ /* TODO: gnome_vfs_volume_get_display_name() does not return
+ * the same string. But why not? Why does hildon needs its own
+ * function for this?
+ */
+ /* printf ("DEBUG: %s Calling hildon_file_system_info_async_new() with URI=%s\n", __FUNCTION__, uri_real); */
+ hildon_file_system_info_async_new(uri_real,
+ on_modest_file_system_info, callback_data /* user_data */);
+
+ /* g_free (uri_real); */
+ }
- g_free (uri);
+ /* g_free (uri); */
}
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));