2015-02-07 00:32:25 +00:00
|
|
|
/*************************************************************************
|
|
|
|
* Copyright (C) 2008, 2010 by Volker Lanz <vl@fidra.de> *
|
2016-03-02 18:33:40 +00:00
|
|
|
* Copyright (C) 2016 by Andrius Štikonas <andrius@stikonas.eu> *
|
2016-04-15 14:45:22 +01:00
|
|
|
* Copyright (C) 2016 by Teo Mrnjavac <teo@kde.org> *
|
2015-02-07 00:32:25 +00:00
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU General Public License as *
|
|
|
|
* published by the Free Software Foundation; either version 3 of *
|
|
|
|
* the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.*
|
|
|
|
*************************************************************************/
|
2008-09-24 20:32:01 +01:00
|
|
|
|
|
|
|
#include "gui/newdialog.h"
|
|
|
|
#include "gui/sizedialogwidget.h"
|
2010-04-15 11:46:36 +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>
|
2008-09-24 20:32:01 +01:00
|
|
|
|
2016-01-12 00:12:49 +00:00
|
|
|
#include <fs/filesystemfactory.h>
|
2016-04-15 14:38:11 +01:00
|
|
|
#include <fs/luks.h>
|
2008-09-24 20:32:01 +01:00
|
|
|
|
2016-01-12 00:12:49 +00:00
|
|
|
#include <util/capacity.h>
|
|
|
|
#include <util/helpers.h>
|
2015-06-12 13:11:29 +01:00
|
|
|
#include "util/guihelpers.h"
|
2008-09-24 20:32:01 +01:00
|
|
|
|
2014-05-18 21:41:48 +01:00
|
|
|
#include <QFontDatabase>
|
2008-09-24 20:32:01 +01:00
|
|
|
#include <QtAlgorithms>
|
|
|
|
|
2016-05-17 01:06:45 +01:00
|
|
|
#include <KColorScheme>
|
2014-05-17 03:06:58 +01:00
|
|
|
#include <KConfigGroup>
|
2014-05-13 23:53:37 +01:00
|
|
|
#include <KLocalizedString>
|
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 NewDialog
|
2015-07-13 15:17:41 +01:00
|
|
|
@param parent the parent widget
|
|
|
|
@param device the Device on which a new Partition is to be created
|
|
|
|
@param unallocatedPartition the unallocated space on the Device to create a Partition in
|
|
|
|
@param r the permitted Roles for the new Partition
|
2008-09-24 20:32:01 +01:00
|
|
|
*/
|
|
|
|
NewDialog::NewDialog(QWidget* parent, Device& device, Partition& unallocatedPartition, PartitionRole::Roles r) :
|
2015-07-13 15:17:41 +01:00
|
|
|
SizeDialogBase(parent, device, unallocatedPartition, unallocatedPartition.firstSector(), unallocatedPartition.lastSector()),
|
|
|
|
m_PartitionRoles(r)
|
2008-09-24 20:32:01 +01:00
|
|
|
{
|
2015-07-13 15:17:41 +01:00
|
|
|
setWindowTitle(i18nc("@title:window", "Create a new partition"));
|
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(), "newDialog");
|
|
|
|
restoreGeometry(kcg.readEntry<QByteArray>("Geometry", QByteArray()));
|
2008-09-24 20:32:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
NewDialog::~NewDialog()
|
|
|
|
{
|
2015-07-13 15:17:41 +01:00
|
|
|
KConfigGroup kcg(KSharedConfig::openConfig(), "newDialog");
|
|
|
|
kcg.writeEntry("Geometry", saveGeometry());
|
2008-09-24 20:32:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void NewDialog::setupDialog()
|
|
|
|
{
|
2015-07-13 15:17:41 +01:00
|
|
|
QStringList fsNames;
|
2016-04-15 14:38:11 +01:00
|
|
|
foreach (const FileSystem * fs, FileSystemFactory::map())
|
|
|
|
if (fs->supportCreate() != FileSystem::cmdSupportNone &&
|
2016-05-17 15:30:57 +01:00
|
|
|
fs->type() != FileSystem::Extended &&
|
|
|
|
fs->type() != FileSystem::Luks)
|
2016-04-15 14:38:11 +01:00
|
|
|
fsNames.append(fs->name());
|
2008-09-24 20:32:01 +01:00
|
|
|
|
2015-07-13 15:17:41 +01:00
|
|
|
qSort(fsNames.begin(), fsNames.end(), caseInsensitiveLessThan);
|
2010-02-17 19:39:24 +00:00
|
|
|
|
2016-04-15 14:38:11 +01:00
|
|
|
foreach (const QString & fsName, fsNames)
|
|
|
|
dialogWidget().comboFileSystem().addItem(createFileSystemColor(FileSystem::typeForName(fsName), 8), fsName);
|
2010-02-17 19:39:24 +00:00
|
|
|
|
2015-07-13 15:17:41 +01:00
|
|
|
QString selected = FileSystem::nameForType(GuiHelpers::defaultFileSystem());
|
|
|
|
const int idx = dialogWidget().comboFileSystem().findText(selected);
|
|
|
|
dialogWidget().comboFileSystem().setCurrentIndex(idx != -1 ? idx : 0);
|
2008-09-24 20:32:01 +01:00
|
|
|
|
2015-07-13 15:17:41 +01:00
|
|
|
dialogWidget().radioPrimary().setVisible(partitionRoles() & PartitionRole::Primary);
|
|
|
|
dialogWidget().radioExtended().setVisible(partitionRoles() & PartitionRole::Extended);
|
|
|
|
dialogWidget().radioLogical().setVisible(partitionRoles() & PartitionRole::Logical);
|
2008-12-27 13:37:44 +00:00
|
|
|
|
2015-07-13 15:17:41 +01:00
|
|
|
if (partitionRoles() & PartitionRole::Primary)
|
|
|
|
dialogWidget().radioPrimary().setChecked(true);
|
|
|
|
else
|
|
|
|
dialogWidget().radioLogical().setChecked(true);
|
2008-09-24 20:32:01 +01:00
|
|
|
|
2015-07-13 15:17:41 +01:00
|
|
|
SizeDialogBase::setupDialog();
|
2008-09-24 20:32:01 +01:00
|
|
|
|
2016-04-21 17:43:44 +01:00
|
|
|
dialogWidget().checkBoxEncrypt().hide();
|
|
|
|
dialogWidget().editPassphrase().hide();
|
|
|
|
|
2016-05-17 01:06:45 +01:00
|
|
|
dialogWidget().editPassphrase().setMinimumPasswordLength(1);
|
|
|
|
dialogWidget().editPassphrase().setMaximumPasswordLength(512); // cryptsetup does not support longer passwords
|
|
|
|
|
|
|
|
// set a background warning color (taken from the current color scheme)
|
|
|
|
KColorScheme colorScheme(QPalette::Active, KColorScheme::View);
|
|
|
|
dialogWidget().editPassphrase().setBackgroundWarningColor(colorScheme.background(KColorScheme::NegativeBackground).color());
|
|
|
|
|
|
|
|
// listen to password status updates
|
|
|
|
connect(&dialogWidget().editPassphrase(), &KNewPasswordWidget::passwordStatusChanged, this, &NewDialog::slotPasswordStatusChanged);
|
|
|
|
|
2015-07-13 15:17:41 +01:00
|
|
|
// don't move these above the call to parent's setupDialog, because only after that has
|
|
|
|
// run there is a valid partition set in the part resizer widget and they will need that.
|
|
|
|
onRoleChanged(false);
|
|
|
|
onFilesystemChanged(dialogWidget().comboFileSystem().currentIndex());
|
2008-09-24 20:32:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void NewDialog::setupConnections()
|
|
|
|
{
|
2016-05-22 20:03:49 +01:00
|
|
|
connect(&dialogWidget().radioPrimary(), &QRadioButton::toggled, this, &NewDialog::onRoleChanged);
|
|
|
|
connect(&dialogWidget().radioExtended(), &QRadioButton::toggled, this, &NewDialog::onRoleChanged);
|
|
|
|
connect(&dialogWidget().radioLogical(), &QRadioButton::toggled, this, &NewDialog::onRoleChanged);
|
|
|
|
connect(&dialogWidget().checkBoxEncrypt(), &QCheckBox::toggled, this, &NewDialog::onRoleChanged);
|
|
|
|
connect(&dialogWidget().comboFileSystem(), static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &NewDialog::onFilesystemChanged);
|
|
|
|
connect(&dialogWidget().label(), &QLineEdit::textChanged, this, &NewDialog::onLabelChanged);
|
2008-09-24 20:32:01 +01:00
|
|
|
|
2015-07-13 15:17:41 +01:00
|
|
|
SizeDialogBase::setupConnections();
|
2008-09-24 20:32:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void NewDialog::accept()
|
|
|
|
{
|
2015-07-13 15:17:41 +01:00
|
|
|
if (partition().roles().has(PartitionRole::Extended)) {
|
|
|
|
partition().deleteFileSystem();
|
2016-04-15 14:38:11 +01:00
|
|
|
partition().setFileSystem(FileSystemFactory::create(FileSystem::Extended,
|
|
|
|
partition().firstSector(),
|
|
|
|
partition().lastSector()));
|
|
|
|
}
|
2016-04-19 15:53:56 +01:00
|
|
|
else if (partition().roles().has(PartitionRole::Luks)) {
|
2016-04-15 14:38:11 +01:00
|
|
|
FileSystem::Type innerFsType = partition().fileSystem().type();
|
|
|
|
partition().deleteFileSystem();
|
|
|
|
FS::luks* luksFs = dynamic_cast< FS::luks* >(
|
|
|
|
FileSystemFactory::create(FileSystem::Luks,
|
|
|
|
partition().firstSector(),
|
|
|
|
partition().lastSector()));
|
|
|
|
luksFs->createInnerFileSystem(innerFsType);
|
2016-04-29 21:27:43 +01:00
|
|
|
luksFs->setPassphrase(dialogWidget().editPassphrase().password());
|
2016-04-15 14:38:11 +01:00
|
|
|
partition().setFileSystem(luksFs);
|
2016-04-24 17:48:24 +01:00
|
|
|
partition().fileSystem().setLabel(dialogWidget().label().text());
|
2015-07-13 15:17:41 +01:00
|
|
|
}
|
2008-09-24 20:32:01 +01:00
|
|
|
|
2015-07-13 15:17:41 +01:00
|
|
|
QDialog::accept();
|
2008-09-24 20:32:01 +01:00
|
|
|
}
|
|
|
|
|
2008-12-27 13:37:44 +00:00
|
|
|
void NewDialog::onRoleChanged(bool)
|
2008-09-24 20:32:01 +01:00
|
|
|
{
|
2015-07-13 15:17:41 +01:00
|
|
|
PartitionRole::Roles r = PartitionRole::None;
|
2008-09-24 20:32:01 +01:00
|
|
|
|
2015-07-13 15:17:41 +01:00
|
|
|
if (dialogWidget().radioPrimary().isChecked())
|
|
|
|
r = PartitionRole::Primary;
|
|
|
|
else if (dialogWidget().radioExtended().isChecked())
|
|
|
|
r = PartitionRole::Extended;
|
|
|
|
else if (dialogWidget().radioLogical().isChecked())
|
|
|
|
r = PartitionRole::Logical;
|
2008-09-24 20:32:01 +01:00
|
|
|
|
2016-04-21 16:57:25 +01:00
|
|
|
bool doEncrypt = dialogWidget().checkBoxEncrypt().isVisible() &&
|
|
|
|
dialogWidget().checkBoxEncrypt().isChecked();
|
|
|
|
if (doEncrypt)
|
2016-04-19 15:53:56 +01:00
|
|
|
r |= PartitionRole::Luks;
|
2016-04-15 14:38:11 +01:00
|
|
|
|
2016-04-21 16:57:25 +01:00
|
|
|
dialogWidget().editPassphrase().setVisible(doEncrypt);
|
|
|
|
|
2015-07-13 15:17:41 +01:00
|
|
|
// Make sure an extended partition gets correctly displayed: Set its file system to extended.
|
|
|
|
// Also make sure to set a primary's or logical's file system once the user goes back from
|
|
|
|
// extended to any of those.
|
|
|
|
if (r == PartitionRole::Extended)
|
|
|
|
updateFileSystem(FileSystem::Extended);
|
|
|
|
else
|
|
|
|
updateFileSystem(FileSystem::typeForName(dialogWidget().comboFileSystem().currentText()));
|
2010-03-11 23:33:41 +00:00
|
|
|
|
2015-07-13 15:17:41 +01:00
|
|
|
dialogWidget().comboFileSystem().setEnabled(r != PartitionRole::Extended);
|
|
|
|
partition().setRoles(PartitionRole(r));
|
2010-03-16 11:40:54 +00:00
|
|
|
|
2015-07-13 15:17:41 +01:00
|
|
|
setupConstraints();
|
2010-03-16 11:40:54 +00:00
|
|
|
|
2015-07-13 15:17:41 +01:00
|
|
|
dialogWidget().partResizerWidget().resizeLogicals(0, 0, true);
|
|
|
|
dialogWidget().partResizerWidget().update();
|
2010-04-15 17:59:56 +01:00
|
|
|
|
2015-07-13 15:17:41 +01:00
|
|
|
updateHideAndShow();
|
2008-09-24 20:32:01 +01:00
|
|
|
}
|
|
|
|
|
2010-03-11 23:33:41 +00:00
|
|
|
void NewDialog::updateFileSystem(FileSystem::Type t)
|
2008-09-24 20:32:01 +01:00
|
|
|
{
|
2015-07-13 15:17:41 +01:00
|
|
|
partition().deleteFileSystem();
|
|
|
|
partition().setFileSystem(FileSystemFactory::create(t, partition().firstSector(), partition().lastSector()));
|
2010-03-11 23:33:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NewDialog::onFilesystemChanged(int idx)
|
|
|
|
{
|
2015-07-13 15:17:41 +01:00
|
|
|
updateFileSystem(FileSystem::typeForName(dialogWidget().comboFileSystem().itemText(idx)));
|
2008-09-24 20:32:01 +01:00
|
|
|
|
2015-07-13 15:17:41 +01:00
|
|
|
setupConstraints();
|
2008-09-24 20:32:01 +01:00
|
|
|
|
2015-07-13 15:17:41 +01:00
|
|
|
const FileSystem* fs = FileSystemFactory::create(FileSystem::typeForName(dialogWidget().comboFileSystem().currentText()), -1, -1, -1, QString());
|
|
|
|
dialogWidget().m_EditLabel->setMaxLength(fs->maxLabelLength());
|
2013-01-03 12:43:03 +00:00
|
|
|
|
2015-07-13 15:17:41 +01:00
|
|
|
updateSpinCapacity(partition().length());
|
|
|
|
dialogWidget().partResizerWidget().update();
|
2009-03-25 12:58:32 +00:00
|
|
|
|
2015-07-13 15:17:41 +01:00
|
|
|
updateHideAndShow();
|
2009-03-25 12:58:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NewDialog::onLabelChanged(const QString& newLabel)
|
|
|
|
{
|
2015-07-13 15:17:41 +01:00
|
|
|
partition().fileSystem().setLabel(newLabel);
|
2009-03-25 12:58:32 +00:00
|
|
|
}
|
|
|
|
|
2016-05-17 01:06:45 +01:00
|
|
|
void NewDialog::slotPasswordStatusChanged()
|
|
|
|
{
|
|
|
|
// You may want to extend this switch with more cases,
|
|
|
|
// in order to warn the user about all the possible password issues.
|
|
|
|
switch (dialogWidget().editPassphrase().passwordStatus()) {
|
|
|
|
case KNewPasswordWidget::WeakPassword:
|
|
|
|
case KNewPasswordWidget::StrongPassword:
|
|
|
|
okButton->setEnabled(true);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
okButton->setEnabled(false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-25 12:58:32 +00:00
|
|
|
void NewDialog::updateHideAndShow()
|
|
|
|
{
|
2015-07-13 15:17:41 +01:00
|
|
|
// this is mostly copy'n'pasted from PartPropsDialog::updateHideAndShow()
|
|
|
|
if (partition().roles().has(PartitionRole::Extended) || partition().fileSystem().supportSetLabel() == FileSystem::cmdSupportNone) {
|
|
|
|
dialogWidget().label().setReadOnly(true);
|
|
|
|
dialogWidget().noSetLabel().setVisible(true);
|
|
|
|
dialogWidget().noSetLabel().setFont(QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont));
|
|
|
|
|
|
|
|
QPalette palette = dialogWidget().noSetLabel().palette();
|
|
|
|
QColor f = palette.color(QPalette::Foreground);
|
|
|
|
f.setAlpha(128);
|
|
|
|
palette.setColor(QPalette::Foreground, f);
|
|
|
|
dialogWidget().noSetLabel().setPalette(palette);
|
2016-04-15 14:38:11 +01:00
|
|
|
dialogWidget().checkBoxEncrypt().hide();
|
2016-04-21 16:57:25 +01:00
|
|
|
dialogWidget().editPassphrase().hide();
|
2015-07-13 15:17:41 +01:00
|
|
|
} else {
|
|
|
|
dialogWidget().label().setReadOnly(false);
|
|
|
|
dialogWidget().noSetLabel().setVisible(false);
|
|
|
|
}
|
2016-04-26 14:39:15 +01:00
|
|
|
if (FS::luks::canEncryptType(FileSystem::typeForName(dialogWidget().comboFileSystem().currentText())) && !partition().roles().has(PartitionRole::Extended) )
|
2016-04-21 18:30:18 +01:00
|
|
|
{
|
2016-04-16 00:28:14 +01:00
|
|
|
dialogWidget().checkBoxEncrypt().show();
|
2016-04-21 18:25:53 +01:00
|
|
|
if (dialogWidget().checkBoxEncrypt().isChecked())
|
|
|
|
{
|
|
|
|
dialogWidget().editPassphrase().show();
|
2016-05-17 01:06:45 +01:00
|
|
|
slotPasswordStatusChanged();
|
2016-04-21 18:25:53 +01:00
|
|
|
}
|
2016-04-21 18:30:18 +01:00
|
|
|
}
|
2016-04-16 00:28:14 +01:00
|
|
|
else
|
2016-04-21 18:21:34 +01:00
|
|
|
{
|
2016-04-16 00:28:14 +01:00
|
|
|
dialogWidget().checkBoxEncrypt().hide();
|
2016-04-21 18:21:34 +01:00
|
|
|
dialogWidget().editPassphrase().hide();
|
|
|
|
}
|
2016-04-16 00:28:14 +01:00
|
|
|
|
2008-09-24 20:32:01 +01:00
|
|
|
}
|