4f499ce51527dfa560244c68c9c8128a076b3409
[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             priv->scene_func = (gpointer)&init_scene_External;
66             priv->hash_theme = store->data;
67             break;
68         }
69         store = g_slist_next(store);
70     }
71
72 }
73 #endif
74 /*******************************************************************************/
75 gint 
76 read_config(Animation_WallpaperPrivate *priv) {
77
78     GConfClient *gconf_client = NULL;
79     gchar *tmp = NULL;
80     GConfValue *value = NULL;
81     gint id = priv->view;
82     gchar * str = NULL;
83
84     gconf_client = gconf_client_get_default();
85     if (!gconf_client) {
86         fprintf(stderr, _("Failed to initialize GConf. Quitting.\n"));
87         return -1;
88     }
89     /* get Theme default Modern */
90     str = g_strdup_printf("%s%i", GCONF_KEY_THEME, id);
91     tmp = gconf_client_get_string(gconf_client,
92                                   str, NULL);
93     if (str){ 
94         g_free(str);
95         str = NULL;
96     }    
97     if (tmp){
98         priv->theme = tmp;
99     }else
100         priv->theme = g_strdup("Modern");
101     /* get Rich animation default TRUE */
102     str = g_strdup_printf("%s%i", GCONF_KEY_RANIMATION, id);
103     value = gconf_client_get(gconf_client, str, NULL);
104     if (str){ 
105         g_free(str);
106         str = NULL;
107     } 
108     if (value) {
109         priv->rich_animation = gconf_value_get_bool(value);
110         gconf_value_free(value);
111     } else
112         priv->rich_animation = TRUE;
113     /* get theme additional parameter 1  */
114     str = g_strdup_printf("%s%i", GCONF_KEY_ADDIONAL_STRING_1 , id);
115     value = gconf_client_get(gconf_client, str, NULL);
116     if (str){ 
117         g_free(str);
118         str = NULL;
119     } 
120     if (value) {
121         priv->theme_string_parametr1 = g_strdup(gconf_value_get_string(value));
122         gconf_value_free(value);
123     } 
124
125     return 0;
126 }
127
128 /*******************************************************************************/
129 void
130 save_config(Animation_WallpaperPrivate *priv) {
131
132     GConfClient *gconf_client;
133     gchar * str = NULL;
134     gint id = priv->view;
135
136     gconf_client = gconf_client_get_default();
137     if (!gconf_client) {
138         fprintf(stderr, _("Failed to initialize GConf. Quitting.\n"));
139         return;
140     }
141     
142     if (priv->theme){
143         str = g_strdup_printf("%s%i", GCONF_KEY_THEME, id);
144         gconf_client_set_string(gconf_client,
145                   str,
146                   priv->theme, NULL);
147         if (str){
148             g_free(str);
149             str = NULL;
150         }
151     }
152
153     str = g_strdup_printf("%s%i", GCONF_KEY_RANIMATION, id);
154     if (priv->rich_animation)
155         gconf_client_set_bool(gconf_client,
156                               str, TRUE, NULL);
157     else
158         gconf_client_set_bool(gconf_client,
159                               str, FALSE, NULL);
160     if (str){
161         g_free(str);
162         str = NULL;
163     }
164     if (priv->theme_string_parametr1){
165         str = g_strdup_printf("%s%i",GCONF_KEY_ADDIONAL_STRING_1, id);
166         gconf_client_set_string(gconf_client,
167                   str,
168                   priv->theme_string_parametr1, NULL);
169         if (str){
170             g_free(str);
171             str = NULL;
172         }
173     }
174
175     
176 }