~michael-sheldon/ubuntu/utopic/maliit-framework/fix-orientation-updates

« back to all changes in this revision

Viewing changes to connection/mdbusglibinputcontextadaptor.cpp

  • 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
 
/* * This file is part of Maliit framework *
2
 
 *
3
 
 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4
 
 * All rights reserved.
5
 
 *
6
 
 * Contact: maliit-discuss@lists.maliit.org
7
 
 *
8
 
 * This library is free software; you can redistribute it and/or
9
 
 * modify it under the terms of the GNU Lesser General Public
10
 
 * License version 2.1 as published by the Free Software Foundation
11
 
 * and appearing in the file LICENSE.LGPL included in the packaging
12
 
 * of this file.
13
 
 */
14
 
 
15
 
#include "mdbusglibinputcontextadaptor.h"
16
 
#include "mimserverconnection.h"
17
 
#include <maliit/settingdata.h>
18
 
 
19
 
#include <variantmarshalling.h>
20
 
 
21
 
#include <dbus/dbus.h>
22
 
 
23
 
G_DEFINE_TYPE(MDBusGlibInputContextAdaptor, m_dbus_glib_input_context_adaptor, G_TYPE_OBJECT)
24
 
 
25
 
 
26
 
static gboolean m_dbus_glib_input_context_adaptor_activation_lost_event(
27
 
    MDBusGlibInputContextAdaptor *obj, GError **/*error*/)
28
 
{
29
 
    Q_EMIT obj->imServerConnection->activationLostEvent();
30
 
    return TRUE;
31
 
}
32
 
 
33
 
static gboolean m_dbus_glib_input_context_adaptor_im_initiated_hide(
34
 
    MDBusGlibInputContextAdaptor *obj, GError **/*error*/)
35
 
{
36
 
    Q_EMIT obj->imServerConnection->imInitiatedHide();
37
 
    return TRUE;
38
 
}
39
 
 
40
 
static gboolean m_dbus_glib_input_context_adaptor_commit_string(
41
 
    MDBusGlibInputContextAdaptor *obj, const char *string, gint32 replaceStart,
42
 
    gint32 replaceLength, gint32 cursorPos, GError **/*error*/)
43
 
{
44
 
    Q_EMIT obj->imServerConnection->commitString(QString::fromUtf8(string), replaceStart,
45
 
                                    replaceLength, cursorPos);
46
 
    return TRUE;
47
 
}
48
 
 
49
 
QDataStream &operator>>(QDataStream &s, Maliit::PreeditTextFormat &t)
50
 
{
51
 
    int preeditFace;
52
 
    s >> t.start;
53
 
    s >> t.length;
54
 
    s >> preeditFace;
55
 
    t.preeditFace = static_cast<Maliit::PreeditFace>(preeditFace);
56
 
    return s;
57
 
}
58
 
 
59
 
static gboolean m_dbus_glib_input_context_adaptor_update_preedit(MDBusGlibInputContextAdaptor *obj,
60
 
                                                                 const char *string,
61
 
                                                                 GPtrArray *formatListData,
62
 
                                                                 gint32 replaceStart,
63
 
                                                                 gint32 replaceLength,
64
 
                                                                 gint32 cursorPos, GError **/*error*/)
65
 
{
66
 
    QList<Maliit::PreeditTextFormat> formatList;
67
 
    for (guint i = 0; i < formatListData->len; ++i) {
68
 
        GValueArray *itemData = ((GValueArray**)formatListData->pdata)[i];
69
 
        formatList.push_back(Maliit::PreeditTextFormat(
70
 
                                    g_value_get_int(g_value_array_get_nth(itemData, 0)),
71
 
                                    g_value_get_int(g_value_array_get_nth(itemData, 1)),
72
 
                                    Maliit::PreeditFace(
73
 
                                        g_value_get_int(g_value_array_get_nth(itemData, 2)))));
74
 
    }
75
 
    Q_EMIT obj->imServerConnection->updatePreedit(QString::fromUtf8(string),
76
 
                                     formatList,
77
 
                                     replaceStart,
78
 
                                     replaceLength,
79
 
                                     cursorPos);
80
 
    return TRUE;
81
 
}
82
 
 
83
 
static gboolean m_dbus_glib_input_context_adaptor_key_event(
84
 
    MDBusGlibInputContextAdaptor *obj, gint32 type, gint32 key, gint32 modifiers, const char *text,
85
 
    gboolean autoRepeat, gint32 count, guchar requestType, GError **/*error*/)
86
 
{
87
 
    Q_EMIT obj->imServerConnection->keyEvent(type, key, modifiers, QString::fromUtf8(text),
88
 
                                autoRepeat == TRUE, count,
89
 
                                static_cast<Maliit::EventRequestType>(requestType));
90
 
    return TRUE;
91
 
}
92
 
 
93
 
static gboolean m_dbus_glib_input_context_adaptor_update_input_method_area(
94
 
    MDBusGlibInputContextAdaptor *obj,
95
 
    gint32 left, gint32 top, gint32 width, gint32 height,
96
 
    GError **/*error*/)
97
 
{
98
 
    Q_EMIT obj->imServerConnection->updateInputMethodArea(QRect(left, top, width, height));
99
 
    return TRUE;
100
 
}
101
 
 
102
 
static gboolean m_dbus_glib_input_context_adaptor_set_global_correction_enabled(
103
 
    MDBusGlibInputContextAdaptor *obj, gboolean value, GError **/*error*/)
104
 
{
105
 
    Q_EMIT obj->imServerConnection->setGlobalCorrectionEnabled(value == TRUE);
106
 
    return TRUE;
107
 
}
108
 
 
109
 
static gboolean m_dbus_glib_input_context_adaptor_preedit_rectangle(
110
 
    MDBusGlibInputContextAdaptor *obj, gboolean *valid, gint *x, gint *y,
111
 
    gint *width, gint *height, GError **/*error*/)
112
 
{
113
 
    bool deserializedValidity;
114
 
    QRect rect;
115
 
    Q_EMIT obj->imServerConnection->getPreeditRectangle(rect, deserializedValidity);
116
 
    *valid = deserializedValidity ? TRUE : FALSE;
117
 
    *x = rect.x();
118
 
    *y = rect.y();
119
 
    *width = rect.width();
120
 
    *height = rect.height();
121
 
    return TRUE;
122
 
}
123
 
 
124
 
static gboolean m_dbus_glib_input_context_adaptor_set_redirect_keys(
125
 
    MDBusGlibInputContextAdaptor *obj, gboolean enabled, GError **/*error*/)
126
 
{
127
 
    Q_EMIT obj->imServerConnection->setRedirectKeys(enabled == TRUE);
128
 
    return TRUE;
129
 
}
130
 
 
131
 
static gboolean m_dbus_glib_input_context_adaptor_set_detectable_auto_repeat(
132
 
    MDBusGlibInputContextAdaptor *obj, gboolean enabled, GError **/*error*/)
133
 
{
134
 
    Q_EMIT obj->imServerConnection->setDetectableAutoRepeat(enabled == TRUE);
135
 
    return TRUE;
136
 
}
137
 
 
138
 
static gboolean m_dbus_glib_input_context_adaptor_set_selection(MDBusGlibInputContextAdaptor *obj,
139
 
                                                                gint32 start, gint32 length, GError **/*error*/)
140
 
{
141
 
    Q_EMIT obj->imServerConnection->setSelection(start,length);
142
 
    return TRUE;
143
 
}
144
 
 
145
 
static gboolean m_dbus_glib_input_context_adaptor_selection(
146
 
    MDBusGlibInputContextAdaptor *obj, gboolean *valid, gchar **gdata, GError **/*error*/)
147
 
{
148
 
    bool validity;
149
 
    QString selection;
150
 
    Q_EMIT obj->imServerConnection->getSelection(selection, validity);
151
 
    *valid = validity ? TRUE : FALSE;
152
 
    *gdata = NULL;
153
 
 
154
 
    if (validity && !selection.isEmpty()) {
155
 
        *gdata = g_strdup(selection.toUtf8().data());
156
 
    }
157
 
    return TRUE;
158
 
}
159
 
 
160
 
static gboolean m_dbus_glib_input_context_adaptor_set_language(
161
 
    MDBusGlibInputContextAdaptor *obj, const char *string,
162
 
    GError **/*error*/)
163
 
{
164
 
    Q_EMIT obj->imServerConnection->setLanguage(QString::fromUtf8(string));
165
 
    return TRUE;
166
 
}
167
 
 
168
 
static gboolean m_dbus_glib_input_context_adaptor_notify_extended_attribute_changed(
169
 
        MDBusGlibInputContextAdaptor *obj,
170
 
        gint32 id,
171
 
        const char *target,
172
 
        const char *targetItem,
173
 
        const char *attribute,
174
 
        GValue *valueData,
175
 
        GError **/*error*/)
176
 
{
177
 
    QVariant value;
178
 
    QString error_message;
179
 
    if (decodeVariant(&value, valueData, &error_message)) {
180
 
         Q_EMIT obj->imServerConnection->extendedAttributeChanged(static_cast<int>(id),
181
 
                                                                  QString::fromUtf8(target),
182
 
                                                                  QString::fromUtf8(targetItem),
183
 
                                                                  QString::fromUtf8(attribute),
184
 
                                                                  value);
185
 
    } else {
186
 
        qWarning() << "notify_extended_attribute_changed.arg[4]" + error_message;
187
 
    }
188
 
    return TRUE;
189
 
}
190
 
 
191
 
static gboolean m_dbus_glib_input_context_adaptor_plugin_settings_loaded(MDBusGlibInputContextAdaptor *obj,
192
 
                                                                         GPtrArray *settingsData, GError **/*error*/)
193
 
{
194
 
    QList<MImPluginSettingsInfo> settings;
195
 
    for (guint i = 0; i < settingsData->len; ++i) {
196
 
        GValueArray *plugin_data = ((GValueArray**)settingsData->pdata)[i];
197
 
        MImPluginSettingsInfo plugin;
198
 
        GPtrArray *entries_data = (GPtrArray *)g_value_get_boxed(g_value_array_get_nth(plugin_data, 4));
199
 
 
200
 
        plugin.description_language = QString::fromUtf8(g_value_get_string(g_value_array_get_nth(plugin_data, 0)));
201
 
        plugin.plugin_name = QString::fromUtf8(g_value_get_string(g_value_array_get_nth(plugin_data, 1)));
202
 
        plugin.plugin_description = QString::fromUtf8(g_value_get_string(g_value_array_get_nth(plugin_data, 2)));
203
 
        plugin.extension_id = g_value_get_int(g_value_array_get_nth(plugin_data, 3));
204
 
 
205
 
        for (guint i = 0; i < entries_data->len; ++i) {
206
 
            GValueArray *entry_data = ((GValueArray**)entries_data->pdata)[i];
207
 
            MImPluginSettingsEntry entry;
208
 
 
209
 
            QString error_message;
210
 
            if (!decodeVariantMap(&entry.attributes, (GHashTable *)g_value_get_boxed(g_value_array_get_nth(entry_data, 5)), &error_message)) {
211
 
                qWarning() << "m_dbus_glib_input_context_adaptor_plugin_settings_loaded entry attributes:" + error_message;
212
 
 
213
 
                return FALSE;
214
 
            }
215
 
 
216
 
            entry.description = QString::fromUtf8(g_value_get_string(g_value_array_get_nth(entry_data, 0)));
217
 
            entry.extension_key = QString::fromUtf8(g_value_get_string(g_value_array_get_nth(entry_data, 1)));
218
 
            entry.type = static_cast<Maliit::SettingEntryType>(g_value_get_int(g_value_array_get_nth(entry_data, 2)));
219
 
 
220
 
            bool valid = g_value_get_boolean(g_value_array_get_nth(entry_data, 3));
221
 
 
222
 
            if (!valid) {
223
 
                entry.value = QVariant();
224
 
            } else if (!decodeVariant(&entry.value, g_value_array_get_nth(entry_data, 4), &error_message)) {
225
 
                qWarning() << "m_dbus_glib_input_context_adaptor_plugin_settings_loaded entry value:" + error_message;
226
 
                return FALSE;
227
 
            }
228
 
 
229
 
            plugin.entries.append(entry);
230
 
        }
231
 
 
232
 
        settings.append(plugin);
233
 
    }
234
 
    Q_EMIT obj->imServerConnection->pluginSettingsReceived(settings);
235
 
 
236
 
    return TRUE;
237
 
}
238
 
 
239
 
#include "mdbusglibinputcontextadaptorglue.h"
240
 
 
241
 
static void
242
 
m_dbus_glib_input_context_adaptor_init(MDBusGlibInputContextAdaptor */*obj*/)
243
 
{
244
 
}
245
 
 
246
 
static void
247
 
m_dbus_glib_input_context_adaptor_class_init(MDBusGlibInputContextAdaptorClass */*klass*/)
248
 
{
249
 
    dbus_g_object_type_install_info(M_TYPE_DBUS_GLIB_INPUT_CONTEXT_ADAPTOR, &dbus_glib_m_dbus_glib_input_context_adaptor_object_info);
250
 
}