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
|
#include "DesktopSelectViewStep.h"
#include <QDir>
#include <QFile>
#include <QLocale>
#include <QQuickItem>
#include <QSet>
#include <QVBoxLayout>
#include <QQuickWidget>
#include <QQmlContext>
#include <QQmlEngine>
#include <GlobalStorage.h>
#include <JobQueue.h>
CALAMARES_PLUGIN_FACTORY_DEFINITION(DesktopSelectViewStepFactory, registerPlugin<DesktopSelectViewStep>();)
DesktopSelectViewStep::DesktopSelectViewStep(QObject* parent)
: Calamares::ViewStep(parent)
, m_backend(new DesktopBackend(this))
{
connect(m_backend, &DesktopBackend::selectionMade, this, [this]() {
emit nextStatusChanged(true);
});
}
DesktopSelectViewStep::~DesktopSelectViewStep()
{
if (m_widget && m_widget->parent() == nullptr)
delete m_widget;
}
QString DesktopSelectViewStep::prettyName() const
{
return tr("Desktop");
}
void DesktopSelectViewStep::buildWidget()
{
m_widget = new QWidget();
auto* layout = new QVBoxLayout(m_widget);
layout->setContentsMargins(0, 0, 0, 0);
m_quickWidget = new QQuickWidget();
m_quickWidget->setResizeMode(QQuickWidget::SizeRootObjectToView);
QString modulePath = QStringLiteral("/usr/lib/calamares/modules/desktopselect/ui");
if (!QDir(modulePath).exists())
modulePath = QDir::currentPath() + QStringLiteral("/desktopselect/ui");
m_quickWidget->engine()->addImportPath(modulePath);
m_quickWidget->rootContext()->setContextProperty("backend", m_backend);
m_locale = getLocale();
m_backend->setLocale(m_locale);
m_quickWidget->rootContext()->setContextProperty("systemLocale", m_locale);
QString qmlPath = QStringLiteral("/usr/lib/calamares/modules/desktopselect/ui/desktopselect.qml");
if (!QFile::exists(qmlPath))
qmlPath = QDir::currentPath() + QStringLiteral("/desktopselect/ui/desktopselect.qml");
m_quickWidget->setSource(QUrl::fromLocalFile(qmlPath));
layout->addWidget(m_quickWidget);
}
QWidget* DesktopSelectViewStep::widget()
{
if (!m_widget)
buildWidget();
return m_widget;
}
bool DesktopSelectViewStep::isNextEnabled() const
{
return m_backend && m_backend->selectedIndex() >= 0;
}
bool DesktopSelectViewStep::isBackEnabled() const { return true; }
bool DesktopSelectViewStep::isAtBeginning() const { return true; }
bool DesktopSelectViewStep::isAtEnd() const { return true; }
Calamares::JobList DesktopSelectViewStep::jobs() const { return {}; }
void DesktopSelectViewStep::onActivate()
{
const QString newLocale = getLocale();
if (newLocale != m_locale)
{
m_locale = newLocale;
m_backend->setLocale(m_locale);
if (m_quickWidget)
m_quickWidget->rootContext()->setContextProperty("systemLocale", m_locale);
}
if (m_quickWidget)
{
QQuickItem* root = m_quickWidget->rootObject();
if (root)
QMetaObject::invokeMethod(root, "updateLanguage", Qt::DirectConnection);
}
}
void DesktopSelectViewStep::onLeave()
{
if (!m_backend || m_backend->selectedIndex() < 0)
return;
// Merge mandatory + selected desktop packages, deduplicated
QStringList combined = m_mandatoryPackages + m_backend->selectedPackages();
QStringList unique;
QSet<QString> seen;
for (const QString& pkg : combined) {
if (!seen.contains(pkg)) {
seen.insert(pkg);
unique << pkg;
}
}
QVariantMap op;
op[QStringLiteral("install")] = unique;
QVariantList ops;
ops.append(op);
if (!Calamares::JobQueue::instance())
return;
auto* gs = Calamares::JobQueue::instance()->globalStorage();
if (gs)
gs->insert(QStringLiteral("packageOperations"), ops);
}
void DesktopSelectViewStep::setConfigurationMap(const QVariantMap& config)
{
m_mandatoryPackages.clear();
for (const auto& v : config.value("mandatory_packages").toList())
m_mandatoryPackages << v.toString();
QVariantList desktops;
for (const auto& item : config.value("desktops").toList())
desktops << item;
m_backend->setDesktops(desktops);
}
QString DesktopSelectViewStep::getLocale() const
{
if (Calamares::JobQueue::instance())
{
Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage();
if (gs)
{
if (gs->contains("locale"))
{
const QString loc = gs->value("locale").toString();
if (!loc.isEmpty())
return loc;
}
if (gs->contains("localeConf"))
{
const QVariantMap localeConf = gs->value("localeConf").toMap();
if (localeConf.contains("LANG"))
{
const QString loc = localeConf.value("LANG").toString();
if (!loc.isEmpty())
return loc;
}
}
}
}
return QLocale::system().name();
}
|