File: gconf-util.c

package info (click to toggle)
gconf-editor 3.0.1-6
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 6,216 kB
  • sloc: sh: 11,060; xml: 7,126; ansic: 5,307; makefile: 209
file content (163 lines) | stat: -rw-r--r-- 3,433 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*
 * Copyright (C) 2001, 2002 Anders Carlsson <andersca@gnu.org>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include <config.h>
#include "gconf-util.h"

#include <string.h>

enum {
	GCONF_NOT_SET,
	GCONF_CANNOT_EDIT,
	GCONF_CAN_EDIT
};
 
GType
gconf_value_get_type (void)
{
	static GType type = 0;

	if (type == 0) {
		type = g_boxed_type_register_static ("GConfValue",
						     (GBoxedCopyFunc)gconf_value_copy,
						     (GBoxedFreeFunc)gconf_value_free);
	}

	return type;
}

gchar *
gconf_get_key_name_from_path (const gchar *path)
{
	const gchar *ptr;

	/* FIXME:  VALIDATE KEY */
	
	ptr = path + strlen (path);

	while (ptr[-1] != '/')
		ptr--;

	return g_strdup (ptr);
}

gchar *
gconf_value_type_to_string (GConfValueType value_type)
{
	switch (value_type) {
	case GCONF_VALUE_STRING:
		return g_strdup ("String");
		break;
	case GCONF_VALUE_INT:
		return g_strdup ("Integer");
		break;
	case GCONF_VALUE_BOOL:
		return g_strdup ("Boolean");
		break;
	case GCONF_VALUE_LIST:
		return g_strdup ("List");
		break;
	default:
		return g_strdup_printf ("UNKNOWN, %d", value_type);
	}
}

GConfSchema *
gconf_client_get_schema_for_key (GConfClient *client, const char *key)
{
	GConfEntry *entry;
	const char *schema_name;
	GConfSchema *schema = NULL;

	entry = gconf_client_get_entry (client, key, NULL, TRUE, NULL);
	schema_name = gconf_entry_get_schema_name (entry);

	if (schema_name == NULL)
		goto out;

	schema = gconf_client_get_schema (client, schema_name, NULL);

out:
	if (entry)
		gconf_entry_free (entry);

	return schema;
}

static gboolean
can_edit_source (const char *source)
{
	GConfEngine *engine;
	GConfClient *client;
	GConfEntry  *entry;
	GError      *error;
	gboolean     retval;

	if (!(engine = gconf_engine_get_for_address (source, NULL)))
		return FALSE;

	error = NULL;
	client = gconf_client_get_for_engine (engine);
	entry = gconf_client_get_entry (client,
					"/apps/gconf-editor/can_edit_source",
					NULL,
					FALSE,
					&error);
	if (error != NULL) {
		g_assert (entry == NULL);
		g_error_free (error);
		g_object_unref (client);
		gconf_engine_unref (engine);
		return FALSE;
	}

	g_assert (entry != NULL);

	retval = gconf_entry_get_is_writable (entry);

	gconf_entry_unref (entry);
	g_object_unref (client);
	gconf_engine_unref (engine);

	return retval;
}

gboolean
gconf_util_can_edit_defaults (void)
{
	static int can_edit_defaults = GCONF_NOT_SET;

	if (can_edit_defaults == GCONF_NOT_SET)
		can_edit_defaults = can_edit_source (GCONF_DEFAULTS_SOURCE);

	return can_edit_defaults;
}

gboolean
gconf_util_can_edit_mandatory (void)
{
	static int can_edit_mandatory = GCONF_NOT_SET;

	if (can_edit_mandatory == GCONF_NOT_SET)
		can_edit_mandatory = can_edit_source (GCONF_MANDATORY_SOURCE);

	return can_edit_mandatory;
}