04876727c452081eedb2074821d8d49f446edcf1
[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 gint 
43 read_config(Animation_WallpaperPrivate *priv) {
44
45     GConfClient *gconf_client = NULL;
46     gchar *tmp = NULL;
47     GConfValue *value = NULL;
48     gint id = priv->view;
49     gchar * str = NULL;
50
51     gconf_client = gconf_client_get_default();
52     if (!gconf_client) {
53         fprintf(stderr, _("Failed to initialize GConf. Quitting.\n"));
54         return -1;
55     }
56     /* get Theme default Modern */
57     str = g_strdup_printf("%s%i", GCONF_KEY_THEME, id);
58     tmp = gconf_client_get_string(gconf_client,
59                                   str, NULL);
60     if (str){ 
61         g_free(str);
62         str = NULL;
63     }    
64     if (tmp){
65         priv->theme = tmp;
66     }else
67         priv->theme = g_strdup("Modern");
68     /* get Rich animation default TRUE */
69     str = g_strdup_printf("%s%i", GCONF_KEY_RANIMATION, id);
70     value = gconf_client_get(gconf_client, str, NULL);
71     if (str){ 
72         g_free(str);
73         str = NULL;
74     } 
75     if (value) {
76         priv->rich_animation = gconf_value_get_bool(value);
77         gconf_value_free(value);
78     } else
79         priv->rich_animation = TRUE;
80     /* get theme additional parameter 1  */
81     str = g_strdup_printf("%s%i", GCONF_KEY_ADDIONAL_STRING_1 , id);
82     value = gconf_client_get(gconf_client, str, NULL);
83     if (str){ 
84         g_free(str);
85         str = NULL;
86     } 
87     if (value) {
88         priv->theme_string_parametr1 = g_strdup(gconf_value_get_string(value));
89         gconf_value_free(value);
90     } 
91
92     return 0;
93 }
94
95 /*******************************************************************************/
96 void
97 save_config(Animation_WallpaperPrivate *priv) {
98
99     GConfClient *gconf_client;
100     gchar * str = NULL;
101     gint id = priv->view;
102
103     gconf_client = gconf_client_get_default();
104     if (!gconf_client) {
105         fprintf(stderr, _("Failed to initialize GConf. Quitting.\n"));
106         return;
107     }
108     
109     if (priv->theme){
110         str = g_strdup_printf("%s%i", GCONF_KEY_THEME, id);
111         gconf_client_set_string(gconf_client,
112                   str,
113                   priv->theme, NULL);
114         if (str){
115             g_free(str);
116             str = NULL;
117         }
118     }
119
120     str = g_strdup_printf("%s%i", GCONF_KEY_RANIMATION, id);
121     if (priv->rich_animation)
122         gconf_client_set_bool(gconf_client,
123                               str, TRUE, NULL);
124     else
125         gconf_client_set_bool(gconf_client,
126                               str, FALSE, NULL);
127     if (str){
128         g_free(str);
129         str = NULL;
130     }
131     if (priv->theme_string_parametr1){
132         str = g_strdup_printf("%s%i",GCONF_KEY_ADDIONAL_STRING_1, id);
133         gconf_client_set_string(gconf_client,
134                   str,
135                   priv->theme_string_parametr1, NULL);
136         if (str){
137             g_free(str);
138             str = NULL;
139         }
140     }
141
142     
143 }