2
* Copyright (C) 2010, Intel Corporation.
4
* Author: Raymond Liu <raymond.liu@intel.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 License
9
* version 2.1 as published by the Free Software Foundation.
11
* This library is distributed in the hope that it will be useful, but
12
* 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 Free Software
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
24
#include "meego-im-proxy.h"
25
#include "meego-im-proxy-glue.h"
26
#include "maliitmarshalers.h"
29
#include <dbus/dbus-glib.h>
30
G_DEFINE_TYPE(MeegoIMProxy, meego_im_proxy, G_TYPE_OBJECT);
32
#define MEEGO_IM_OBJECT_PATH "/com/meego/inputmethod/uiserver1"
33
#define MEEGO_IM_SERVICE_INTERFACE "com.meego.inputmethod.uiserver1"
35
static void meego_im_proxy_finalize(GObject *object);
36
static void meego_im_proxy_class_init(MeegoIMProxyClass *klass);
37
static void meego_im_proxy_init(MeegoIMProxy *meego_im_proxy);
40
SIGNAL_CONNECTION_DROPPED = 0,
41
SIGNAL_CONNECTION_ESTABLISHED,
46
static guint meego_im_proxy_signals[N_SIGNALS];
49
struct _MeegoImProxyPrivate {
50
DBusGProxy *dbusproxy;
54
handle_disconnect(gpointer instance, MeegoIMProxy *im_proxy)
56
g_return_if_fail(im_proxy);
58
im_proxy->priv->dbusproxy = NULL;
59
g_signal_emit(im_proxy, meego_im_proxy_signals[SIGNAL_CONNECTION_DROPPED], 0, NULL);
64
handle_invoke_action(gpointer instance, const char *action, const char *sequence, MeegoIMProxy *im_proxy)
66
g_signal_emit(im_proxy, meego_im_proxy_signals[SIGNAL_INVOKE_ACTION], 0, action, sequence);
70
meego_im_proxy_new(void)
72
return g_object_new(MEEGO_TYPE_IM_PROXY, NULL);
77
meego_im_proxy_finalize(GObject *object)
79
G_OBJECT_CLASS(meego_im_proxy_parent_class)->finalize(object);
84
meego_im_proxy_class_init(MeegoIMProxyClass *klass)
86
GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
88
gobject_class->finalize = meego_im_proxy_finalize;
90
meego_im_proxy_signals[SIGNAL_CONNECTION_DROPPED] =
91
g_signal_new("connection-dropped", G_TYPE_FROM_CLASS(klass),
92
0, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
94
meego_im_proxy_signals[SIGNAL_CONNECTION_ESTABLISHED] =
95
g_signal_new("connection-established", G_TYPE_FROM_CLASS(klass),
96
0, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
98
meego_im_proxy_signals[SIGNAL_INVOKE_ACTION] =
99
g_signal_new("invoke-action", G_TYPE_FROM_CLASS(klass),
100
0, 0, NULL, NULL, _maliit_marshal_VOID__STRING_STRING, G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_STRING);
102
g_type_class_add_private(klass, sizeof(MeegoImProxyPrivate));
106
meego_im_proxy_init(MeegoIMProxy *self)
108
MeegoImProxyPrivate *priv = G_TYPE_INSTANCE_GET_PRIVATE (self, MEEGO_TYPE_IM_PROXY, MeegoImProxyPrivate);
110
self->load_plugin_settings_observer = NULL;
112
priv->dbusproxy = NULL;
117
meego_im_proxy_connect(MeegoIMProxy *proxy, gpointer connection)
119
DBusGProxy *dbusproxy;
120
DBusGConnection *dbus_connection = (DBusGConnection *)connection;
121
g_return_if_fail(dbus_connection != NULL);
123
if (proxy->priv->dbusproxy) {
124
g_object_unref(proxy->priv->dbusproxy);
127
dbusproxy = dbus_g_proxy_new_for_peer(dbus_connection,
128
MEEGO_IM_OBJECT_PATH, /* obj path */
129
MEEGO_IM_SERVICE_INTERFACE /* interface */);
131
if (dbusproxy == NULL) {
132
g_warning("could not create dbus_proxy\n");
135
g_signal_connect(G_OBJECT(dbusproxy), "destroy", G_CALLBACK(handle_disconnect), proxy);
137
dbus_g_object_register_marshaller(_maliit_marshal_VOID__STRING_STRING, G_TYPE_NONE, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
138
dbus_g_proxy_add_signal(dbusproxy, "invokeAction", G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
139
dbus_g_proxy_connect_signal(dbusproxy, "invokeAction", G_CALLBACK(handle_invoke_action), proxy, 0);
141
proxy->priv->dbusproxy = dbusproxy;
143
g_signal_emit(proxy, meego_im_proxy_signals[SIGNAL_CONNECTION_ESTABLISHED], 0);
147
meego_im_proxy_activate_context(MeegoIMProxy *proxy)
149
GError *error = NULL;
153
if (!proxy || proxy->priv->dbusproxy == NULL)
156
ret = com_meego_inputmethod_uiserver1_activate_context(proxy->priv->dbusproxy, &error);
159
g_warning("%s", error->message);
166
meego_im_proxy_register_extension (MeegoIMProxy *proxy,
168
const gchar *filename)
170
GError *error = NULL;
175
if (!proxy || proxy->priv->dbusproxy == NULL)
178
ret = com_meego_inputmethod_uiserver1_register_attribute_extension (proxy->priv->dbusproxy,
184
g_warning("%s", error->message);
191
meego_im_proxy_unregister_extension (MeegoIMProxy *proxy,
194
GError *error = NULL;
199
if (!proxy || proxy->priv->dbusproxy == NULL)
202
ret = com_meego_inputmethod_uiserver1_unregister_attribute_extension (proxy->priv->dbusproxy,
207
g_warning("%s", error->message);
214
meego_im_proxy_app_orientation_changed(MeegoIMProxy *proxy, const gint angle)
216
GError *error = NULL;
220
if (!proxy || proxy->priv->dbusproxy == NULL)
223
ret = com_meego_inputmethod_uiserver1_app_orientation_changed(proxy->priv->dbusproxy, angle, &error);
226
g_warning("%s", error->message);
234
meego_im_proxy_hide_input_method(MeegoIMProxy *proxy)
236
GError *error = NULL;
240
if (!proxy || proxy->priv->dbusproxy == NULL)
243
ret = com_meego_inputmethod_uiserver1_hide_input_method(proxy->priv->dbusproxy, &error);
246
g_warning("%s", error->message);
254
// Not yet really implemented
257
meego_im_proxy_mouse_clicked_on_preedit(MeegoIMProxy *proxy, const GValueArray *pos,
258
const GValueArray *preedit_rect)
260
GError *error = NULL;
263
if (!proxy || proxy->priv->dbusproxy == NULL)
266
ret = com_meego_inputmethod_uiserver1_mouse_clicked_on_preedit(proxy->priv->dbusproxy,
267
pos, preedit_rect, &error);
270
g_warning("%s", error->message);
278
meego_im_proxy_update_widget_info(MeegoIMProxy *proxy, const GHashTable *state_information, gboolean focus_changed)
280
GError *error = NULL;
284
if (!proxy || proxy->priv->dbusproxy == NULL)
287
ret = com_meego_inputmethod_uiserver1_update_widget_information(proxy->priv->dbusproxy,
288
state_information, focus_changed, &error);
291
g_warning("%s", error->message);
301
meego_im_proxy_process_key_event(MeegoIMProxy *proxy, const gint type, const gint code,
302
const gint modifiers, const char *text,
303
const gboolean auto_repeat, const gint count,
304
const guint native_scan_code,
305
const guint native_modifiers,
308
GError *error = NULL;
311
DBG("QT key event type=0x%x, code=0x%x, modifiers=0x%x, text=%s",
312
type, code, modifiers, text);
313
if (!proxy || proxy->priv->dbusproxy == NULL)
316
ret = com_meego_inputmethod_uiserver1_process_key_event(proxy->priv->dbusproxy,
317
type, code, modifiers, text, auto_repeat,
318
count, native_scan_code, native_modifiers,
322
g_warning("%s", error->message);
330
meego_im_proxy_reset(MeegoIMProxy *proxy)
332
GError *error = NULL;
336
if (!proxy || proxy->priv->dbusproxy == NULL)
339
ret = com_meego_inputmethod_uiserver1_reset(proxy->priv->dbusproxy, &error);
342
g_warning("%s", error->message);
350
meego_im_proxy_set_copy_paste_state(MeegoIMProxy *proxy, const gboolean copy_available,
351
const gboolean paste_available)
353
GError *error = NULL;
357
if (!proxy || proxy->priv->dbusproxy == NULL)
360
ret = com_meego_inputmethod_uiserver1_set_copy_paste_state(proxy->priv->dbusproxy,
361
copy_available, paste_available, &error);
364
g_warning("%s", error->message);
372
meego_im_proxy_set_preedit(MeegoIMProxy *proxy, const char *text, gint cursor_pos)
374
GError *error = NULL;
378
if (!proxy || proxy->priv->dbusproxy == NULL)
381
ret = com_meego_inputmethod_uiserver1_set_preedit(proxy->priv->dbusproxy, text, cursor_pos, &error);
384
g_warning("%s", error->message);
392
meego_im_proxy_show_input_method(MeegoIMProxy *proxy)
394
GError *error = NULL;
398
if (!proxy || proxy->priv->dbusproxy == NULL)
401
ret = com_meego_inputmethod_uiserver1_show_input_method(proxy->priv->dbusproxy, &error);
404
g_warning("%s", error->message);
411
meego_im_proxy_set_extended_attribute (MeegoIMProxy *proxy,
414
const gchar *target_item,
415
const gchar *attribute,
418
GError *error = NULL;
422
if (!proxy || proxy->priv->dbusproxy == NULL)
425
ret = com_meego_inputmethod_uiserver1_set_extended_attribute (proxy->priv->dbusproxy,
434
g_warning("%s", error->message);
441
meego_im_proxy_load_plugin_settings (MeegoIMProxy *proxy,
442
const gchar *locale_name)
447
g_return_val_if_fail (MEEGO_IS_IM_PROXY (proxy), FALSE);
449
if (proxy->load_plugin_settings_observer) {
450
proxy->load_plugin_settings_observer(proxy, locale_name);
453
if (!proxy->priv->dbusproxy) {
458
ret = com_meego_inputmethod_uiserver1_load_plugin_settings (proxy->priv->dbusproxy,
463
g_warning ("%s", error->message);
464
g_error_free (error);