From e26932852b353da6fa471a37922105651bb2c9d5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Pekka=20Geh=C3=B6r?= Date: Thu, 2 Oct 2008 12:10:02 +0000 Subject: [PATCH] added irreco_webdb_cache_get_themes function --- irreco/trunk/src/core/irreco_theme_manager_dlg.c | 32 ++++++------- irreco/trunk/src/core/irreco_theme_manager_dlg.h | 2 +- irreco/trunk/src/webdb/irreco_webdb_cache.c | 57 ++++++++++++++++++++++++ irreco/trunk/src/webdb/irreco_webdb_cache.h | 8 ++++ 4 files changed, 79 insertions(+), 20 deletions(-) diff --git a/irreco/trunk/src/core/irreco_theme_manager_dlg.c b/irreco/trunk/src/core/irreco_theme_manager_dlg.c index 2707c579..1000bb95 100644 --- a/irreco/trunk/src/core/irreco_theme_manager_dlg.c +++ b/irreco/trunk/src/core/irreco_theme_manager_dlg.c @@ -47,9 +47,9 @@ static gboolean irreco_theme_manager_dlg_loader_user(IrrecoThemeManagerDlg *self); static gboolean irreco_theme_manager_dlg_loader_web(IrrecoThemeManagerDlg *self); -/*static gboolean +static gboolean irreco_theme_manager_dlg_loader_db(IrrecoThemeManagerDlg *self); -*/ + static gboolean irreco_theme_manager_dlg_display_config_detail(IrrecoThemeManagerDlg *self, @@ -1014,13 +1014,6 @@ irreco_theme_manager_dlg_loader_user(IrrecoThemeManagerDlg *self) self->loader_iter = gtk_tree_iter_copy(&iter); - gtk_combo_box_insert_text(GTK_COMBO_BOX(self->combobox), - 0, "11"); - gtk_combo_box_insert_text(GTK_COMBO_BOX(self->combobox), - 1, "222"); - gtk_combo_box_insert_text(GTK_COMBO_BOX(self->combobox), - 2, "3333"); - IRRECO_RETURN_BOOL(TRUE); @@ -1065,9 +1058,9 @@ irreco_theme_manager_dlg_loader_user(IrrecoThemeManagerDlg *self) } irreco_theme_manager_dlg_hide_banner(self); irreco_theme_manager_dlg_loader_stop(self); - /* irreco_theme_manager_dlg_loader_start(self, + irreco_theme_manager_dlg_loader_start(self, G_SOURCEFUNC(irreco_theme_manager_dlg_loader_db), NULL); -*/ + } @@ -1155,7 +1148,7 @@ static gboolean irreco_theme_manager_dlg_loader_web(IrrecoThemeManagerDlg *self) IRRECO_RETURN_BOOL(FALSE); } -/* + static gboolean irreco_theme_manager_dlg_loader_db(IrrecoThemeManagerDlg *self) { @@ -1191,21 +1184,21 @@ irreco_theme_manager_dlg_loader_db(IrrecoThemeManagerDlg *self) case LOADER_STATE_LOOP: { GtkTreeIter iter; - GtkTreeIter iter_loading; + /* GtkTreeIter iter_loading;*/ IrrecoStringTable *themes = NULL; IrrecoWebdbCache *webdb_cache = NULL; webdb_cache = irreco_data_get_webdb_cache(self->irreco_data, FALSE); if(irreco_webdb_cache_get_themes(webdb_cache, &themes)){ - IRRECO_STRING_TABLE_FOREACH_KEY(themes, key) + IRRECO_STRING_TABLE_FOREACH_KEY(themes, theme) gtk_tree_store_append(self->tree_store, &iter, self->loader_iter); gtk_tree_store_set(self->tree_store, &iter, - TEXT_COL, theme->name->str, + TEXT_COL, theme, FLAG_COL, ROW_TYPE_DB, DATA_COL, NULL, -1); @@ -1218,19 +1211,20 @@ irreco_theme_manager_dlg_loader_db(IrrecoThemeManagerDlg *self) webdb_cache)); } - irreco_webdb_dlg_set_banner(self, _("Loading ..."), 1); + /*irreco_webdb_dlg_set_banner(self, _("Loading ..."), 1);*/ self->loader_state = LOADER_STATE_END; IRRECO_RETURN_BOOL(TRUE); } case LOADER_STATE_END: - irreco_webdb_dlg_hide_banner(self); - irreco_webdb_dlg_loader_stop(self); + irreco_theme_manager_dlg_hide_banner(self); + irreco_theme_manager_dlg_loader_stop(self); + } IRRECO_RETURN_BOOL(FALSE); } -*/ + /** * Theme Configuration details loader. diff --git a/irreco/trunk/src/core/irreco_theme_manager_dlg.h b/irreco/trunk/src/core/irreco_theme_manager_dlg.h index 3381f1c1..6badf776 100644 --- a/irreco/trunk/src/core/irreco_theme_manager_dlg.h +++ b/irreco/trunk/src/core/irreco_theme_manager_dlg.h @@ -84,7 +84,7 @@ typedef struct _IrrecoThemeManagerDlgClass IrrecoThemeManagerDlgClass; #include "irreco_internal_dlg.h" #include "irreco_internal_widget.h" #include "irreco_theme_upload_dlg.h" - +#include "irreco_webdb_cache.h" /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/ /* Datatypes */ diff --git a/irreco/trunk/src/webdb/irreco_webdb_cache.c b/irreco/trunk/src/webdb/irreco_webdb_cache.c index 28a28985..5b47a212 100644 --- a/irreco/trunk/src/webdb/irreco_webdb_cache.c +++ b/irreco/trunk/src/webdb/irreco_webdb_cache.c @@ -53,6 +53,10 @@ IrrecoWebdbCache *irreco_webdb_cache_new() IRRECO_SECONDS_TO_USEC(3)); self->conf_hash = g_hash_table_new_full(g_int_hash, g_int_equal, NULL, (GDestroyNotify) irreco_webdb_conf_free); + + self->themes = irreco_string_table_new ( + (GDestroyNotify) irreco_webdb_theme_free, NULL); + IRRECO_RETURN_PTR(self); } @@ -71,6 +75,7 @@ void irreco_webdb_cache_free(IrrecoWebdbCache *self) g_slice_free(IrrecoWebdbCache, self); g_hash_table_destroy(self->conf_hash); self->conf_hash = NULL; + irreco_string_table_free (self->themes); IRRECO_RETURN } @@ -696,6 +701,58 @@ gboolean irreco_webdb_cache_login(IrrecoWebdbCache *self, IRRECO_RETURN_BOOL(FALSE); } +gboolean irreco_webdb_cache_get_themes(IrrecoWebdbCache *self, + IrrecoStringTable **theme) +{ + gboolean success = FALSE; + IrrecoWebdbClient *client = (IrrecoWebdbClient *) self->private; + IRRECO_ENTER + + IRRECO_RETRY_LOOP_START(self->loop) + if (irreco_webdb_cache_test(self) == FALSE) break; + success = irreco_webdb_client_get_themes(client, theme); + + if (success) break; + irreco_webdb_client_get_error_msg(client, self->error_msg); + IRRECO_RETRY_LOOP_END(self->loop) + + IRRECO_RETURN_BOOL(success) +} + +gboolean irreco_webdb_cache_get_theme_by_id(IrrecoWebdbCache *self, + gint theme_id, + IrrecoWebdbTheme **theme) +{ + IrrecoWebdbTheme *get_theme; + IRRECO_ENTER + + if (g_hash_table_lookup(self->conf_hash, (gconstpointer) &theme_id) == NULL) { + gboolean success = FALSE; + IrrecoWebdbClient *client = (IrrecoWebdbClient *) self->private; + + IRRECO_RETRY_LOOP_START(self->loop) + if (irreco_webdb_cache_test(self) == FALSE) break; + success = irreco_webdb_client_get_theme_by_id( + client, theme_id, &get_theme); + + if (success) break; + irreco_webdb_client_get_error_msg(client, + self->error_msg); + IRRECO_RETRY_LOOP_END(self->loop) + + if (success == FALSE) IRRECO_RETURN_BOOL(FALSE); + + g_hash_table_insert(self->conf_hash, + (gpointer) &get_theme->id, + (gpointer) get_theme); + } + + *theme = g_hash_table_lookup(self->conf_hash, (gconstpointer) &theme_id); + + IRRECO_RETURN_BOOL(TRUE) +} + + /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/ /* Events and Callbacks */ /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/ diff --git a/irreco/trunk/src/webdb/irreco_webdb_cache.h b/irreco/trunk/src/webdb/irreco_webdb_cache.h index ff2aa245..4ec9606a 100644 --- a/irreco/trunk/src/webdb/irreco_webdb_cache.h +++ b/irreco/trunk/src/webdb/irreco_webdb_cache.h @@ -43,6 +43,7 @@ typedef struct _IrrecoWebdbCache IrrecoWebdbCache; #include "irreco_webdb.h" #include #include "irreco_webdb_conf.h" +#include "irreco_webdb_theme.h" /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/ /* Datatypes */ @@ -57,6 +58,7 @@ struct _IrrecoWebdbCache IrrecoStringTable *manufacturers; GString *error_msg; GHashTable *conf_hash; + IrrecoStringTable *themes; }; @@ -128,6 +130,12 @@ gboolean irreco_webdb_cache_get_user_exists(IrrecoWebdbCache *self, gboolean irreco_webdb_cache_login(IrrecoWebdbCache *self, const gchar *user, const gchar *password); +gboolean irreco_webdb_cache_get_themes(IrrecoWebdbCache *self, + IrrecoStringTable **theme); +gboolean irreco_webdb_cache_get_theme_by_id(IrrecoWebdbCache *self, + gint theme_id, + IrrecoWebdbTheme **theme); + #endif /* __IRRECO_WEBDB_CACHE_H__ */ -- 2.11.4.GIT