~ubuntu-branches/ubuntu/hardy/network-manager-applet/hardy

« back to all changes in this revision

Viewing changes to src/gconf-helpers.c

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Mercatante
  • Date: 2007-06-15 12:46:22 UTC
  • Revision ID: james.westby@ubuntu.com-20070615124622-01cyrnf0uxxun4lz
Tags: upstream-0.6.5
ImportĀ upstreamĀ versionĀ 0.6.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* NetworkManager -- Network link manager
 
2
 *
 
3
 * Dan Williams <dcbw@redhat.com>
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License as published by
 
7
 * the Free Software Foundation; either version 2 of the License, or
 
8
 * (at your option) any later version.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program; if not, write to the Free Software
 
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
18
 *
 
19
 * (C) Copyright 2005 Red Hat, Inc.
 
20
 */
 
21
 
 
22
#include <gconf/gconf.h>
 
23
#include <gconf/gconf-client.h>
 
24
#include <glib.h>
 
25
 
 
26
#include "gconf-helpers.h"
 
27
 
 
28
 
 
29
gboolean
 
30
nm_gconf_get_int_helper (GConfClient *client,
 
31
                                        const char *path,
 
32
                                        const char *key,
 
33
                                        const char *network,
 
34
                                        int *value)
 
35
{
 
36
        char *          gc_key;
 
37
        GConfValue *    gc_value;
 
38
        gboolean                success = FALSE;
 
39
 
 
40
        g_return_val_if_fail (key != NULL, FALSE);
 
41
        g_return_val_if_fail (network != NULL, FALSE);
 
42
        g_return_val_if_fail (value != NULL, FALSE);
 
43
 
 
44
        gc_key = g_strdup_printf ("%s/%s/%s", path, network, key);
 
45
        if ((gc_value = gconf_client_get (client, gc_key, NULL)))
 
46
        {
 
47
                if (gc_value->type == GCONF_VALUE_INT)
 
48
                {
 
49
                        *value = gconf_value_get_int (gc_value);
 
50
                        success = TRUE;
 
51
                }
 
52
                gconf_value_free (gc_value);
 
53
        }
 
54
        g_free (gc_key);
 
55
 
 
56
        return success;
 
57
}
 
58
 
 
59
 
 
60
gboolean
 
61
nm_gconf_get_string_helper (GConfClient *client,
 
62
                                        const char *path,
 
63
                                        const char *key,
 
64
                                        const char *network,
 
65
                                        char **value)
 
66
{
 
67
        char *          gc_key;
 
68
        GConfValue *    gc_value;
 
69
        gboolean                success = FALSE;
 
70
 
 
71
        g_return_val_if_fail (key != NULL, FALSE);
 
72
        g_return_val_if_fail (network != NULL, FALSE);
 
73
        g_return_val_if_fail (value != NULL, FALSE);
 
74
        g_return_val_if_fail (*value == NULL, FALSE);
 
75
 
 
76
        gc_key = g_strdup_printf ("%s/%s/%s", path, network, key);
 
77
        if ((gc_value = gconf_client_get (client, gc_key, NULL)))
 
78
        {
 
79
                if (gc_value->type == GCONF_VALUE_STRING)
 
80
                {
 
81
                        *value = g_strdup (gconf_value_get_string (gc_value));
 
82
                        success = TRUE;
 
83
                }
 
84
                gconf_value_free (gc_value);
 
85
        }
 
86
        g_free (gc_key);
 
87
 
 
88
        return success;
 
89
}
 
90
 
 
91
 
 
92
gboolean
 
93
nm_gconf_get_bool_helper (GConfClient *client,
 
94
                                        const char *path,
 
95
                                        const char *key,
 
96
                                        const char *network,
 
97
                                        gboolean *value)
 
98
{
 
99
        char *          gc_key;
 
100
        GConfValue *    gc_value;
 
101
        gboolean                success = FALSE;
 
102
 
 
103
        g_return_val_if_fail (key != NULL, FALSE);
 
104
        g_return_val_if_fail (network != NULL, FALSE);
 
105
        g_return_val_if_fail (value != NULL, FALSE);
 
106
 
 
107
        gc_key = g_strdup_printf ("%s/%s/%s", path, network, key);
 
108
        if ((gc_value = gconf_client_get (client, gc_key, NULL)))
 
109
        {
 
110
                if (gc_value->type == GCONF_VALUE_BOOL)
 
111
                {
 
112
                        *value = gconf_value_get_bool (gc_value);
 
113
                        success = TRUE;
 
114
                }
 
115
                gconf_value_free (gc_value);
 
116
        }
 
117
        g_free (gc_key);
 
118
 
 
119
        return success;
 
120
}