File: dbusinputcontextconnection.cpp

package info (click to toggle)
maliit-framework 2.3.0-3.2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 2,488 kB
  • sloc: cpp: 13,098; ansic: 2,506; xml: 299; sh: 34; makefile: 23; sed: 4
file content (382 lines) | stat: -rw-r--r-- 13,349 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
/* * This file is part of Maliit framework *
 *
 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
 * All rights reserved.
 *
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License version 2.1 as published by the Free Software Foundation
 * and appearing in the file LICENSE.LGPL included in the packaging
 * of this file.
 */

#include "dbusinputcontextconnection.h"

#include "minputmethodserver1interfaceadaptor.h"
#include "minputmethodcontext1interface_interface.h"
#include "dbuscustomarguments.h"

#include <QDBusConnection>
#include <QDBusMessage>
#include <QDBusServer>

#include <QKeyEvent>

namespace
{

const char * const DBusPath = "/com/meego/inputmethod/uiserver1";
const char * const DBusInterface = "com.meego.inputmethod.uiserver1";

const char * const DBusClientPath = "/com/meego/inputmethod/inputcontext";
const char * const DBusClientInterface = "com.meego.inputmethod.inputcontext1";

const char * const DBusLocalPath("/org/freedesktop/DBus/Local");
const char * const DBusLocalInterface("org.freedesktop.DBus.Local");
const char * const DisconnectedSignal("Disconnected");

}

DBusInputContextConnection::DBusInputContextConnection(const QSharedPointer<Maliit::Server::DBus::Address> &address)
    : MInputContextConnection(0)
    , mAddress(address)
    , mServer(mAddress->connect())
    , mConnectionNumbers()
    , mProxys()
    , lastLanguage()
{
    connect(mServer.data(), SIGNAL(newConnection(QDBusConnection)), this, SLOT(newConnection(QDBusConnection)));

    qDBusRegisterMetaType<MImPluginSettingsEntry>();
    qDBusRegisterMetaType<MImPluginSettingsInfo>();
    qDBusRegisterMetaType<QList<MImPluginSettingsInfo> >();
    qDBusRegisterMetaType<Maliit::PreeditTextFormat>();
    qDBusRegisterMetaType<QList<Maliit::PreeditTextFormat> >();

    new Uiserver1Adaptor(this);
}

DBusInputContextConnection::~DBusInputContextConnection()
{
}

void
DBusInputContextConnection::newConnection(const QDBusConnection &connection)
{
    ComMeegoInputmethodInputcontext1Interface *proxy = new ComMeegoInputmethodInputcontext1Interface(QString(), QString::fromLatin1(DBusClientPath), connection, this);

    static unsigned int connectionCounter = 1; // Start at 1 so 0 can be used as a sentinel value
    unsigned int connectionNumber = connectionCounter++;

    mConnectionNumbers.insert(connection.name(), connectionNumber);
    mProxys.insert(connectionNumber, proxy);
    mConnections.insert(connectionNumber, connection.name());

    QDBusConnection c(connection);

    c.connect(QString(), QString::fromLatin1(DBusLocalPath), QString::fromLatin1(DBusLocalInterface),
              QString::fromLatin1(DisconnectedSignal),
              this, SLOT(onDisconnection()));

    c.registerObject(QString::fromLatin1(DBusPath), this);

    proxy->setLanguage(lastLanguage);
}

void
DBusInputContextConnection::onDisconnection()
{
    const QString &name = connection().name();
    unsigned int connectionNumber = mConnectionNumbers.take(name);
    ComMeegoInputmethodInputcontext1Interface *proxy = mProxys.take(connectionNumber);
    mConnections.remove(connectionNumber);
    delete proxy;
    handleDisconnection(connectionNumber);
    QDBusConnection::disconnectFromPeer(name);
}

void
DBusInputContextConnection::sendPreeditString(const QString &string,
                                              const QList<Maliit::PreeditTextFormat> &preeditFormats,
                                              int replacementStart, int replacementLength,
                                              int cursorPos)
{
    if (activeConnection) {
        MInputContextConnection::sendPreeditString(string, preeditFormats, replacementStart, replacementLength, cursorPos);

        ComMeegoInputmethodInputcontext1Interface *proxy = mProxys.value(activeConnection);
        if (proxy) {
            proxy->updatePreedit(string, preeditFormats, replacementStart, replacementLength, cursorPos);
        }
    }
}

void
DBusInputContextConnection::sendCommitString(const QString &string, int replaceStart,
                                             int replaceLength, int cursorPos)
{
    if (activeConnection) {
        MInputContextConnection::sendCommitString(string, replaceStart, replaceLength, cursorPos);

        ComMeegoInputmethodInputcontext1Interface *proxy = mProxys.value(activeConnection);
        if (proxy) {
            proxy->commitString(string, replaceStart, replaceLength, cursorPos);
        }
    }
}

void
DBusInputContextConnection::sendKeyEvent(const QKeyEvent &keyEvent,
                                         Maliit::EventRequestType requestType)
{
    if (activeConnection) {
        MInputContextConnection::sendKeyEvent(keyEvent, requestType);

        ComMeegoInputmethodInputcontext1Interface *proxy = mProxys.value(activeConnection);
        if (proxy) {
            proxy->keyEvent(keyEvent.type(), keyEvent.key(), keyEvent.modifiers(),
                            keyEvent.text(), keyEvent.isAutoRepeat(), keyEvent.count(), requestType);
        }
    }
}

void
DBusInputContextConnection::notifyImInitiatedHiding()
{
    ComMeegoInputmethodInputcontext1Interface *proxy = mProxys.value(activeConnection);
    if (proxy) {
        proxy->imInitiatedHide();
    }
}

void
DBusInputContextConnection::setGlobalCorrectionEnabled(bool enabled)
{
    ComMeegoInputmethodInputcontext1Interface *proxy = mProxys.value(activeConnection);
    if ((enabled != globalCorrectionEnabled()) && proxy) {
        proxy->setGlobalCorrectionEnabled(enabled);
        MInputContextConnection::setGlobalCorrectionEnabled(enabled);
    }
}

QRect
DBusInputContextConnection::preeditRectangle(bool &valid)
{
    ComMeegoInputmethodInputcontext1Interface *proxy = mProxys.value(activeConnection);
    if (proxy) {
        int x, y, width, height;
        if (proxy->preeditRectangle(x, y, width, height)) {
            valid = true;
            return QRect(x, y, width, height);
        }
    }
    valid = false;
    return QRect();
}

void
DBusInputContextConnection::setRedirectKeys(bool enabled)
{
    ComMeegoInputmethodInputcontext1Interface *proxy = mProxys.value(activeConnection);
    if ((enabled != redirectKeysEnabled()) && proxy) {
        proxy->setRedirectKeys(enabled);
        MInputContextConnection::setRedirectKeys(enabled);
    }
}

void
DBusInputContextConnection::setDetectableAutoRepeat(bool enabled)
{
    ComMeegoInputmethodInputcontext1Interface *proxy = mProxys.value(activeConnection);
    if ((enabled != detectableAutoRepeat()) && proxy) {
        proxy->setDetectableAutoRepeat(enabled);
        MInputContextConnection::setDetectableAutoRepeat(enabled);
    }
}

void
DBusInputContextConnection::invokeAction(const QString &action,
                                         const QKeySequence &sequence)
{
    if (activeConnection) {
        QDBusMessage message = QDBusMessage::createSignal(DBusPath, DBusInterface, "invokeAction");
        QList<QVariant> arguments;
        arguments << action << sequence.toString();
        message.setArguments(arguments);
        QDBusConnection(mConnections.value(activeConnection)).send(message);
    }
}

void
DBusInputContextConnection::setSelection(int start, int length)
{
    ComMeegoInputmethodInputcontext1Interface *proxy = mProxys.value(activeConnection);
    if (proxy) {
        proxy->setSelection(start, length);
    }
}

QString
DBusInputContextConnection::selection(bool &valid)
{
    ComMeegoInputmethodInputcontext1Interface *proxy = mProxys.value(activeConnection);
    if (proxy) {
        QString selectionText;
        if (proxy->selection(selectionText)) {
            valid = true;
            return selectionText;
        }
    }
    valid = false;
    return QString();
}

void
DBusInputContextConnection::setLanguage(const QString &language)
{
    lastLanguage = language;
    ComMeegoInputmethodInputcontext1Interface *proxy = mProxys.value(activeConnection);
    if (proxy) {
        proxy->setLanguage(language);
    }
}

void
DBusInputContextConnection::sendActivationLostEvent()
{
    ComMeegoInputmethodInputcontext1Interface *proxy = mProxys.value(activeConnection);
    if (proxy) {
        proxy->activationLostEvent();
    }
}

void
DBusInputContextConnection::updateInputMethodArea(const QRegion &region)
{
    ComMeegoInputmethodInputcontext1Interface *proxy = mProxys.value(activeConnection);
    if (proxy) {
        QRect rect = region.boundingRect();
        proxy->updateInputMethodArea(rect.x(), rect.y(), rect.width(), rect.height());
    }
}

void
DBusInputContextConnection::notifyExtendedAttributeChanged(int id,
                                                           const QString &target,
                                                           const QString &targetItem,
                                                           const QString &attribute,
                                                           const QVariant &value)
{
    ComMeegoInputmethodInputcontext1Interface *proxy = mProxys.value(activeConnection);
    if (proxy) {
        proxy->notifyExtendedAttributeChanged(id, target, targetItem, attribute, QDBusVariant(value));
    }
}

void
DBusInputContextConnection::notifyExtendedAttributeChanged(const QList<int> &clientIds,
                                                           int id,
                                                           const QString &target,
                                                           const QString &targetItem,
                                                           const QString &attribute,
                                                           const QVariant &value)
{
    Q_FOREACH (int clientId, clientIds) {
        ComMeegoInputmethodInputcontext1Interface *proxy = mProxys.value(clientId);
        if (proxy) {
            proxy->notifyExtendedAttributeChanged(id, target, targetItem, attribute, QDBusVariant(value));
        }
    }
}

void
DBusInputContextConnection::pluginSettingsLoaded(int clientId, const QList<MImPluginSettingsInfo> &info)
{
    ComMeegoInputmethodInputcontext1Interface *proxy = mProxys.value(clientId);
    if (proxy) {
        proxy->pluginSettingsLoaded(info);
    }
}


unsigned int
DBusInputContextConnection::connectionNumber()
{
    return mConnectionNumbers.value(connection().name());
}

void DBusInputContextConnection::activateContext()
{
    MInputContextConnection::activateContext(connectionNumber());
}

void DBusInputContextConnection::showInputMethod()
{
    MInputContextConnection::showInputMethod(connectionNumber());
}

void DBusInputContextConnection::hideInputMethod()
{
    MInputContextConnection::hideInputMethod(connectionNumber());
}

void DBusInputContextConnection::mouseClickedOnPreedit(int posX, int posY, int preeditRectX, int preeditRectY, int preeditRectWidth, int preeditRectHeight)
{
    MInputContextConnection::mouseClickedOnPreedit(connectionNumber(), QPoint(posX, posY), QRect(preeditRectX, preeditRectY, preeditRectWidth, preeditRectHeight));
}

void DBusInputContextConnection::setPreedit(const QString &text, int cursorPos)
{
    MInputContextConnection::setPreedit(connectionNumber(), text, cursorPos);
}

void DBusInputContextConnection::updateWidgetInformation(const QVariantMap &stateInformation, bool focusChanged)
{
    MInputContextConnection::updateWidgetInformation(connectionNumber(), stateInformation, focusChanged);
}

void DBusInputContextConnection::reset()
{
    MInputContextConnection::reset(connectionNumber());
}

void DBusInputContextConnection::appOrientationAboutToChange(int angle)
{
    MInputContextConnection::receivedAppOrientationAboutToChange(connectionNumber(), angle);
}

void DBusInputContextConnection::appOrientationChanged(int angle)
{
    MInputContextConnection::receivedAppOrientationChanged(connectionNumber(), angle);
}

void DBusInputContextConnection::setCopyPasteState(bool copyAvailable, bool pasteAvailable)
{
    MInputContextConnection::setCopyPasteState(connectionNumber(), copyAvailable, pasteAvailable);
}

void DBusInputContextConnection::processKeyEvent(int keyType, int keyCode, int modifiers, const QString &text, bool autoRepeat, int count, uint nativeScanCode, uint nativeModifiers, uint time)
{
    MInputContextConnection::processKeyEvent(connectionNumber(), static_cast<QEvent::Type>(keyType), static_cast<Qt::Key>(keyCode), static_cast<Qt::KeyboardModifier>(modifiers), text, autoRepeat, count, nativeScanCode, nativeModifiers, time);
}

void DBusInputContextConnection::registerAttributeExtension(int id, const QString &fileName)
{
    MInputContextConnection::registerAttributeExtension(connectionNumber(), id, fileName);
}

void DBusInputContextConnection::unregisterAttributeExtension(int id)
{
    MInputContextConnection::unregisterAttributeExtension(connectionNumber(), id);
}

void DBusInputContextConnection::setExtendedAttribute(int id, const QString &target, const QString &targetItem, const QString &attribute, const QDBusVariant &value)
{
    MInputContextConnection::setExtendedAttribute(connectionNumber(), id, target, targetItem, attribute, value.variant());
}

void DBusInputContextConnection::loadPluginSettings(const QString &descriptionLanguage)
{
    MInputContextConnection::loadPluginSettings(connectionNumber(), descriptionLanguage);
}