2
* vinagre-cache-prefs.c
3
* This file is part of vinagre
5
* Copyright (C) Jonh Wendell 2010 <wendell@bani.com.br>
7
* vinagre-prefs.c is free software: you can redistribute it and/or modify it
8
* under the terms of the GNU General Public License as published by the
9
* Free Software Foundation, either version 2 of the License, or
10
* (at your option) any later version.
12
* vinagre-prefs.c is distributed in the hope that it will be useful, but
13
* WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
* See the GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License along
18
* with this program. If not, see <http://www.gnu.org/licenses/>.
22
#include <glib/gi18n.h>
23
#include "vinagre-cache-prefs.h"
25
static GKeyFile *keyfile = NULL;
26
static char* filename = NULL;
29
vinagre_cache_prefs_init (void)
31
gchar *dir = vinagre_dirs_get_user_cache_dir ();
33
keyfile = g_key_file_new ();
34
filename = g_build_filename (dir,
35
"vinagre-prefs-cache.ini",
39
g_key_file_load_from_file (keyfile, filename, 0, NULL);
46
gchar *data = g_key_file_to_data (keyfile, NULL, NULL);
47
gchar *dir = vinagre_dirs_get_user_cache_dir ();
49
g_mkdir_with_parents (dir, 0700);
51
if (!g_file_set_contents (filename,
56
g_warning (_("Error while saving preferences: %s"), error ? error->message: _("Unknown error"));
57
g_clear_error (&error);
65
vinagre_cache_prefs_finalize (void)
72
g_key_file_free (keyfile);
80
vinagre_cache_prefs_get_boolean (const gchar *group, const gchar *key, gboolean default_value)
85
g_return_val_if_fail (keyfile != NULL, FALSE);
87
result = g_key_file_get_boolean (keyfile, group, key, &error);
90
result = default_value;
98
vinagre_cache_prefs_set_boolean (const gchar *group, const gchar *key, gboolean value)
100
g_return_if_fail (keyfile != NULL);
102
g_key_file_set_boolean (keyfile, group, key, value);
106
vinagre_cache_prefs_get_string (const gchar *group, const gchar *key, const gchar *default_value)
109
GError *error = NULL;
111
g_return_val_if_fail (keyfile != NULL, NULL);
113
result = g_key_file_get_string (keyfile, group, key, &error);
116
result = g_strdup (default_value);
117
g_error_free (error);
124
vinagre_cache_prefs_set_string (const gchar *group, const gchar *key, const gchar *value)
126
g_return_if_fail (keyfile != NULL);
128
g_key_file_set_string (keyfile, group, key, value);
132
vinagre_cache_prefs_get_integer (const gchar *group, const gchar *key, gint default_value)
135
GError *error = NULL;
137
g_return_val_if_fail (keyfile != NULL, 0);
139
result = g_key_file_get_integer (keyfile, group, key, &error);
142
result = default_value;
143
g_error_free (error);
150
vinagre_cache_prefs_set_integer (const gchar *group, const gchar *key, gint value)
152
g_return_if_fail (keyfile != NULL);
154
g_key_file_set_integer (keyfile, group, key, value);