~timo-jyrinki/ubuntu/trusty/maliit-framework/fix_qt52

« back to all changes in this revision

Viewing changes to connection-glib/meego-im-proxy.c

  • Committer: Package Import Robot
  • Author(s): Ricardo Salveti de Araujo, Sergio Schvezov, Ricardo Salveti de Araujo
  • Date: 2013-07-23 19:47:04 UTC
  • mfrom: (1.1.2) (1.2.1 experimental)
  • Revision ID: package-import@ubuntu.com-20130723194704-1lsy1kmlda069cea
Tags: 0.99.0+git20130615+97e8335-0ubuntu1
[ Sergio Schvezov ]
* New build from HEAD 97e8335.
* Packaging import from lp:phablet-extras/maliit-framework.

[ Ricardo Salveti de Araujo ]
* debian/control: adding vcs and fixing dependencies
* General package cleanup

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2010, Intel Corporation.
3
 
 *
4
 
 * Author: Raymond Liu <raymond.liu@intel.com>
5
 
 *
6
 
 *
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.
10
 
 *
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.
15
 
 *
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
19
 
 * 02110-1301 USA
20
 
 */
21
 
 
22
 
#include <string.h>
23
 
 
24
 
#include "meego-im-proxy.h"
25
 
#include "meego-im-proxy-glue.h"
26
 
#include "maliitmarshalers.h"
27
 
#include "debug.h"
28
 
 
29
 
#include <dbus/dbus-glib.h>
30
 
G_DEFINE_TYPE(MeegoIMProxy, meego_im_proxy, G_TYPE_OBJECT);
31
 
 
32
 
#define MEEGO_IM_OBJECT_PATH "/com/meego/inputmethod/uiserver1"
33
 
#define MEEGO_IM_SERVICE_INTERFACE "com.meego.inputmethod.uiserver1"
34
 
 
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);
38
 
 
39
 
enum {
40
 
    SIGNAL_CONNECTION_DROPPED = 0,
41
 
    SIGNAL_CONNECTION_ESTABLISHED,
42
 
    SIGNAL_INVOKE_ACTION,
43
 
    N_SIGNALS
44
 
};
45
 
 
46
 
static guint meego_im_proxy_signals[N_SIGNALS];
47
 
 
48
 
/* Private struct */
49
 
struct _MeegoImProxyPrivate {
50
 
    DBusGProxy *dbusproxy;
51
 
};
52
 
 
53
 
static void
54
 
handle_disconnect(gpointer instance, MeegoIMProxy *im_proxy)
55
 
{
56
 
    g_return_if_fail(im_proxy);
57
 
 
58
 
    im_proxy->priv->dbusproxy = NULL;
59
 
    g_signal_emit(im_proxy, meego_im_proxy_signals[SIGNAL_CONNECTION_DROPPED], 0, NULL);
60
 
 
61
 
}
62
 
 
63
 
static void
64
 
handle_invoke_action(gpointer instance, const char *action, const char *sequence, MeegoIMProxy *im_proxy)
65
 
{
66
 
    g_signal_emit(im_proxy, meego_im_proxy_signals[SIGNAL_INVOKE_ACTION], 0, action, sequence);
67
 
}
68
 
 
69
 
MeegoIMProxy *
70
 
meego_im_proxy_new(void)
71
 
{
72
 
    return g_object_new(MEEGO_TYPE_IM_PROXY, NULL);
73
 
}
74
 
 
75
 
 
76
 
static void
77
 
meego_im_proxy_finalize(GObject *object)
78
 
{
79
 
    G_OBJECT_CLASS(meego_im_proxy_parent_class)->finalize(object);
80
 
}
81
 
 
82
 
 
83
 
static void
84
 
meego_im_proxy_class_init(MeegoIMProxyClass *klass)
85
 
{
86
 
    GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
87
 
 
88
 
    gobject_class->finalize = meego_im_proxy_finalize;
89
 
 
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);
93
 
 
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);
97
 
 
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);
101
 
 
102
 
    g_type_class_add_private(klass, sizeof(MeegoImProxyPrivate));
103
 
}
104
 
 
105
 
static void
106
 
meego_im_proxy_init(MeegoIMProxy *self)
107
 
{
108
 
    MeegoImProxyPrivate *priv = G_TYPE_INSTANCE_GET_PRIVATE (self, MEEGO_TYPE_IM_PROXY, MeegoImProxyPrivate);
109
 
 
110
 
    self->load_plugin_settings_observer = NULL;
111
 
 
112
 
    priv->dbusproxy = NULL;
113
 
    self->priv = priv;
114
 
}
115
 
 
116
 
void
117
 
meego_im_proxy_connect(MeegoIMProxy *proxy, gpointer connection)
118
 
{
119
 
    DBusGProxy *dbusproxy;
120
 
    DBusGConnection *dbus_connection = (DBusGConnection *)connection;
121
 
    g_return_if_fail(dbus_connection != NULL);
122
 
 
123
 
    if (proxy->priv->dbusproxy) {
124
 
        g_object_unref(proxy->priv->dbusproxy);
125
 
    }
126
 
 
127
 
    dbusproxy = dbus_g_proxy_new_for_peer(dbus_connection,
128
 
                                          MEEGO_IM_OBJECT_PATH, /* obj path */
129
 
                                          MEEGO_IM_SERVICE_INTERFACE /* interface */);
130
 
 
131
 
    if (dbusproxy == NULL) {
132
 
        g_warning("could not create dbus_proxy\n");
133
 
    }
134
 
 
135
 
    g_signal_connect(G_OBJECT(dbusproxy), "destroy", G_CALLBACK(handle_disconnect), proxy);
136
 
 
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);
140
 
 
141
 
    proxy->priv->dbusproxy = dbusproxy;
142
 
 
143
 
    g_signal_emit(proxy, meego_im_proxy_signals[SIGNAL_CONNECTION_ESTABLISHED], 0);
144
 
}
145
 
 
146
 
gboolean
147
 
meego_im_proxy_activate_context(MeegoIMProxy *proxy)
148
 
{
149
 
    GError *error = NULL;
150
 
    gboolean ret = TRUE;
151
 
 
152
 
    STEP();
153
 
    if (!proxy || proxy->priv->dbusproxy == NULL)
154
 
        return FALSE;
155
 
 
156
 
    ret = com_meego_inputmethod_uiserver1_activate_context(proxy->priv->dbusproxy, &error);
157
 
 
158
 
    if (error != NULL) {
159
 
        g_warning("%s", error->message);
160
 
    }
161
 
 
162
 
    return ret;
163
 
}
164
 
 
165
 
gboolean
166
 
meego_im_proxy_register_extension (MeegoIMProxy *proxy,
167
 
                                   gint id,
168
 
                                   const gchar *filename)
169
 
{
170
 
    GError *error = NULL;
171
 
    gboolean ret = TRUE;
172
 
 
173
 
    STEP();
174
 
 
175
 
    if (!proxy || proxy->priv->dbusproxy == NULL)
176
 
        return FALSE;
177
 
 
178
 
    ret = com_meego_inputmethod_uiserver1_register_attribute_extension (proxy->priv->dbusproxy,
179
 
                                                                        id,
180
 
                                                                        filename,
181
 
                                                                        &error);
182
 
 
183
 
    if (error != NULL) {
184
 
      g_warning("%s", error->message);
185
 
    }
186
 
 
187
 
    return ret;
188
 
}
189
 
 
190
 
gboolean
191
 
meego_im_proxy_unregister_extension (MeegoIMProxy *proxy,
192
 
                                     gint id)
193
 
{
194
 
    GError *error = NULL;
195
 
    gboolean ret = TRUE;
196
 
 
197
 
    STEP();
198
 
 
199
 
    if (!proxy || proxy->priv->dbusproxy == NULL)
200
 
        return FALSE;
201
 
 
202
 
    ret = com_meego_inputmethod_uiserver1_unregister_attribute_extension (proxy->priv->dbusproxy,
203
 
                                                                          id,
204
 
                                                                          &error);
205
 
 
206
 
    if (error != NULL) {
207
 
      g_warning("%s", error->message);
208
 
    }
209
 
 
210
 
    return ret;
211
 
}
212
 
 
213
 
gboolean
214
 
meego_im_proxy_app_orientation_changed(MeegoIMProxy *proxy, const gint angle)
215
 
{
216
 
    GError *error = NULL;
217
 
    gboolean ret = TRUE;
218
 
 
219
 
    STEP();
220
 
    if (!proxy || proxy->priv->dbusproxy == NULL)
221
 
        return FALSE;
222
 
 
223
 
    ret = com_meego_inputmethod_uiserver1_app_orientation_changed(proxy->priv->dbusproxy, angle, &error);
224
 
 
225
 
    if (error != NULL) {
226
 
        g_warning("%s", error->message);
227
 
    }
228
 
 
229
 
    return ret;
230
 
}
231
 
 
232
 
 
233
 
gboolean
234
 
meego_im_proxy_hide_input_method(MeegoIMProxy *proxy)
235
 
{
236
 
    GError *error = NULL;
237
 
    gboolean ret = TRUE;
238
 
 
239
 
    STEP();
240
 
    if (!proxy || proxy->priv->dbusproxy == NULL)
241
 
        return FALSE;
242
 
 
243
 
    ret = com_meego_inputmethod_uiserver1_hide_input_method(proxy->priv->dbusproxy, &error);
244
 
 
245
 
    if (error != NULL) {
246
 
        g_warning("%s", error->message);
247
 
    }
248
 
 
249
 
    return ret;
250
 
}
251
 
 
252
 
 
253
 
#if 0
254
 
// Not yet really implemented
255
 
 
256
 
gboolean
257
 
meego_im_proxy_mouse_clicked_on_preedit(MeegoIMProxy *proxy, const GValueArray *pos,
258
 
                                        const GValueArray *preedit_rect)
259
 
{
260
 
    GError *error = NULL;
261
 
    gboolean ret = TRUE;
262
 
 
263
 
    if (!proxy || proxy->priv->dbusproxy == NULL)
264
 
        return FALSE;
265
 
 
266
 
    ret = com_meego_inputmethod_uiserver1_mouse_clicked_on_preedit(proxy->priv->dbusproxy,
267
 
            pos, preedit_rect, &error);
268
 
 
269
 
    if (error != NULL) {
270
 
        g_warning("%s", error->message);
271
 
    }
272
 
 
273
 
    return ret;
274
 
}
275
 
#endif
276
 
 
277
 
gboolean
278
 
meego_im_proxy_update_widget_info(MeegoIMProxy *proxy, const GHashTable *state_information, gboolean focus_changed)
279
 
{
280
 
    GError *error = NULL;
281
 
    gboolean ret = TRUE;
282
 
 
283
 
    STEP();
284
 
    if (!proxy || proxy->priv->dbusproxy == NULL)
285
 
        return FALSE;
286
 
 
287
 
    ret = com_meego_inputmethod_uiserver1_update_widget_information(proxy->priv->dbusproxy,
288
 
            state_information, focus_changed, &error);
289
 
 
290
 
    if (error != NULL) {
291
 
        g_warning("%s", error->message);
292
 
    }
293
 
 
294
 
    return ret;
295
 
}
296
 
 
297
 
 
298
 
 
299
 
 
300
 
gboolean
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,
306
 
                                 const guint time)
307
 
{
308
 
    GError *error = NULL;
309
 
    gboolean ret = TRUE;
310
 
 
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)
314
 
        return FALSE;
315
 
 
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,
319
 
            time, &error);
320
 
 
321
 
    if (error != NULL) {
322
 
        g_warning("%s", error->message);
323
 
    }
324
 
 
325
 
    return ret;
326
 
}
327
 
 
328
 
 
329
 
gboolean
330
 
meego_im_proxy_reset(MeegoIMProxy *proxy)
331
 
{
332
 
    GError *error = NULL;
333
 
    gboolean ret = TRUE;
334
 
 
335
 
    STEP();
336
 
    if (!proxy || proxy->priv->dbusproxy == NULL)
337
 
        return FALSE;
338
 
 
339
 
    ret = com_meego_inputmethod_uiserver1_reset(proxy->priv->dbusproxy, &error);
340
 
 
341
 
    if (error != NULL) {
342
 
        g_warning("%s", error->message);
343
 
    }
344
 
 
345
 
    return ret;
346
 
}
347
 
 
348
 
 
349
 
gboolean
350
 
meego_im_proxy_set_copy_paste_state(MeegoIMProxy *proxy, const gboolean copy_available,
351
 
                                    const gboolean paste_available)
352
 
{
353
 
    GError *error = NULL;
354
 
    gboolean ret = TRUE;
355
 
 
356
 
    STEP();
357
 
    if (!proxy || proxy->priv->dbusproxy == NULL)
358
 
        return FALSE;
359
 
 
360
 
    ret = com_meego_inputmethod_uiserver1_set_copy_paste_state(proxy->priv->dbusproxy,
361
 
            copy_available, paste_available, &error);
362
 
 
363
 
    if (error != NULL) {
364
 
        g_warning("%s", error->message);
365
 
    }
366
 
 
367
 
    return ret;
368
 
}
369
 
 
370
 
 
371
 
gboolean
372
 
meego_im_proxy_set_preedit(MeegoIMProxy *proxy, const char *text, gint cursor_pos)
373
 
{
374
 
    GError *error = NULL;
375
 
    gboolean ret = TRUE;
376
 
 
377
 
    STEP();
378
 
    if (!proxy || proxy->priv->dbusproxy == NULL)
379
 
        return FALSE;
380
 
 
381
 
    ret = com_meego_inputmethod_uiserver1_set_preedit(proxy->priv->dbusproxy, text, cursor_pos, &error);
382
 
 
383
 
    if (error != NULL) {
384
 
        g_warning("%s", error->message);
385
 
    }
386
 
 
387
 
    return ret;
388
 
}
389
 
 
390
 
 
391
 
gboolean
392
 
meego_im_proxy_show_input_method(MeegoIMProxy *proxy)
393
 
{
394
 
    GError *error = NULL;
395
 
    gboolean ret = TRUE;
396
 
 
397
 
    STEP();
398
 
    if (!proxy || proxy->priv->dbusproxy == NULL)
399
 
        return FALSE;
400
 
 
401
 
    ret = com_meego_inputmethod_uiserver1_show_input_method(proxy->priv->dbusproxy, &error);
402
 
 
403
 
    if (error != NULL) {
404
 
        g_warning("%s", error->message);
405
 
    }
406
 
 
407
 
    return ret;
408
 
}
409
 
 
410
 
gboolean
411
 
meego_im_proxy_set_extended_attribute (MeegoIMProxy *proxy,
412
 
                                       gint id,
413
 
                                       const gchar *target,
414
 
                                       const gchar *target_item,
415
 
                                       const gchar *attribute,
416
 
                                       GValue *value)
417
 
{
418
 
    GError *error = NULL;
419
 
    gboolean ret = TRUE;
420
 
 
421
 
    STEP();
422
 
    if (!proxy || proxy->priv->dbusproxy == NULL)
423
 
        return FALSE;
424
 
 
425
 
    ret = com_meego_inputmethod_uiserver1_set_extended_attribute (proxy->priv->dbusproxy,
426
 
                                                                  id,
427
 
                                                                  target,
428
 
                                                                  target_item,
429
 
                                                                  attribute,
430
 
                                                                  value,
431
 
                                                                  &error);
432
 
 
433
 
    if (error != NULL) {
434
 
        g_warning("%s", error->message);
435
 
    }
436
 
 
437
 
    return ret;
438
 
}
439
 
 
440
 
gboolean
441
 
meego_im_proxy_load_plugin_settings (MeegoIMProxy *proxy,
442
 
                                     const gchar *locale_name)
443
 
{
444
 
    GError *error;
445
 
    gboolean ret;
446
 
 
447
 
    g_return_val_if_fail (MEEGO_IS_IM_PROXY (proxy), FALSE);
448
 
 
449
 
    if (proxy->load_plugin_settings_observer) {
450
 
        proxy->load_plugin_settings_observer(proxy, locale_name);
451
 
    }
452
 
 
453
 
    if (!proxy->priv->dbusproxy) {
454
 
        return FALSE;
455
 
    }
456
 
 
457
 
    error = NULL;
458
 
    ret = com_meego_inputmethod_uiserver1_load_plugin_settings (proxy->priv->dbusproxy,
459
 
                                                                locale_name,
460
 
                                                                &error);
461
 
 
462
 
    if (error) {
463
 
        g_warning ("%s", error->message);
464
 
        g_error_free (error);
465
 
    }
466
 
 
467
 
    return ret;
468
 
}