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
|
/* * 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 "dbusserverconnection.h"
#include <maliit/namespace.h>
#include <maliit/settingdata.h>
#include "minputmethodcontext1interfaceadaptor.h"
#include "minputmethodserver1interface_interface.h"
#include "dbuscustomarguments.h"
#include <QDBusConnection>
#include <QDebug>
namespace
{
const char * const IMServerPath("/com/meego/inputmethod/uiserver1");
const char * const IMServerConnection("Maliit::IMServerConnection");
const char * const InputContextAdaptorPath("/com/meego/inputmethod/inputcontext");
const char * const DBusLocalPath("/org/freedesktop/DBus/Local");
const char * const DBusLocalInterface("org.freedesktop.DBus.Local");
const char * const DisconnectedSignal("Disconnected");
const int ConnectionRetryInterval(6*1000); // in ms
}
DBusServerConnection::DBusServerConnection(const QSharedPointer<Maliit::InputContext::DBus::Address> &address) :
MImServerConnection(0)
, mAddress(address)
, mProxy(0)
, mActive(true)
, pendingResetCalls()
{
qDBusRegisterMetaType<MImPluginSettingsEntry>();
qDBusRegisterMetaType<MImPluginSettingsInfo>();
qDBusRegisterMetaType<QList<MImPluginSettingsInfo> >();
qDBusRegisterMetaType<Maliit::PreeditTextFormat>();
qDBusRegisterMetaType<QList<Maliit::PreeditTextFormat> >();
new Inputcontext1Adaptor(this);
connect(mAddress.data(), SIGNAL(addressReceived(QString)),
this, SLOT(openDBusConnection(QString)));
connect(mAddress.data(), SIGNAL(addressFetchError(QString)),
this, SLOT(connectToDBusFailed(QString)));
QTimer::singleShot(0, this, SLOT(connectToDBus()));
}
DBusServerConnection::~DBusServerConnection()
{
mActive = false;
Q_FOREACH (QDBusPendingCallWatcher *watcher, pendingResetCalls) {
disconnect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
this, SLOT(resetCallFinished(QDBusPendingCallWatcher*)));
}
}
void DBusServerConnection::connectToDBus()
{
mAddress->get();
}
void DBusServerConnection::openDBusConnection(const QString &addressString)
{
if (addressString.isEmpty()) {
QTimer::singleShot(ConnectionRetryInterval, this, SLOT(connectToDBus()));
return;
}
QDBusConnection connection = QDBusConnection::connectToPeer(addressString, QString::fromLatin1(IMServerConnection));
if (!connection.isConnected()) {
QTimer::singleShot(ConnectionRetryInterval, this, SLOT(connectToDBus()));
return;
}
mProxy = new ComMeegoInputmethodUiserver1Interface(QString(), QString::fromLatin1(IMServerPath), connection, this);
connection.connect(QString(), QString::fromLatin1(DBusLocalPath), QString::fromLatin1(DBusLocalInterface),
QString::fromLatin1(DisconnectedSignal),
this, SLOT(onDisconnection()));
connection.registerObject(QString::fromLatin1(InputContextAdaptorPath), this);
#if 0
connect(mProxy, SIGNAL(invokeAction(QString,QKeySequence)), this, SIGNAL(invokeAction(QString,QKeySequence)));
#endif
Q_EMIT connected();
}
void DBusServerConnection::connectToDBusFailed(const QString &)
{
QTimer::singleShot(ConnectionRetryInterval, this, SLOT(connectToDBus()));
}
void DBusServerConnection::onDisconnection()
{
delete mProxy;
mProxy = 0;
QDBusConnection::disconnectFromPeer(QString::fromLatin1(IMServerConnection));
Q_EMIT disconnected();
if (mActive)
QTimer::singleShot(ConnectionRetryInterval, this, SLOT(connectToDBus()));
}
void DBusServerConnection::resetCallFinished(QDBusPendingCallWatcher *watcher)
{
pendingResetCalls.remove(watcher);
watcher->deleteLater();
}
bool DBusServerConnection::pendingResets()
{
return !pendingResetCalls.empty();
}
void DBusServerConnection::activateContext()
{
if (!mProxy)
return;
mProxy->activateContext();
}
void DBusServerConnection::showInputMethod()
{
if (!mProxy)
return;
mProxy->showInputMethod();
}
void DBusServerConnection::hideInputMethod()
{
if (!mProxy)
return;
mProxy->hideInputMethod();
}
void DBusServerConnection::mouseClickedOnPreedit(const QPoint &pos, const QRect &preeditRect)
{
if (!mProxy)
return;
mProxy->mouseClickedOnPreedit(pos.x(), pos.y(), preeditRect.x(), preeditRect.y(),
preeditRect.width(), preeditRect.height());
}
void DBusServerConnection::setPreedit(const QString &text, int cursorPos)
{
if (!mProxy)
return;
mProxy->setPreedit(text, cursorPos);
}
void DBusServerConnection::updateWidgetInformation(const QMap<QString, QVariant> &stateInformation, bool focusChanged)
{
if (!mProxy)
return;
mProxy->updateWidgetInformation(stateInformation, focusChanged);
}
void DBusServerConnection::reset(bool requireSynchronization)
{
if (!mProxy)
return;
QDBusPendingCall resetCall = mProxy->reset();
if (requireSynchronization) {
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(resetCall, this);
pendingResetCalls.insert(watcher);
QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
this, SLOT(resetCallFinished(QDBusPendingCallWatcher*)));
}
}
void DBusServerConnection::appOrientationAboutToChange(int angle)
{
if (!mProxy)
return;
mProxy->appOrientationAboutToChange(angle);
}
void DBusServerConnection::appOrientationChanged(int angle)
{
if (!mProxy)
return;
mProxy->appOrientationChanged(angle);
}
void DBusServerConnection::setCopyPasteState(bool copyAvailable, bool pasteAvailable)
{
if (!mProxy)
return;
mProxy->setCopyPasteState(copyAvailable, pasteAvailable);
}
void DBusServerConnection::processKeyEvent(QEvent::Type keyType, Qt::Key keyCode,
Qt::KeyboardModifiers modifiers,
const QString &text, bool autoRepeat, int count,
quint32 nativeScanCode, quint32 nativeModifiers, unsigned long time)
{
if (!mProxy)
return;
mProxy->processKeyEvent(keyType, keyCode, modifiers, text, autoRepeat, count, nativeScanCode, nativeModifiers, time);
}
void DBusServerConnection::registerAttributeExtension(int id, const QString &fileName)
{
if (!mProxy)
return;
mProxy->registerAttributeExtension(id, fileName);
}
void DBusServerConnection::unregisterAttributeExtension(int id)
{
if (!mProxy)
return;
mProxy->unregisterAttributeExtension(id);
}
void DBusServerConnection::setExtendedAttribute(int id, const QString &target, const QString &targetItem,
const QString &attribute, const QVariant &value)
{
if (!mProxy)
return;
mProxy->setExtendedAttribute(id, target, targetItem, attribute, QDBusVariant(value));
}
void DBusServerConnection::loadPluginSettings(const QString &descriptionLanguage)
{
if (!mProxy)
return;
mProxy->loadPluginSettings(descriptionLanguage);
}
void DBusServerConnection::pluginSettingsLoaded(const QList<MImPluginSettingsInfo> &info)
{
pluginSettingsReceived(info);
}
void DBusServerConnection::keyEvent(int type, int key, int modifiers, const QString &text, bool autoRepeat,
int count, uchar requestType)
{
keyEvent(type, key, modifiers, text, autoRepeat, count, static_cast<Maliit::EventRequestType>(requestType));
}
void DBusServerConnection::notifyExtendedAttributeChanged(int id, const QString &target, const QString &targetItem,
const QString &attribute, const QDBusVariant &value)
{
extendedAttributeChanged(id, target, targetItem, attribute, value.variant());
}
bool DBusServerConnection::preeditRectangle(int &x, int &y, int &width, int &height) const
{
bool valid;
QRect result;
getPreeditRectangle(result, valid);
x = result.x();
y = result.y();
width = result.width();
height = result.height();
return valid;
}
bool DBusServerConnection::selection(QString &selection) const
{
bool valid;
getSelection(selection, valid);
return valid;
}
void DBusServerConnection::updateInputMethodArea(int x, int y, int width, int height)
{
updateInputMethodArea(QRect(x, y, width, height));
}
|