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