1 /* vim:set et sts=4: */
2 /* ibus - The Input Bus
3 * Copyright (C) 2008-2009 Peng Huang <shawn.p.huang@gmail.com>
4 * Copyright (C) 2008-2009 Red Hat, Inc.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
22 #include "ibusshare.h"
23 #include "ibusconfigservice.h"
34 // static guint config_service_signals[LAST_SIGNAL] = { 0 };
36 /* functions prototype */
37 static void ibus_config_service_class_init (IBusConfigServiceClass *klass);
38 static void ibus_config_service_init (IBusConfigService *config);
39 static void ibus_config_service_set_property (IBusConfigService *config,
43 static void ibus_config_service_get_property (IBusConfigService *config,
47 static void ibus_config_service_destroy (IBusConfigService *config);
48 static gboolean ibus_config_service_ibus_message (IBusConfigService *config,
49 IBusConnection *connection,
50 IBusMessage *message);
51 static gboolean ibus_config_service_set_value (IBusConfigService *config,
56 static gboolean ibus_config_service_get_value (IBusConfigService *config,
61 static gboolean ibus_config_service_unset (IBusConfigService *config,
66 static IBusServiceClass *parent_class = NULL;
69 ibus_config_service_get_type (void)
71 static GType type = 0;
73 static const GTypeInfo type_info = {
74 sizeof (IBusConfigServiceClass),
76 (GBaseFinalizeFunc) NULL,
77 (GClassInitFunc) ibus_config_service_class_init,
78 NULL, /* class finalize */
79 NULL, /* class data */
80 sizeof (IBusConfigService),
82 (GInstanceInitFunc) ibus_config_service_init,
86 type = g_type_register_static (IBUS_TYPE_SERVICE,
95 ibus_config_service_new (IBusConnection *connection)
97 g_assert (IBUS_IS_CONNECTION (connection));
99 IBusConfigService *config;
101 config = (IBusConfigService *) g_object_new (IBUS_TYPE_CONFIG_SERVICE,
102 "path", IBUS_PATH_CONFIG,
103 "connection", connection,
110 ibus_config_service_class_init (IBusConfigServiceClass *klass)
112 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
114 parent_class = (IBusServiceClass *) g_type_class_peek_parent (klass);
116 gobject_class->set_property = (GObjectSetPropertyFunc) ibus_config_service_set_property;
117 gobject_class->get_property = (GObjectGetPropertyFunc) ibus_config_service_get_property;
119 IBUS_OBJECT_CLASS (gobject_class)->destroy = (IBusObjectDestroyFunc) ibus_config_service_destroy;
121 IBUS_SERVICE_CLASS (klass)->ibus_message = (ServiceIBusMessageFunc) ibus_config_service_ibus_message;
123 klass->set_value = ibus_config_service_set_value;
124 klass->get_value = ibus_config_service_get_value;
125 klass->unset = ibus_config_service_unset;
127 /* install properties */
129 * IBusConfigService:connection:
131 * Connection of this IBusConfigService.
133 g_object_class_install_property (gobject_class,
135 g_param_spec_object ("connection",
137 "The connection of config object",
138 IBUS_TYPE_CONNECTION,
139 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
143 ibus_config_service_init (IBusConfigService *config)
148 ibus_config_service_set_property (IBusConfigService *config,
154 case PROP_CONNECTION:
155 ibus_service_add_to_connection ((IBusService *) config,
156 g_value_get_object (value));
160 G_OBJECT_WARN_INVALID_PROPERTY_ID (config, prop_id, pspec);
165 ibus_config_service_get_property (IBusConfigService *config,
171 case PROP_CONNECTION:
173 GList *connections = ibus_service_get_connections ((IBusService *) config);
175 g_value_set_object (value, connections->data);
178 g_value_set_object (value, NULL);
180 g_list_foreach (connections, (GFunc) g_object_unref, NULL);
181 g_list_free (connections);
185 G_OBJECT_WARN_INVALID_PROPERTY_ID (config, prop_id, pspec);
190 ibus_config_service_destroy (IBusConfigService *config)
192 IBUS_OBJECT_CLASS(parent_class)->destroy ((IBusObject *) config);
196 ibus_config_service_ibus_message (IBusConfigService *config,
197 IBusConnection *connection,
198 IBusMessage *message)
200 g_assert (IBUS_IS_CONFIG_SERVICE (config));
201 g_assert (IBUS_IS_CONNECTION (connection));
202 g_assert (message != NULL);
204 IBusMessage *reply = NULL;
206 if (ibus_message_is_method_call (message, IBUS_INTERFACE_CONFIG, "SetValue")) {
209 GValue value = { 0 };
210 IBusError *error = NULL;
213 retval = ibus_message_get_args (message,
215 G_TYPE_STRING, §ion,
216 G_TYPE_STRING, &name,
217 G_TYPE_VALUE, &value,
220 reply = ibus_message_new_error_printf (message,
221 DBUS_ERROR_INVALID_ARGS,
222 "Can not parse arguments 1 of SetValue");
223 ibus_error_free (error);
225 else if (!IBUS_CONFIG_SERVICE_GET_CLASS (config)->set_value (config, section, name, &value, &error)) {
226 reply = ibus_message_new_error (message,
229 ibus_error_free (error);
232 reply = ibus_message_new_method_return (message);
235 else if (ibus_message_is_method_call (message, IBUS_INTERFACE_CONFIG, "GetValue")) {
238 GValue value = { 0 };
239 IBusError *error = NULL;
242 retval = ibus_message_get_args (message,
244 G_TYPE_STRING, §ion,
245 G_TYPE_STRING, &name,
249 reply = ibus_message_new_error (message,
252 ibus_error_free (error);
254 else if (!IBUS_CONFIG_SERVICE_GET_CLASS (config)->get_value (config, section, name, &value, &error)) {
255 reply = ibus_message_new_error (message,
258 ibus_error_free (error);
261 reply = ibus_message_new_method_return (message);
262 ibus_message_append_args (reply,
263 G_TYPE_VALUE, &value,
265 g_value_unset (&value);
268 else if (ibus_message_is_method_call (message, IBUS_INTERFACE_CONFIG, "Unset")) {
271 IBusError *error = NULL;
274 retval = ibus_message_get_args (message,
276 G_TYPE_STRING, §ion,
277 G_TYPE_STRING, &name,
280 reply = ibus_message_new_error_printf (message,
281 DBUS_ERROR_INVALID_ARGS,
282 "Can not parse arguments 1 of Unset");
283 ibus_error_free (error);
285 else if (!IBUS_CONFIG_SERVICE_GET_CLASS (config)->unset (config, section, name, &error)) {
286 reply = ibus_message_new_error (message,
289 ibus_error_free (error);
292 reply = ibus_message_new_method_return (message);
297 ibus_connection_send (connection, reply);
298 ibus_message_unref (reply);
302 return parent_class->ibus_message ((IBusService *) config, connection, message);
306 ibus_config_service_set_value (IBusConfigService *config,
307 const gchar *section,
313 *error = ibus_error_new_from_printf (DBUS_ERROR_FAILED,
314 "Can not set value [%s, %s]",
321 ibus_config_service_get_value (IBusConfigService *config,
322 const gchar *section,
328 *error = ibus_error_new_from_printf (DBUS_ERROR_FAILED,
329 "Can not get value [%s, %s]",
336 ibus_config_service_unset (IBusConfigService *config,
337 const gchar *section,
342 *error = ibus_error_new_from_printf (DBUS_ERROR_FAILED,
343 "Can not unset [%s, %s]",
350 ibus_config_service_value_changed (IBusConfigService *config,
351 const gchar *section,
355 g_assert (IBUS_IS_CONFIG_SERVICE (config));
358 g_assert (G_IS_VALUE (value));
360 ibus_service_send_signal ((IBusService *) config,
361 IBUS_INTERFACE_CONFIG,
363 G_TYPE_STRING, §ion,
364 G_TYPE_STRING, &name,