blob: 9c1fbcb5d94a1b6f422397d9e180e8ca80609022 (
plain)
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
|
// Copyright (C) 2021 The Qt Company Ltd.
// Copyright (C) 2019 Luxoft Sweden AB
// Copyright (C) 2018 Pelagicore AG
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QCoreApplication>
#include "logging.h"
#include "application.h"
#include "abstractruntime.h"
#include "abstractcontainer.h"
#include "runtimefactory.h"
#include <memory>
using namespace Qt::StringLiterals;
QT_BEGIN_NAMESPACE_AM
RuntimeFactory *RuntimeFactory::s_instance = nullptr;
RuntimeFactory *RuntimeFactory::instance()
{
if (!s_instance)
s_instance = new RuntimeFactory(QCoreApplication::instance());
return s_instance;
}
RuntimeFactory::RuntimeFactory(QObject *parent)
: QObject(parent)
{ }
RuntimeFactory::~RuntimeFactory()
{
qDeleteAll(m_runtimes);
s_instance = nullptr;
}
QStringList RuntimeFactory::runtimeIds() const
{
return m_runtimes.keys();
}
AbstractRuntimeManager *RuntimeFactory::manager(const QString &id)
{
return m_runtimes.value(id);
}
AbstractRuntime *RuntimeFactory::create(AbstractContainer *container, Application *app)
{
std::unique_ptr<AbstractContainer> ac(container);
if (!app || app->runtimeName().isEmpty() || app->currentRuntime())
return nullptr;
AbstractRuntimeManager *arm = manager(app->runtimeName());
if (!arm)
return nullptr;
AbstractRuntime *art = arm->create(ac.release(), app);
if (art) {
art->setSlowAnimations(m_slowAnimations);
app->setCurrentRuntime(art);
}
return art;
}
AbstractRuntime *RuntimeFactory::createQuickLauncher(AbstractContainer *container, const QString &id)
{
std::unique_ptr<AbstractContainer> ac(container);
AbstractRuntimeManager *arm = manager(id);
if (!arm)
return nullptr;
auto runtime = arm->create(ac.release(), nullptr);
if (runtime)
runtime->setSlowAnimations(m_slowAnimations);
return runtime;
}
void RuntimeFactory::setConfiguration(const QVariantMap &configuration)
{
for (auto it = m_runtimes.cbegin(); it != m_runtimes.cend(); ++it)
it.value()->setConfiguration(configuration.value(it.key()).toMap());
}
void RuntimeFactory::setSlowAnimations(bool value)
{
m_slowAnimations = value;
}
bool RuntimeFactory::registerRuntime(AbstractRuntimeManager *manager)
{
return registerRuntime(manager, manager->identifier());
}
bool RuntimeFactory::registerRuntime(AbstractRuntimeManager *manager, const QString &identifier)
{
if (!manager || identifier.isEmpty() || m_runtimes.contains(identifier))
return false;
m_runtimes.insert(identifier, manager);
manager->setParent(this);
static bool once = false;
if (!once) {
qCDebug(LogSystem) << "Registering runtimes:";
once = true;
}
qCDebug(LogSystem).noquote() << " *" << identifier;
return true;
}
QT_END_NAMESPACE_AM
#include "moc_runtimefactory.cpp"
|