6a1624b375e7c743a796dbd45036c140996a4783
[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     /* 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             /* Default function for external themes init_scene_External */
66             if (priv->scene_func)
67                 priv->scene_func = (gpointer)&init_scene_External;
68             if (!strcmp(priv->theme, "Conky"))
69                 priv->scene_func = (gpointer)&init_scene_Conky;
70             priv->hash_theme = store->data;
71             break;
72         }
73         store = g_slist_next(store);
74     }
75
76 }
77 #endif
78 /*******************************************************************************/
79 gint 
80 read_config(Animation_WallpaperPrivate *priv) {
81
82     GConfClient *gconf_client = NULL;
83     gchar *tmp = NULL;
84     GConfValue *value = NULL;
85     gint id = priv->view;
86     gchar * str = NULL;
87
88     gconf_client = gconf_client_get_default();
89     if (!gconf_client) {
90         fprintf(stderr, _("Failed to initialize GConf. Quitting.\n"));
91         return -1;
92     }
93     /* get Theme default Modern */
94     str = g_strdup_printf("%s%i", GCONF_KEY_THEME, id);
95     tmp = gconf_client_get_string(gconf_client,
96                                   str, NULL);
97     if (str){ 
98         g_free(str);
99         str = NULL;
100     }    
101     if (tmp){
102         priv->theme = tmp;
103     }else
104         priv->theme = g_strdup("Modern");
105     /* get Rich animation default TRUE */
106     str = g_strdup_printf("%s%i", GCONF_KEY_RANIMATION, id);
107     value = gconf_client_get(gconf_client, str, NULL);
108     if (str){ 
109         g_free(str);
110         str = NULL;
111     } 
112     if (value) {
113         priv->rich_animation = gconf_value_get_bool(value);
114         gconf_value_free(value);
115     } else
116         priv->rich_animation = TRUE;
117     /* get theme additional bool aparametr 1 default  TRUE */
118     str = g_strdup_printf("%s%i", GCONF_KEY_ADDITIONAL_BOOL_1, id);
119     value = gconf_client_get(gconf_client, str, NULL);
120     if (str){ 
121         g_free(str);
122         str = NULL;
123     } 
124     if (value) {
125         priv->theme_bool_parametr1 = gconf_value_get_bool(value);
126         gconf_value_free(value);
127     } else
128        priv->theme_bool_parametr1= TRUE;
129
130     /* get theme additional parameter 1  */
131     str = g_strdup_printf("%s%i", GCONF_KEY_ADDITIONAL_STRING_1 , id);
132     value = gconf_client_get(gconf_client, str, NULL);
133     if (str){ 
134         g_free(str);
135         str = NULL;
136     } 
137     if (value) {
138         priv->theme_string_parametr1 = g_strdup(gconf_value_get_string(value));
139         gconf_value_free(value);
140     } 
141     /* get parameter one theme in all view */
142     priv->one_in_all_view = get_one_in_all_views_from_config();
143     return 0;
144 }
145 /*******************************************************************************/
146 gboolean
147 get_one_in_all_views_from_config(void){
148     GConfClient *gconf_client;
149     GConfValue *value = NULL;
150     gboolean result;
151
152     gconf_client = gconf_client_get_default();
153     if (!gconf_client) {
154         fprintf(stderr, _("Failed to initialize GConf. Quitting.\n"));
155         return FALSE;
156     }
157     /* get parameter one theme in all view */
158     value = gconf_client_get(gconf_client, GCONF_KEY_ONE_IN_ALL_VIEW, NULL);
159     if (value) {
160         result = gconf_value_get_bool(value);
161         gconf_value_free(value);
162     } else
163         result = FALSE;
164     return result;
165 }
166 /*******************************************************************************/
167 void
168 save_one_in_all_views_to_config(gboolean one_in_all_views){
169     GConfClient *gconf_client;
170
171     gconf_client = gconf_client_get_default();
172     if (!gconf_client) {
173         fprintf(stderr, _("Failed to initialize GConf. Quitting.\n"));
174         return;
175     }
176
177     if (one_in_all_views)
178         gconf_client_set_bool(gconf_client,
179                               GCONF_KEY_ONE_IN_ALL_VIEW, TRUE, NULL);
180     else
181         gconf_client_set_bool(gconf_client,
182                               GCONF_KEY_ONE_IN_ALL_VIEW, FALSE, NULL);
183
184 }
185 /*******************************************************************************/
186 void
187 save_config(Animation_WallpaperPrivate *priv) {
188
189     GConfClient *gconf_client;
190     gchar * str = NULL;
191     gint id = priv->view;
192
193     gconf_client = gconf_client_get_default();
194     if (!gconf_client) {
195         fprintf(stderr, _("Failed to initialize GConf. Quitting.\n"));
196         return;
197     }
198     
199     if (priv->theme){
200         str = g_strdup_printf("%s%i", GCONF_KEY_THEME, id);
201         gconf_client_set_string(gconf_client,
202                   str,
203                   priv->theme, NULL);
204         if (str){
205             g_free(str);
206             str = NULL;
207         }
208     }
209
210     str = g_strdup_printf("%s%i", GCONF_KEY_RANIMATION, id);
211     if (priv->rich_animation)
212         gconf_client_set_bool(gconf_client,
213                               str, TRUE, NULL);
214     else
215         gconf_client_set_bool(gconf_client,
216                               str, FALSE, NULL);
217     if (str){
218         g_free(str);
219         str = NULL;
220     }
221     str = g_strdup_printf("%s%i", GCONF_KEY_ADDITIONAL_BOOL_1, id);
222     if (priv->theme_bool_parametr1)
223         gconf_client_set_bool(gconf_client,
224                               str, TRUE, NULL);
225     else
226         gconf_client_set_bool(gconf_client,
227                               str, FALSE, NULL);
228     if (str){
229         g_free(str);
230         str = NULL;
231     }
232
233     if (priv->theme_string_parametr1){
234         str = g_strdup_printf("%s%i",GCONF_KEY_ADDITIONAL_STRING_1, id);
235         gconf_client_set_string(gconf_client,
236                   str,
237                   priv->theme_string_parametr1, NULL);
238         if (str){
239             g_free(str);
240             str = NULL;
241         }
242     }
243 }