From: Murray Cumming Date: Wed, 27 Jun 2007 15:28:30 +0000 (+0000) Subject: 2007-06-27 Murray Cumming - - reviewed by: - - * src/modest-mail-operation.c: (update_account_thread), - (get_msgs_full_thread): - * please check the svn log instead diff --git a/ChangeLog2 b/ChangeLog2 index 1a09ef2..e078b19 100644 --- a/ChangeLog2 +++ b/ChangeLog2 @@ -1,5 +1,20 @@ 2007-06-27 Murray Cumming domain, error->code, error->message); */ + /* This debug output is useful. Please keep it uncommented until + * we have fixed the problems in this function: */ + g_debug ("%s: Handling GError domain=%d, code=%d, message=%s", + __FUNCTION__, error->domain, error->code, error->message); /* TODO: Remove the internal error message for the real release. * This is just so the testers can give us more information: */ diff --git a/src/modest-tny-account.c b/src/modest-tny-account.c index 6779724..61e61c5 100644 --- a/src/modest-tny-account.c +++ b/src/modest-tny-account.c @@ -429,8 +429,10 @@ modest_tny_account_new_from_account (ModestAccountMgr *account_mgr, const gchar g_object_set_data (G_OBJECT(tny_account), "account_store", (gpointer)astore); tny_camel_account_set_online (TNY_CAMEL_ACCOUNT (tny_account), tny_device_is_online (device), &err); - if (err) - g_print ("Error connecting: %s\n", err->message); + if (err) { + g_print ("%s: tny_camel_account_set_online() failed: %s\n", __FUNCTION__, err->message); + g_error_free (err); + } g_object_unref (device); } */ @@ -438,15 +440,25 @@ modest_tny_account_new_from_account (ModestAccountMgr *account_mgr, const gchar return tny_account; } -/* TODO: Notify the treemodel somehow that the display name - * is now available. We should probably request this from the cell_data_func - * so we can provide a treerowreference. */ +typedef struct +{ + TnyStoreAccount *account; + + ModestTnyAccountGetMmcAccountNameCallback callback; + gpointer user_data; +} GetMmcAccountNameData; + +/* Gets the memory card name: */ static void on_modest_file_system_info(HildonFileSystemInfoHandle *handle, - HildonFileSystemInfo *info, - const GError *error, gpointer data) + HildonFileSystemInfo *info, + const GError *error, gpointer data) { - TnyAccount *account = TNY_ACCOUNT (data); + GetMmcAccountNameData *callback_data = (GetMmcAccountNameData*)data; + + if (error) { + g_warning ("%s: error=%s", __FUNCTION__, error->message); + } if (error) { /* printf (" DEBUG: %s: error=%s\n", __FUNCTION__, error->message); */ @@ -457,12 +469,49 @@ on_modest_file_system_info(HildonFileSystemInfoHandle *handle, display_name = hildon_file_system_info_get_display_name(info); } - if (display_name) { + 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); + + /* 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) +{ + gchar* uri = tny_account_get_url_string (TNY_ACCOUNT (self)); + if (!uri) + return; + + //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? + */ + hildon_file_system_info_async_new(uri, + on_modest_file_system_info, callback_data /* user_data */); + + g_free (uri); +} + + TnyAccount* modest_tny_account_new_for_local_folders (ModestAccountMgr *account_mgr, TnySessionCamel *session, const gchar* location_filepath) @@ -529,12 +578,11 @@ modest_tny_account_new_for_local_folders (ModestAccountMgr *account_mgr, TnySess g_error_free (error); error = NULL; } else if (uri) { - /* 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? + /* Get the account name asynchronously: + * This might not happen soon enough, so some UI code might + * need to call this again, specifying a callback. */ - hildon_file_system_info_async_new(uri, - on_modest_file_system_info, tny_account /* user_data */); + modest_tny_account_get_mmc_account_name (tny_account, NULL, NULL); g_free (uri); uri = NULL; @@ -749,3 +797,5 @@ void modest_tny_account_set_parent_modest_account_name_for_server_account (TnyAc } + + diff --git a/src/modest-tny-account.h b/src/modest-tny-account.h index 2e4b056..d4a2e3f 100644 --- a/src/modest-tny-account.h +++ b/src/modest-tny-account.h @@ -161,7 +161,17 @@ const gchar* modest_tny_account_get_parent_modest_account_name_for_server_accoun * so it can be retrieved later with * modest_tny_account_get_parent_modest_account_name_for_server_account(). */ -void modest_tny_account_set_parent_modest_account_name_for_server_account (TnyAccount *self, const gchar* parent_modest_acount_name); +void modest_tny_account_set_parent_modest_account_name_for_server_account (TnyAccount *account, const gchar* parent_modest_acount_name); + + +typedef void (*ModestTnyAccountGetMmcAccountNameCallback) (TnyStoreAccount* self, gpointer user_data); + +/** modest_tny_account_get_mmc_account_name: + * Asnchronously get the name of a memory card account and set it in the TnyAccount, + * calling the callback (if not NULL) to notify that the name is changed. + * if the name was changed. The callback will not be called if the name was not changed. + */ +void modest_tny_account_get_mmc_account_name (TnyStoreAccount* self, ModestTnyAccountGetMmcAccountNameCallback callback, gpointer user_data); G_END_DECLS diff --git a/src/widgets/modest-folder-view.c b/src/widgets/modest-folder-view.c index e798afc..05af376 100644 --- a/src/widgets/modest-folder-view.c +++ b/src/widgets/modest-folder-view.c @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -249,6 +250,57 @@ modest_folder_view_class_init (ModestFolderViewClass *klass) G_TYPE_NONE, 1, G_TYPE_STRING); } +static gboolean on_model_foreach_set_name(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data) +{ + GObject *instance = NULL; + + gtk_tree_model_get (model, iter, + TNY_GTK_FOLDER_STORE_TREE_MODEL_INSTANCE_COLUMN, &instance, + -1); + + if (!instance) + return FALSE; /* keep walking */ + + if (!TNY_IS_ACCOUNT (instance)) { + g_object_unref (instance); + return FALSE; /* keep walking */ + } + + /* Check if this is the looked-for account: */ + TnyAccount *this_account = TNY_ACCOUNT (instance); + TnyAccount *account = TNY_ACCOUNT (data); + + 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)) { + + /* Tell the model that the data has changed, so that + * it calls the cell_data_func callbacks again: */ + 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) +{ + ModestFolderView *self = MODEST_FOLDER_VIEW (user_data); + + /* 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); +} + static void text_cell_data (GtkTreeViewColumn *column, GtkCellRenderer *renderer, GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data) @@ -281,8 +333,8 @@ text_cell_data (GtkTreeViewColumn *column, GtkCellRenderer *renderer, return; } - - priv = MODEST_FOLDER_VIEW_GET_PRIVATE (data); + ModestFolderView *self = MODEST_FOLDER_VIEW (data); + priv = MODEST_FOLDER_VIEW_GET_PRIVATE (self); gchar *item_name = NULL; gint item_weight = 400; @@ -343,6 +395,14 @@ text_cell_data (GtkTreeViewColumn *column, GtkCellRenderer *renderer, } + /* If it is a Memory card account, make sure that we have the correct name: */ + if (TNY_IS_STORE_ACCOUNT (instance) && + modest_tny_account_is_memory_card_account (TNY_ACCOUNT (instance))) { + /* Get the account name asynchronously: */ + modest_tny_account_get_mmc_account_name (TNY_STORE_ACCOUNT (instance), + on_get_mmc_account_name, self); + } + g_object_unref (G_OBJECT (instance)); g_free (fname); }