1
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
2
/* vim:set et sts=4: */
3
/* ibus - The Input Bus
4
* Copyright (c) 2010, Google Inc. All rights reserved.
5
* Copyright (C) 2010 Peng Huang <shawn.p.huang@gmail.com>
7
* This library is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU Lesser General Public
9
* License as published by the Free Software Foundation; either
10
* version 2 of the License, or (at your option) any later version.
12
* This library is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Lesser General Public License for more details.
17
* You should have received a copy of the GNU Lesser General Public
18
* License along with this library; if not, write to the
19
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20
* Boston, MA 02111-1307, USA.
27
typedef struct _IBusConfigMemconfClass IBusConfigMemconfClass;
29
struct _IBusConfigMemconf {
30
IBusConfigService parent;
34
struct _IBusConfigMemconfClass {
35
IBusConfigServiceClass parent;
38
/* functions prototype */
39
static void ibus_config_memconf_class_init (IBusConfigMemconfClass *class);
40
static void ibus_config_memconf_init (IBusConfigMemconf *config);
41
static void ibus_config_memconf_destroy (IBusConfigMemconf *config);
42
static gboolean ibus_config_memconf_set_value (IBusConfigService *config,
47
static GVariant *ibus_config_memconf_get_value (IBusConfigService *config,
51
static gboolean ibus_config_memconf_unset_value (IBusConfigService *config,
56
G_DEFINE_TYPE (IBusConfigMemconf, ibus_config_memconf, IBUS_TYPE_CONFIG_SERVICE)
59
ibus_config_memconf_class_init (IBusConfigMemconfClass *class)
61
GObjectClass *object_class = G_OBJECT_CLASS (class);
63
IBUS_OBJECT_CLASS (object_class)->destroy = (IBusObjectDestroyFunc) ibus_config_memconf_destroy;
64
IBUS_CONFIG_SERVICE_CLASS (object_class)->set_value = ibus_config_memconf_set_value;
65
IBUS_CONFIG_SERVICE_CLASS (object_class)->get_value = ibus_config_memconf_get_value;
66
IBUS_CONFIG_SERVICE_CLASS (object_class)->unset_value = ibus_config_memconf_unset_value;
70
ibus_config_memconf_init (IBusConfigMemconf *config)
72
config->values = g_hash_table_new_full (g_str_hash,
74
(GDestroyNotify)g_free,
75
(GDestroyNotify)g_variant_unref);
79
ibus_config_memconf_destroy (IBusConfigMemconf *config)
81
g_hash_table_destroy (config->values);
82
IBUS_OBJECT_CLASS (ibus_config_memconf_parent_class)->destroy ((IBusObject *)config);
86
ibus_config_memconf_set_value (IBusConfigService *config,
92
g_assert (IBUS_IS_CONFIG_MEMCONF (config));
96
g_assert (error == NULL || *error == NULL);
98
gchar *key = g_strdup_printf ("%s:%s", section, name);
100
g_hash_table_insert (IBUS_CONFIG_MEMCONF (config)->values,
101
key, g_variant_ref_sink (value));
103
ibus_config_service_value_changed (config, section, name, value);
109
ibus_config_memconf_get_value (IBusConfigService *config,
110
const gchar *section,
114
g_assert (IBUS_IS_CONFIG_MEMCONF (config));
117
g_assert (error == NULL || *error == NULL);
119
gchar *key = g_strdup_printf ("%s:%s", section, name);
120
GVariant *value = (GVariant *)g_hash_table_lookup (IBUS_CONFIG_MEMCONF (config)->values, key);
124
g_variant_ref (value);
126
else if (error != NULL) {
127
*error = g_error_new (G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
128
"Config value [%s:%s] does not exist.", section, name);
134
ibus_config_memconf_unset_value (IBusConfigService *config,
135
const gchar *section,
139
g_assert (IBUS_IS_CONFIG_MEMCONF (config));
142
g_assert (error == NULL || *error == NULL);
144
gchar *key = g_strdup_printf ("%s:%s", section, name);
145
gboolean retval = g_hash_table_remove (IBUS_CONFIG_MEMCONF (config)->values, key);
151
if (error && *error) {
152
*error = g_error_new (G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
153
"Config value [%s:%s] does not exist.", section, name);
160
ibus_config_memconf_new (GDBusConnection *connection)
162
IBusConfigMemconf *config;
163
config = (IBusConfigMemconf *) g_object_new (IBUS_TYPE_CONFIG_MEMCONF,
164
"object-path", IBUS_PATH_CONFIG,
165
"connection", connection,