Added Buttonlistdir = $(buttonstyledir)
[irreco.git] / irreco / src / webdb / irreco_webdb_cache.c
blobb535370ddcd9ad362114d86f6a56fa2bab0c5784
1 /*
2 * irreco - Ir Remote Control
3 * Copyright (C) 2007,2008 Arto Karppinen (arto.karppinen@iki.fi),
4 * Joni Kokko (t5kojo01@students.oamk.fi),
5 * Sami Mäki (kasmra@xob.kapsi.fi),
6 * Harri Vattulainen (t5vaha01@students.oamk.fi),
7 * Pekka Gehör (pegu6@msn.com)
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 #include "irreco_webdb_cache.h"
25 #include "irreco_webdb_client.h"
27 /**
28 * @addtogroup IrrecoWebdbCache
29 * @ingroup IrrecoWebdb
31 * Caches XML-RPC calls, enables error handling and retries failed calls.
33 * @{
36 /**
37 * @file
38 * Source file of @ref IrrecoWebdbCache.
43 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
44 /* Prototypes */
45 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
47 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
48 /* Construction & Destruction */
49 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
51 /**
52 * @name Construction & Destruction
53 * @{
56 /**
57 * Create new IrrecoWebdb Object
59 IrrecoWebdbCache *irreco_webdb_cache_new()
61 IrrecoWebdbCache *self;
62 IRRECO_ENTER
64 self = g_slice_new0(IrrecoWebdbCache);
65 self->private = irreco_webdb_client_new();
66 self->error_msg = g_string_new("");
67 self->loop = irreco_retry_loop_new(IRRECO_SECONDS_TO_USEC(0.3),
68 IRRECO_SECONDS_TO_USEC(3));
69 self->conf_hash = g_hash_table_new_full(g_int_hash, g_int_equal, NULL,
70 (GDestroyNotify) irreco_webdb_conf_free);
72 self->theme_id_hash = g_hash_table_new_full(g_int_hash, g_int_equal, NULL,
73 (GDestroyNotify) irreco_webdb_theme_free);
75 IRRECO_RETURN_PTR(self);
78 /**
79 * Free resources of IrrecoWebdbCache Object.
81 void irreco_webdb_cache_free(IrrecoWebdbCache *self)
83 IRRECO_ENTER
84 g_string_free(self->error_msg, TRUE);
85 self->error_msg = NULL;
86 irreco_retry_loop_free(self->loop);
87 self->loop = NULL;
88 irreco_webdb_client_free(self->private);
89 self->private = NULL;
90 g_slice_free(IrrecoWebdbCache, self);
91 g_hash_table_destroy(self->conf_hash);
92 self->conf_hash = NULL;
93 g_hash_table_destroy(self->theme_id_hash);
94 self->theme_id_hash = NULL;
95 IRRECO_RETURN
98 /** @} */
100 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
101 /* Private Functions */
102 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
105 * @name Private Functions
106 * @{
110 * A simple test on Irreco WebDB to test if WebDB returns correct and
111 * meaningfull results.
113 * This function generates two numbers and asks WebDB to sum them. If the sum
114 * if correct, then our connection to the WebDB seems to be working.
116 * @return TRUE on success, FALSE otherwise.
118 static gboolean irreco_webdb_cache_test(IrrecoWebdbCache *self)
120 IrrecoWebdbClient *client;
121 GRand *rand;
122 gint32 num_a;
123 gint32 num_b;
124 gint sum;
125 IRRECO_ENTER
127 if (self->test_ok) IRRECO_RETURN_BOOL(self->test_ok);
129 rand = g_rand_new();
130 client = (IrrecoWebdbClient *) self->private;
132 IRRECO_RETRY_LOOP_START(self->loop)
133 num_a = g_rand_int_range(rand, 1, 1000);
134 num_b = g_rand_int_range(rand, 1, 1000);
135 self->test_ok = irreco_webdb_client_sum(
136 client, num_a, num_b, &sum);
138 if (self->test_ok) {
139 if (sum == num_a + num_b) {
140 break;
141 } else {
142 g_string_printf(self->error_msg,
143 "Got invalid result from "
144 "sum method. %i + %i = %i. "
145 "Expected %i.",
146 num_a, num_b, sum,
147 num_a + num_b);
148 IRRECO_PRINTF("%s\n", self->error_msg->str);
149 self->test_ok = FALSE;
151 } else {
152 irreco_webdb_client_get_error_msg(
153 client, self->error_msg);
155 IRRECO_RETRY_LOOP_END(self->loop)
157 g_rand_free(rand);
158 IRRECO_RETURN_BOOL(self->test_ok);
162 * Shows error message in case categories list is empty.
164 * @return TRUE if categories is not empty, FALSE otherwise.
166 static gboolean irreco_webdb_cache_verify_category(IrrecoWebdbCache *self)
168 IRRECO_ENTER
169 if (self->categories == NULL) {
170 g_string_printf(self->error_msg, "list of categories is NULL");
171 IRRECO_PRINTF("%s\n", self->error_msg->str);
172 IRRECO_RETURN_BOOL(FALSE)
174 IRRECO_RETURN_BOOL(TRUE)
178 * Shows error message in case manufacturers list is empty.
180 * @return TRUE if manufacturers list contains data, FALSE otherwise.
182 static gboolean
183 irreco_webdb_cache_verify_manufacturer(IrrecoWebdbCache *self,
184 const gchar *category,
185 IrrecoStringTable **manufactures)
187 IRRECO_ENTER
188 if (!irreco_string_table_get(self->categories, category,
189 (gpointer*) manufactures)) {
190 g_string_printf(self->error_msg,
191 "list of manufacturers is NULL");
192 IRRECO_PRINTF("%s\n", self->error_msg->str);
193 IRRECO_RETURN_BOOL(FALSE)
195 IRRECO_RETURN_BOOL(TRUE)
200 * Shows error message in case models list is empty.
202 * @return TRUE if models list contains data, FALSE otherwise.
204 static gboolean irreco_webdb_cache_verify_model(IrrecoWebdbCache *self,
205 IrrecoStringTable *manuf_list,
206 const gchar *manufacturer,
207 IrrecoStringTable **models)
209 IRRECO_ENTER
210 if (!irreco_string_table_get(manuf_list, manufacturer,
211 (gpointer*) models)) {
212 g_string_printf(self->error_msg, "list of models is NULL");
213 IRRECO_PRINTF("%s\n", self->error_msg->str);
214 IRRECO_RETURN_BOOL(FALSE)
216 IRRECO_RETURN_BOOL(TRUE)
220 * Shows error message in case configurations list is empty.
222 * @return TRUE if configurations list contains data, FALSE otherwise.
224 static gboolean irreco_webdb_cache_verify_config(IrrecoWebdbCache *self,
225 IrrecoStringTable *models,
226 const gchar *model,
227 IrrecoStringTable **configs)
229 IRRECO_ENTER
230 if (!irreco_string_table_get(models, model, (gpointer*) configs)) {
231 g_string_printf(self->error_msg,
232 "list of configurations is NULL");
233 IRRECO_PRINTF("%s\n", self->error_msg->str);
234 IRRECO_RETURN_BOOL(FALSE)
236 IRRECO_RETURN_BOOL(TRUE)
239 /** @} */
241 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
242 /* Functions */
243 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
246 * @name Public Functions
247 * @{
252 * Adds new user (name, email, password) to database.
254 * @return TRUE if user is added succesfully, FALSE otherwise.
256 gboolean irreco_webdb_cache_add_user(IrrecoWebdbCache *self,
257 const gchar *name,
258 const gchar *email,
259 const gchar *passwd)
261 IrrecoWebdbClient *client;
263 IRRECO_ENTER
265 client = (IrrecoWebdbClient *) self->private;
267 IRRECO_RETRY_LOOP_START(self->loop)
268 /* test connection to webdb */
269 if (irreco_webdb_cache_test(self) == FALSE){
270 g_string_printf(self->error_msg,
271 "Failed cache self test.");
272 IRRECO_PRINTF("%s\n", self->error_msg->str);
273 IRRECO_RETURN_BOOL(FALSE);
276 if(irreco_webdb_client_add_user(client, name, email, passwd)) {
277 IRRECO_RETURN_BOOL(TRUE);
278 } else {
279 /* irreco_webdb_client_add_user failed, get err msg */
280 irreco_webdb_client_get_error_msg(client,
281 self->error_msg);
282 IRRECO_RETURN_BOOL(FALSE);
284 IRRECO_RETRY_LOOP_END(self->loop)
286 IRRECO_RETURN_BOOL(FALSE);
290 * Adds new configuration to database.
292 * @return TRUE if configuration is uploaded succesfully, FALSE otherwise.
294 gboolean irreco_webdb_cache_upload_configuration(IrrecoWebdbCache *self,
295 const gchar *backend,
296 const gchar *category,
297 const gchar *file_hash,
298 const gchar *file_name,
299 const gchar *manufacturer,
300 const gchar *model,
301 const gchar *password,
302 const gchar *user,
303 const gchar *data)
305 IrrecoWebdbClient *client;
307 IRRECO_ENTER
309 client = (IrrecoWebdbClient *) self->private;
311 IRRECO_RETRY_LOOP_START(self->loop)
312 /* test connection to webdb */
313 if (irreco_webdb_cache_test(self) == FALSE){
314 g_string_printf(self->error_msg,
315 "Failed cache self test.");
316 IRRECO_PRINTF("%s\n", self->error_msg->str);
317 IRRECO_RETURN_BOOL(FALSE);
320 if(irreco_webdb_client_upload_configuration(client, backend,
321 category, file_hash, file_name,
322 manufacturer, model, password, user,
323 data)) {
325 IRRECO_RETURN_BOOL(TRUE);
326 } else {
327 /* irreco_webdb_client_upload_configuration failed,
328 get err msg */
329 irreco_webdb_client_get_error_msg(client,
330 self->error_msg);
331 IRRECO_RETURN_BOOL(FALSE);
333 IRRECO_RETRY_LOOP_END(self->loop)
335 IRRECO_RETURN_BOOL(FALSE);
339 * Extracts error message from IrrecoWebdbCache object.
341 * @return error message as string.
343 const gchar *irreco_webdb_cache_get_error(IrrecoWebdbCache *self)
345 IRRECO_ENTER
346 IRRECO_RETURN_STR(self->error_msg->str);
350 * Fetches categories from DB
352 * @return TRUE if categories are fetched succesfully, FALSE otherwise.
354 gboolean irreco_webdb_cache_get_categories(IrrecoWebdbCache *self,
355 IrrecoStringTable **categories)
357 IRRECO_ENTER
359 if (self->categories == NULL) {
360 gboolean success = FALSE;
361 IrrecoWebdbClient *client = (IrrecoWebdbClient *) self->private;
363 IRRECO_RETRY_LOOP_START(self->loop)
364 if (irreco_webdb_cache_test(self) == FALSE) break;
365 success = irreco_webdb_client_get_categories(
366 client, &self->categories);
367 if (success) {
368 break;
370 irreco_webdb_client_get_error_msg(
371 client, self->error_msg);
372 IRRECO_RETRY_LOOP_END(self->loop)
374 if (success == FALSE) IRRECO_RETURN_BOOL(FALSE);
376 irreco_string_table_sort_abc (self->categories);
379 *categories = self->categories;
380 IRRECO_RETURN_BOOL(TRUE)
384 * Fetches all categories from DB.
386 * @param all_categories must be freed if return value is TRUE.
387 * @return TRUE if categories are fetched succesfully, FALSE otherwise.
389 gboolean irreco_webdb_cache_get_all_categories(IrrecoWebdbCache *self,
390 IrrecoStringTable **all_categories)
392 gboolean success = FALSE;
393 IrrecoWebdbClient *client = (IrrecoWebdbClient *) self->private;
394 IRRECO_ENTER
397 IRRECO_RETRY_LOOP_START(self->loop)
398 if (irreco_webdb_cache_test(self) == FALSE) break;
399 success = irreco_webdb_client_get_all_categories(
400 client, all_categories);
401 if (success) {
402 break;
404 irreco_webdb_client_get_error_msg(
405 client, self->error_msg);
406 IRRECO_RETRY_LOOP_END(self->loop)
408 if (success == FALSE) IRRECO_RETURN_BOOL(FALSE);
410 irreco_string_table_sort_abc(*all_categories);
412 IRRECO_RETURN_BOOL(TRUE)
416 * Fetches manufacturers from DB.
418 * @param category contains category in which type manufacturers are returned.
419 * @return TRUE if manufacturers are fetched succesfully, FALSE otherwise.
421 gboolean irreco_webdb_cache_get_manufacturers(IrrecoWebdbCache *self,
422 const gchar *category,
423 IrrecoStringTable **manufacturers)
425 IrrecoStringTable *manufacturer_list;
426 IRRECO_ENTER
428 if (!irreco_webdb_cache_verify_category(self) ||
429 !irreco_webdb_cache_verify_manufacturer(self, category,
430 &manufacturer_list)) {
431 IRRECO_RETURN_BOOL(FALSE)
434 if(manufacturer_list == NULL) {
435 gboolean success = FALSE;
436 IrrecoWebdbClient *client = (IrrecoWebdbClient *) self->private;
438 IRRECO_RETRY_LOOP_START(self->loop)
439 if (irreco_webdb_cache_test(self) == FALSE) break;
440 success = irreco_webdb_client_get_manufacturers(
441 client, category, &manufacturer_list);
443 if (success) break;
444 irreco_webdb_client_get_error_msg(
445 client, self->error_msg);
446 IRRECO_RETRY_LOOP_END(self->loop)
448 if (success == FALSE) IRRECO_RETURN_BOOL(FALSE);
450 irreco_string_table_sort_abc (manufacturer_list);
451 irreco_string_table_change_data(self->categories, category,
452 manufacturer_list);
455 irreco_string_table_get(self->categories, category,
456 (gpointer *) manufacturers);
457 IRRECO_RETURN_BOOL(TRUE)
461 * Fetches all manufacturers from DB.
463 * @param all_manufacturers must be released if function returns TRUE.
464 * @return TRUE if manufacturers are fetched succesfully, FALSE otherwise.
466 gboolean irreco_webdb_cache_get_all_manufacturers(IrrecoWebdbCache *self,
467 IrrecoStringTable **all_manufacturers)
469 gboolean success = FALSE;
470 IrrecoWebdbClient *client = (IrrecoWebdbClient *) self->private;
471 IRRECO_ENTER
474 IRRECO_RETRY_LOOP_START(self->loop)
475 if (irreco_webdb_cache_test(self) == FALSE) break;
476 success = irreco_webdb_client_get_all_manufacturers(
477 client, all_manufacturers);
478 if (success) {
479 break;
481 irreco_webdb_client_get_error_msg(
482 client, self->error_msg);
483 IRRECO_RETRY_LOOP_END(self->loop)
485 if (success == FALSE) IRRECO_RETURN_BOOL(FALSE);
487 irreco_string_table_sort_abc(*all_manufacturers);
489 IRRECO_RETURN_BOOL(TRUE)
493 * Fetches models belonging given category and manufacturer.
495 * @param models must be freed if function returns TRUE.
496 * @return TRUE if models are fetched succesfully, FALSE otherwise.
498 gboolean irreco_webdb_cache_get_models(IrrecoWebdbCache *self,
499 const gchar *category,
500 const gchar *manufacturer,
501 IrrecoStringTable **models)
503 IrrecoStringTable *model_list;
504 IrrecoStringTable *manufacturer_list;
505 IRRECO_ENTER
507 if (!irreco_webdb_cache_verify_category(self) ||
508 !irreco_webdb_cache_verify_manufacturer(self, category,
509 &manufacturer_list) ||
510 !irreco_webdb_cache_verify_model(self, manufacturer_list,
511 manufacturer, &model_list)) {
512 IRRECO_RETURN_BOOL(FALSE)
515 if(model_list == NULL) {
516 gboolean success = FALSE;
517 IrrecoWebdbClient *client = (IrrecoWebdbClient *) self->private;
519 IRRECO_RETRY_LOOP_START(self->loop)
520 if (irreco_webdb_cache_test(self) == FALSE) break;
521 success = irreco_webdb_client_get_models(
522 client, category, manufacturer, &model_list);
524 if (success) break;
525 irreco_webdb_client_get_error_msg(
526 client, self->error_msg);
527 IRRECO_RETRY_LOOP_END(self->loop)
529 if (success == FALSE) IRRECO_RETURN_BOOL(FALSE);
531 irreco_string_table_sort_abc (model_list);
532 irreco_string_table_change_data(manufacturer_list, manufacturer,
533 model_list);
536 irreco_string_table_get(manufacturer_list, manufacturer,
537 (gpointer *) models);
538 IRRECO_RETURN_BOOL(TRUE)
542 * Fetches configs belonging given category, manufacturer and model.
544 * @return TRUE if configs are fetched succesfully, FALSE otherwise.
546 gboolean irreco_webdb_cache_get_configs(IrrecoWebdbCache *self,
547 const gchar *category,
548 const gchar *manufacturer,
549 const gchar *model,
550 IrrecoStringTable **configs)
552 IrrecoStringTable * config_list;
553 IrrecoStringTable * model_list;
554 IrrecoStringTable * manufacturer_list;
555 IRRECO_ENTER
557 if (!irreco_webdb_cache_verify_category(self) ||
558 !irreco_webdb_cache_verify_manufacturer(self, category,
559 &manufacturer_list) ||
560 !irreco_webdb_cache_verify_model(self, manufacturer_list,
561 manufacturer, &model_list) ||
562 !irreco_webdb_cache_verify_config(self, model_list, model,
563 &config_list)) {
564 IRRECO_RETURN_BOOL(FALSE)
567 if(config_list == NULL) {
568 gboolean success = FALSE;
569 IrrecoWebdbClient *client = (IrrecoWebdbClient *) self->private;
571 IRRECO_RETRY_LOOP_START(self->loop)
572 if (irreco_webdb_cache_test(self) == FALSE) break;
573 success = irreco_webdb_client_get_configs(client,
574 category, manufacturer, model, &config_list);
576 if (success) break;
577 irreco_webdb_client_get_error_msg(
578 client, self->error_msg);
579 IRRECO_RETRY_LOOP_END(self->loop)
581 if (success == FALSE) IRRECO_RETURN_BOOL(FALSE);
583 irreco_string_table_change_data(model_list, model, config_list);
586 irreco_string_table_get(model_list, model, (gpointer *) configs);
587 IRRECO_RETURN_BOOL(TRUE)
591 * Fetches configuration by given ID.
593 * @return TRUE if configuration is fetched succesfully, FALSE otherwise.
595 gboolean irreco_webdb_cache_get_configuration(IrrecoWebdbCache *self,
596 gint id,
597 IrrecoWebdbConf **config)
599 IrrecoWebdbConf * configuration;
600 IRRECO_ENTER
602 if (g_hash_table_lookup(self->conf_hash, (gconstpointer) &id) == NULL) {
603 gboolean success = FALSE;
604 IrrecoWebdbClient *client = (IrrecoWebdbClient *) self->private;
606 IRRECO_RETRY_LOOP_START(self->loop)
607 if (irreco_webdb_cache_test(self) == FALSE) break;
608 success = irreco_webdb_client_get_configuration(
609 client, id, &configuration);
611 if (success) break;
612 irreco_webdb_client_get_error_msg(client,
613 self->error_msg);
614 IRRECO_RETRY_LOOP_END(self->loop)
616 if (success == FALSE) IRRECO_RETURN_BOOL(FALSE);
618 g_hash_table_insert(self->conf_hash,
619 (gpointer) &configuration->id,
620 (gpointer) configuration);
623 *config = g_hash_table_lookup(self->conf_hash, (gconstpointer) &id);
625 IRRECO_RETURN_BOOL(TRUE)
629 * Fetches file by given hash and name.
631 * @return TRUE if configuration is fetched succesfully, FALSE otherwise.
633 gboolean irreco_webdb_cache_get_file(IrrecoWebdbCache *self,
634 const gchar *file_hash,
635 const gchar *file_name,
636 GString **file_data)
638 GString *file;
639 gboolean success = FALSE;
640 IrrecoWebdbClient *client;
641 IRRECO_ENTER
643 client = (IrrecoWebdbClient *) self->private;
645 IRRECO_RETRY_LOOP_START(self->loop)
646 if (irreco_webdb_cache_test(self) == FALSE) break;
647 success = irreco_webdb_client_get_file(
648 client, file_hash, file_name, &file);
650 if (success) break;
651 irreco_webdb_client_get_error_msg(client, self->error_msg);
652 IRRECO_RETRY_LOOP_END(self->loop)
654 if (success == FALSE) IRRECO_RETURN_BOOL(FALSE);
656 *file_data = file;
658 IRRECO_RETURN_BOOL(TRUE)
662 * Check if user with given name is already at DB.
664 *.@param user_exists will contain info wether user name was at DB.
665 * @return TRUE if test is done succesfully, FALSE otherwise.
667 gboolean irreco_webdb_cache_get_user_exists(IrrecoWebdbCache *self,
668 const gchar *name,
669 gboolean *user_exists)
671 IrrecoWebdbClient *client;
672 gboolean success = FALSE;
674 IRRECO_ENTER
675 client = (IrrecoWebdbClient *) self->private;
676 IRRECO_RETRY_LOOP_START(self->loop)
677 /* test connection to webdb */
678 if (irreco_webdb_cache_test(self) == FALSE) break;
680 success = irreco_webdb_client_get_user_exists(client,
681 name,
682 user_exists);
684 if (success) break;
686 /* irreco_webdb_client_get_user_exists failed, get err msg */
687 irreco_webdb_client_get_error_msg(client, self->error_msg);
688 IRRECO_RETRY_LOOP_END(self->loop)
690 if (success == FALSE) IRRECO_RETURN_BOOL(FALSE);
692 IRRECO_RETURN_BOOL(TRUE)
696 * Login to database.
698 * @return TRUE if login is succesful, FALSE otherwise.
700 gboolean irreco_webdb_cache_login(IrrecoWebdbCache *self,
701 const gchar *user,
702 const gchar *password)
704 IrrecoWebdbClient *client;
706 IRRECO_ENTER
708 client = (IrrecoWebdbClient *) self->private;
710 IRRECO_RETRY_LOOP_START(self->loop)
711 /* test connection to webdb */
712 if (irreco_webdb_cache_test(self) == FALSE){
713 g_string_printf(self->error_msg,
714 "Failed cache self test.");
715 IRRECO_PRINTF("%s\n", self->error_msg->str);
716 IRRECO_RETURN_BOOL(FALSE);
719 if(irreco_webdb_client_login(client, user, password)) {
721 IRRECO_RETURN_BOOL(TRUE);
722 } else {
723 /* irreco_webdb_client_login failed,
724 get err msg */
725 irreco_webdb_client_get_error_msg(client,
726 self->error_msg);
727 IRRECO_RETURN_BOOL(FALSE);
729 IRRECO_RETRY_LOOP_END(self->loop)
731 IRRECO_RETURN_BOOL(FALSE);
734 gboolean irreco_webdb_cache_get_themes(IrrecoWebdbCache *self,
735 IrrecoStringTable **theme)
737 gboolean success = FALSE;
738 IrrecoWebdbClient *client = (IrrecoWebdbClient *) self->private;
739 IRRECO_ENTER
741 IRRECO_RETRY_LOOP_START(self->loop)
742 if (irreco_webdb_cache_test(self) == FALSE) break;
743 success = irreco_webdb_client_get_themes(client, theme);
745 if (success) break;
746 irreco_webdb_client_get_error_msg(client, self->error_msg);
747 IRRECO_RETRY_LOOP_END(self->loop)
749 IRRECO_RETURN_BOOL(success)
752 gboolean irreco_webdb_cache_get_theme_by_id(IrrecoWebdbCache *self,
753 gint theme_id,
754 IrrecoWebdbTheme **theme)
756 IrrecoWebdbTheme *get_theme;
757 IRRECO_ENTER
760 if (g_hash_table_lookup(self->theme_id_hash,
761 (gconstpointer) &theme_id) == NULL) {
762 gboolean success = FALSE;
763 IrrecoWebdbClient *client = (IrrecoWebdbClient *) self->private;
765 IRRECO_RETRY_LOOP_START(self->loop)
766 if (irreco_webdb_cache_test(self) == FALSE) break;
767 success = irreco_webdb_client_get_theme_by_id(
768 client, theme_id, &get_theme);
770 if (success) break;
771 irreco_webdb_client_get_error_msg(client,
772 self->error_msg);
773 IRRECO_RETRY_LOOP_END(self->loop)
775 if (success == FALSE) IRRECO_RETURN_BOOL(FALSE);
777 g_hash_table_insert(self->theme_id_hash,
778 (gpointer) &get_theme->id,
779 (gpointer) get_theme);
782 *theme = g_hash_table_lookup(self->theme_id_hash, (gconstpointer) &theme_id);
784 IRRECO_RETURN_BOOL(TRUE)
789 gboolean irreco_webdb_cache_get_preview_button(IrrecoWebdbCache *self,
790 gint theme_id,
791 IrrecoWebdbTheme **theme)
793 gboolean success = TRUE;
794 IrrecoWebdbClient *client = (IrrecoWebdbClient *) self->private;
795 IRRECO_ENTER
797 *theme = g_hash_table_lookup(self->theme_id_hash,
798 (gconstpointer) &theme_id);
799 if (*theme == NULL) {
800 success = irreco_webdb_cache_get_theme_by_id(self, theme_id,
801 theme);
802 if (success == FALSE) {
803 irreco_webdb_client_get_error_msg(client, self->error_msg);
804 goto end;
808 if ((*theme)->preview_button == NULL)
810 IRRECO_RETRY_LOOP_START(self->loop)
812 if (irreco_webdb_cache_test(self) == FALSE) break;
814 success = irreco_webdb_client_get_preview_button(client,
815 theme_id, &(*theme)->preview_button);
817 if (success) break;
819 irreco_webdb_client_get_error_msg(client, self->error_msg);
820 IRRECO_RETRY_LOOP_END(self->loop)
823 end:
825 IRRECO_RETURN_BOOL(success)
828 gboolean irreco_webdb_cache_get_backgrounds(IrrecoWebdbCache *self,
829 gint theme_id,
830 IrrecoStringTable **bg_list){
831 IrrecoWebdbClient *client;
832 gboolean success = TRUE;
833 IRRECO_ENTER
835 client = (IrrecoWebdbClient *) self->private;
836 IRRECO_RETRY_LOOP_START(self->loop)
837 if (irreco_webdb_cache_test(self) == FALSE) break;
838 success = irreco_webdb_client_get_backgrounds(client,
839 theme_id,
840 bg_list);
841 if (success) break;
842 irreco_webdb_client_get_error_msg(client, self->error_msg);
843 IRRECO_RETRY_LOOP_END(self->loop)
845 IRRECO_RETURN_BOOL(success)
848 gboolean irreco_webdb_cache_get_bg_by_id(IrrecoWebdbCache *self,
849 gint bg_id,
850 const char *theme_bg_dir)
852 IrrecoWebdbClient *client = (IrrecoWebdbClient *) self->private;
853 gboolean success = TRUE;
854 IRRECO_ENTER
856 IRRECO_RETRY_LOOP_START(self->loop)
857 if (irreco_webdb_cache_test(self) == FALSE) break;
858 success = irreco_webdb_client_get_bg_by_id(client,
859 bg_id,
860 theme_bg_dir);
861 if (success) break;
862 irreco_webdb_client_get_error_msg(client, self->error_msg);
863 IRRECO_RETRY_LOOP_END(self->loop)
864 IRRECO_RETURN_BOOL(success)
867 gboolean irreco_webdb_cache_get_buttons(IrrecoWebdbCache *self,
868 gint theme_id,
869 IrrecoStringTable **button_list)
871 IrrecoWebdbClient *client = (IrrecoWebdbClient *) self->private;
872 gboolean success = TRUE;
873 IRRECO_ENTER
875 IRRECO_RETRY_LOOP_START(self->loop)
876 if (irreco_webdb_cache_test(self) == FALSE) break;
877 success = irreco_webdb_client_get_buttons(client,
878 theme_id,
879 button_list);
880 if (success) break;
881 irreco_webdb_client_get_error_msg(client, self->error_msg);
882 IRRECO_RETRY_LOOP_END(self->loop)
883 IRRECO_RETURN_BOOL(success)
886 gboolean irreco_webdb_cache_get_button_by_id(IrrecoWebdbCache *self,
887 gint button_id,
888 const char *theme_button_dir)
890 IrrecoWebdbClient *client = (IrrecoWebdbClient *) self->private;
891 gboolean success = TRUE;
892 IRRECO_ENTER
894 IRRECO_RETRY_LOOP_START(self->loop)
895 if (irreco_webdb_cache_test(self) == FALSE) break;
896 success = irreco_webdb_client_get_button_by_id(client,
897 button_id,
898 theme_button_dir);
899 if (success) break;
900 irreco_webdb_client_get_error_msg(client, self->error_msg);
901 IRRECO_RETRY_LOOP_END(self->loop)
903 IRRECO_RETURN_BOOL(success)
907 /** @} */
909 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
910 /* Events and Callbacks */
911 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
913 /** @} */