~ubuntu-branches/ubuntu/quantal/ibus/quantal

« back to all changes in this revision

Viewing changes to src/ibusinputcontext.c

  • Committer: Bazaar Package Importer
  • Author(s): Barry Warsaw
  • Date: 2011-08-11 17:00:57 UTC
  • mfrom: (6.2.14 sid)
  • Revision ID: james.westby@ubuntu.com-20110811170057-6dmbfs4s3cchzl7x
Tags: 1.3.99.20110419-1ubuntu1
* Merge with Debian unstable.  Remaining Ubuntu changes:
  - Indicator support:
    + Add 05_appindicator.patch: Use an indicator rather than a notification
      icon.
    + debian/control: Recommend python-appindicator.
  - debian/control: Install im-switch instead of im-config by default.
  - debian/README.source: Removed, it was outdated and no longer correct
  - debian/patches/01_ubuntu_desktop: Fix "Desktop entry needs the
    X-Ubuntu-Gettext-Domain key"  (LP: #457632)
  - debian/patches/02_title_update.patch: Rename "IBus Preferences" to
    "Keyboard Input Methods"
  - debian/patches/06_locale_parser.patch: Cherry-picked from upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20
20
 * Boston, MA 02111-1307, USA.
21
21
 */
22
 
#include <dbus/dbus.h>
 
22
#include "ibusinputcontext.h"
 
23
#include <gio/gio.h>
23
24
#include "ibusshare.h"
24
25
#include "ibusinternal.h"
25
 
#include "ibusinputcontext.h"
 
26
#include "ibusmarshalers.h"
26
27
#include "ibusattribute.h"
27
28
#include "ibuslookuptable.h"
28
29
#include "ibusproplist.h"
54
55
    LAST_SIGNAL,
55
56
};
56
57
 
57
 
 
58
 
/* BusInputContextPriv */
 
58
/* IBusInputContextPrivate */
59
59
struct _IBusInputContextPrivate {
60
 
    gboolean own;
 
60
    /* TRUE if the current engine needs surrounding text; FALSE otherwise */
 
61
    gboolean  needs_surrounding_text;
 
62
 
 
63
    /* cached surrounding text (see also IBusEnginePrivate and
 
64
       BusEngineProxy) */
 
65
    IBusText *surrounding_text;
 
66
    guint     surrounding_cursor_pos;
61
67
};
 
68
 
62
69
typedef struct _IBusInputContextPrivate IBusInputContextPrivate;
63
70
 
64
71
static guint            context_signals[LAST_SIGNAL] = { 0 };
65
 
// static guint            context_signals[LAST_SIGNAL] = { 0 };
 
72
 
 
73
static IBusText *text_empty = NULL;
66
74
 
67
75
/* functions prototype */
68
 
static void     ibus_input_context_real_destroy (IBusInputContext       *context);
69
 
static gboolean ibus_input_context_ibus_signal  (IBusProxy              *proxy,
70
 
                                                 DBusMessage            *message);
 
76
static void     ibus_input_context_real_destroy (IBusProxy              *context);
 
77
static void     ibus_input_context_g_signal     (GDBusProxy             *proxy,
 
78
                                                 const gchar            *sender_name,
 
79
                                                 const gchar            *signal_name,
 
80
                                                 GVariant               *parameters);
71
81
 
72
82
G_DEFINE_TYPE (IBusInputContext, ibus_input_context, IBUS_TYPE_PROXY)
73
83
 
74
 
IBusInputContext *
75
 
ibus_input_context_new (const gchar     *path,
76
 
                        IBusConnection  *connection)
77
 
{
78
 
    g_assert (path != NULL);
79
 
    g_assert (IBUS_IS_CONNECTION (connection));
80
 
    GObject *obj;
81
 
 
82
 
    obj = g_object_new (IBUS_TYPE_INPUT_CONTEXT,
83
 
                        "name", IBUS_SERVICE_IBUS,
84
 
                        "interface", IBUS_INTERFACE_INPUT_CONTEXT,
85
 
                        "path", path,
86
 
                        "connection", connection,
87
 
                        NULL);
88
 
 
89
 
    return IBUS_INPUT_CONTEXT (obj);
90
 
}
91
 
 
92
 
IBusInputContext *
93
 
ibus_input_context_get_input_context (const gchar        *path,
94
 
                                      IBusConnection     *connection)
95
 
{
96
 
    IBusInputContext *context = ibus_input_context_new (path, connection);
97
 
    IBusInputContextPrivate *priv;
98
 
    if (!context)
99
 
        return NULL;
100
 
    priv = IBUS_INPUT_CONTEXT_GET_PRIVATE (context);
101
 
    priv->own = FALSE;
102
 
    return context;
103
 
}
104
 
 
105
84
static void
106
 
ibus_input_context_class_init (IBusInputContextClass *klass)
 
85
ibus_input_context_class_init (IBusInputContextClass *class)
107
86
{
108
 
    IBusObjectClass *ibus_object_class = IBUS_OBJECT_CLASS (klass);
109
 
    IBusProxyClass *proxy_class = IBUS_PROXY_CLASS (klass);
110
 
 
111
 
    g_type_class_add_private (klass, sizeof (IBusInputContextPrivate));
112
 
 
113
 
    ibus_object_class->destroy = (IBusObjectDestroyFunc) ibus_input_context_real_destroy;
114
 
 
115
 
    proxy_class->ibus_signal = ibus_input_context_ibus_signal;
 
87
    IBusProxyClass *ibus_proxy_class = IBUS_PROXY_CLASS (class);
 
88
    GDBusProxyClass *g_dbus_proxy_class = G_DBUS_PROXY_CLASS (class);
 
89
 
 
90
    g_type_class_add_private (class, sizeof (IBusInputContextPrivate));
 
91
 
 
92
    ibus_proxy_class->destroy = ibus_input_context_real_destroy;
 
93
 
 
94
    g_dbus_proxy_class->g_signal = ibus_input_context_g_signal;
116
95
 
117
96
    /* install signals */
118
97
    /**
123
102
     */
124
103
    context_signals[ENABLED] =
125
104
        g_signal_new (I_("enabled"),
126
 
            G_TYPE_FROM_CLASS (klass),
 
105
            G_TYPE_FROM_CLASS (class),
127
106
            G_SIGNAL_RUN_LAST,
128
107
            0,
129
108
            NULL, NULL,
130
 
            ibus_marshal_VOID__VOID,
 
109
            _ibus_marshal_VOID__VOID,
131
110
            G_TYPE_NONE, 0);
132
111
 
133
112
    /**
138
117
     */
139
118
    context_signals[DISABLED] =
140
119
        g_signal_new (I_("disabled"),
141
 
            G_TYPE_FROM_CLASS (klass),
 
120
            G_TYPE_FROM_CLASS (class),
142
121
            G_SIGNAL_RUN_LAST,
143
122
            0,
144
123
            NULL, NULL,
145
 
            ibus_marshal_VOID__VOID,
 
124
            _ibus_marshal_VOID__VOID,
146
125
            G_TYPE_NONE, 0);
147
126
 
148
127
    /**
158
137
     */
159
138
    context_signals[COMMIT_TEXT] =
160
139
        g_signal_new (I_("commit-text"),
161
 
            G_TYPE_FROM_CLASS (klass),
 
140
            G_TYPE_FROM_CLASS (class),
162
141
            G_SIGNAL_RUN_LAST,
163
142
            0,
164
143
            NULL, NULL,
165
 
            ibus_marshal_VOID__OBJECT,
 
144
            _ibus_marshal_VOID__OBJECT,
166
145
            G_TYPE_NONE,
167
146
            1,
168
147
            IBUS_TYPE_TEXT);
178
157
     */
179
158
    context_signals[FORWARD_KEY_EVENT] =
180
159
        g_signal_new (I_("forward-key-event"),
181
 
            G_TYPE_FROM_CLASS (klass),
 
160
            G_TYPE_FROM_CLASS (class),
182
161
            G_SIGNAL_RUN_LAST,
183
162
            0,
184
163
            NULL, NULL,
185
 
            ibus_marshal_VOID__UINT_UINT_UINT,
 
164
            _ibus_marshal_VOID__UINT_UINT_UINT,
186
165
            G_TYPE_NONE,
187
166
            3,
188
167
            G_TYPE_UINT,
200
179
     */
201
180
    context_signals[DELETE_SURROUNDING_TEXT] =
202
181
        g_signal_new (I_("delete-surrounding-text"),
203
 
            G_TYPE_FROM_CLASS (klass),
 
182
            G_TYPE_FROM_CLASS (class),
204
183
            G_SIGNAL_RUN_LAST,
205
184
            0,
206
185
            NULL, NULL,
207
 
            ibus_marshal_VOID__INT_UINT,
 
186
            _ibus_marshal_VOID__INT_UINT,
208
187
            G_TYPE_NONE,
209
188
            2,
210
189
            G_TYPE_INT,
225
204
     */
226
205
    context_signals[UPDATE_PREEDIT_TEXT] =
227
206
        g_signal_new (I_("update-preedit-text"),
228
 
            G_TYPE_FROM_CLASS (klass),
 
207
            G_TYPE_FROM_CLASS (class),
229
208
            G_SIGNAL_RUN_LAST,
230
209
            0,
231
210
            NULL, NULL,
232
 
            ibus_marshal_VOID__OBJECT_UINT_BOOLEAN,
 
211
            _ibus_marshal_VOID__OBJECT_UINT_BOOLEAN,
233
212
            G_TYPE_NONE,
234
213
            3,
235
214
            IBUS_TYPE_TEXT,
244
223
     */
245
224
    context_signals[SHOW_PREEDIT_TEXT] =
246
225
        g_signal_new (I_("show-preedit-text"),
247
 
            G_TYPE_FROM_CLASS (klass),
 
226
            G_TYPE_FROM_CLASS (class),
248
227
            G_SIGNAL_RUN_LAST,
249
228
            0,
250
229
            NULL, NULL,
251
 
            ibus_marshal_VOID__VOID,
 
230
            _ibus_marshal_VOID__VOID,
252
231
            G_TYPE_NONE, 0);
253
232
 
254
233
    /**
259
238
     */
260
239
    context_signals[HIDE_PREEDIT_TEXT] =
261
240
        g_signal_new (I_("hide-preedit-text"),
262
 
            G_TYPE_FROM_CLASS (klass),
 
241
            G_TYPE_FROM_CLASS (class),
263
242
            G_SIGNAL_RUN_LAST,
264
243
            0,
265
244
            NULL, NULL,
266
 
            ibus_marshal_VOID__VOID,
 
245
            _ibus_marshal_VOID__VOID,
267
246
            G_TYPE_NONE, 0);
268
247
 
269
248
    /**
278
257
     */
279
258
    context_signals[UPDATE_AUXILIARY_TEXT] =
280
259
        g_signal_new (I_("update-auxiliary-text"),
281
 
            G_TYPE_FROM_CLASS (klass),
 
260
            G_TYPE_FROM_CLASS (class),
282
261
            G_SIGNAL_RUN_LAST,
283
262
            0,
284
263
            NULL, NULL,
285
 
            ibus_marshal_VOID__OBJECT_BOOLEAN,
 
264
            _ibus_marshal_VOID__OBJECT_BOOLEAN,
286
265
            G_TYPE_NONE, 2,
287
266
            IBUS_TYPE_TEXT,
288
267
            G_TYPE_BOOLEAN);
295
274
     */
296
275
    context_signals[SHOW_AUXILIARY_TEXT] =
297
276
        g_signal_new (I_("show-auxiliary-text"),
298
 
            G_TYPE_FROM_CLASS (klass),
 
277
            G_TYPE_FROM_CLASS (class),
299
278
            G_SIGNAL_RUN_LAST,
300
279
            0,
301
280
            NULL, NULL,
302
 
            ibus_marshal_VOID__VOID,
 
281
            _ibus_marshal_VOID__VOID,
303
282
            G_TYPE_NONE, 0);
304
283
 
305
284
    /**
310
289
     */
311
290
    context_signals[HIDE_AUXILIARY_TEXT] =
312
291
        g_signal_new (I_("hide-auxiliary-text"),
313
 
            G_TYPE_FROM_CLASS (klass),
 
292
            G_TYPE_FROM_CLASS (class),
314
293
            G_SIGNAL_RUN_LAST,
315
294
            0,
316
295
            NULL, NULL,
317
 
            ibus_marshal_VOID__VOID,
 
296
            _ibus_marshal_VOID__VOID,
318
297
            G_TYPE_NONE, 0);
319
298
 
320
299
    /**
331
310
     */
332
311
    context_signals[UPDATE_LOOKUP_TABLE] =
333
312
        g_signal_new (I_("update-lookup-table"),
334
 
            G_TYPE_FROM_CLASS (klass),
 
313
            G_TYPE_FROM_CLASS (class),
335
314
            G_SIGNAL_RUN_LAST,
336
315
            0,
337
316
            NULL, NULL,
338
 
            ibus_marshal_VOID__OBJECT_BOOLEAN,
 
317
            _ibus_marshal_VOID__OBJECT_BOOLEAN,
339
318
            G_TYPE_NONE, 2,
340
319
            IBUS_TYPE_LOOKUP_TABLE,
341
320
            G_TYPE_BOOLEAN);
348
327
     */
349
328
    context_signals[SHOW_LOOKUP_TABLE] =
350
329
        g_signal_new (I_("show-lookup-table"),
351
 
            G_TYPE_FROM_CLASS (klass),
 
330
            G_TYPE_FROM_CLASS (class),
352
331
            G_SIGNAL_RUN_LAST,
353
332
            0,
354
333
            NULL, NULL,
355
 
            ibus_marshal_VOID__VOID,
 
334
            _ibus_marshal_VOID__VOID,
356
335
            G_TYPE_NONE, 0);
357
336
 
358
337
    /**
363
342
     */
364
343
    context_signals[HIDE_LOOKUP_TABLE] =
365
344
        g_signal_new (I_("hide-lookup-table"),
366
 
            G_TYPE_FROM_CLASS (klass),
 
345
            G_TYPE_FROM_CLASS (class),
367
346
            G_SIGNAL_RUN_LAST,
368
347
            0,
369
348
            NULL, NULL,
370
 
            ibus_marshal_VOID__VOID,
 
349
            _ibus_marshal_VOID__VOID,
371
350
            G_TYPE_NONE, 0);
372
351
 
373
352
    /**
378
357
     */
379
358
    context_signals[PAGE_UP_LOOKUP_TABLE] =
380
359
        g_signal_new (I_("page-up-lookup-table"),
381
 
            G_TYPE_FROM_CLASS (klass),
 
360
            G_TYPE_FROM_CLASS (class),
382
361
            G_SIGNAL_RUN_LAST,
383
362
            0,
384
363
            NULL, NULL,
385
 
            ibus_marshal_VOID__VOID,
 
364
            _ibus_marshal_VOID__VOID,
386
365
            G_TYPE_NONE, 0);
387
366
 
388
367
    /**
393
372
     */
394
373
    context_signals[PAGE_DOWN_LOOKUP_TABLE] =
395
374
        g_signal_new (I_("page-down-lookup-table"),
396
 
            G_TYPE_FROM_CLASS (klass),
 
375
            G_TYPE_FROM_CLASS (class),
397
376
            G_SIGNAL_RUN_LAST,
398
377
            0,
399
378
            NULL, NULL,
400
 
            ibus_marshal_VOID__VOID,
 
379
            _ibus_marshal_VOID__VOID,
401
380
            G_TYPE_NONE, 0);
402
381
 
403
382
    /**
408
387
     */
409
388
    context_signals[CURSOR_UP_LOOKUP_TABLE] =
410
389
        g_signal_new (I_("cursor-up-lookup-table"),
411
 
            G_TYPE_FROM_CLASS (klass),
 
390
            G_TYPE_FROM_CLASS (class),
412
391
            G_SIGNAL_RUN_LAST,
413
392
            0,
414
393
            NULL, NULL,
415
 
            ibus_marshal_VOID__VOID,
 
394
            _ibus_marshal_VOID__VOID,
416
395
            G_TYPE_NONE, 0);
417
396
 
418
397
    /**
423
402
     */
424
403
    context_signals[CURSOR_DOWN_LOOKUP_TABLE] =
425
404
        g_signal_new (I_("cursor-down-lookup-table"),
426
 
            G_TYPE_FROM_CLASS (klass),
 
405
            G_TYPE_FROM_CLASS (class),
427
406
            G_SIGNAL_RUN_LAST,
428
407
            0,
429
408
            NULL, NULL,
430
 
            ibus_marshal_VOID__VOID,
 
409
            _ibus_marshal_VOID__VOID,
431
410
            G_TYPE_NONE,
432
411
            0);
433
412
 
444
423
     */
445
424
    context_signals[REGISTER_PROPERTIES] =
446
425
        g_signal_new (I_("register-properties"),
447
 
            G_TYPE_FROM_CLASS (klass),
 
426
            G_TYPE_FROM_CLASS (class),
448
427
            G_SIGNAL_RUN_LAST,
449
428
            0,
450
429
            NULL, NULL,
451
 
            ibus_marshal_VOID__OBJECT,
 
430
            _ibus_marshal_VOID__OBJECT,
452
431
            G_TYPE_NONE,
453
432
            1,
454
433
            IBUS_TYPE_PROP_LIST);
466
445
     */
467
446
    context_signals[UPDATE_PROPERTY] =
468
447
        g_signal_new (I_("update-property"),
469
 
            G_TYPE_FROM_CLASS (klass),
 
448
            G_TYPE_FROM_CLASS (class),
470
449
            G_SIGNAL_RUN_LAST,
471
450
            0,
472
451
            NULL, NULL,
473
 
            ibus_marshal_VOID__OBJECT,
 
452
            _ibus_marshal_VOID__OBJECT,
474
453
            G_TYPE_NONE,
475
454
            1,
476
455
            IBUS_TYPE_PROPERTY);
 
456
 
 
457
    text_empty = ibus_text_new_from_static_string ("");
 
458
    g_object_ref_sink (text_empty);
477
459
}
478
460
 
479
461
static void
480
462
ibus_input_context_init (IBusInputContext *context)
481
463
{
482
464
    IBusInputContextPrivate *priv;
 
465
 
483
466
    priv = IBUS_INPUT_CONTEXT_GET_PRIVATE (context);
484
 
    priv->own = TRUE;
 
467
    priv->surrounding_text = g_object_ref_sink (text_empty);
 
468
    priv->surrounding_cursor_pos = 0;
485
469
}
486
470
 
487
471
static void
488
 
ibus_input_context_real_destroy (IBusInputContext *context)
 
472
ibus_input_context_real_destroy (IBusProxy *context)
489
473
{
490
474
    IBusInputContextPrivate *priv;
491
 
    priv = IBUS_INPUT_CONTEXT_GET_PRIVATE (context);
 
475
    priv = IBUS_INPUT_CONTEXT_GET_PRIVATE (IBUS_INPUT_CONTEXT (context));
492
476
 
493
 
    if (priv->own && ibus_proxy_get_connection ((IBusProxy *) context) != NULL) {
494
 
        ibus_proxy_call (IBUS_PROXY (context),
495
 
                         "Destroy",
496
 
                         G_TYPE_INVALID);
 
477
    if (priv->surrounding_text) {
 
478
        g_object_unref (priv->surrounding_text);
 
479
        priv->surrounding_text = NULL;
497
480
    }
498
481
 
499
 
    IBUS_OBJECT_CLASS(ibus_input_context_parent_class)->destroy (IBUS_OBJECT (context));
 
482
    IBUS_PROXY_CLASS(ibus_input_context_parent_class)->destroy (context);
500
483
}
501
484
 
502
 
static gboolean
503
 
ibus_input_context_ibus_signal (IBusProxy           *proxy,
504
 
                                IBusMessage         *message)
 
485
static void
 
486
ibus_input_context_g_signal (GDBusProxy  *proxy,
 
487
                             const gchar *sender_name,
 
488
                             const gchar *signal_name,
 
489
                             GVariant    *parameters)
505
490
{
506
491
    g_assert (IBUS_IS_INPUT_CONTEXT (proxy));
507
 
    g_assert (message != NULL);
508
 
    g_assert (ibus_message_get_type (message) == DBUS_MESSAGE_TYPE_SIGNAL);
509
492
 
510
493
    IBusInputContext *context;
511
 
    IBusError *error = NULL;
512
 
    gint i;
513
 
    const gchar *interface;
514
 
    const gchar *name;
515
 
 
516
494
    context = IBUS_INPUT_CONTEXT (proxy);
517
495
 
518
496
    static const struct {
519
 
        const gchar *member;
 
497
        const gchar *signal_name;
520
498
        guint signal_id;
521
499
    } signals [] = {
522
 
        { "Enabled",                ENABLED                  },
523
 
        { "Disabled",               DISABLED                 },
524
500
        { "ShowPreeditText",        SHOW_PREEDIT_TEXT        },
525
501
        { "HidePreeditText",        HIDE_PREEDIT_TEXT        },
526
502
        { "ShowAuxiliaryText",      SHOW_AUXILIARY_TEXT      },
533
509
        { "CursorDownLookupTable",  CURSOR_DOWN_LOOKUP_TABLE },
534
510
    };
535
511
 
536
 
    do {
537
 
        interface = ibus_message_get_interface (message);
538
 
        name = ibus_message_get_member (message);
539
 
 
540
 
        if (interface != NULL && g_strcmp0 (interface, IBUS_INTERFACE_INPUT_CONTEXT) != 0) {
541
 
            error = ibus_error_new_from_printf (DBUS_ERROR_FAILED,
542
 
                                                "Signal %s.%s is not handled", interface, name);
543
 
            break;
544
 
        }
545
 
 
546
 
        if (g_strcmp0 (name, "CommitText") == 0) {
547
 
            IBusText *text;
548
 
            gboolean retval;
549
 
 
550
 
            retval = ibus_message_get_args (message,
551
 
                                            &error,
552
 
                                            IBUS_TYPE_TEXT, &text,
553
 
                                            G_TYPE_INVALID);
554
 
            if (retval) {
555
 
                g_signal_emit (context, context_signals[COMMIT_TEXT], 0, text);
556
 
                if (g_object_is_floating (text))
557
 
                    g_object_unref (text);
558
 
            }
559
 
            break;
560
 
        }
561
 
        if (g_strcmp0 (name, "UpdatePreeditText") == 0) {
562
 
            IBusText *text;
563
 
            gint32 cursor_pos;
564
 
            gboolean visible;
565
 
            gboolean retval;
566
 
 
567
 
            retval = ibus_message_get_args (message,
568
 
                                            &error,
569
 
                                            IBUS_TYPE_TEXT, &text,
570
 
                                            G_TYPE_UINT, &cursor_pos,
571
 
                                            G_TYPE_BOOLEAN, &visible,
572
 
                                            G_TYPE_INVALID);
573
 
 
574
 
            if (retval) {
575
 
                g_signal_emit (context,
576
 
                               context_signals[UPDATE_PREEDIT_TEXT],
577
 
                               0,
578
 
                               text,
579
 
                               cursor_pos,
580
 
                               visible);
581
 
                if (g_object_is_floating (text))
582
 
                    g_object_unref (text);
583
 
            }
584
 
            break;
585
 
        }
586
 
 
587
 
        for (i = 0;
588
 
             i < G_N_ELEMENTS (signals) && g_strcmp0 (name, signals[i].member) != 0;
589
 
             i++);
590
 
 
591
 
        if (i < G_N_ELEMENTS (signals)) {
592
 
            g_signal_emit (context, context_signals[signals[i].signal_id], 0);
593
 
            break;
594
 
        }
595
 
 
596
 
        if (g_strcmp0 (name, "UpdateAuxiliaryText") == 0) {
597
 
            IBusText *text;
598
 
            gboolean visible;
599
 
            gboolean retval;
600
 
 
601
 
            retval = ibus_message_get_args (message,
602
 
                                            &error,
603
 
                                            IBUS_TYPE_TEXT, &text,
604
 
                                            G_TYPE_BOOLEAN, &visible,
605
 
                                            G_TYPE_INVALID);
606
 
 
607
 
            if (retval) {
608
 
                g_signal_emit (context,
609
 
                               context_signals[UPDATE_AUXILIARY_TEXT],
610
 
                               0,
611
 
                               text,
612
 
                               visible);
613
 
                if (g_object_is_floating (text))
614
 
                    g_object_unref (text);
615
 
            }
616
 
        }
617
 
        else if (g_strcmp0 (name, "UpdateLookupTable") == 0) {
618
 
            IBusLookupTable *table;
619
 
            gboolean visible;
620
 
            gboolean retval;
621
 
 
622
 
            retval = ibus_message_get_args (message,
623
 
                                            &error,
624
 
                                            IBUS_TYPE_LOOKUP_TABLE, &table,
625
 
                                            G_TYPE_BOOLEAN, &visible,
626
 
                                            G_TYPE_INVALID);
627
 
 
628
 
            if (retval) {
629
 
                g_signal_emit (context,
630
 
                               context_signals[UPDATE_LOOKUP_TABLE],
631
 
                               0,
632
 
                               table,
633
 
                               visible);
634
 
                if (g_object_is_floating (table))
635
 
                    g_object_unref (table);
636
 
            }
637
 
        }
638
 
        else if (g_strcmp0 (name, "RegisterProperties") == 0) {
639
 
            IBusPropList *prop_list;
640
 
            gboolean retval;
641
 
 
642
 
            retval = ibus_message_get_args (message,
643
 
                                            &error,
644
 
                                            IBUS_TYPE_PROP_LIST, &prop_list,
645
 
                                            G_TYPE_INVALID);
646
 
 
647
 
            if (retval) {
648
 
                g_signal_emit (context,
649
 
                               context_signals[REGISTER_PROPERTIES],
650
 
                               0,
651
 
                               prop_list);
652
 
                if (g_object_is_floating (prop_list))
653
 
                    g_object_unref (prop_list);
654
 
            }
655
 
        }
656
 
        else if (g_strcmp0 (name, "UpdateProperty") == 0) {
657
 
            IBusProperty *prop;
658
 
            gboolean retval;
659
 
 
660
 
            retval = ibus_message_get_args (message,
661
 
                                            &error,
662
 
                                            IBUS_TYPE_PROPERTY, &prop,
663
 
                                            G_TYPE_INVALID);
664
 
            if (retval) {
665
 
                g_signal_emit (context, context_signals[UPDATE_PROPERTY], 0, prop);
666
 
                if (g_object_is_floating (prop))
667
 
                    g_object_unref (prop);
668
 
            }
669
 
        }
670
 
        else if (g_strcmp0 (name, "ForwardKeyEvent") == 0) {
671
 
            guint32 keyval;
672
 
            guint32 keycode;
673
 
            guint32 state;
674
 
            gboolean retval;
675
 
 
676
 
 
677
 
            retval = ibus_message_get_args (message,
678
 
                                            &error,
679
 
                                            G_TYPE_UINT, &keyval,
680
 
                                            G_TYPE_UINT, &keycode,
681
 
                                            G_TYPE_UINT, &state,
682
 
                                            G_TYPE_INVALID);
683
 
 
684
 
            if (retval) {
685
 
                /* Forward key event back with IBUS_FORWARD_MASK. And process_key_event will
686
 
                 * not process key event with IBUS_FORWARD_MASK again. */
687
 
                g_signal_emit (context,
688
 
                               context_signals[FORWARD_KEY_EVENT],
689
 
                               0,
690
 
                               keyval,
691
 
                               keycode,
692
 
                               state | IBUS_FORWARD_MASK);
693
 
            }
694
 
        }
695
 
        else if (g_strcmp0 (name, "DeleteSurroundingText") == 0) {
696
 
            gint offset_from_cursor;
697
 
            guint nchars;
698
 
            gboolean retval;
699
 
            retval = ibus_message_get_args (message,
700
 
                                            &error,
701
 
                                            G_TYPE_INT, &offset_from_cursor,
702
 
                                            G_TYPE_UINT, &nchars,
703
 
                                            G_TYPE_INVALID);
704
 
 
705
 
 
706
 
            if (retval) {
707
 
                g_signal_emit (context,
708
 
                               context_signals[DELETE_SURROUNDING_TEXT],
709
 
                               0,
710
 
                               offset_from_cursor,
711
 
                               nchars);
712
 
            }
713
 
        }
714
 
        else {
715
 
            error = ibus_error_new_from_printf (DBUS_ERROR_FAILED,
716
 
                                                "Signal %s.%s is not handled", interface, name);
717
 
            break;
718
 
        }
719
 
    } while (0);
720
 
 
721
 
    if (error == NULL) {
722
 
        g_signal_stop_emission_by_name (context, "ibus-signal");
723
 
        return TRUE;
724
 
    }
725
 
 
726
 
    /* some error happens */
727
 
    g_warning ("%s: %s", error->name, error->message);
728
 
    ibus_error_free (error);
729
 
    return FALSE;
730
 
}
731
 
 
732
 
typedef struct {
733
 
    IBusInputContext *context;
734
 
    guint32 keyval;
735
 
    guint32 keycode;
736
 
    guint32 state;
737
 
} CallData;
738
 
 
739
 
static void
740
 
_process_key_event_reply_cb (IBusPendingCall *pending,
741
 
                             CallData        *call_data)
742
 
{
743
 
    IBusMessage *reply_message;
744
 
    IBusError *error;
745
 
    gboolean retval = FALSE;
746
 
 
747
 
    reply_message = dbus_pending_call_steal_reply (pending);
748
 
 
749
 
    if (reply_message == NULL) {
750
 
        /* reply timeout */
751
 
        retval = FALSE;
752
 
    }
753
 
    else if ((error = ibus_error_new_from_message (reply_message)) != NULL) {
754
 
        /* some error happens */
755
 
        g_warning ("%s: %s", error->name, error->message);
756
 
        ibus_error_free (error);
757
 
        retval = FALSE;
758
 
    }
759
 
    else if (!ibus_message_get_args (reply_message,
760
 
                                    &error,
761
 
                                     G_TYPE_BOOLEAN, &retval,
762
 
                                     G_TYPE_INVALID)) {
763
 
        /* can not get return value */
764
 
        g_warning ("%s: %s", error->name, error->message);
765
 
        ibus_error_free (error);
766
 
        retval = FALSE;
767
 
    }
768
 
 
769
 
    if (!retval) {
 
512
    if (g_strcmp0 (signal_name, "CommitText") == 0) {
 
513
        GVariant *variant = NULL;
 
514
        g_variant_get (parameters, "(v)", &variant);
 
515
        IBusText *text = IBUS_TEXT (ibus_serializable_deserialize (variant));
 
516
        g_variant_unref (variant);
 
517
        g_signal_emit (context, context_signals[COMMIT_TEXT], 0, text);
 
518
 
 
519
        if (g_object_is_floating (text))
 
520
            g_object_unref (text);
 
521
        return;
 
522
    }
 
523
    if (g_strcmp0 (signal_name, "UpdatePreeditText") == 0) {
 
524
        GVariant *variant = NULL;
 
525
        gint32 cursor_pos;
 
526
        gboolean visible;
 
527
        g_variant_get (parameters, "(vub)", &variant, &cursor_pos, &visible);
 
528
        IBusText *text = IBUS_TEXT (ibus_serializable_deserialize (variant));
 
529
        g_variant_unref (variant);
 
530
 
 
531
        g_signal_emit (context,
 
532
                       context_signals[UPDATE_PREEDIT_TEXT],
 
533
                       0,
 
534
                       text,
 
535
                       cursor_pos,
 
536
                       visible);
 
537
 
 
538
        if (g_object_is_floating (text))
 
539
            g_object_unref (text);
 
540
        return;
 
541
    }
 
542
 
 
543
    /* lookup signal in table */
 
544
    gint i;
 
545
    for (i = 0;
 
546
         i < G_N_ELEMENTS (signals) && g_strcmp0 (signal_name, signals[i].signal_name) != 0;
 
547
         i++);
 
548
 
 
549
    if (i < G_N_ELEMENTS (signals)) {
 
550
        g_signal_emit (context, context_signals[signals[i].signal_id], 0);
 
551
        return;
 
552
    }
 
553
 
 
554
    if (g_strcmp0 (signal_name, "UpdateAuxiliaryText") == 0) {
 
555
        GVariant *variant = NULL;
 
556
        gboolean visible;
 
557
        g_variant_get (parameters, "(vb)", &variant, &visible);
 
558
        IBusText *text = IBUS_TEXT (ibus_serializable_deserialize (variant));
 
559
        g_variant_unref (variant);
 
560
 
 
561
        g_signal_emit (context,
 
562
                       context_signals[UPDATE_AUXILIARY_TEXT],
 
563
                       0,
 
564
                       text,
 
565
                       visible);
 
566
        if (g_object_is_floating (text))
 
567
            g_object_unref (text);
 
568
        return;
 
569
    }
 
570
 
 
571
    if (g_strcmp0 (signal_name, "UpdateLookupTable") == 0) {
 
572
        GVariant *variant = NULL;
 
573
        gboolean visible;
 
574
        g_variant_get (parameters, "(vb)", &variant, &visible);
 
575
 
 
576
        IBusLookupTable *table = IBUS_LOOKUP_TABLE (ibus_serializable_deserialize (variant));
 
577
        g_variant_unref (variant);
 
578
 
 
579
        g_signal_emit (context,
 
580
                       context_signals[UPDATE_LOOKUP_TABLE],
 
581
                       0,
 
582
                       table,
 
583
                       visible);
 
584
        if (g_object_is_floating (table))
 
585
            g_object_unref (table);
 
586
        return;
 
587
 
 
588
    }
 
589
 
 
590
    if (g_strcmp0 (signal_name, "RegisterProperties") == 0) {
 
591
        GVariant *variant = NULL;
 
592
        g_variant_get (parameters, "(v)", &variant);
 
593
 
 
594
        IBusPropList *prop_list = IBUS_PROP_LIST (ibus_serializable_deserialize (variant));
 
595
        g_variant_unref (variant);
 
596
 
 
597
        g_signal_emit (context,
 
598
                       context_signals[REGISTER_PROPERTIES],
 
599
                       0,
 
600
                       prop_list);
 
601
 
 
602
        if (g_object_is_floating (prop_list))
 
603
            g_object_unref (prop_list);
 
604
        return;
 
605
    }
 
606
 
 
607
    if (g_strcmp0 (signal_name, "UpdateProperty") == 0) {
 
608
        GVariant *variant = NULL;
 
609
        g_variant_get (parameters, "(v)", &variant);
 
610
        IBusProperty *prop = IBUS_PROPERTY (ibus_serializable_deserialize (variant));
 
611
        g_variant_unref (variant);
 
612
 
 
613
        g_signal_emit (context, context_signals[UPDATE_PROPERTY], 0, prop);
 
614
 
 
615
        if (g_object_is_floating (prop))
 
616
            g_object_unref (prop);
 
617
        return;
 
618
    }
 
619
 
 
620
    if (g_strcmp0 (signal_name, "ForwardKeyEvent") == 0) {
 
621
        guint32 keyval;
 
622
        guint32 keycode;
 
623
        guint32 state;
 
624
 
 
625
        g_variant_get (parameters, "(uuu)", &keyval, &keycode, &state);
 
626
 
770
627
        /* Forward key event back with IBUS_FORWARD_MASK. And process_key_event will
771
628
         * not process key event with IBUS_FORWARD_MASK again. */
772
 
        g_signal_emit (call_data->context,
 
629
        g_signal_emit (context,
773
630
                       context_signals[FORWARD_KEY_EVENT],
774
631
                       0,
775
 
                       call_data->keyval,
776
 
                       call_data->keycode,
777
 
                       call_data->state | IBUS_FORWARD_MASK);
778
 
    }
779
 
 
780
 
    if (reply_message != NULL) {
781
 
        dbus_message_unref (reply_message);
782
 
    }
783
 
}
784
 
 
785
 
static void
786
 
_call_data_free (CallData *call_data)
787
 
{
788
 
    g_object_unref (call_data->context);
789
 
    g_slice_free (CallData, call_data);
 
632
                       keyval,
 
633
                       keycode,
 
634
                       state | IBUS_FORWARD_MASK);
 
635
        return;
 
636
    }
 
637
 
 
638
    if (g_strcmp0 (signal_name, "DeleteSurroundingText") == 0) {
 
639
        gint offset_from_cursor;
 
640
        guint nchars;
 
641
 
 
642
        g_variant_get (parameters, "(iu)", &offset_from_cursor, &nchars);
 
643
 
 
644
        g_signal_emit (context,
 
645
                       context_signals[DELETE_SURROUNDING_TEXT],
 
646
                       0,
 
647
                       offset_from_cursor,
 
648
                       nchars);
 
649
        return;
 
650
    }
 
651
 
 
652
    IBusInputContextPrivate *priv;
 
653
    priv = IBUS_INPUT_CONTEXT_GET_PRIVATE (IBUS_INPUT_CONTEXT (context));
 
654
 
 
655
    if (g_strcmp0 (signal_name, "Enabled") == 0) {
 
656
        priv->needs_surrounding_text = FALSE;
 
657
        g_signal_emit (context, context_signals[ENABLED], 0);
 
658
        return;
 
659
    }
 
660
 
 
661
    if (g_strcmp0 (signal_name, "Disabled") == 0) {
 
662
        priv->needs_surrounding_text = FALSE;
 
663
        g_signal_emit (context, context_signals[DISABLED], 0);
 
664
        return;
 
665
    }
 
666
 
 
667
    if (g_strcmp0 (signal_name, "RequireSurroundingText") == 0) {
 
668
        priv->needs_surrounding_text = TRUE;
 
669
        return;
 
670
    }
 
671
 
 
672
    G_DBUS_PROXY_CLASS (ibus_input_context_parent_class)->g_signal (
 
673
                                proxy, sender_name, signal_name, parameters);
 
674
}
 
675
 
 
676
IBusInputContext *
 
677
ibus_input_context_new (const gchar     *path,
 
678
                        GDBusConnection *connection,
 
679
                        GCancellable    *cancellable,
 
680
                        GError         **error)
 
681
{
 
682
    g_assert (path != NULL);
 
683
    g_assert (G_IS_DBUS_CONNECTION (connection));
 
684
 
 
685
    GInitable *initable;
 
686
 
 
687
    GDBusProxyFlags flags = G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START |
 
688
                            G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES;
 
689
 
 
690
    initable = g_initable_new (IBUS_TYPE_INPUT_CONTEXT,
 
691
                               cancellable,
 
692
                               error,
 
693
                               "g-connection",      connection,
 
694
                               "g-name",            IBUS_SERVICE_IBUS,
 
695
                               "g-flags",           flags,
 
696
                               "g-interface-name",  IBUS_INTERFACE_INPUT_CONTEXT,
 
697
                               "g-object-path",     path,
 
698
                               "g-default-timeout", ibus_get_timeout (),
 
699
                               NULL);
 
700
    if (initable != NULL)
 
701
        return IBUS_INPUT_CONTEXT (initable);
 
702
    return NULL;
 
703
}
 
704
 
 
705
void
 
706
ibus_input_context_new_async (const gchar         *path,
 
707
                              GDBusConnection     *connection,
 
708
                              GCancellable        *cancellable,
 
709
                              GAsyncReadyCallback  callback,
 
710
                              gpointer             user_data)
 
711
{
 
712
    g_assert (path != NULL);
 
713
    g_assert (G_IS_DBUS_CONNECTION (connection));
 
714
    g_assert (callback != NULL);
 
715
 
 
716
    GDBusProxyFlags flags = G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START |
 
717
                            G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES;
 
718
    
 
719
    g_async_initable_new_async (IBUS_TYPE_INPUT_CONTEXT,
 
720
                                G_PRIORITY_DEFAULT,
 
721
                                cancellable,
 
722
                                callback,
 
723
                                user_data,
 
724
                                "g-connection",      connection,
 
725
                                "g-name",            IBUS_SERVICE_IBUS,
 
726
                                "g-flags",           flags,
 
727
                                "g-interface-name",  IBUS_INTERFACE_INPUT_CONTEXT,
 
728
                                "g-object-path",     path,
 
729
                                "g-default-timeout", ibus_get_timeout (),
 
730
                                NULL);
 
731
}
 
732
 
 
733
IBusInputContext *
 
734
ibus_input_context_new_async_finish (GAsyncResult  *res,
 
735
                                     GError       **error)
 
736
{
 
737
    GObject *object = NULL;
 
738
    GObject *source_object = NULL;
 
739
 
 
740
    source_object = g_async_result_get_source_object (res);
 
741
    g_assert (source_object != NULL);
 
742
 
 
743
    object = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object),
 
744
                                          res,
 
745
                                          error);
 
746
    g_object_unref (source_object);
 
747
 
 
748
    if (object != NULL) {
 
749
        return IBUS_INPUT_CONTEXT (object);
 
750
    }
 
751
    else {
 
752
        return NULL;
 
753
    }
 
754
}
 
755
 
 
756
IBusInputContext *
 
757
ibus_input_context_get_input_context (const gchar     *path,
 
758
                                      GDBusConnection *connection)
 
759
{
 
760
    IBusInputContext *context = NULL;
 
761
    GError *error = NULL;
 
762
 
 
763
    context = ibus_input_context_new (path, connection, NULL, &error);
 
764
    if (context == NULL) {
 
765
        g_warning ("ibus_input_context_get_input_context: %s", error->message);
 
766
        g_error_free (error);
 
767
        return NULL;
 
768
    }
 
769
 
 
770
    /* Do not call "org.freedesktop.IBus.Service.Destroy" when the input
 
771
     * context object is disposed. */
 
772
    IBUS_PROXY (context)->own = FALSE;
 
773
    return context;
 
774
}
 
775
 
 
776
void
 
777
ibus_input_context_get_input_context_async (const gchar         *path,
 
778
                                            GDBusConnection     *connection,
 
779
                                            GCancellable        *cancellable,
 
780
                                            GAsyncReadyCallback  callback,
 
781
                                            gpointer             user_data)
 
782
{
 
783
    ibus_input_context_new_async (path,
 
784
                                  connection,
 
785
                                  cancellable,
 
786
                                  callback,
 
787
                                  user_data);
 
788
}
 
789
 
 
790
IBusInputContext *
 
791
ibus_input_context_get_input_context_async_finish (GAsyncResult  *res,
 
792
                                                   GError       **error)
 
793
{
 
794
    IBusInputContext *context = NULL;
 
795
 
 
796
    context = ibus_input_context_new_async_finish (res, error);
 
797
    if (context == NULL) {
 
798
        return NULL;
 
799
    }
 
800
 
 
801
    /* Do not call "org.freedesktop.IBus.Service.Destroy" when the input
 
802
     * context object is disposed. */
 
803
    IBUS_PROXY (context)->own = FALSE;
 
804
    return context;
 
805
}
 
806
 
 
807
void
 
808
ibus_input_context_process_key_event_async (IBusInputContext   *context,
 
809
                                            guint32             keyval,
 
810
                                            guint32             keycode,
 
811
                                            guint32             state,
 
812
                                            gint                timeout_msec,
 
813
                                            GCancellable       *cancellable,
 
814
                                            GAsyncReadyCallback callback,
 
815
                                            gpointer            user_data)
 
816
{
 
817
    g_assert (IBUS_IS_INPUT_CONTEXT (context));
 
818
 
 
819
    g_dbus_proxy_call ((GDBusProxy *) context,
 
820
                       "ProcessKeyEvent",                   /* method_name */
 
821
                       g_variant_new ("(uuu)",
 
822
                            keyval, keycode, state),        /* parameters */
 
823
                       G_DBUS_CALL_FLAGS_NONE,              /* flags */
 
824
                       timeout_msec,                        /* timeout */
 
825
                       cancellable,                         /* cancellable */
 
826
                       callback,                            /* callback */
 
827
                       user_data                            /* user_data */
 
828
                       );
 
829
 
 
830
}
 
831
 
 
832
gboolean
 
833
ibus_input_context_process_key_event_async_finish (IBusInputContext  *context,
 
834
                                                   GAsyncResult      *res,
 
835
                                                   gboolean          *processed,
 
836
                                                   GError           **error)
 
837
{
 
838
    g_assert (IBUS_IS_INPUT_CONTEXT (context));
 
839
    g_assert (G_IS_ASYNC_RESULT (res));
 
840
    g_assert (processed != NULL);
 
841
    g_assert (error == NULL || *error == NULL);
 
842
 
 
843
    GVariant *variant = g_dbus_proxy_call_finish ((GDBusProxy *) context,
 
844
                                                   res, error);
 
845
    if (variant == NULL) {
 
846
        *processed = FALSE;
 
847
        return FALSE;
 
848
    }
 
849
    else {
 
850
        *processed = FALSE;
 
851
        g_variant_get (variant, "(b)", processed);
 
852
        g_variant_unref (variant);
 
853
        return TRUE;
 
854
    }
790
855
}
791
856
 
792
857
gboolean
797
862
{
798
863
    g_assert (IBUS_IS_INPUT_CONTEXT (context));
799
864
 
800
 
    IBusPendingCall *pending = NULL;
801
 
    IBusError *error = NULL;
802
 
    CallData *call_data;
803
 
    gboolean retval;
804
 
 
805
 
    if (state & IBUS_HANDLED_MASK)
806
 
        return TRUE;
807
 
 
808
 
    if (state & IBUS_IGNORED_MASK)
809
 
        return FALSE;
810
 
 
811
 
    retval = ibus_proxy_call_with_reply ((IBusProxy *) context,
812
 
                                         "ProcessKeyEvent",
813
 
                                         &pending,
814
 
                                         -1,
815
 
                                         &error,
816
 
                                         G_TYPE_UINT, &keyval,
817
 
                                         G_TYPE_UINT, &keycode,
818
 
                                         G_TYPE_UINT, &state,
819
 
                                         G_TYPE_INVALID);
820
 
    if (!retval) {
821
 
        g_debug ("%s: %s", error->name, error->message);
822
 
        ibus_error_free (error);
823
 
        return FALSE;
824
 
    }
825
 
 
826
 
    call_data = g_slice_new0 (CallData);
827
 
    g_object_ref (context);
828
 
    call_data->context = context;
829
 
    call_data->keyval = keyval;
830
 
    call_data->keycode = keycode;
831
 
    call_data->state = state;
832
 
 
833
 
    /* set notify callback to handle the reply from daemon */
834
 
    retval = ibus_pending_call_set_notify (pending,
835
 
                                           (IBusPendingCallNotifyFunction)_process_key_event_reply_cb,
836
 
                                           call_data,
837
 
                                           (GDestroyNotify)_call_data_free);
838
 
    ibus_pending_call_unref (pending);
839
 
 
840
 
    if (!retval) {
841
 
        _call_data_free (call_data);
842
 
        g_warning ("%s : ProcessKeyEvent", DBUS_ERROR_NO_MEMORY);
843
 
        return FALSE;
844
 
    }
845
 
 
846
 
    return TRUE;
 
865
    GVariant *result = g_dbus_proxy_call_sync ((GDBusProxy *) context,
 
866
                            "ProcessKeyEvent",              /* method_name */
 
867
                            g_variant_new ("(uuu)",
 
868
                                 keyval, keycode, state),   /* parameters */
 
869
                            G_DBUS_CALL_FLAGS_NONE,         /* flags */
 
870
                            -1,                             /* timeout */
 
871
                            NULL,                           /* cancellable */
 
872
                            NULL);
 
873
 
 
874
    if (result != NULL) {
 
875
        gboolean processed = FALSE;
 
876
 
 
877
        g_variant_get (result, "(b)", &processed);
 
878
        g_variant_unref (result);
 
879
        return processed;
 
880
    }
 
881
 
 
882
    return FALSE;
847
883
}
848
884
 
849
885
void
855
891
{
856
892
    g_assert (IBUS_IS_INPUT_CONTEXT (context));
857
893
 
858
 
    ibus_proxy_call ((IBusProxy *) context,
859
 
                     "SetCursorLocation",
860
 
                     G_TYPE_INT, &x,
861
 
                     G_TYPE_INT, &y,
862
 
                     G_TYPE_INT, &w,
863
 
                     G_TYPE_INT, &h,
864
 
                     G_TYPE_INVALID);
 
894
    g_dbus_proxy_call ((GDBusProxy *) context,
 
895
                       "SetCursorLocation",                 /* method_name */
 
896
                       g_variant_new ("(iiii)", x, y, w, h),/* parameters */
 
897
                       G_DBUS_CALL_FLAGS_NONE,              /* flags */
 
898
                       -1,                                  /* timeout */
 
899
                       NULL,                                /* cancellable */
 
900
                       NULL,                                /* callback */
 
901
                       NULL                                 /* user_data */
 
902
                       );
865
903
}
866
904
 
867
905
void
869
907
                                     guint32             capabilites)
870
908
{
871
909
    g_assert (IBUS_IS_INPUT_CONTEXT (context));
872
 
 
873
 
    ibus_proxy_call ((IBusProxy *) context,
874
 
                     "SetCapabilities",
875
 
                     G_TYPE_UINT, &capabilites,
876
 
                     G_TYPE_INVALID);
 
910
    g_dbus_proxy_call ((GDBusProxy *) context,
 
911
                       "SetCapabilities",                   /* method_name */
 
912
                       g_variant_new ("(u)", capabilites),  /* parameters */
 
913
                       G_DBUS_CALL_FLAGS_NONE,              /* flags */
 
914
                       -1,                                  /* timeout */
 
915
                       NULL,                                /* cancellable */
 
916
                       NULL,                                /* callback */
 
917
                       NULL                                 /* user_data */
 
918
                       );
877
919
}
878
920
 
879
921
void
880
922
ibus_input_context_property_activate (IBusInputContext *context,
881
923
                                      const gchar      *prop_name,
882
 
                                      gint32            state)
 
924
                                      guint32           state)
883
925
{
884
926
    g_assert (IBUS_IS_INPUT_CONTEXT (context));
885
 
 
886
 
    ibus_proxy_call ((IBusProxy *) context,
887
 
                     "PropertyActivate",
888
 
                     G_TYPE_STRING, &prop_name,
889
 
                     G_TYPE_INT, &state,
890
 
                     G_TYPE_INVALID);
 
927
    g_dbus_proxy_call ((GDBusProxy *) context,
 
928
                       "PropertyActivate",                  /* method_name */
 
929
                       g_variant_new ("(su)",
 
930
                                prop_name, state),          /* parameters */
 
931
                       G_DBUS_CALL_FLAGS_NONE,              /* flags */
 
932
                       -1,                                  /* timeout */
 
933
                       NULL,                                /* cancellable */
 
934
                       NULL,                                /* callback */
 
935
                       NULL                                 /* user_data */
 
936
                       );
891
937
}
892
938
 
893
939
void
895
941
                                  const gchar     *prop_name)
896
942
{
897
943
    g_assert (IBUS_IS_INPUT_CONTEXT (context));
898
 
 
899
 
    ibus_proxy_call ((IBusProxy *) context,
900
 
                     "PropertyShow",
901
 
                     G_TYPE_STRING, &prop_name,
902
 
                     G_TYPE_INVALID);
 
944
    g_dbus_proxy_call ((GDBusProxy *) context,
 
945
                       "PropertyShow",                      /* method_name */
 
946
                       g_variant_new ("(s)", prop_name),    /* parameters */
 
947
                       G_DBUS_CALL_FLAGS_NONE,              /* flags */
 
948
                       -1,                                  /* timeout */
 
949
                       NULL,                                /* cancellable */
 
950
                       NULL,                                /* callback */
 
951
                       NULL                                 /* user_data */
 
952
                       );
903
953
}
904
954
 
905
955
void
907
957
                                       const gchar      *prop_name)
908
958
{
909
959
    g_assert (IBUS_IS_INPUT_CONTEXT (context));
910
 
 
911
 
    ibus_proxy_call ((IBusProxy *) context,
912
 
                     "PropertyHide",
913
 
                     G_TYPE_STRING, &prop_name,
914
 
                     G_TYPE_INVALID);
 
960
    g_dbus_proxy_call ((GDBusProxy *) context,
 
961
                       "PropertyHide",                      /* method_name */
 
962
                       g_variant_new ("(s)", prop_name),    /* parameters */
 
963
                       G_DBUS_CALL_FLAGS_NONE,              /* flags */
 
964
                       -1,                                  /* timeout */
 
965
                       NULL,                                /* cancellable */
 
966
                       NULL,                                /* callback */
 
967
                       NULL                                 /* user_data */
 
968
                       );
 
969
}
 
970
 
 
971
void
 
972
ibus_input_context_is_enabled_async (IBusInputContext   *context,
 
973
                                     gint                timeout_msec,
 
974
                                     GCancellable       *cancellable,
 
975
                                     GAsyncReadyCallback callback,
 
976
                                     gpointer            user_data)
 
977
{
 
978
    g_assert (IBUS_IS_INPUT_CONTEXT (context));
 
979
    g_dbus_proxy_call ((GDBusProxy *) context,
 
980
                       "IsEnabled",               /* method_name */
 
981
                       NULL,                      /* parameters */
 
982
                       G_DBUS_CALL_FLAGS_NONE,    /* flags */
 
983
                       timeout_msec,
 
984
                       cancellable,
 
985
                       callback,
 
986
                       user_data);
 
987
}
 
988
 
 
989
gboolean
 
990
ibus_input_context_is_enabled_async_finish (IBusInputContext   *context,
 
991
                                            GAsyncResult       *res,
 
992
                                            gboolean           *retval,
 
993
                                            GError            **error)
 
994
{
 
995
    g_assert (IBUS_IS_INPUT_CONTEXT (context));
 
996
    g_assert (G_IS_ASYNC_RESULT (res));
 
997
    g_assert (retval != NULL);
 
998
    g_assert (error == NULL || *error == NULL);
 
999
 
 
1000
    GVariant *variant = g_dbus_proxy_call_finish ((GDBusProxy *) context,
 
1001
                                                   res, error);
 
1002
    if (variant == NULL) {
 
1003
        return FALSE;
 
1004
    }
 
1005
    g_variant_get (variant, "(b)", retval);
 
1006
    g_variant_unref (variant);
 
1007
    return TRUE;
 
1008
}
 
1009
 
 
1010
void
 
1011
ibus_input_context_set_surrounding_text (IBusInputContext   *context,
 
1012
                                         IBusText           *text,
 
1013
                                         guint32             cursor_pos)
 
1014
{
 
1015
    g_assert (IBUS_IS_INPUT_CONTEXT (context));
 
1016
    g_assert (IBUS_IS_TEXT (text));
 
1017
 
 
1018
    IBusInputContextPrivate *priv;
 
1019
    priv = IBUS_INPUT_CONTEXT_GET_PRIVATE (context);
 
1020
 
 
1021
    if (priv->surrounding_text == NULL ||
 
1022
        g_strcmp0 (text->text, priv->surrounding_text->text) != 0 ||
 
1023
        cursor_pos != priv->surrounding_cursor_pos) {
 
1024
        GVariant *variant = ibus_serializable_serialize ((IBusSerializable *)text);
 
1025
        if (priv->surrounding_text)
 
1026
            g_object_unref (priv->surrounding_text);
 
1027
        priv->surrounding_text = (IBusText *) g_object_ref_sink (text);
 
1028
        priv->surrounding_cursor_pos = cursor_pos;
 
1029
 
 
1030
        g_dbus_proxy_call ((GDBusProxy *) context,
 
1031
                         "SetSurroundingText",              /* method_name */
 
1032
                         g_variant_new ("(vu)", variant, cursor_pos), /* parameters */
 
1033
                         G_DBUS_CALL_FLAGS_NONE,            /* flags */
 
1034
                         -1,                                /* timeout */
 
1035
                         NULL,                              /* cancellable */
 
1036
                         NULL,                              /* callback */
 
1037
                         NULL                               /* user_data */
 
1038
                         );
 
1039
    }
 
1040
}
 
1041
 
 
1042
gboolean
 
1043
ibus_input_context_needs_surrounding_text (IBusInputContext *context)
 
1044
{
 
1045
    IBusInputContextPrivate *priv;
 
1046
    priv = IBUS_INPUT_CONTEXT_GET_PRIVATE (IBUS_INPUT_CONTEXT (context));
 
1047
    return priv->needs_surrounding_text;
915
1048
}
916
1049
 
917
1050
gboolean
918
1051
ibus_input_context_is_enabled (IBusInputContext *context)
919
1052
{
920
1053
    g_assert (IBUS_IS_INPUT_CONTEXT (context));
 
1054
    GVariant *result;
 
1055
    GError *error = NULL;
 
1056
    result = g_dbus_proxy_call_sync ((GDBusProxy *) context,
 
1057
                                     "IsEnabled",               /* method_name */
 
1058
                                     NULL,                      /* parameters */
 
1059
                                     G_DBUS_CALL_FLAGS_NONE,    /* flags */
 
1060
                                     -1,                        /* timeout */
 
1061
                                     NULL,                      /* cancellable */
 
1062
                                     &error                     /* error */
 
1063
                                     );
 
1064
 
 
1065
    if (result == NULL) {
 
1066
        g_warning ("%s.IsEnabled: %s", IBUS_INTERFACE_INPUT_CONTEXT, error->message);
 
1067
        g_error_free (error);
 
1068
        return FALSE;
 
1069
    }
 
1070
 
921
1071
    gboolean retval = FALSE;
922
 
 
923
 
    IBusMessage *reply_message;
924
 
    IBusError *error = NULL;
925
 
 
926
 
    reply_message = ibus_proxy_call_with_reply_and_block ((IBusProxy *) context,
927
 
                                                          "IsEnabled",
928
 
                                                          -1,
929
 
                                                          &error,
930
 
                                                          G_TYPE_INVALID);
931
 
    if (!reply_message) {
932
 
        g_debug ("%s: %s", error->name, error->message);
933
 
        ibus_error_free (error);
934
 
        return FALSE;
935
 
    }
936
 
 
937
 
    if (!ibus_message_get_args (reply_message,
938
 
                                &error,
939
 
                                G_TYPE_BOOLEAN, &retval,
940
 
                                G_TYPE_INVALID)) {
941
 
        g_debug ("%s: %s", error->name, error->message);
942
 
        ibus_error_free (error);
943
 
        retval = FALSE;
944
 
    }
945
 
    ibus_message_unref (reply_message);
 
1072
    g_variant_get (result, "(b)", &retval);
 
1073
    g_variant_unref (result);
946
1074
 
947
1075
    return retval;
948
1076
}
949
1077
 
 
1078
void
 
1079
ibus_input_context_get_engine_async (IBusInputContext   *context,
 
1080
                                     gint                timeout_msec,
 
1081
                                     GCancellable       *cancellable,
 
1082
                                     GAsyncReadyCallback callback,
 
1083
                                     gpointer            user_data)
 
1084
{
 
1085
    g_assert (IBUS_IS_INPUT_CONTEXT (context));
 
1086
    g_dbus_proxy_call ((GDBusProxy *) context,
 
1087
                       "GetEngine",               /* method_name */
 
1088
                       NULL,                      /* parameters */
 
1089
                       G_DBUS_CALL_FLAGS_NONE,    /* flags */
 
1090
                       timeout_msec,
 
1091
                       cancellable,
 
1092
                       callback,
 
1093
                       user_data);
 
1094
}
 
1095
 
 
1096
IBusEngineDesc *
 
1097
ibus_input_context_get_engine_async_finish (IBusInputContext   *context,
 
1098
                                            GAsyncResult       *res,
 
1099
                                            GError            **error)
 
1100
{
 
1101
    g_assert (IBUS_IS_INPUT_CONTEXT (context));
 
1102
    g_assert (G_IS_ASYNC_RESULT (res));
 
1103
    g_assert (error == NULL || *error == NULL);
 
1104
 
 
1105
    GVariant *variant = g_dbus_proxy_call_finish ((GDBusProxy *) context,
 
1106
                                                   res, error);
 
1107
    if (variant == NULL) {
 
1108
        return NULL;
 
1109
    }
 
1110
 
 
1111
    GVariant *engine_desc_variant = g_variant_get_child_value (variant, 0);
 
1112
    IBusEngineDesc *desc = IBUS_ENGINE_DESC (ibus_serializable_deserialize (engine_desc_variant));
 
1113
    g_variant_unref (engine_desc_variant);
 
1114
    g_variant_unref (variant);
 
1115
 
 
1116
    return desc;
 
1117
}
 
1118
 
950
1119
IBusEngineDesc *
951
1120
ibus_input_context_get_engine (IBusInputContext *context)
952
1121
{
953
1122
    g_assert (IBUS_IS_INPUT_CONTEXT (context));
954
 
    IBusMessage *reply_message;
955
 
    IBusError *error = NULL;
956
 
    IBusSerializable *object = NULL;
957
 
 
958
 
    reply_message = ibus_proxy_call_with_reply_and_block ((IBusProxy *) context,
959
 
                                                          "GetEngine",
960
 
                                                          -1,
961
 
                                                          &error,
962
 
                                                          G_TYPE_INVALID);
963
 
    if (!reply_message) {
964
 
        g_debug ("%s: %s", error->name, error->message);
965
 
        ibus_error_free (error);
966
 
        return NULL;
967
 
    }
968
 
 
969
 
    if (!ibus_message_get_args (reply_message,
970
 
                                &error,
971
 
                                IBUS_TYPE_ENGINE_DESC, &object,
972
 
                                G_TYPE_INVALID)) {
973
 
        g_debug ("%s: %s", error->name, error->message);
974
 
        ibus_error_free (error);
975
 
        ibus_message_unref (reply_message);
976
 
        return NULL;
977
 
    }
978
 
    ibus_message_unref (reply_message);
979
 
 
980
 
    return IBUS_ENGINE_DESC (object);
 
1123
    GVariant *result;
 
1124
    GError *error = NULL;
 
1125
    result = g_dbus_proxy_call_sync ((GDBusProxy *) context,
 
1126
                                     "GetEngine",               /* method_name */
 
1127
                                     NULL,                      /* parameters */
 
1128
                                     G_DBUS_CALL_FLAGS_NONE,    /* flags */
 
1129
                                     -1,                        /* timeout */
 
1130
                                     NULL,                      /* cancellable */
 
1131
                                     &error                     /* error */
 
1132
                                     );
 
1133
 
 
1134
    if (result == NULL) {
 
1135
        g_warning ("%s.GetEngine: %s", IBUS_INTERFACE_INPUT_CONTEXT, error->message);
 
1136
        g_error_free (error);
 
1137
        return NULL;
 
1138
    }
 
1139
 
 
1140
    GVariant *engine_desc_variant = g_variant_get_child_value (result, 0);
 
1141
    IBusEngineDesc *desc = IBUS_ENGINE_DESC (ibus_serializable_deserialize (engine_desc_variant));
 
1142
    g_variant_unref (engine_desc_variant);
 
1143
    g_variant_unref (result);
 
1144
 
 
1145
    return desc;
981
1146
}
982
1147
 
983
1148
void
985
1150
                               const gchar *name)
986
1151
{
987
1152
    g_assert (IBUS_IS_INPUT_CONTEXT (context));
988
 
 
989
 
    ibus_proxy_call ((IBusProxy *) context,
990
 
                     "SetEngine",
991
 
                     G_TYPE_STRING, &name,
992
 
                     G_TYPE_INVALID);
 
1153
    g_assert (name);
 
1154
    g_dbus_proxy_call ((GDBusProxy *) context,
 
1155
                       "SetEngine",                         /* method_name */
 
1156
                       g_variant_new ("(s)", name),         /* parameters */
 
1157
                       G_DBUS_CALL_FLAGS_NONE,              /* flags */
 
1158
                       -1,                                  /* timeout */
 
1159
                       NULL,                                /* cancellable */
 
1160
                       NULL,                                /* callback */
 
1161
                       NULL                                 /* user_data */
 
1162
                       );
993
1163
}
994
1164
 
995
 
#define DEFINE_FUNC(name,Name)                              \
996
 
    void                                                    \
997
 
    ibus_input_context_##name (IBusInputContext *context)   \
998
 
    {                                                       \
999
 
        g_assert (IBUS_IS_INPUT_CONTEXT (context));         \
1000
 
        ibus_proxy_call ((IBusProxy *) context,             \
1001
 
                         #Name,                             \
1002
 
                         G_TYPE_INVALID);                   \
 
1165
#define DEFINE_FUNC(name, Name)                                         \
 
1166
    void                                                                \
 
1167
    ibus_input_context_##name (IBusInputContext *context)               \
 
1168
    {                                                                   \
 
1169
        g_assert (IBUS_IS_INPUT_CONTEXT (context));                     \
 
1170
        g_dbus_proxy_call ((GDBusProxy *) context,                      \
 
1171
                           #Name,                   /* method_name */   \
 
1172
                           NULL,                    /* parameters */    \
 
1173
                           G_DBUS_CALL_FLAGS_NONE,  /* flags */         \
 
1174
                           -1,                      /* timeout */       \
 
1175
                           NULL,                    /* cancellable */   \
 
1176
                           NULL,                    /* callback */      \
 
1177
                           NULL                     /* user_data */     \
 
1178
                           );                                           \
1003
1179
    }
1004
1180
 
1005
1181
DEFINE_FUNC(focus_in, FocusIn);
1011
1187
DEFINE_FUNC(cursor_down, CursorDown);
1012
1188
DEFINE_FUNC(enable, Enable);
1013
1189
DEFINE_FUNC(disable, Disable);
1014
 
 
1015
1190
#undef DEFINE_FUNC
1016
1191