summaryrefslogtreecommitdiff
path: root/ui/qt5/partitionpage.cc
blob: a74b1a96de162665b037c5c4218b09986c714470 (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
/*
 * partitionpage.cc - Implementation of the UI.Partition page:
 * either UI.Partition.Runtime.DiskDetails, or UI.Partition.Install.Details
 * horizon-qt5, the Qt 5 user interface for
 * Project Horizon
 *
 * Copyright (c) 2020 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 "partitionpage.hh"

#include <QVBoxLayout>
#include "partitiondiskpage.hh"

PartitionPage::PartitionPage(QWidget *parent) : HorizonWizardPage(parent) {
    loadWatermark("disk");
#ifdef HAS_INSTALL_ENV
    setTitle(tr("Detecting Disks"));

    thread = nullptr;
    scanDone = false;

    descLabel = new QLabel;
    descLabel->setWordWrap(true);
    progress = new QProgressBar;
    progress->setRange(0, 0);

    scanButton = new QPushButton(tr("Rescan Devices"));
    connect(scanButton, &QPushButton::clicked, this, &PartitionPage::scanDisks);
    scanButton->setHidden(true);

    QVBoxLayout *layout = new QVBoxLayout;
    layout->addStretch();
    layout->addWidget(descLabel);
    layout->addWidget(progress);
    layout->addWidget(scanButton, 0, Qt::AlignCenter);
    layout->addStretch();

    setLayout(layout);
#else  /* !HAS_INSTALL_ENV */
    setTitle(tr("Enter Disk Information"));
#endif  /* HAS_INSTALL_ENV */
}

void PartitionPage::initializePage() {
#ifdef HAS_INSTALL_ENV
    scanDisks();
#endif
}

bool PartitionPage::isComplete() const {
#ifdef HAS_INSTALL_ENV
    return scanDone;
#else  /* !HAS_INSTALL_ENV */
    // determine whether a valid disk has been input
    return false;
#endif  /* HAS_INSTALL_ENV */
}

#ifdef HAS_INSTALL_ENV
void PartitionPage::scanDisks() {
    descLabel->setText(tr("Please wait while System Installation collects information on your computer's disk drives."));
    scanButton->setEnabled(false);
    scanButton->setHidden(true);
    progress->setHidden(false);

    if(thread != nullptr) {
        thread->deleteLater();
    }

    thread = new PartitionProbeThread;
    thread->setParent(this);
    connect(thread, &PartitionProbeThread::foundDisks,
            this, &PartitionPage::processDisks);
    thread->start();
}

void PartitionPage::processDisks(void *disk_obj) {
    /* Qt can only fling void*s around threads; convert back to vec of Disk */
    vector<Disk> *disks = static_cast<vector<Disk> *>(disk_obj);

    scanButton->setEnabled(true);
    scanButton->setHidden(false);
    progress->setHidden(true);
    descLabel->setText(tr("System Installation has finished scanning your computer for disk drives.\n\nIf you've changed your computer's disk drive layout, choose Rescan Devices to run another scan."));

    /* Copy our disk information into the wizard's global object */
    horizonWizard()->disks.swap(*disks);
    delete disks;

    /* ensure that the Disk page receives our new disk information */
    horizonWizard()->removePage(HorizonWizard::Page_PartitionDisk);
    horizonWizard()->setPage(HorizonWizard::Page_PartitionDisk, new PartitionDiskPage);

    scanDone = true;
    emit completeChanged();
    wizard()->next();
}
#endif