prepared to release 0.6 version
[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     gconf_client = gconf_client_get_default();
37     if (!gconf_client) {
38         fprintf(stderr, _("Failed to initialize GConf. Quitting.\n"));
39         return -1;
40     }
41     /* get Theme default Modern */
42     str = g_strdup_printf("%s%i", GCONF_KEY_THEME, id);
43     tmp = gconf_client_get_string(gconf_client,
44                                   str, NULL);
45     if (str){ 
46         g_free(str);
47         str = NULL;
48     }    
49     if (tmp){
50         priv->theme = tmp;
51     }else
52         priv->theme = g_strdup("Modern");
53     /* get Rich animation default TRUE */
54     str = g_strdup_printf("%s%i", GCONF_KEY_RANIMATION, id);
55     value = gconf_client_get(gconf_client, str, NULL);
56     if (str){ 
57         g_free(str);
58         str = NULL;
59     } 
60     if (value) {
61         priv->rich_animation = gconf_value_get_bool(value);
62         gconf_value_free(value);
63     } else
64         priv->rich_animation = TRUE;
65     
66
67     return 0;
68 }
69
70 /*******************************************************************************/
71 void
72 save_config(Animation_WallpaperPrivate *priv) {
73
74     GConfClient *gconf_client;
75     gchar * str = NULL;
76     gint id = priv->view;
77
78     gconf_client = gconf_client_get_default();
79     if (!gconf_client) {
80         fprintf(stderr, _("Failed to initialize GConf. Quitting.\n"));
81         return;
82     }
83     
84     if (priv->theme){
85         str = g_strdup_printf("%s%i", GCONF_KEY_THEME, id);
86         gconf_client_set_string(gconf_client,
87                   str,
88                   priv->theme, NULL);
89         if (str){
90             g_free(str);
91             str = NULL;
92         }
93     }
94
95     str = g_strdup_printf("%s%i", GCONF_KEY_RANIMATION, id);
96     if (priv->rich_animation)
97         gconf_client_set_bool(gconf_client,
98                               str, TRUE, NULL);
99     else
100         gconf_client_set_bool(gconf_client,
101                               str, FALSE, NULL);
102     if (str){
103         g_free(str);
104         str = NULL;
105     }
106     
107 }