Add plugin mechanism to load platform input contexts

Change-Id: I6e74fd395325445420efce4adf13e89abe8177ee
Reviewed-on: http://codereview.qt-project.org/4482
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
bb10
Joona Petrell 2011-09-08 17:22:55 +03:00 committed by Lars Knoll
parent 7ad91ad9ca
commit 8be1122710
27 changed files with 441 additions and 33 deletions

View File

@ -59,8 +59,6 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Gui)
class QPlatformIntegration;
class Q_GUI_EXPORT QGuiApplicationPrivate : public QCoreApplicationPrivate
{
Q_DECLARE_PUBLIC(QGuiApplication)

View File

@ -53,7 +53,6 @@ QInputPanel::~QInputPanel()
{
}
QObject *QInputPanel::inputItem() const
{
Q_D(const QInputPanel);

View File

@ -53,8 +53,9 @@ QT_MODULE(Gui)
class QWindow;
class QMouseEvent;
class Q_GUI_EXPORT QPlatformInputContext
class Q_GUI_EXPORT QPlatformInputContext : public QObject
{
Q_OBJECT
public:
QPlatformInputContext();
virtual ~QPlatformInputContext();

View File

@ -0,0 +1,6 @@
HEADERS += \
$$PWD/qplatforminputcontextplugin_qpa_p.h \
$$PWD/qplatforminputcontextfactory_qpa_p.h
SOURCES += \
$$PWD/qplatforminputcontextplugin_qpa.cpp \
$$PWD/qplatforminputcontextfactory_qpa.cpp

View File

@ -0,0 +1,83 @@
/****************************************************************************
**
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtGui module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** This file may be used 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. Please review the following information to ensure the GNU Lesser
** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qplatforminputcontextfactory_qpa_p.h"
#include "qplatforminputcontextplugin_qpa_p.h"
#include <QPlatformInputContext>
#include "private/qfactoryloader_p.h"
#include "qguiapplication.h"
#include "qdebug.h"
QT_BEGIN_NAMESPACE
#if !defined(QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader,
(QPlatformInputContextFactoryInterface_iid, QLatin1String("/platforminputcontexts"), Qt::CaseInsensitive))
Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, directLoader,
(QPlatformInputContextFactoryInterface_iid, QLatin1String(""), Qt::CaseInsensitive))
#endif
QStringList QPlatformInputContextFactory::keys()
{
#if !defined(QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
QStringList list = loader()->keys();
#else
QStringList list;
#endif
return list;
}
QPlatformInputContext *QPlatformInputContextFactory::create(const QString& key)
{
QPlatformInputContext *ret = 0;
QStringList paramList = key.split(QLatin1Char(':'));
QString platform = paramList.takeFirst().toLower();
#if !defined(QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
if (QPlatformInputContextFactoryInterface *factory = qobject_cast<QPlatformInputContextFactoryInterface*>(loader()->instance(platform)))
ret = factory->create(platform, paramList);
#endif
return ret;
}
QT_END_NAMESPACE

View File

@ -0,0 +1,78 @@
/****************************************************************************
**
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtGui module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** This file may be used 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. Please review the following information to ensure the GNU Lesser
** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QPLATFORMINPUTCONTEXTFACTORY_H
#define QPLATFORMINPUTCONTEXTFACTORY_H
//
// W A R N I N G
// -------------
//
// This file is not part of the Qt API. It exists purely as an
// implementation detail. This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//
#include <QtCore/qstringlist.h>
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
QT_MODULE(Gui)
class QPlatformInputContext;
class QPlatformInputContextFactory
{
public:
static QStringList keys();
static QPlatformInputContext *create(const QString &key);
};
QT_END_NAMESPACE
QT_END_HEADER
#endif // QPLATFORMINPUTCONTEXTFACTORY_H

View File

@ -0,0 +1,55 @@
/****************************************************************************
**
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtGui module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** This file may be used 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. Please review the following information to ensure the GNU Lesser
** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qplatforminputcontextplugin_qpa_p.h"
QT_BEGIN_NAMESPACE
QPlatformInputContextPlugin::QPlatformInputContextPlugin(QObject *parent)
: QObject(parent)
{
}
QPlatformInputContextPlugin::~QPlatformInputContextPlugin()
{
}
QT_END_NAMESPACE

View File

@ -0,0 +1,92 @@
/****************************************************************************
**
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtGui module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** This file may be used 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. Please review the following information to ensure the GNU Lesser
** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QPLATFORMINPUTCONTEXTPLUGIN_H
#define QPLATFORMINPUTCONTEXTPLUGIN_H
//
// W A R N I N G
// -------------
//
// This file is not part of the Qt API. It exists purely as an
// implementation detail. This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//
#include <QtCore/qplugin.h>
#include <QtCore/qfactoryinterface.h>
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
QT_MODULE(Gui)
class QPlatformInputContext;
struct QPlatformInputContextFactoryInterface : public QFactoryInterface
{
virtual QPlatformInputContext *create(const QString &key, const QStringList &paramList) = 0;
};
#define QPlatformInputContextFactoryInterface_iid "com.nokia.Qt.QPlatformInputContextFactoryInterface"
Q_DECLARE_INTERFACE(QPlatformInputContextFactoryInterface, QPlatformInputContextFactoryInterface_iid)
class Q_GUI_EXPORT QPlatformInputContextPlugin : public QObject, public QPlatformInputContextFactoryInterface
{
Q_OBJECT
Q_INTERFACES(QPlatformInputContextFactoryInterface:QFactoryInterface)
public:
explicit QPlatformInputContextPlugin(QObject *parent = 0);
~QPlatformInputContextPlugin();
virtual QStringList keys() const = 0;
virtual QPlatformInputContext *create(const QString &key, const QStringList &paramList) = 0;
};
QT_END_NAMESPACE
QT_END_HEADER
#endif // QPLATFORMINPUTCONTEXTPLUGIN_H

View File

@ -1,11 +0,0 @@
QT += dbus
SOURCES += $$PWD/qibusplatforminputcontext.cpp \
$$PWD/qibusproxy.cpp \
$$PWD/qibusinputcontextproxy.cpp \
$$PWD/qibustypes.cpp
HEADERS += $$PWD/qibusplatforminputcontext.h \
$$PWD/qibusproxy.h \
$$PWD/qibusinputcontextproxy.h \
$$PWD/qibustypes.h

View File

@ -1,5 +0,0 @@
contains(QT_CONFIG, dbus) {
!mac:unix: {
include($$PWD/ibus/ibus.pri)
}
}

View File

@ -30,4 +30,4 @@ include(fb_base/fb_base.pri)
include(fontdatabases/fontdatabases.pri)
include(glxconvenience/glxconvenience.pri)
include(printersupport/printersupport.pri)
include(inputmethods/inputmethods.pri)
include(inputcontext/inputcontext.pri)

View File

@ -0,0 +1,19 @@
TARGET = ibusplatforminputcontextplugin
load(qt_plugin)
QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/platforminputcontexts
QT += dbus platformsupport-private
SOURCES += $$PWD/qibusplatforminputcontext.cpp \
$$PWD/qibusproxy.cpp \
$$PWD/qibusinputcontextproxy.cpp \
$$PWD/qibustypes.cpp \
$$PWD/main.cpp
HEADERS += $$PWD/qibusplatforminputcontext.h \
$$PWD/qibusproxy.h \
$$PWD/qibusinputcontextproxy.h \
$$PWD/qibustypes.h
target.path += $$[QT_INSTALL_PLUGINS]/platforminputcontexts
INSTALLS += target

View File

@ -0,0 +1,71 @@
/****************************************************************************
**
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (info@qt.nokia.com)
**
** This file is part of the plugins of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** This file may be used 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. Please review the following information to ensure the GNU Lesser
** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include <private/qplatforminputcontextplugin_qpa_p.h>
#include <QtCore/QStringList>
#include "qibusplatforminputcontext.h"
QT_BEGIN_NAMESPACE
class QIbusPlatformInputContextPlugin : public QPlatformInputContextPlugin
{
public:
QStringList keys() const;
QIBusPlatformInputContext *create(const QString&, const QStringList&);
};
QStringList QIbusPlatformInputContextPlugin::keys() const
{
return QStringList(QStringLiteral("ibus"));
}
QIBusPlatformInputContext *QIbusPlatformInputContextPlugin::create(const QString& system, const QStringList& paramList)
{
Q_UNUSED(paramList);
if (system.compare(system, QStringLiteral("ibus"), Qt::CaseInsensitive) == 0)
return new QIBusPlatformInputContext;
return 0;
}
Q_EXPORT_PLUGIN2(ibusplatforminputcontextplugin, QIbusPlatformInputContextPlugin)
QT_END_NAMESPACE

View File

@ -46,7 +46,7 @@
class QIBusPlatformInputContextPrivate;
class QDBusVariant;
class QIBusPlatformInputContext : public QObject, public QPlatformInputContext
class QIBusPlatformInputContext : public QPlatformInputContext
{
Q_OBJECT
public:

View File

@ -0,0 +1,4 @@
TEMPLATE = subdirs
SUBDIRS += ibus

View File

@ -63,7 +63,8 @@
#endif
#if defined(XCB_USE_IBUS)
#include "QtPlatformSupport/qibusplatforminputcontext.h"
#include <private/qplatforminputcontextfactory_qpa_p.h>
#include <qplatforminputcontext_qpa.h>
#endif
#if defined(XCB_USE_GLX)
@ -102,12 +103,15 @@ QXcbIntegration::QXcbIntegration(const QStringList &parameters)
m_inputContext = 0;
#if defined(XCB_USE_IBUS)
QIBusPlatformInputContext *context = new QIBusPlatformInputContext;
if (context->isValid()) {
m_inputContext = context;
} else {
delete context;
QPlatformInputContext *platformInputContext = QPlatformInputContextFactory::create("ibus");
if (platformInputContext) {
QVariant value;
QMetaObject::invokeMethod(platformInputContext, "isValid", Qt::DirectConnection, Q_RETURN_ARG(QVariant, value));
if (value.toBool())
m_inputContext = platformInputContext;
}
if (platformInputContext && !m_inputContext)
delete platformInputContext;
#endif
}

View File

@ -50,7 +50,7 @@
#include <stdio.h>
#if defined(XCB_USE_IBUS)
#include "QtPlatformSupport/qibusplatforminputcontext.h"
#include <qplatforminputcontext_qpa.h>
#endif
#ifndef XK_ISO_Left_Tab
@ -1029,9 +1029,20 @@ void QXcbKeyboard::handleKeyEvent(QWindow *window, QEvent::Type type, xcb_keycod
QByteArray chars;
xcb_keysym_t sym = lookupString(window, state, code, type, &chars);
QIBusPlatformInputContext *ic = static_cast<QIBusPlatformInputContext *>(QGuiApplicationPrivate::platformIntegration()->inputContext());
if (ic && ic->x11FilterEvent(sym, code, state, type == QEvent::KeyPress))
return;
#if defined(XCB_USE_IBUS)
if (QObject* inputContext = QGuiApplicationPrivate::platformIntegration()->inputContext()) {
QVariant value;
QMetaObject::invokeMethod(inputContext, "x11FilterEvent", Qt::DirectConnection,
Q_RETURN_ARG(QVariant, value),
Q_ARG(uint, sym),
Q_ARG(uint, code),
Q_ARG(uint, state),
Q_ARG(bool, type == QEvent::KeyPress));
if (value.toBool())
return;
}
#endif
Qt::KeyboardModifiers modifiers;
int qtcode = 0;

View File

@ -9,4 +9,7 @@ unix:!symbian {
!contains(QT_CONFIG, no-gui): SUBDIRS *= imageformats
!symbian:!contains(QT_CONFIG, no-gui):SUBDIRS += accessible
symbian:SUBDIRS += s60
qpa:SUBDIRS += platforms
qpa: {
SUBDIRS += platforms
SUBDIRS += platforminputcontexts
}