2eb151b99221811836678f2b432f01c9aaeb3d8c
[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 Lesser General Public License
11  * as published by the Free Software Foundation; either version 2.1 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     /* Load config */
48     read_config(priv);
49     /* Set function */
50     if (!strcmp(priv->theme, "Accel"))
51         priv->scene_func = (gpointer)&init_scene_Accel;
52     if (!strcmp(priv->theme, "Berlin"))
53         priv->scene_func = (gpointer)&init_scene_Berlin;
54     if (!strcmp(priv->theme, "Modern"))
55         priv->scene_func = (gpointer)&init_scene_Modern;
56     if (!strcmp(priv->theme, "Matrix"))
57         priv->scene_func = (gpointer)&init_scene_Matrix;
58     if (!strcmp(priv->theme, "Video"))
59         priv->scene_func = (gpointer)&init_scene_Video;
60     
61     priv->extheme_list = get_list_exthemes();
62     GSList *store = priv->extheme_list;
63     while (store){
64         if (!strcmp(priv->theme, g_hash_table_lookup(store->data, "name"))){
65             if (!strcmp(priv->theme, "Conky"))
66                 priv->scene_func = (gpointer)&init_scene_Conky;
67
68             /* Default function for external themes init_scene_External */
69             if (priv->scene_func)
70                 priv->scene_func = (gpointer)&init_scene_External;
71             priv->hash_theme = store->data;
72             break;
73         }
74         store = g_slist_next(store);
75     }
76
77 }
78 #endif
79 /*******************************************************************************/
80 gint 
81 read_config(Animation_WallpaperPrivate *priv) {
82
83     GConfClient *gconf_client = NULL;
84     gchar *tmp = NULL;
85     GConfValue *value = NULL;
86     gint id = priv->view;
87     gchar * str = NULL;
88
89     gconf_client = gconf_client_get_default();
90     if (!gconf_client) {
91         fprintf(stderr, _("Failed to initialize GConf. Quitting.\n"));
92         return -1;
93     }
94     /* get Theme default Modern */
95     str = g_strdup_printf("%s%i", GCONF_KEY_THEME, id);
96     tmp = gconf_client_get_string(gconf_client,
97                                   str, NULL);
98     if (str){ 
99         g_free(str);
100         str = NULL;
101     }    
102     if (tmp){
103         priv->theme = tmp;
104     }else
105         priv->theme = g_strdup("Modern");
106     /* get Rich animation default TRUE */
107     str = g_strdup_printf("%s%i", GCONF_KEY_RANIMATION, id);
108     value = gconf_client_get(gconf_client, str, NULL);
109     if (str){ 
110         g_free(str);
111         str = NULL;
112     } 
113     if (value) {
114         priv->rich_animation = gconf_value_get_bool(value);
115         gconf_value_free(value);
116     } else
117         priv->rich_animation = TRUE;
118     /* get theme additional bool aparametr 1 default  TRUE */
119     str = g_strdup_printf("%s%i", GCONF_KEY_ADDITIONAL_BOOL_1, id);
120     value = gconf_client_get(gconf_client, str, NULL);
121     if (str){ 
122         g_free(str);
123         str = NULL;
124     } 
125     if (value) {
126         priv->theme_bool_parametr1 = gconf_value_get_bool(value);
127         gconf_value_free(value);
128     } else
129        priv->theme_bool_parametr1= TRUE;
130
131     /* get theme additional parameter 1  */
132     str = g_strdup_printf("%s%i", GCONF_KEY_ADDITIONAL_STRING_1 , id);
133     value = gconf_client_get(gconf_client, str, NULL);
134     if (str){ 
135         g_free(str);
136         str = NULL;
137     } 
138     if (value) {
139         priv->theme_string_parametr1 = g_strdup(gconf_value_get_string(value));
140         gconf_value_free(value);
141     } 
142
143     return 0;
144 }
145
146 /*******************************************************************************/
147 void
148 save_config(Animation_WallpaperPrivate *priv) {
149
150     GConfClient *gconf_client;
151     gchar * str = NULL;
152     gint id = priv->view;
153
154     gconf_client = gconf_client_get_default();
155     if (!gconf_client) {
156         fprintf(stderr, _("Failed to initialize GConf. Quitting.\n"));
157         return;
158     }
159     
160     if (priv->theme){
161         str = g_strdup_printf("%s%i", GCONF_KEY_THEME, id);
162         gconf_client_set_string(gconf_client,
163                   str,
164                   priv->theme, NULL);
165         if (str){
166             g_free(str);
167             str = NULL;
168         }
169     }
170
171     str = g_strdup_printf("%s%i", GCONF_KEY_RANIMATION, id);
172     if (priv->rich_animation)
173         gconf_client_set_bool(gconf_client,
174                               str, TRUE, NULL);
175     else
176         gconf_client_set_bool(gconf_client,
177                               str, FALSE, NULL);
178     if (str){
179         g_free(str);
180         str = NULL;
181     }
182     str = g_strdup_printf("%s%i", GCONF_KEY_ADDITIONAL_BOOL_1, id);
183     if (priv->theme_bool_parametr1)
184         gconf_client_set_bool(gconf_client,
185                               str, TRUE, NULL);
186     else
187         gconf_client_set_bool(gconf_client,
188                               str, FALSE, NULL);
189     if (str){
190         g_free(str);
191         str = NULL;
192     }
193
194     if (priv->theme_string_parametr1){
195         str = g_strdup_printf("%s%i",GCONF_KEY_ADDITIONAL_STRING_1, id);
196         gconf_client_set_string(gconf_client,
197                   str,
198                   priv->theme_string_parametr1, NULL);
199         if (str){
200             g_free(str);
201             str = NULL;
202         }
203     }
204
205     
206 }