2020-09-16 00:35:12 +01:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2008-2010 Volker Lanz <vl@fidra.de>
|
|
|
|
SPDX-FileCopyrightText: 2014-2018 Andrius Štikonas <andrius@stikonas.eu>
|
|
|
|
SPDX-FileCopyrightText: 2016 Chantara Tith <tith.chantara@gmail.com>
|
|
|
|
|
|
|
|
SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
*/
|
2008-09-24 20:32:01 +01:00
|
|
|
|
|
|
|
#include "gui/resizedialog.h"
|
|
|
|
#include "gui/sizedialogwidget.h"
|
2016-06-26 18:08:15 +01:00
|
|
|
#include "gui/sizedetailswidget.h"
|
2008-09-24 20:32:01 +01:00
|
|
|
|
2016-01-12 00:12:49 +00:00
|
|
|
#include <core/partition.h>
|
|
|
|
#include <core/device.h>
|
2010-04-15 16:30:08 +01:00
|
|
|
|
2016-01-12 00:12:49 +00:00
|
|
|
#include <fs/filesystem.h>
|
2017-12-29 20:05:42 +00:00
|
|
|
#include <fs/luks2.h>
|
2008-09-24 20:32:01 +01:00
|
|
|
|
2016-01-12 00:12:49 +00:00
|
|
|
#include <ops/resizeoperation.h>
|
2008-09-24 20:32:01 +01:00
|
|
|
|
2016-01-12 00:12:49 +00:00
|
|
|
#include <util/capacity.h>
|
2008-09-24 20:32:01 +01:00
|
|
|
|
2014-05-17 03:06:58 +01:00
|
|
|
#include <KConfigGroup>
|
2014-05-13 23:53:37 +01:00
|
|
|
#include <KLocalizedString>
|
2017-12-29 20:05:42 +00:00
|
|
|
#include <KPasswordDialog>
|
2014-05-17 03:06:58 +01:00
|
|
|
#include <KSharedConfig>
|
2014-05-13 23:53:37 +01:00
|
|
|
|
2008-09-24 20:32:01 +01:00
|
|
|
/** Creates a new ResizeDialog
|
2015-07-13 15:17:41 +01:00
|
|
|
@param parent pointer to the parent widget
|
2016-05-18 11:59:06 +01:00
|
|
|
@param d the Device the Partition to resize is on
|
2015-07-13 15:17:41 +01:00
|
|
|
@param p the Partition to resize
|
2016-05-18 11:59:06 +01:00
|
|
|
@param minFirst the first free sector before the Partition to resize
|
|
|
|
@param maxLast the last free sector free after the Partition to resize
|
2008-09-24 20:32:01 +01:00
|
|
|
*/
|
2010-04-15 11:26:51 +01:00
|
|
|
ResizeDialog::ResizeDialog(QWidget* parent, Device& d, Partition& p, qint64 minFirst, qint64 maxLast) :
|
2015-07-13 15:17:41 +01:00
|
|
|
SizeDialogBase(parent, d, p, minFirst, maxLast),
|
|
|
|
m_OriginalFirstSector(p.firstSector()),
|
|
|
|
m_OriginalLastSector(p.lastSector()),
|
|
|
|
m_ResizedFirstSector(p.firstSector()),
|
|
|
|
m_ResizedLastSector(p.lastSector())
|
2008-09-24 20:32:01 +01:00
|
|
|
{
|
2015-07-13 15:17:41 +01:00
|
|
|
setWindowTitle(xi18nc("@title:window", "Resize/move partition: <filename>%1</filename>", partition().deviceNode()));
|
2008-09-24 20:32:01 +01:00
|
|
|
|
2015-07-13 15:17:41 +01:00
|
|
|
dialogWidget().hideRole();
|
|
|
|
dialogWidget().hideFileSystem();
|
|
|
|
dialogWidget().hideLabel();
|
2016-06-25 15:12:47 +01:00
|
|
|
dialogWidget().textLVName().hide();
|
|
|
|
dialogWidget().lvName().hide();
|
2008-09-24 20:32:01 +01:00
|
|
|
|
2015-07-13 15:17:41 +01:00
|
|
|
setupDialog();
|
|
|
|
setupConstraints();
|
|
|
|
setupConnections();
|
2008-09-24 20:32:01 +01:00
|
|
|
|
2015-07-13 15:17:41 +01:00
|
|
|
KConfigGroup kcg(KSharedConfig::openConfig(), "resizeDialog");
|
|
|
|
restoreGeometry(kcg.readEntry<QByteArray>("Geometry", QByteArray()));
|
2008-09-24 20:32:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Destroys a ResizeDialog */
|
|
|
|
ResizeDialog::~ResizeDialog()
|
|
|
|
{
|
2015-07-13 15:17:41 +01:00
|
|
|
KConfigGroup kcg(KSharedConfig::openConfig(), "resizeDialog");
|
|
|
|
kcg.writeEntry("Geometry", saveGeometry());
|
2008-09-24 20:32:01 +01:00
|
|
|
}
|
|
|
|
|
2010-04-15 16:30:08 +01:00
|
|
|
void ResizeDialog::rollback()
|
|
|
|
{
|
2015-07-13 15:17:41 +01:00
|
|
|
partition().setFirstSector(originalFirstSector());
|
|
|
|
partition().fileSystem().setFirstSector(originalFirstSector());
|
2010-04-15 16:30:08 +01:00
|
|
|
|
2015-07-13 15:17:41 +01:00
|
|
|
partition().setLastSector(originalLastSector());
|
|
|
|
partition().fileSystem().setLastSector(originalLastSector());
|
2010-04-15 16:30:08 +01:00
|
|
|
|
2015-07-13 15:17:41 +01:00
|
|
|
if (partition().roles().has(PartitionRole::Extended)) {
|
|
|
|
device().partitionTable()->removeUnallocated(&partition());
|
|
|
|
device().partitionTable()->insertUnallocated(device(), &partition(), partition().firstSector());
|
|
|
|
}
|
2010-04-15 16:30:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ResizeDialog::accept()
|
|
|
|
{
|
2017-12-29 20:05:42 +00:00
|
|
|
if (partition().roles().has(PartitionRole::Luks)) {
|
|
|
|
FS::luks2* luksFs = dynamic_cast<FS::luks2*>(&partition().fileSystem());
|
|
|
|
if (luksFs) {
|
2018-04-09 15:14:48 +01:00
|
|
|
if (luksFs->keyLocation() == FS::luks::KeyLocation::keyring) {
|
2017-12-29 20:05:42 +00:00
|
|
|
bool validPassphrase = false;
|
|
|
|
QString errorMessage;
|
|
|
|
QString passphrase;
|
|
|
|
|
2018-10-28 21:27:52 +00:00
|
|
|
while (!validPassphrase) {
|
2017-12-29 20:05:42 +00:00
|
|
|
KPasswordDialog dlg( this );
|
|
|
|
dlg.setPrompt(i18nc("%2 is either empty or says Invalid passphrase.", "%2Enter passphrase for %1:", partition().deviceNode(), errorMessage));
|
2018-10-28 21:27:52 +00:00
|
|
|
if (!dlg.exec()) {
|
2017-12-29 20:05:42 +00:00
|
|
|
reject();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
passphrase = dlg.password();
|
|
|
|
validPassphrase = luksFs->testPassphrase(partition().deviceNode(), passphrase);
|
|
|
|
if(!validPassphrase)
|
|
|
|
errorMessage = i18nc("Part of %2Enter passphrase for %1:", "Invalid passphrase. ");
|
|
|
|
}
|
|
|
|
luksFs->setPassphrase(passphrase);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-13 15:17:41 +01:00
|
|
|
setResizedFirstSector(partition().firstSector());
|
|
|
|
setResizedLastSector(partition().lastSector());
|
2010-04-15 16:30:08 +01:00
|
|
|
|
2015-07-13 15:17:41 +01:00
|
|
|
rollback();
|
|
|
|
QDialog::accept();
|
2010-04-15 16:30:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ResizeDialog::reject()
|
|
|
|
{
|
2015-07-13 15:17:41 +01:00
|
|
|
rollback();
|
|
|
|
QDialog::reject();
|
2010-04-15 16:30:08 +01:00
|
|
|
}
|
|
|
|
|
2008-10-06 09:01:28 +01:00
|
|
|
void ResizeDialog::setupDialog()
|
|
|
|
{
|
2015-07-13 15:17:41 +01:00
|
|
|
SizeDialogBase::setupDialog();
|
2018-04-09 02:58:03 +01:00
|
|
|
if (device().type() == Device::Type::LVM_Device) {
|
2016-06-26 18:08:15 +01:00
|
|
|
dialogWidget().hideBeforeAndAfter();
|
|
|
|
detailsWidget().checkAlign().setChecked(false);
|
|
|
|
detailsWidget().checkAlign().setEnabled(false);
|
|
|
|
detailsButton->hide();
|
|
|
|
}
|
2015-07-13 15:17:41 +01:00
|
|
|
okButton->setEnabled(false);
|
2008-10-06 09:01:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ResizeDialog::setDirty()
|
|
|
|
{
|
2015-07-13 15:17:41 +01:00
|
|
|
okButton->setEnabled(isModified());
|
2008-10-06 09:01:28 +01:00
|
|
|
}
|
|
|
|
|
2008-09-24 20:32:01 +01:00
|
|
|
/** @return true if the user modified anything */
|
|
|
|
bool ResizeDialog::isModified() const
|
|
|
|
{
|
2015-07-13 15:17:41 +01:00
|
|
|
return partition().firstSector() != originalFirstSector() || partition().lastSector() != originalLastSector();
|
2008-09-24 20:32:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ResizeDialog::canGrow() const
|
|
|
|
{
|
2015-07-13 15:17:41 +01:00
|
|
|
return ResizeOperation::canGrow(&partition());
|
2008-09-24 20:32:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ResizeDialog::canShrink() const
|
|
|
|
{
|
2015-07-13 15:17:41 +01:00
|
|
|
return ResizeOperation::canShrink(&partition());
|
2008-09-24 20:32:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ResizeDialog::canMove() const
|
|
|
|
{
|
2018-04-09 02:58:03 +01:00
|
|
|
return (device().type() == Device::Type::LVM_Device) ? false : ResizeOperation::canMove(&partition());
|
2008-09-24 20:32:01 +01:00
|
|
|
}
|