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