modified start settings and read and save config
[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 read_config(Animation_WallpaperPrivate *priv) {
29
30     GConfClient *gconf_client = NULL;
31     gchar *tmp = NULL;
32     GConfValue *value = NULL;
33     gint id = priv->view;
34     gchar * str = NULL;
35
36     fprintf(stderr,"read_config\n");
37     gconf_client = gconf_client_get_default();
38     if (!gconf_client) {
39         fprintf(stderr, _("Failed to initialize GConf. Quitting.\n"));
40         return -1;
41     }
42     /* get Theme default Modern */
43     str = g_strdup_printf("%s%i", GCONF_KEY_THEME, id);
44     tmp = gconf_client_get_string(gconf_client,
45                                   str, NULL);
46     if (str){ 
47         g_free(str);
48         str = NULL;
49     }    
50     if (tmp){
51         priv->theme = tmp;
52     }else
53         priv->theme = g_strdup("Modern");
54     /* get Rich animation default TRUE */
55     str = g_strdup_printf("%s%i", GCONF_KEY_RANIMATION, id);
56     value = gconf_client_get(gconf_client, str, NULL);
57     if (str){ 
58         g_free(str);
59         str = NULL;
60     } 
61     if (value) {
62         priv->rich_animation = gconf_value_get_bool(value);
63         gconf_value_free(value);
64     } else
65         priv->rich_animation = TRUE;
66     
67     str = g_strdup_printf("%s%i", GCONF_KEY_ENABLE, id);
68     value = gconf_client_get(gconf_client, str, NULL);
69     if (str){ 
70         g_free(str);
71         str = NULL;
72     } 
73     if (value) {
74         priv->enable = gconf_value_get_bool(value);
75         gconf_value_free(value);
76     } else
77         priv->enable = FALSE;
78
79
80     return 0;
81 }
82
83 /*******************************************************************************/
84 void
85 save_config(Animation_WallpaperPrivate *priv) {
86
87     GConfClient *gconf_client;
88     gchar * str = NULL;
89     gint id = priv->view;
90
91     gconf_client = gconf_client_get_default();
92     if (!gconf_client) {
93         fprintf(stderr, _("Failed to initialize GConf. Quitting.\n"));
94         return;
95     }
96     
97     if (priv->theme){
98         str = g_strdup_printf("%s%i", GCONF_KEY_THEME, id);
99         gconf_client_set_string(gconf_client,
100                   str,
101                   priv->theme, NULL);
102         if (str){
103             g_free(str);
104             str = NULL;
105         }
106     }
107
108     str = g_strdup_printf("%s%i", GCONF_KEY_RANIMATION, id);
109     if (priv->rich_animation)
110         gconf_client_set_bool(gconf_client,
111                               str, TRUE, NULL);
112     else
113         gconf_client_set_bool(gconf_client,
114                               str, FALSE, NULL);
115     if (str){
116         g_free(str);
117         str = NULL;
118     }
119     
120     str = g_strdup_printf("%s%i", GCONF_KEY_ENABLE, id);
121     if (priv->enable)
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
132 }