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) 2008-2010 Peng Huang <shawn.p.huang@gmail.com>
5 * Copyright (C) 2008-2010 Red Hat, Inc.
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.
22 #include "ibusshare.h"
23 #include "ibusconfigservice.h"
33 /* functions prototype */
34 static void ibus_config_service_class_init (IBusConfigServiceClass *class);
35 static void ibus_config_service_init (IBusConfigService *config);
36 static void ibus_config_service_destroy (IBusConfigService *config);
37 static void ibus_config_service_service_method_call
38 (IBusService *service,
39 GDBusConnection *connection,
41 const gchar *object_path,
42 const gchar *interface_name,
43 const gchar *method_name,
45 GDBusMethodInvocation *invocation);
46 static GVariant *ibus_config_service_service_get_property
47 (IBusService *service,
48 GDBusConnection *connection,
50 const gchar *object_path,
51 const gchar *interface_name,
52 const gchar *property_name,
54 static gboolean ibus_config_service_service_set_property
55 (IBusService *service,
56 GDBusConnection *connection,
58 const gchar *object_path,
59 const gchar *interface_name,
60 const gchar *property_name,
63 static gboolean ibus_config_service_set_value (IBusConfigService *config,
68 static GVariant *ibus_config_service_get_value (IBusConfigService *config,
72 static GVariant *ibus_config_service_get_values (IBusConfigService *config,
75 static gboolean ibus_config_service_unset_value (IBusConfigService *config,
80 G_DEFINE_TYPE (IBusConfigService, ibus_config_service, IBUS_TYPE_SERVICE)
82 static const gchar introspection_xml[] =
84 " <interface name='org.freedesktop.IBus.Config'>"
85 " <method name='SetValue'>"
86 " <arg direction='in' type='s' name='section' />"
87 " <arg direction='in' type='s' name='name' />"
88 " <arg direction='in' type='v' name='value' />"
90 " <method name='GetValue'>"
91 " <arg direction='in' type='s' name='section' />"
92 " <arg direction='in' type='s' name='name' />"
93 " <arg direction='out' type='v' name='value' />"
95 " <method name='GetValues'>"
96 " <arg direction='in' type='s' name='section' />"
97 " <arg direction='out' type='a{sv}' name='values' />"
99 " <method name='UnsetValue'>"
100 " <arg direction='in' type='s' name='section' />"
101 " <arg direction='in' type='s' name='name' />"
103 " <signal name='ValueChanged'>"
104 " <arg type='s' name='section' />"
105 " <arg type='s' name='name' />"
106 " <arg type='v' name='value' />"
112 ibus_config_service_class_init (IBusConfigServiceClass *class)
114 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
116 IBUS_OBJECT_CLASS (gobject_class)->destroy = (IBusObjectDestroyFunc) ibus_config_service_destroy;
118 IBUS_SERVICE_CLASS (class)->service_method_call = ibus_config_service_service_method_call;
119 IBUS_SERVICE_CLASS (class)->service_get_property = ibus_config_service_service_get_property;
120 IBUS_SERVICE_CLASS (class)->service_set_property = ibus_config_service_service_set_property;
122 ibus_service_class_add_interfaces (IBUS_SERVICE_CLASS (class), introspection_xml);
124 class->set_value = ibus_config_service_set_value;
125 class->get_value = ibus_config_service_get_value;
126 class->get_values = ibus_config_service_get_values;
127 class->unset_value = ibus_config_service_unset_value;
131 ibus_config_service_init (IBusConfigService *config)
136 ibus_config_service_destroy (IBusConfigService *config)
138 IBUS_OBJECT_CLASS(ibus_config_service_parent_class)->destroy ((IBusObject *) config);
142 ibus_config_service_service_method_call (IBusService *service,
143 GDBusConnection *connection,
145 const gchar *object_path,
146 const gchar *interface_name,
147 const gchar *method_name,
148 GVariant *parameters,
149 GDBusMethodInvocation *invocation)
151 IBusConfigService *config = IBUS_CONFIG_SERVICE (service);
153 if (g_strcmp0 (interface_name, IBUS_INTERFACE_CONFIG) != 0) {
154 IBUS_SERVICE_CLASS (ibus_config_service_parent_class)->
155 service_method_call (service,
166 if (g_strcmp0 (method_name, "SetValue") == 0) {
171 GError *error = NULL;
173 g_variant_get (parameters, "(&s&sv)", §ion, &name, &value);
175 retval = IBUS_CONFIG_SERVICE_GET_CLASS (config)->set_value (config, section, name, value, &error);
177 g_dbus_method_invocation_return_value (invocation, NULL);
180 g_dbus_method_invocation_return_gerror (invocation, error);
181 g_error_free (error);
186 if (g_strcmp0 (method_name, "GetValue") == 0) {
190 GError *error = NULL;
192 g_variant_get (parameters, "(&s&s)", §ion, &name);
194 value = IBUS_CONFIG_SERVICE_GET_CLASS (config)->get_value (config, section, name, &error);
196 g_dbus_method_invocation_return_value (invocation, g_variant_new ("(v)", value));
199 g_dbus_method_invocation_return_gerror (invocation, error);
200 g_error_free (error);
205 if (g_strcmp0 (method_name, "GetValues") == 0) {
208 GError *error = NULL;
210 g_variant_get (parameters, "(&s)", §ion);
212 value = IBUS_CONFIG_SERVICE_GET_CLASS (config)->get_values (config,
216 g_dbus_method_invocation_return_value (invocation,
217 g_variant_new ("(@a{sv})", value));
220 g_dbus_method_invocation_return_gerror (invocation, error);
221 g_error_free (error);
226 if (g_strcmp0 (method_name, "UnsetValue") == 0) {
230 GError *error = NULL;
232 g_variant_get (parameters, "(&s&s)", §ion, &name);
234 retval = IBUS_CONFIG_SERVICE_GET_CLASS (config)->unset_value (config, section, name, &error);
236 g_dbus_method_invocation_return_value (invocation, NULL);
239 g_dbus_method_invocation_return_gerror (invocation, error);
240 g_error_free (error);
245 /* should not be reached */
246 g_return_if_reached ();
250 ibus_config_service_service_get_property (IBusService *service,
251 GDBusConnection *connection,
253 const gchar *object_path,
254 const gchar *interface_name,
255 const gchar *property_name,
258 return IBUS_SERVICE_CLASS (ibus_config_service_parent_class)->
259 service_get_property (service,
269 ibus_config_service_service_set_property (IBusService *service,
270 GDBusConnection *connection,
272 const gchar *object_path,
273 const gchar *interface_name,
274 const gchar *property_name,
278 return IBUS_SERVICE_CLASS (ibus_config_service_parent_class)->
279 service_set_property (service,
290 ibus_config_service_set_value (IBusConfigService *config,
291 const gchar *section,
297 gchar *str = g_variant_print (value, TRUE);
298 *error = g_error_new (G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
299 "Cannot set value %s::%s to %s", section, name, str);
306 ibus_config_service_get_value (IBusConfigService *config,
307 const gchar *section,
312 *error = g_error_new (G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
313 "Cannot get value %s::%s", section, name);
319 ibus_config_service_get_values (IBusConfigService *config,
320 const gchar *section,
324 *error = g_error_new (G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
325 "Cannot get values %s", section);
331 ibus_config_service_unset_value (IBusConfigService *config,
332 const gchar *section,
337 *error = g_error_new (G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
338 "Cannot unset value %s::%s", section, name);
344 ibus_config_service_new (GDBusConnection *connection)
346 g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL);
348 GObject *object = g_object_new (IBUS_TYPE_CONFIG_SERVICE,
349 "object-path", IBUS_PATH_CONFIG,
350 "connection", connection,
352 return IBUS_CONFIG_SERVICE (object);
356 ibus_config_service_value_changed (IBusConfigService *config,
357 const gchar *section,
361 g_return_if_fail (IBUS_IS_CONFIG_SERVICE (config));
362 g_return_if_fail (section != NULL);
363 g_return_if_fail (name != NULL);
364 g_return_if_fail (value != NULL);
366 ibus_service_emit_signal ((IBusService *) config,
368 IBUS_INTERFACE_CONFIG,
370 g_variant_new ("(ssv)", section, name, value),