X-Git-Url: http://git.maemo.org/git/?p=modest;a=blobdiff_plain;f=src%2Fmodest-tny-folder.c;h=26b5f41f47a3e4fca22d34168a8375e2426a80e3;hp=9e6dbf092131016f2446b32872c3da6dcc2e5c52;hb=b969746bd8d9e021f79a19350e85a6fdbd3226a5;hpb=db85a9f5535044df6b8fec79eea241cc799366bd diff --git a/src/modest-tny-folder.c b/src/modest-tny-folder.c index 9e6dbf0..26b5f41 100644 --- a/src/modest-tny-folder.c +++ b/src/modest-tny-folder.c @@ -467,8 +467,7 @@ modest_tny_folder_has_subfolder_with_name (TnyFolderStore *parent, } /* free */ - if (iter != NULL) - g_object_unref (iter); + g_object_unref (iter); g_object_unref (subfolders); return has_name; @@ -529,3 +528,60 @@ modest_tny_folder_get_display_name (TnyFolder *folder) return fname; } + +TnyFolder * +modest_tny_folder_store_find_folder_from_uri (TnyFolderStore *folder_store, const gchar *uri) +{ + TnyList *children; + TnyIterator *iterator; + TnyFolder *result; + gchar *uri_to_find, *slash; + gint uri_lenght; + + if (uri == NULL) + return NULL; + + slash = strrchr (uri, '/'); + if (slash == NULL) + return NULL; + + result = NULL; + children = TNY_LIST (tny_simple_list_new ()); + tny_folder_store_get_folders (folder_store, children, NULL, FALSE, NULL); + + uri_lenght = slash - uri + 1; + uri_to_find = g_malloc0 (sizeof(char) * uri_lenght); + strncpy (uri_to_find, uri, uri_lenght); + uri_to_find[uri_lenght - 1] = '\0'; + + for (iterator = tny_list_create_iterator (children); + iterator && !tny_iterator_is_done (iterator) && (result == NULL); + tny_iterator_next (iterator)) { + TnyFolderStore *child; + + child = TNY_FOLDER_STORE (tny_iterator_get_current (iterator)); + if (!child) + continue; + + if (TNY_IS_FOLDER (child)) { + gchar *folder_url; + + folder_url = tny_folder_get_url_string (TNY_FOLDER (child)); + if (uri_to_find && folder_url && !strcmp (folder_url, uri_to_find)) + result = g_object_ref (child); + g_free (folder_url); + } + + if ((result == NULL) && TNY_IS_FOLDER_STORE (child)) { + result = modest_tny_folder_store_find_folder_from_uri (child, uri); + } + + g_object_unref (child); + } + + g_free (uri_to_find); + g_object_unref (iterator); + g_object_unref (children); + + return result; +}