~ubuntu-branches/debian/stretch/gnac/stretch

« back to all changes in this revision

Viewing changes to src/gnac-settings.c

  • Committer: Package Import Robot
  • Author(s): Khalid El Fathi
  • Date: 2012-04-14 20:15:31 UTC
  • Revision ID: package-import@ubuntu.com-20120414201531-2gcfq8fs94kgp9qr
Tags: upstream-0.2.4
ImportĀ upstreamĀ versionĀ 0.2.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This file is part of GNAC - Gnome Audio Converter
 
3
 *
 
4
 * Copyright (C) 2007 - 2012 Gnac
 
5
 *    
 
6
 *    - DUPASQUIER  Benoit    <bdupasqu@src.gnome.org>
 
7
 *    - JOAQUIM     David     <djoaquim@src.gnome.org>
 
8
 *    - ROUX        Alexandre <alexroux@src.gnome.org>
 
9
 *
 
10
 * GNAC is free software; you can redistribute it and/or modify
 
11
 * it under the terms of the GNU General Public License as published by
 
12
 * the Free Software Foundation; either version 3 of the License, or
 
13
 * (at your option) any later version.
 
14
 *
 
15
 * GNAC is distributed in the hope that it will be useful,
 
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
18
 * GNU General Public License for more details.
 
19
 *
 
20
 * You should have received a copy of the GNU General Public License
 
21
 * along with GNAC; if not, write to the Free Software
 
22
 * Foundation, Inc., 51 Franklin St, Fifth Floor, 
 
23
 * Boston, MA  02110-1301  USA
 
24
 */
 
25
 
 
26
#include "gnac-settings.h"
 
27
#include "libgnac-debug.h"
 
28
 
 
29
 
 
30
GSettings *settings;
 
31
GSettings *settings_ui;
 
32
 
 
33
 
 
34
static gboolean gnac_settings_set(GSettings   *settings,
 
35
                                  const gchar *key,
 
36
                                  GVariant    *value);
 
37
 
 
38
void
 
39
gnac_settings_init(void)
 
40
{
 
41
  settings = g_settings_new(GNAC_SCHEMA);
 
42
  settings_ui = g_settings_new(GNAC_SCHEMA_UI);
 
43
}
 
44
 
 
45
 
 
46
void
 
47
gnac_settings_bind(const gchar *key,
 
48
                   gpointer     object)
 
49
{
 
50
  g_settings_bind(settings, key, object, "active", G_SETTINGS_BIND_DEFAULT);
 
51
}
 
52
 
 
53
 
 
54
void
 
55
gnac_settings_ui_bind(const gchar *key,
 
56
                      gpointer     object)
 
57
{
 
58
  g_settings_bind(settings_ui, key, object, "active", G_SETTINGS_BIND_DEFAULT);
 
59
}
 
60
 
 
61
 
 
62
gboolean
 
63
gnac_settings_get_boolean(const gchar *key)
 
64
{
 
65
  return g_settings_get_boolean(settings, key);
 
66
}
 
67
 
 
68
 
 
69
gboolean
 
70
gnac_settings_ui_get_boolean(const gchar *key)
 
71
{
 
72
  return g_settings_get_boolean(settings_ui, key);
 
73
}
 
74
 
 
75
 
 
76
gboolean
 
77
gnac_settings_set_boolean(const gchar *key,
 
78
                          gboolean     value)
 
79
{
 
80
  return gnac_settings_set(settings, key, g_variant_new_boolean(value));
 
81
}
 
82
 
 
83
 
 
84
gboolean
 
85
gnac_settings_ui_set_boolean(const gchar *key,
 
86
                             gboolean     value)
 
87
{
 
88
  return gnac_settings_set(settings_ui, key, g_variant_new_boolean(value));
 
89
}
 
90
 
 
91
 
 
92
gint
 
93
gnac_settings_get_int(const gchar *key)
 
94
{
 
95
  return g_settings_get_int(settings, key);
 
96
}
 
97
 
 
98
 
 
99
gboolean
 
100
gnac_settings_set_int(const gchar *key,
 
101
                      gint         value)
 
102
{
 
103
  return gnac_settings_set(settings, key, g_variant_new_int32(value));
 
104
}
 
105
 
 
106
 
 
107
gchar *
 
108
gnac_settings_get_string(const gchar *key)
 
109
{
 
110
  return g_settings_get_string(settings, key);
 
111
}
 
112
 
 
113
 
 
114
gboolean
 
115
gnac_settings_set_string(const gchar *key,
 
116
                         const gchar *value)
 
117
{
 
118
  if (!value) return FALSE;
 
119
  return gnac_settings_set(settings, key, g_variant_new_string(value));
 
120
}
 
121
 
 
122
 
 
123
static gboolean
 
124
gnac_settings_set(GSettings   *settings,
 
125
                  const gchar *key,
 
126
                  GVariant    *value)
 
127
{
 
128
  gchar *val_str = g_variant_print(value, FALSE);
 
129
  gboolean ret = g_settings_set_value(settings, key, value);
 
130
 
 
131
  if (!ret) {
 
132
    libgnac_debug("Failed to set key \"%s\" to \"%s\"", key, val_str);
 
133
  } else {
 
134
    libgnac_debug("Key \"%s\" set to \"%s\"", key, val_str);
 
135
  }
 
136
 
 
137
  g_free(val_str);
 
138
 
 
139
  return ret;
 
140
}