~ubuntu-branches/ubuntu/precise/vinagre/precise-updates

« back to all changes in this revision

Viewing changes to .pc/02_bugzilla_build_workarounds.patch/vinagre/vinagre-cache-prefs.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Terry
  • Date: 2011-07-26 13:46:00 UTC
  • Revision ID: james.westby@ubuntu.com-20110726134600-lftg5gio4xbt28uq
Tags: 3.1.4-0ubuntu2
* debian/patches/02_bugzilla_build_workarounds.patch:
  - Update for new codebase to avoid implicitly defined functions
    causing a FTBFS

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * vinagre-cache-prefs.c
 
3
 * This file is part of vinagre
 
4
 *
 
5
 * Copyright (C) Jonh Wendell 2010 <wendell@bani.com.br>
 
6
 *
 
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.
 
11
 *
 
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.
 
16
 *
 
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/>.
 
19
 */
 
20
 
 
21
#include <config.h>
 
22
#include <glib/gi18n.h>
 
23
#include "vinagre-cache-prefs.h"
 
24
 
 
25
static GKeyFile *keyfile = NULL;
 
26
static char* filename = NULL;
 
27
 
 
28
void
 
29
vinagre_cache_prefs_init (void)
 
30
{
 
31
  gchar *dir = vinagre_dirs_get_user_cache_dir ();
 
32
 
 
33
  keyfile = g_key_file_new ();
 
34
  filename = g_build_filename (dir,
 
35
                               "vinagre-prefs-cache.ini",
 
36
                               NULL);
 
37
  g_free (dir);
 
38
 
 
39
  g_key_file_load_from_file (keyfile, filename, 0, NULL);
 
40
}
 
41
 
 
42
static void
 
43
save_file (void)
 
44
{
 
45
  GError *error = NULL;
 
46
  gchar *data = g_key_file_to_data (keyfile, NULL, NULL);
 
47
  gchar *dir = vinagre_dirs_get_user_cache_dir ();
 
48
 
 
49
  g_mkdir_with_parents (dir, 0700);
 
50
 
 
51
  if (!g_file_set_contents (filename,
 
52
                            data,
 
53
                            -1,
 
54
                            &error))
 
55
    {
 
56
      g_warning (_("Error while saving preferences: %s"), error ? error->message: _("Unknown error"));
 
57
      g_clear_error (&error);
 
58
    }
 
59
 
 
60
  g_free (data);
 
61
  g_free (dir);
 
62
}
 
63
 
 
64
void
 
65
vinagre_cache_prefs_finalize (void)
 
66
{
 
67
  if (keyfile == NULL)
 
68
    return;
 
69
 
 
70
  save_file ();
 
71
 
 
72
  g_key_file_free (keyfile);
 
73
  keyfile = NULL;
 
74
 
 
75
  g_free (filename);
 
76
  filename = NULL;
 
77
}
 
78
 
 
79
gboolean
 
80
vinagre_cache_prefs_get_boolean (const gchar *group, const gchar *key, gboolean default_value)
 
81
{
 
82
  gboolean result;
 
83
  GError *error = NULL;
 
84
 
 
85
  g_return_val_if_fail (keyfile != NULL, FALSE);
 
86
 
 
87
  result = g_key_file_get_boolean (keyfile, group, key, &error);
 
88
  if (error)
 
89
    {
 
90
      result = default_value;
 
91
      g_error_free (error);
 
92
    }
 
93
 
 
94
  return result;
 
95
}
 
96
 
 
97
void
 
98
vinagre_cache_prefs_set_boolean (const gchar *group, const gchar *key, gboolean value)
 
99
{
 
100
  g_return_if_fail (keyfile != NULL);
 
101
 
 
102
  g_key_file_set_boolean (keyfile, group, key, value);
 
103
}
 
104
 
 
105
gchar *
 
106
vinagre_cache_prefs_get_string (const gchar *group, const gchar *key, const gchar *default_value)
 
107
{
 
108
  gchar *result;
 
109
  GError *error = NULL;
 
110
 
 
111
  g_return_val_if_fail (keyfile != NULL, NULL);
 
112
 
 
113
  result = g_key_file_get_string (keyfile, group, key, &error);
 
114
  if (error)
 
115
    {
 
116
      result = g_strdup (default_value);
 
117
      g_error_free (error);
 
118
    }
 
119
 
 
120
  return result;
 
121
}
 
122
 
 
123
void
 
124
vinagre_cache_prefs_set_string (const gchar *group, const gchar *key, const gchar *value)
 
125
{
 
126
  g_return_if_fail (keyfile != NULL);
 
127
 
 
128
  g_key_file_set_string (keyfile, group, key, value);
 
129
}
 
130
 
 
131
gint
 
132
vinagre_cache_prefs_get_integer (const gchar *group, const gchar *key, gint default_value)
 
133
{
 
134
  gint result;
 
135
  GError *error = NULL;
 
136
 
 
137
  g_return_val_if_fail (keyfile != NULL, 0);
 
138
 
 
139
  result = g_key_file_get_integer (keyfile, group, key, &error);
 
140
  if (error)
 
141
    {
 
142
      result = default_value;
 
143
      g_error_free (error);
 
144
    }
 
145
 
 
146
  return result;
 
147
}
 
148
 
 
149
void
 
150
vinagre_cache_prefs_set_integer (const gchar *group, const gchar *key, gint value)
 
151
{
 
152
  g_return_if_fail (keyfile != NULL);
 
153
 
 
154
  g_key_file_set_integer (keyfile, group, key, value);
 
155
}