blob: 4af261cf2e5bb3a6dad3c508abc9af8e0555e53c (
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
117
|
#include "DesktopSelectViewStep.h"
#include <QDir>
#include <QFile>
#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);
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::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);
}
|