1 | // Copyright (C) 2016 The Qt Company Ltd. |
---|---|
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #include <qpa/qplatforminputcontextfactory_p.h> |
5 | #include <qpa/qplatforminputcontextplugin_p.h> |
6 | #include <qpa/qplatforminputcontext.h> |
7 | #include "private/qfactoryloader_p.h" |
8 | |
9 | #include "qguiapplication.h" |
10 | #include "qdebug.h" |
11 | #include <stdlib.h> |
12 | |
13 | QT_BEGIN_NAMESPACE |
14 | |
15 | using namespace Qt::StringLiterals; |
16 | |
17 | #if QT_CONFIG(settings) |
18 | Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, icLoader, |
19 | (QPlatformInputContextFactoryInterface_iid, "/platforminputcontexts"_L1, Qt::CaseInsensitive)) |
20 | #endif |
21 | |
22 | QStringList QPlatformInputContextFactory::keys() |
23 | { |
24 | #if QT_CONFIG(settings) |
25 | return icLoader()->keyMap().values(); |
26 | #else |
27 | return QStringList(); |
28 | #endif |
29 | } |
30 | |
31 | QString QPlatformInputContextFactory::requested() |
32 | { |
33 | QByteArray env = qgetenv(varName: "QT_IM_MODULE"); |
34 | return env.isNull() ? QString() : QString::fromLocal8Bit(ba: env); |
35 | } |
36 | |
37 | QPlatformInputContext *QPlatformInputContextFactory::create(const QString& key) |
38 | { |
39 | #if QT_CONFIG(settings) |
40 | if (!key.isEmpty()) { |
41 | QStringList paramList = key.split(sep: u':'); |
42 | const QString platform = paramList.takeFirst().toLower(); |
43 | |
44 | QPlatformInputContext *ic = qLoadPlugin<QPlatformInputContext, QPlatformInputContextPlugin> |
45 | (loader: icLoader(), key: platform, args&: paramList); |
46 | if (ic && ic->isValid()) |
47 | return ic; |
48 | |
49 | delete ic; |
50 | } |
51 | #else |
52 | Q_UNUSED(key); |
53 | #endif |
54 | return nullptr; |
55 | } |
56 | |
57 | QPlatformInputContext *QPlatformInputContextFactory::create() |
58 | { |
59 | return create(key: requested()); |
60 | } |
61 | |
62 | QT_END_NAMESPACE |
63 | |
64 |