35
33
// static guint config_service_signals[LAST_SIGNAL] = { 0 };
37
35
/* functions prototype */
38
static void ibus_config_service_class_init (IBusConfigServiceClass *klass);
39
static void ibus_config_service_init (IBusConfigService *config);
40
static void ibus_config_service_set_property (IBusConfigService *config,
44
static void ibus_config_service_get_property (IBusConfigService *config,
48
static void ibus_config_service_destroy (IBusConfigService *config);
49
static gboolean ibus_config_service_ibus_message (IBusConfigService *config,
50
IBusConnection *connection,
51
IBusMessage *message);
52
static gboolean ibus_config_service_set_value (IBusConfigService *config,
57
static gboolean ibus_config_service_get_value (IBusConfigService *config,
62
static gboolean ibus_config_service_unset (IBusConfigService *config,
67
static IBusServiceClass *parent_class = NULL;
70
ibus_config_service_get_type (void)
72
static GType type = 0;
74
static const GTypeInfo type_info = {
75
sizeof (IBusConfigServiceClass),
77
(GBaseFinalizeFunc) NULL,
78
(GClassInitFunc) ibus_config_service_class_init,
79
NULL, /* class finalize */
80
NULL, /* class data */
81
sizeof (IBusConfigService),
83
(GInstanceInitFunc) ibus_config_service_init,
87
type = g_type_register_static (IBUS_TYPE_SERVICE,
96
ibus_config_service_new (IBusConnection *connection)
98
g_assert (IBUS_IS_CONNECTION (connection));
100
IBusConfigService *config;
102
config = (IBusConfigService *) g_object_new (IBUS_TYPE_CONFIG_SERVICE,
103
"path", IBUS_PATH_CONFIG,
104
"connection", connection,
36
static void ibus_config_service_class_init (IBusConfigServiceClass *class);
37
static void ibus_config_service_init (IBusConfigService *config);
38
static void ibus_config_service_set_property (IBusConfigService *config,
42
static void ibus_config_service_get_property (IBusConfigService *config,
46
static void ibus_config_service_destroy (IBusConfigService *config);
47
static void ibus_config_service_service_method_call
48
(IBusService *service,
49
GDBusConnection *connection,
51
const gchar *object_path,
52
const gchar *interface_name,
53
const gchar *method_name,
55
GDBusMethodInvocation *invocation);
56
static GVariant *ibus_config_service_service_get_property
57
(IBusService *service,
58
GDBusConnection *connection,
60
const gchar *object_path,
61
const gchar *interface_name,
62
const gchar *property_name,
64
static gboolean ibus_config_service_service_set_property
65
(IBusService *service,
66
GDBusConnection *connection,
68
const gchar *object_path,
69
const gchar *interface_name,
70
const gchar *property_name,
73
static gboolean ibus_config_service_set_value (IBusConfigService *config,
78
static GVariant *ibus_config_service_get_value (IBusConfigService *config,
82
static gboolean ibus_config_service_unset_value (IBusConfigService *config,
87
G_DEFINE_TYPE (IBusConfigService, ibus_config_service, IBUS_TYPE_SERVICE)
89
static const gchar introspection_xml[] =
91
" <interface name='org.freedesktop.IBus.Config'>"
92
" <method name='SetValue'>"
93
" <arg direction='in' type='s' name='section' />"
94
" <arg direction='in' type='s' name='name' />"
95
" <arg direction='in' type='v' name='value' />"
97
" <method name='GetValue'>"
98
" <arg direction='in' type='s' name='section' />"
99
" <arg direction='in' type='s' name='name' />"
100
" <arg direction='out' type='v' name='value' />"
102
" <method name='UnsetValue'>"
103
" <arg direction='in' type='s' name='section' />"
104
" <arg direction='in' type='s' name='name' />"
106
" <signal name='ValueChanged'>"
107
" <arg type='s' name='section' />"
108
" <arg type='s' name='name' />"
109
" <arg type='v' name='value' />"
111
ibus_config_service_class_init (IBusConfigServiceClass *klass)
115
ibus_config_service_class_init (IBusConfigServiceClass *class)
113
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
115
parent_class = (IBusServiceClass *) g_type_class_peek_parent (klass);
117
GObjectClass *gobject_class = G_OBJECT_CLASS (class);
117
119
gobject_class->set_property = (GObjectSetPropertyFunc) ibus_config_service_set_property;
118
120
gobject_class->get_property = (GObjectGetPropertyFunc) ibus_config_service_get_property;
120
122
IBUS_OBJECT_CLASS (gobject_class)->destroy = (IBusObjectDestroyFunc) ibus_config_service_destroy;
122
IBUS_SERVICE_CLASS (klass)->ibus_message = (ServiceIBusMessageFunc) ibus_config_service_ibus_message;
124
klass->set_value = ibus_config_service_set_value;
125
klass->get_value = ibus_config_service_get_value;
126
klass->unset = ibus_config_service_unset;
128
/* install properties */
130
* IBusConfigService:connection:
132
* Connection of this IBusConfigService.
134
g_object_class_install_property (gobject_class,
136
g_param_spec_object ("connection",
138
"The connection of config object",
139
IBUS_TYPE_CONNECTION,
140
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
124
IBUS_SERVICE_CLASS (class)->service_method_call = ibus_config_service_service_method_call;
125
IBUS_SERVICE_CLASS (class)->service_get_property = ibus_config_service_service_get_property;
126
IBUS_SERVICE_CLASS (class)->service_set_property = ibus_config_service_service_set_property;
128
ibus_service_class_add_interfaces (IBUS_SERVICE_CLASS (class), introspection_xml);
130
class->set_value = ibus_config_service_set_value;
131
class->get_value = ibus_config_service_get_value;
132
class->unset_value = ibus_config_service_unset_value;
190
169
ibus_config_service_destroy (IBusConfigService *config)
192
IBUS_OBJECT_CLASS(parent_class)->destroy ((IBusObject *) config);
171
IBUS_OBJECT_CLASS(ibus_config_service_parent_class)->destroy ((IBusObject *) config);
175
ibus_config_service_service_method_call (IBusService *service,
176
GDBusConnection *connection,
178
const gchar *object_path,
179
const gchar *interface_name,
180
const gchar *method_name,
181
GVariant *parameters,
182
GDBusMethodInvocation *invocation)
184
IBusConfigService *config = IBUS_CONFIG_SERVICE (service);
186
if (g_strcmp0 (interface_name, IBUS_INTERFACE_CONFIG) != 0) {
187
IBUS_SERVICE_CLASS (ibus_config_service_parent_class)->
188
service_method_call (service,
199
if (g_strcmp0 (method_name, "SetValue") == 0) {
204
GError *error = NULL;
206
g_variant_get (parameters, "(&s&sv)", §ion, &name, &value);
208
retval = IBUS_CONFIG_SERVICE_GET_CLASS (config)->set_value (config, section, name, value, &error);
210
g_dbus_method_invocation_return_value (invocation, NULL);
213
g_dbus_method_invocation_return_gerror (invocation, error);
214
g_error_free (error);
219
if (g_strcmp0 (method_name, "GetValue") == 0) {
223
GError *error = NULL;
225
g_variant_get (parameters, "(&s&s)", §ion, &name);
227
value = IBUS_CONFIG_SERVICE_GET_CLASS (config)->get_value (config, section, name, &error);
229
g_dbus_method_invocation_return_value (invocation, g_variant_new ("(v)", value));
232
g_dbus_method_invocation_return_gerror (invocation, error);
233
g_error_free (error);
238
if (g_strcmp0 (method_name, "UnsetValue") == 0) {
242
GError *error = NULL;
244
g_variant_get (parameters, "(&s&s)", §ion, &name);
246
retval = IBUS_CONFIG_SERVICE_GET_CLASS (config)->unset_value (config, section, name, &error);
248
g_dbus_method_invocation_return_value (invocation, NULL);
251
g_dbus_method_invocation_return_gerror (invocation, error);
252
g_error_free (error);
257
/* should not be reached */
258
g_return_if_reached ();
262
ibus_config_service_service_get_property (IBusService *service,
263
GDBusConnection *connection,
265
const gchar *object_path,
266
const gchar *interface_name,
267
const gchar *property_name,
270
return IBUS_SERVICE_CLASS (ibus_config_service_parent_class)->
271
service_get_property (service,
196
ibus_config_service_ibus_message (IBusConfigService *config,
197
IBusConnection *connection,
198
IBusMessage *message)
281
ibus_config_service_service_set_property (IBusService *service,
282
GDBusConnection *connection,
284
const gchar *object_path,
285
const gchar *interface_name,
286
const gchar *property_name,
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);
226
if (!IBUS_CONFIG_SERVICE_GET_CLASS (config)->set_value (config, section, name, &value, &error)) {
227
reply = ibus_message_new_error (message,
230
ibus_error_free (error);
233
reply = ibus_message_new_method_return (message);
235
g_value_unset (&value);
238
else if (ibus_message_is_method_call (message, IBUS_INTERFACE_CONFIG, "GetValue")) {
241
GValue value = { 0 };
242
IBusError *error = NULL;
245
retval = ibus_message_get_args (message,
247
G_TYPE_STRING, §ion,
248
G_TYPE_STRING, &name,
252
reply = ibus_message_new_error (message,
255
ibus_error_free (error);
257
else if (!IBUS_CONFIG_SERVICE_GET_CLASS (config)->get_value (config, section, name, &value, &error)) {
258
reply = ibus_message_new_error (message,
261
ibus_error_free (error);
264
reply = ibus_message_new_method_return (message);
265
ibus_message_append_args (reply,
266
G_TYPE_VALUE, &value,
268
g_value_unset (&value);
271
else if (ibus_message_is_method_call (message, IBUS_INTERFACE_CONFIG, "Unset")) {
274
IBusError *error = NULL;
277
retval = ibus_message_get_args (message,
279
G_TYPE_STRING, §ion,
280
G_TYPE_STRING, &name,
283
reply = ibus_message_new_error_printf (message,
284
DBUS_ERROR_INVALID_ARGS,
285
"Can not parse arguments 1 of Unset");
286
ibus_error_free (error);
288
else if (!IBUS_CONFIG_SERVICE_GET_CLASS (config)->unset (config, section, name, &error)) {
289
reply = ibus_message_new_error (message,
292
ibus_error_free (error);
295
reply = ibus_message_new_method_return (message);
300
ibus_connection_send (connection, reply);
301
ibus_message_unref (reply);
305
return parent_class->ibus_message ((IBusService *) config, connection, message);
290
return IBUS_SERVICE_CLASS (ibus_config_service_parent_class)->
291
service_set_property (service,
309
302
ibus_config_service_set_value (IBusConfigService *config,
310
303
const gchar *section,
311
304
const gchar *name,
316
*error = ibus_error_new_from_printf (DBUS_ERROR_FAILED,
317
"Can not set value [%s, %s]",
309
gchar *str = g_variant_print (value, TRUE);
310
*error = g_error_new (G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
311
"Cannot set value %s::%s to %s", section, name, str);
324
318
ibus_config_service_get_value (IBusConfigService *config,
325
319
const gchar *section,
326
320
const gchar *name,
331
*error = ibus_error_new_from_printf (DBUS_ERROR_FAILED,
332
"Can not get value [%s, %s]",
324
*error = g_error_new (G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
325
"Cannot get value %s::%s", section, name);
339
ibus_config_service_unset (IBusConfigService *config,
340
const gchar *section,
331
ibus_config_service_unset_value (IBusConfigService *config,
332
const gchar *section,
345
*error = ibus_error_new_from_printf (DBUS_ERROR_FAILED,
346
"Can not unset [%s, %s]",
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);
353
356
ibus_config_service_value_changed (IBusConfigService *config,
354
357
const gchar *section,
355
358
const gchar *name,
358
g_assert (IBUS_IS_CONFIG_SERVICE (config));
361
g_assert (G_IS_VALUE (value));
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);
363
ibus_service_send_signal ((IBusService *) config,
366
ibus_service_emit_signal ((IBusService *) config,
364
368
IBUS_INTERFACE_CONFIG,
366
G_TYPE_STRING, §ion,
367
G_TYPE_STRING, &name,
370
g_variant_new ("(ssv)", section, name, value),