X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=src%2Fmodest-tny-account.c;h=60d6a556e6ec0280123bc4500cee6a1fb28a7270;hb=e3f312c4d0f48a21dd619ef44abbe3b915862f7e;hp=d6011708f61afbad9366766f7d5e7411e691fd49;hpb=e88c60204c494bf63fa39d2fec4969d2d91146a9;p=modest diff --git a/src/modest-tny-account.c b/src/modest-tny-account.c index d601170..60d6a55 100644 --- a/src/modest-tny-account.c +++ b/src/modest-tny-account.c @@ -411,54 +411,123 @@ modest_tny_account_new_from_account (ModestAccountMgr *account_mgr, const gchar get_pass_func ? get_pass_func: get_pass_dummy); - TnyAccountStore *astore = (TnyAccountStore *) modest_runtime_get_account_store (); - if (astore) { + /* This name is what shows up in the folder view -- so for some POP/IMAP/... server + * account, we set its name to the account of which it is part. */ + + if (account_data->display_name) + tny_account_set_name (tny_account, account_data->display_name); + + modest_tny_account_set_parent_modest_account_name_for_server_account (tny_account, account_name); + + modest_account_mgr_free_account_data (account_mgr, account_data); + +/* + TnyAccountStore *astore = (TnyAccountStore *) modest_runtime_get_account_store (); + if (astore) { TnyDevice *device = tny_account_store_get_device (astore); GError *err = NULL; + 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); - } - - /* This name is what shows up in the folder view -- so for some POP/IMAP/... server - * account, we set its name to the account of which it is part. */ - if (account_data->display_name) - tny_account_set_name (tny_account, account_data->display_name); - - modest_tny_account_set_parent_modest_account_name_for_server_account (tny_account, account_name); - - modest_account_mgr_free_account_data (account_mgr, account_data); + } +*/ 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) { -/* printf (" DEBUG: %s: error=%s\n", __FUNCTION__, error->message); */ - } + 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); + previous_display_name = tny_account_get_name (account); } + + /* 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); - if (display_name) { - /* printf ("DEBUG: %s: display name=%s\n", __FUNCTION__, display_name); */ - tny_account_set_name (account, display_name); + 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; + + /* 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); */ } + TnyAccount* modest_tny_account_new_for_local_folders (ModestAccountMgr *account_mgr, TnySessionCamel *session, const gchar* location_filepath) @@ -525,12 +594,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; @@ -745,3 +813,5 @@ void modest_tny_account_set_parent_modest_account_name_for_server_account (TnyAc } + +