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 | QStringList QPlatformInputContextFactory::requested() |
32 | { |
33 | QStringList imList; |
34 | QByteArray env = qgetenv(varName: "QT_IM_MODULES"); |
35 | |
36 | if (!env.isEmpty()) |
37 | imList = QString::fromLocal8Bit(ba: env).split(sep: QChar::fromLatin1(c: ';'), behavior: Qt::SkipEmptyParts); |
38 | |
39 | if (!imList.isEmpty()) |
40 | return imList; |
41 | |
42 | env = qgetenv(varName: "QT_IM_MODULE"); |
43 | if (!env.isEmpty()) |
44 | imList = {QString::fromLocal8Bit(ba: env)}; |
45 | |
46 | return imList; |
47 | } |
48 | |
49 | QPlatformInputContext *QPlatformInputContextFactory::create(const QStringList& keys) |
50 | { |
51 | for (const QString &key : keys) { |
52 | auto plugin = create(key); |
53 | if (plugin) |
54 | return plugin; |
55 | } |
56 | |
57 | return nullptr; |
58 | } |
59 | |
60 | QPlatformInputContext *QPlatformInputContextFactory::create(const QString& key) |
61 | { |
62 | #if QT_CONFIG(settings) |
63 | if (!key.isEmpty()) { |
64 | QStringList paramList = key.split(sep: u':'); |
65 | const QString platform = paramList.takeFirst().toLower(); |
66 | |
67 | QPlatformInputContext *ic = qLoadPlugin<QPlatformInputContext, QPlatformInputContextPlugin> |
68 | (loader: icLoader(), key: platform, args&: paramList); |
69 | if (ic && ic->isValid()) |
70 | return ic; |
71 | |
72 | delete ic; |
73 | } |
74 | #else |
75 | Q_UNUSED(key); |
76 | #endif |
77 | return nullptr; |
78 | } |
79 | |
80 | QPlatformInputContext *QPlatformInputContextFactory::create() |
81 | { |
82 | return create(keys: requested()); |
83 | } |
84 | |
85 | QT_END_NAMESPACE |
86 | |
87 |