summaryrefslogtreecommitdiff
path: root/ui/qt5/pkgsimple.cc
blob: e168583913632d20e301a5317854498df4c8c18c (plain) (blame)
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/*
 * pkgsimple.cc - Implementation of the UI.Packages.SimpleSel page
 * horizon-qt5, the Qt 5 user interface for
 * Project Horizon
 *
 * Copyright (c) 2019-2022 Adélie Linux and contributors.  All rights reserved.
 * This code is licensed under the AGPL 3.0 license, as noted in the
 * LICENSE-code file in the root directory of this repository.
 *
 * SPDX-License-Identifier: AGPL-3.0-only
 */

#include "pkgsimple.hh"
#include "pkgdefaults.hh"

#include <QButtonGroup>
#include <QGridLayout>
#include <QLabel>
#include <QVBoxLayout>

PkgSimplePage::PkgSimplePage(QWidget *parent) : HorizonWizardPage(parent) {
    setTitle(tr("Software Selection"));
    loadWatermark("software");

    QLabel *descLabel = new QLabel(tr(
            "Select the software you want to install on this computer.\n\n"
            "You can install and uninstall more software at any time using the Package Manager.  For more information, see the User Handbook in Online Help."));
    descLabel->setWordWrap(true);

    QRadioButton *mobileButton, *compactButton, *textButton, *customButton;
    QLabel *standardLabel, *mobileLabel, *compactLabel, *textLabel,
            *customLabel;

    standardButton = new QRadioButton(tr("&Standard"));
    standardButton->setIcon(QIcon::fromTheme("preferences-desktop-theme"));
    standardButton->setIconSize(QSize(32, 32));
    standardLabel = new QLabel(
            tr("Includes a full desktop environment, including Web browser, email client, media player, and office suite."));
    standardLabel->setBuddy(standardButton);
    standardLabel->setIndent(40);
    standardLabel->setWordWrap(true);
    standardButton->setWhatsThis(standardLabel->text());

    mobileButton = new QRadioButton(tr("&Mobile"));
    mobileButton->setIcon(QIcon::fromTheme("battery"));
    mobileButton->setIconSize(QSize(32, 32));
    mobileLabel = new QLabel(
            tr("Includes the Standard software and additional utilities for notebook and tablet computers."));
    mobileLabel->setBuddy(mobileButton);
    mobileLabel->setIndent(40);
    mobileLabel->setWordWrap(true);
    mobileButton->setWhatsThis(mobileLabel->text());

    compactButton = new QRadioButton(tr("&Compact"));
    compactButton->setIcon(QIcon::fromTheme("preferences-ubuntu-panel"));
    compactButton->setIconSize(QSize(32, 32));
    compactLabel = new QLabel(tr("Includes a lightweight LXQt desktop environment and a text editor."));
    compactLabel->setBuddy(compactButton);
    compactLabel->setIndent(40);
    compactLabel->setWordWrap(true);
    compactButton->setWhatsThis(compactLabel->text());

    textButton = new QRadioButton(tr("&Text-Only"));
    textButton->setIcon(QIcon::fromTheme("utilities-terminal"));
    textButton->setIconSize(QSize(32, 32));
    textLabel = new QLabel(
            tr("Includes only text-mode support.  Select for servers, or computers with very limited resources."));
    textLabel->setBuddy(textButton);
    textLabel->setIndent(40);
    textLabel->setWordWrap(true);
    textButton->setWhatsThis(textLabel->text());

    customButton = new QRadioButton(tr("C&ustom"));
    customButton->setIcon(QIcon::fromTheme("preferences-activities"));
    customButton->setIconSize(QSize(32, 32));
    customLabel = new QLabel(tr("Customise the packages installed on your computer."));
    customLabel->setBuddy(customButton);
    customLabel->setIndent(40);
    customLabel->setWordWrap(true);
    customButton->setWhatsThis(customLabel->text());

    deskPlasmaButton = new QRadioButton(tr("KDE Plasma"));
    deskLXQtButton = new QRadioButton(tr("LXQt"));
    deskMATEButton = new QRadioButton(tr("MATE"));
    deskXFCEButton = new QRadioButton(tr("XFCE"));

    auto *desktopGroup = new QButtonGroup(this);
    desktopGroup->addButton(deskPlasmaButton, HorizonWizard::Plasma);
    desktopGroup->addButton(deskLXQtButton, HorizonWizard::LXQt);
    desktopGroup->addButton(deskMATEButton, HorizonWizard::MATE);
    desktopGroup->addButton(deskXFCEButton, HorizonWizard::XFCE);
    connect(desktopGroup, QOverload<QAbstractButton *>::of(&QButtonGroup::buttonClicked),
            [this, desktopGroup](QAbstractButton *choice) {
        horizonWizard()->desktopType = static_cast<HorizonWizard::DesktopType>(desktopGroup->id(choice));
    });

    auto *buttonLayout = new QVBoxLayout;
    buttonLayout->addWidget(standardButton);
    buttonLayout->addWidget(standardLabel);
    buttonLayout->addWidget(mobileButton);
    buttonLayout->addWidget(mobileLabel);
    buttonLayout->addWidget(compactButton);
    buttonLayout->addWidget(compactLabel);
    buttonLayout->addWidget(textButton);
    buttonLayout->addWidget(textLabel);
    buttonLayout->addWidget(customButton);
    buttonLayout->addWidget(customLabel);

    QButtonGroup *group = new QButtonGroup(this);
    group->addButton(standardButton, HorizonWizard::Standard);
    group->addButton(mobileButton, HorizonWizard::Mobile);
    group->addButton(compactButton, HorizonWizard::Compact);
    group->addButton(textButton, HorizonWizard::TextOnly);
    group->addButton(customButton, HorizonWizard::Custom);
    connect(group, QOverload<QAbstractButton *>::of(&QButtonGroup::buttonClicked),
            [this, group, buttonLayout](QAbstractButton *choice) {
        horizonWizard()->pkgtype = static_cast<HorizonWizard::PackageType>(group->id(choice));
        if(choice == standardButton) {
            auto *desktopLayout = new QHBoxLayout;
            desktopLayout->setObjectName("desk-buttons");
            for(auto button: {deskPlasmaButton, deskLXQtButton, deskMATEButton, deskXFCEButton}) {
                button->show();
                desktopLayout->addWidget(button);
            }
            buttonLayout->insertLayout(2, desktopLayout);
            layout()->invalidate();
        } else {
            auto item = buttonLayout->itemAt(2);
            if(item->layout() && item->layout()->objectName() == "desk-buttons") {
                buttonLayout->removeItem(item);
                for (auto button: {deskPlasmaButton, deskLXQtButton, deskMATEButton, deskXFCEButton}) {
                    button->hide();
                }
            }
        }
    });

    auto *mainLayout = new QVBoxLayout;
    mainLayout->addWidget(descLabel);
    mainLayout->addStretch();
    mainLayout->addLayout(buttonLayout);
    setLayout(mainLayout);
}

void PkgSimplePage::initializePage() {
    standardButton->click();
#ifdef HAS_INSTALL_ENV
    auto curr_desktop = qEnvironmentVariable("XDG_CURRENT_DESKTOP").toStdString();
    if(curr_desktop == "LXQt") {
        deskLXQtButton->click();
    } else if(curr_desktop == "MATE") {
        deskMATEButton->click();
    } else if(curr_desktop == "XFCE") {
        deskXFCEButton->click();
    } else
#endif  /* HAS_INSTALL_ENV */
        deskPlasmaButton->click();
}

int PkgSimplePage::nextId() const {
    if(horizonWizard()->pkgtype == HorizonWizard::Custom)
        return HorizonWizard::Page_PkgCustom;

    return HorizonWizard::Page_Boot;
}

bool PkgSimplePage::validatePage() {
    /* This code handles the following scenario:
     *
     * - 'Custom' is selected
     * - A non-default option is selected on the Defaults page (i.e., mdevd)
     * - Back is chosen
     * - A non-custom package selection choice is selected
     *
     * We need to completely 'reset' the state of the Defaults, including
     * the selections on the Defaults page, whenever Next is chosen.
     */
    if(horizonWizard()->pkgtype == HorizonWizard::Custom) {
        horizonWizard()->removePage(HorizonWizard::Page_PkgCustomDefault);
        horizonWizard()->setPage(HorizonWizard::Page_PkgCustomDefault, new PkgDefaultsPage);
    } else {
        horizonWizard()->sbininit = HorizonWizard::S6;
        horizonWizard()->binsh = HorizonWizard::Dash;
        horizonWizard()->eudev = true;
    }

    return true;
}