fixed time to change image, added icons to slideshow and flash, added change image...
[livewp] / applet / src / livewp-config.c
1 /* vim: set sw=4 ts=4 et: */
2 /*
3  * This file is part of Live Wallpaper (livewp)
4  *
5  * Copyright (C) 2010 Vlad Vasiliev
6  * Copyright (C) 2010 Tanya Makova
7  *       for the code
8  *
9  * This software 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 of
12  * the License, or (at your option) any later version.
13  *
14  * This software is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this software; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22  * 02110-1301 USA
23 */
24 /*******************************************************************************/
25 #include "livewp-config.h"
26 /*******************************************************************************/
27 gint
28 current_active_view(void){
29     GConfClient *gconf_client = NULL;
30     gint result = -1;
31
32     gconf_client = gconf_client_get_default();
33     if (!gconf_client) {
34         fprintf(stderr, _("Failed to initialize GConf. Quitting.\n"));
35         return result;
36     }
37     result = gconf_client_get_int(gconf_client, "/apps/osso/hildon-desktop/views/current", NULL);
38
39     return result;
40 }
41
42 /*******************************************************************************/
43 #ifdef APPLICATION
44 void
45 fill_priv(Animation_WallpaperPrivate *priv)
46 {
47     /* Reset data */
48     priv->hash_theme = NULL;
49     /* Load config */
50     read_config(priv);
51     /* Set function */
52     if (!strcmp(priv->theme, "Accel"))
53         priv->scene_func = (gpointer)&init_scene_Accel;
54     if (!strcmp(priv->theme, "Berlin"))
55         priv->scene_func = (gpointer)&init_scene_Berlin;
56     if (!strcmp(priv->theme, "Modern"))
57         priv->scene_func = (gpointer)&init_scene_Modern;
58     if (!strcmp(priv->theme, "Matrix"))
59         priv->scene_func = (gpointer)&init_scene_Matrix;
60     if (!strcmp(priv->theme, "Video"))
61         priv->scene_func = (gpointer)&init_scene_Video;
62     if (!strcmp(priv->theme, "Slideshow"))
63         priv->scene_func = (gpointer)&init_scene_Slideshow;
64
65     priv->extheme_list = get_list_exthemes();
66     GSList *store = priv->extheme_list;
67     while (store){
68         if (!strcmp(priv->theme, g_hash_table_lookup(store->data, "name"))){
69             /* Default function for external themes init_scene_External */
70             if (priv->scene_func)
71                 priv->scene_func = (gpointer)&init_scene_External;
72             if (!strcmp(priv->theme, "Conky"))
73                 priv->scene_func = (gpointer)&init_scene_Conky;
74             if (!strcmp(priv->theme, "Flash"))
75                 priv->scene_func = (gpointer)&init_scene_Flash;
76             priv->hash_theme = store->data;
77             break;
78         }
79         store = g_slist_next(store);
80     }
81
82 }
83 #endif
84 /*******************************************************************************/
85 gint
86 read_config(Animation_WallpaperPrivate *priv) {
87
88     GConfClient *gconf_client = NULL;
89     gchar *tmp = NULL;
90     GConfValue *value = NULL;
91     gint id = priv->view;
92     gchar * str = NULL;
93
94     gconf_client = gconf_client_get_default();
95     if (!gconf_client) {
96         fprintf(stderr, _("Failed to initialize GConf. Quitting.\n"));
97         return -1;
98     }
99     /* get Theme default Modern */
100     str = g_strdup_printf("%s%i", GCONF_KEY_THEME, id);
101     tmp = gconf_client_get_string(gconf_client,
102                                   str, NULL);
103     if (str){
104         g_free(str);
105         str = NULL;
106     }
107     if (tmp){
108         priv->theme = tmp;
109     }else
110         priv->theme = g_strdup("Modern");
111     /* get Rich animation default TRUE */
112     str = g_strdup_printf("%s%i", GCONF_KEY_RANIMATION, id);
113     value = gconf_client_get(gconf_client, str, NULL);
114     if (str){
115         g_free(str);
116         str = NULL;
117     }
118     if (value) {
119         priv->rich_animation = gconf_value_get_bool(value);
120         gconf_value_free(value);
121     } else
122         priv->rich_animation = TRUE;
123     /* get theme additional bool aparametr 1 default  TRUE */
124     str = g_strdup_printf("%s%i", GCONF_KEY_ADDITIONAL_BOOL_1, id);
125     value = gconf_client_get(gconf_client, str, NULL);
126     if (str){
127         g_free(str);
128         str = NULL;
129     }
130     if (value) {
131         priv->theme_bool_parametr1 = gconf_value_get_bool(value);
132         gconf_value_free(value);
133     } else
134        priv->theme_bool_parametr1= TRUE;
135
136     /* get theme additional parameter 1  */
137     str = g_strdup_printf("%s%i", GCONF_KEY_ADDITIONAL_STRING_1 , id);
138     value = gconf_client_get(gconf_client, str, NULL);
139     if (str){
140         g_free(str);
141         str = NULL;
142     }
143     if (value) {
144         priv->theme_string_parametr1 = g_strdup(gconf_value_get_string(value));
145         gconf_value_free(value);
146     }
147     /* get theme additional int parameter 1  */
148     str = g_strdup_printf("%s%i", GCONF_KEY_ADDITIONAL_INT_1 , id);
149     value = gconf_client_get(gconf_client, str, NULL);
150     if (str){
151         g_free(str);
152         str = NULL;
153     }
154     if (value) {
155         priv->theme_int_parametr1 = gconf_value_get_int(value);
156         gconf_value_free(value);
157     }
158
159     /* get parameter one theme in all view */
160     priv->one_in_all_view = get_one_in_all_views_from_config();
161     return 0;
162 }
163 /*******************************************************************************/
164 gboolean
165 get_one_in_all_views_from_config(void){
166     GConfClient *gconf_client;
167     GConfValue *value = NULL;
168     gboolean result;
169
170     gconf_client = gconf_client_get_default();
171     if (!gconf_client) {
172         fprintf(stderr, _("Failed to initialize GConf. Quitting.\n"));
173         return FALSE;
174     }
175     /* get parameter one theme in all view */
176     value = gconf_client_get(gconf_client, GCONF_KEY_ONE_IN_ALL_VIEW, NULL);
177     if (value) {
178         result = gconf_value_get_bool(value);
179         gconf_value_free(value);
180     } else
181         result = FALSE;
182     return result;
183 }
184 /*******************************************************************************/
185 void
186 save_one_in_all_views_to_config(gboolean one_in_all_views){
187     GConfClient *gconf_client;
188
189     gconf_client = gconf_client_get_default();
190     if (!gconf_client) {
191         fprintf(stderr, _("Failed to initialize GConf. Quitting.\n"));
192         return;
193     }
194
195     if (one_in_all_views)
196         gconf_client_set_bool(gconf_client,
197                               GCONF_KEY_ONE_IN_ALL_VIEW, TRUE, NULL);
198     else
199         gconf_client_set_bool(gconf_client,
200                               GCONF_KEY_ONE_IN_ALL_VIEW, FALSE, NULL);
201
202 }
203 /*******************************************************************************/
204 void
205 save_config(Animation_WallpaperPrivate *priv) {
206
207     GConfClient *gconf_client;
208     gchar * str = NULL;
209     gint id = priv->view;
210
211     gconf_client = gconf_client_get_default();
212     if (!gconf_client) {
213         fprintf(stderr, _("Failed to initialize GConf. Quitting.\n"));
214         return;
215     }
216
217     if (priv->theme){
218         str = g_strdup_printf("%s%i", GCONF_KEY_THEME, id);
219         gconf_client_set_string(gconf_client,
220                   str,
221                   priv->theme, NULL);
222         if (str){
223             g_free(str);
224             str = NULL;
225         }
226     }
227
228     str = g_strdup_printf("%s%i", GCONF_KEY_RANIMATION, id);
229     if (priv->rich_animation)
230         gconf_client_set_bool(gconf_client,
231                               str, TRUE, NULL);
232     else
233         gconf_client_set_bool(gconf_client,
234                               str, FALSE, NULL);
235     if (str){
236         g_free(str);
237         str = NULL;
238     }
239     str = g_strdup_printf("%s%i", GCONF_KEY_ADDITIONAL_BOOL_1, id);
240     if (priv->theme_bool_parametr1)
241         gconf_client_set_bool(gconf_client,
242                               str, TRUE, NULL);
243     else
244         gconf_client_set_bool(gconf_client,
245                               str, FALSE, NULL);
246     if (str){
247         g_free(str);
248         str = NULL;
249     }
250
251     str = g_strdup_printf("%s%i",GCONF_KEY_ADDITIONAL_STRING_1, id);
252     if (priv->theme_string_parametr1){
253         gconf_client_set_string(gconf_client,
254                   str,
255                   priv->theme_string_parametr1, NULL);
256     }else
257         gconf_client_unset(gconf_client, str, NULL);
258     if (str){
259             g_free(str);
260             str = NULL;
261     }
262     str = g_strdup_printf("%s%i",GCONF_KEY_ADDITIONAL_INT_1, id);
263     if (priv->theme_int_parametr1){
264         gconf_client_set_int(gconf_client,
265                   str,
266                   priv->theme_int_parametr1, NULL);
267     }else
268         gconf_client_unset(gconf_client, str, NULL);
269     if (str){
270             g_free(str);
271             str = NULL;
272     }
273
274 }
275 /*******************************************************************************/
276 gint
277 get_count_themes_from_config(gchar *theme_name){
278     GConfClient *gconf_client;
279     gint i, count;
280     gchar *str, *value;
281
282     gconf_client = gconf_client_get_default();
283     if (!gconf_client) {
284         fprintf(stderr, _("Failed to initialize GConf. Quitting.\n"));
285         return FALSE;
286     }
287     /* get count such themes */
288     count = 0;
289     for (i=1; i<=9; i++){
290         str = g_strdup_printf("%s%i", GCONF_KEY_THEME, i);
291         value = gconf_client_get_string(gconf_client, str, NULL);
292         if (str){
293             g_free(str);
294             str = NULL;
295         }
296         if (value && !strcmp(value, theme_name)){
297             count++;
298         }
299
300     }
301     //fprintf(stderr, "get count_theme from config = %d\n", count);
302     return count;
303 }
304