fixed problem that disappears configurations and themes.
[irreco.git] / irreco / src / webdb / irreco_webdb_remote.c
blob2446b3f1227a80be174c95c4b6cebcaf8a1682dd
1 /*
2 * irreco - Ir Remote Control
3 * Copyright (C) 2008 Joni Kokko (t5kojo01@students.oamk.fi)
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #include "irreco_webdb_remote.h"
22 /**
23 * @addtogroup IrrecoWebdbRemote
24 * @ingroup IrrecoWebdb
26 * Contains information of remote.
28 * @{
31 /**
32 * @file
33 * Source file of @ref IrrecoWebdbRemote.
36 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
37 /* Prototypes */
38 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
40 /**
41 * @name Construction & Destruction
42 * @{
45 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
46 /* Construction & Destruction */
47 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
48 IrrecoWebdbRemote *irreco_webdb_remote_new()
50 IrrecoWebdbRemote *self;
51 IRRECO_ENTER
53 self = g_slice_new0(IrrecoWebdbRemote);
55 self->id = 0;
56 self->name = g_string_new("");
57 self->creator = g_string_new("");
58 self->comment = g_string_new("");
59 self->category = g_string_new("");
60 self->manufacturer = g_string_new("");
61 self->model = g_string_new("");
62 self->file_hash = g_string_new("");
63 self->file_name = g_string_new("");
64 self->uploaded = g_string_new("");
65 self->modified = g_string_new("");
66 self->downloaded = g_string_new("");
67 self->download_count = 0;
69 self->configurations = NULL;
71 self->themes = NULL;
73 IRRECO_RETURN_PTR(self);
76 void irreco_webdb_remote_free(IrrecoWebdbRemote *self)
78 IRRECO_ENTER
80 g_assert(self != NULL);
82 g_string_free(self->name, TRUE);
83 self->name = NULL;
85 g_string_free(self->creator, TRUE);
86 self->creator = NULL;
88 g_string_free(self->comment, TRUE);
89 self->comment = NULL;
91 g_string_free(self->category, TRUE);
92 self->category = NULL;
94 g_string_free(self->manufacturer, TRUE);
95 self->manufacturer = NULL;
97 g_string_free(self->model, TRUE);
98 self->model = NULL;
100 g_string_free(self->file_hash, TRUE);
101 self->file_hash = NULL;
103 g_string_free(self->file_name, TRUE);
104 self->file_name = NULL;
106 g_string_free(self->uploaded, TRUE);
107 self->uploaded = NULL;
109 g_string_free(self->modified, TRUE);
110 self->modified = NULL;
112 g_string_free(self->downloaded, TRUE);
113 self->downloaded = NULL;
115 if (self->configurations != NULL) {
116 g_list_free(self->configurations);
117 self->configurations = NULL;
119 if (self->themes != NULL) {
120 g_list_free(self->themes);
121 self->themes = NULL;
124 g_slice_free(IrrecoWebdbRemote, self);
125 self = NULL;
127 IRRECO_RETURN
130 /** @} */
132 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
133 /* Private Functions */
134 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
137 * @name Public Functions
138 * @{
142 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
143 /* Functions */
144 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
146 void irreco_webdb_remote_set(IrrecoWebdbRemote *self,
147 gint id,
148 const char *name,
149 const char *creator,
150 const char *comment,
151 const char *category,
152 const char *manufacturer,
153 const char *model,
154 const char *file_hash,
155 const char *file_name,
156 const char *uploaded,
157 const char *modified,
158 const char *downloaded,
159 gint download_count)
161 IRRECO_ENTER
163 g_assert(self != NULL);
165 self->id = id;
166 g_string_printf(self->name, "%s", name);
167 g_string_printf(self->creator, "%s", creator);
168 g_string_printf(self->comment, "%s", comment);
169 g_string_printf(self->category, "%s", category);
170 g_string_printf(self->manufacturer, "%s", manufacturer);
171 g_string_printf(self->model, "%s", model);
172 g_string_printf(self->file_hash, "%s", file_hash);
173 g_string_printf(self->file_name, "%s", file_name);
174 g_string_printf(self->uploaded, "%s", uploaded);
175 g_string_printf(self->modified, "%s", modified);
176 g_string_printf(self->downloaded, "%s", downloaded);
177 self->download_count = download_count;
179 IRRECO_RETURN
182 void irreco_webdb_remote_add_configuration_id(IrrecoWebdbRemote *self, gint id)
184 IRRECO_ENTER
186 g_assert(self != NULL);
188 self->configurations = g_list_append(self->configurations,
189 GINT_TO_POINTER(id));
191 self->configurations = g_list_first(self->configurations);
193 IRRECO_RETURN
196 void irreco_webdb_remote_add_theme_id(IrrecoWebdbRemote *self, gint id)
198 IRRECO_ENTER
200 g_assert(self != NULL);
202 self->themes = g_list_append(self->themes, GINT_TO_POINTER(id));
204 self->themes = g_list_first(self->themes);
206 IRRECO_RETURN
209 void irreco_webdb_remote_print(IrrecoWebdbRemote *self)
211 GList *configurations;
212 GList *themes;
213 IRRECO_ENTER
215 g_assert(self != NULL);
217 IRRECO_PRINTF("ID: %d\n", self->id);
218 IRRECO_PRINTF("Name: %s\n", self->name->str);
219 IRRECO_PRINTF("Creator: %s\n", self->creator->str);
220 IRRECO_PRINTF("Comment: %s\n", self->comment->str);
221 IRRECO_PRINTF("Category: %s\n", self->category->str);
222 IRRECO_PRINTF("Manufacturer: %s\n", self->manufacturer->str);
223 IRRECO_PRINTF("Model: %s\n", self->model->str);
224 IRRECO_PRINTF("File hash: %s\n", self->file_hash->str);
225 IRRECO_PRINTF("File name: %s\n", self->file_name->str);
226 IRRECO_PRINTF("Uploaded: %s\n", self->uploaded->str);
227 IRRECO_PRINTF("Modified: %s\n", self->modified->str);
228 IRRECO_PRINTF("Last download: %s\n", self->downloaded->str);
229 IRRECO_PRINTF("Download_count: %d\n", self->download_count);
231 configurations = g_list_first(self->configurations);
232 if (configurations != NULL) IRRECO_PRINTF("Configurations:");
233 while(configurations) {
234 g_print(" (%d)", GPOINTER_TO_INT(configurations->data));
236 configurations = configurations->next;
239 themes = g_list_first(self->themes);
240 if (themes != NULL) IRRECO_PRINTF("Themes:");
241 while(themes) {
242 g_print(" (%d)", GPOINTER_TO_INT(themes->data));
244 themes = themes->next;
246 g_print("\n");
248 IRRECO_RETURN
251 /** @} */
253 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
254 /* Events and Callbacks */
255 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
257 /** @} */