From 6e18c39b59f0d2a4e4f10eb917b0a61aed5dd4df Mon Sep 17 00:00:00 2001 From: Joni Kokko Date: Thu, 18 Dec 2008 17:04:02 +0200 Subject: [PATCH] Created functions which fetches themes and configurations belonging given remote_id --- irreco/src/webdb/irreco_webdb_cache.c | 103 ++++++++++++++++++++++++++++++++++ irreco/src/webdb/irreco_webdb_cache.h | 6 ++ 2 files changed, 109 insertions(+) diff --git a/irreco/src/webdb/irreco_webdb_cache.c b/irreco/src/webdb/irreco_webdb_cache.c index a5fb79bc..87da6a3d 100644 --- a/irreco/src/webdb/irreco_webdb_cache.c +++ b/irreco/src/webdb/irreco_webdb_cache.c @@ -1345,6 +1345,109 @@ gboolean irreco_webdb_cache_get_remote_by_id(IrrecoWebdbCache *self, IRRECO_RETURN_BOOL(TRUE) } +/** + * Fetches configurations belonging given remote_id. + * + * @param configs points to internally allocated storage in the cache + * and must not be freed + * @return TRUE if remote is fetched succesfully, FALSE otherwise. + */ +gboolean irreco_webdb_cache_get_configurations_of_remote(IrrecoWebdbCache *self, + gint remote_id, + GList **configs) +{ + IrrecoWebdbRemote *remote; + GList *configuration_list = NULL; + gboolean success = FALSE; + IRRECO_ENTER + + if (!irreco_webdb_cache_get_remote_by_id(self, remote_id, &remote)) { + IRRECO_RETURN_BOOL(FALSE) + } + + + if (remote->configurations != NULL) { + goto end; + } + + IRRECO_RETRY_LOOP_START(self->loop) + if (irreco_webdb_cache_test(self) == FALSE) break; + success = irreco_webdb_client_get_configurations_of_remote( + self->private, remote_id, + &configuration_list); + + if (success) break; + irreco_webdb_client_get_error_msg(self->private, + self->error_msg); + IRRECO_RETRY_LOOP_END(self->loop) + + if (success == FALSE) IRRECO_RETURN_BOOL(FALSE); + + configuration_list = g_list_first(configuration_list); + while(configuration_list) { + irreco_webdb_remote_add_configuration_id(remote, + GPOINTER_TO_INT(configuration_list->data)); + configuration_list = configuration_list->next; + } + g_list_free(configuration_list); + + end: + *configs = remote->configurations; + + IRRECO_RETURN_BOOL(TRUE) +} + +/** + * Fetches themes belonging given remote_id. + * + * @param themes points to internally allocated storage in the cache + * and must not be freed + * @return TRUE if remote is fetched succesfully, FALSE otherwise. + */ +gboolean irreco_webdb_cache_get_themes_of_remote(IrrecoWebdbCache *self, + gint remote_id, + GList **themes) +{ + IrrecoWebdbRemote *remote; + GList *theme_list = NULL; + gboolean success = FALSE; + IRRECO_ENTER + + if (!irreco_webdb_cache_get_remote_by_id(self, remote_id, &remote)) { + IRRECO_RETURN_BOOL(FALSE) + } + + if (remote->themes != NULL) { + goto end; + } + + IRRECO_RETRY_LOOP_START(self->loop) + if (irreco_webdb_cache_test(self) == FALSE) break; + success = irreco_webdb_client_get_themes_of_remote( + self->private, remote_id, + &theme_list); + + if (success) break; + irreco_webdb_client_get_error_msg(self->private, + self->error_msg); + IRRECO_RETRY_LOOP_END(self->loop) + + if (success == FALSE) IRRECO_RETURN_BOOL(FALSE); + + theme_list = g_list_first(theme_list); + while(theme_list) { + irreco_webdb_remote_add_theme_id(remote, GPOINTER_TO_INT( + theme_list->data)); + theme_list = theme_list->next; + } + g_list_free(theme_list); + + end: + *themes = remote->themes; + + IRRECO_RETURN_BOOL(TRUE) +} + /** @} */ /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/ diff --git a/irreco/src/webdb/irreco_webdb_cache.h b/irreco/src/webdb/irreco_webdb_cache.h index 23b9b19e..b7bd497c 100644 --- a/irreco/src/webdb/irreco_webdb_cache.h +++ b/irreco/src/webdb/irreco_webdb_cache.h @@ -228,6 +228,12 @@ gboolean irreco_webdb_cache_get_remotes(IrrecoWebdbCache *self, gboolean irreco_webdb_cache_get_remote_by_id(IrrecoWebdbCache *self, gint id, IrrecoWebdbRemote **remote); +gboolean irreco_webdb_cache_get_configurations_of_remote(IrrecoWebdbCache *self, + gint remote_id, + GList **configs); +gboolean irreco_webdb_cache_get_themes_of_remote(IrrecoWebdbCache *self, + gint remote_id, + GList **themes); #endif /* __IRRECO_WEBDB_CACHE_H__ */ -- 2.11.4.GIT