File indexing completed on 2024-04-28 05:46:31

0001 /*
0002     SPDX-FileCopyrightText: 2010 Volker Lanz <vl@fidra.de>
0003     SPDX-FileCopyrightText: 2014-2016 Andrius Štikonas <andrius@stikonas.eu>
0004     SPDX-FileCopyrightText: 2016 Chantara Tith <tith.chantara@gmail.com>
0005     SPDX-FileCopyrightText: 2019 Yuri Chornoivan <yurchor@ukr.net>
0006 
0007     SPDX-License-Identifier: GPL-3.0-or-later
0008 */
0009 
0010 #include "gui/createpartitiontabledialog.h"
0011 #include "gui/createpartitiontablewidget.h"
0012 
0013 #include <core/device.h>
0014 
0015 #include <QDialogButtonBox>
0016 #include <QPushButton>
0017 
0018 #include <KLocalizedString>
0019 #include <KMessageBox>
0020 
0021 #include <config.h>
0022 
0023 CreatePartitionTableDialog::CreatePartitionTableDialog(QWidget* parent, const Device& d) :
0024     QDialog(parent),
0025     m_DialogWidget(new CreatePartitionTableWidget(this)),
0026     m_Device(d)
0027 {
0028     QVBoxLayout *mainLayout = new QVBoxLayout(this);
0029     setLayout(mainLayout);
0030     mainLayout->addWidget(&widget());
0031     setWindowTitle(xi18nc("@title:window", "Create a New Partition Table on <filename>%1</filename>", device().deviceNode()));
0032     dialogButtonBox = new QDialogButtonBox;
0033     createButton = dialogButtonBox->addButton(QDialogButtonBox::Ok);
0034     createButton->setText(xi18nc("@action:button", "Create &New Partition Table"));
0035     cancelButton = dialogButtonBox->addButton(QDialogButtonBox::Cancel);
0036     mainLayout->addWidget(dialogButtonBox);
0037 
0038     connect(&widget().radioMSDOS(), &QRadioButton::toggled, this, &CreatePartitionTableDialog::onMSDOSToggled);
0039     connect(dialogButtonBox, &QDialogButtonBox::accepted, this, &CreatePartitionTableDialog::accept);
0040     connect(dialogButtonBox, &QDialogButtonBox::rejected, this, &CreatePartitionTableDialog::reject);
0041 }
0042 
0043 PartitionTable::TableType CreatePartitionTableDialog::type() const
0044 {
0045     if (widget().radioGPT().isChecked())
0046         return PartitionTable::gpt;
0047 
0048     if (widget().radioMSDOS().isChecked() && Config::useCylinderAlignment() == true)
0049         return PartitionTable::msdos;
0050 
0051     return PartitionTable::msdos_sectorbased;
0052 }
0053 
0054 void CreatePartitionTableDialog::onMSDOSToggled(bool on)
0055 {
0056     if (on && device().totalLogical() > 0xffffffff) {
0057         if (KMessageBox::warningContinueCancel(this,
0058                                                xi18nc("@info",
0059                                                        "<para>Do you really want to create an MS-Dos partition table on <filename>%1</filename>?</para>"
0060                                                        "<para>This device has more than 2^32 sectors. That is the most the MS-Dos partition table type supports, so you will not be able to use the whole device.</para>", device().deviceNode()),
0061                                                xi18nc("@title:window", "Really Create MS-Dos Partition Table Type?"),
0062                                                KGuiItem(xi18nc("@action:button", "Create MS-Dos Type"), QStringLiteral("arrow-right")),
0063                                                KStandardGuiItem::cancel(), QStringLiteral("reallyCreateMSDOSOnLargeDevice")) == KMessageBox::Cancel) {
0064             widget().radioGPT().setChecked(true);
0065         }
0066     }
0067 }
0068