From 1edb9475259a09291912f05694a63fff356ada5a Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Sun, 12 Dec 2021 20:13:52 +0000 Subject: [PATCH] Change the way the button is created / fix crash --- src/gui/newdialog.cpp | 24 ++- src/gui/partitionmanagerwidget.cpp | 2 +- src/gui/sizedialogwidget.h | 18 ++ src/gui/sizedialogwidgetbase.ui | 332 ++++++++++++++++------------- 4 files changed, 217 insertions(+), 159 deletions(-) diff --git a/src/gui/newdialog.cpp b/src/gui/newdialog.cpp index 203d35d..cd0711f 100644 --- a/src/gui/newdialog.cpp +++ b/src/gui/newdialog.cpp @@ -55,14 +55,6 @@ NewDialog::NewDialog(QWidget* parent, Device& device, Partition& unallocatedPart KConfigGroup kcg(KSharedConfig::openConfig(), "newDialog"); restoreGeometry(kcg.readEntry("Geometry", QByteArray())); - - // Hack on top of hack. The dialog is created via two inheritances. - auto *allowEveryone = new QCheckBox(i18n("Allow everyone to use this partition")); - allowEveryone->setToolTip(i18n("If you are creating a partition on a usb stick, leave this on")); - - QBoxLayout *l = qobject_cast(layout()); - int lCount = l->count(); - l->insertWidget(lCount-1, allowEveryone); } NewDialog::~NewDialog() @@ -122,6 +114,20 @@ void NewDialog::setupDialog() // run there is a valid partition set in the part resizer widget and they will need that. onRoleChanged(false); onFilesystemChanged(dialogWidget().comboFileSystem().currentIndex()); + + connect(&dialogWidget().comboFileSystem(), QOverload::of(&QComboBox::currentIndexChanged), this, [this]{ + const QString currText = dialogWidget().comboFileSystem().currentText(); + const bool enablePosixPermission = QList({ + QStringLiteral("ext2"), + QStringLiteral("ext3"), + QStringLiteral("ext4")} + ).contains(currText); + if (enablePosixPermission) { + dialogWidget().showPosixPermissions(); + } else { + dialogWidget().hidePosixPermissions(); + } + }); } void NewDialog::setupConnections() @@ -296,5 +302,5 @@ void NewDialog::updateOkButtonStatus() bool NewDialog::useUnsecuredPartition() const { - return m_unsecuredPartition->checkState() == Qt::CheckState::Checked; + return !dialogWidget().isPermissionOnlyRoot(); } diff --git a/src/gui/partitionmanagerwidget.cpp b/src/gui/partitionmanagerwidget.cpp index acd0782..b085eec 100644 --- a/src/gui/partitionmanagerwidget.cpp +++ b/src/gui/partitionmanagerwidget.cpp @@ -506,7 +506,7 @@ void PartitionManagerWidget::onNewPartition() QPointer dlg = new NewDialog(this, *selectedDevice(), *newPartition, selectedDevice()->partitionTable()->childRoles(*selectedPartition())); if (dlg->exec() == QDialog::Accepted) { if (dlg->useUnsecuredPartition()) { - newPartition->setPermissions(QStringLiteral("777")); + newPartition->fileSystem().setPosixPermissions(QStringLiteral("777")); } operationStack().push(new NewOperation(*selectedDevice(), newPartition)); } else { diff --git a/src/gui/sizedialogwidget.h b/src/gui/sizedialogwidget.h index 007108d..21fdd01 100644 --- a/src/gui/sizedialogwidget.h +++ b/src/gui/sizedialogwidget.h @@ -22,6 +22,7 @@ class SizeDialogWidget : public QWidget, public Ui::SizeDialogWidgetBase public: SizeDialogWidget(QWidget* parent) : QWidget(parent), Ui::SizeDialogWidgetBase() { setupUi(this); + hidePosixPermissions(); } public: @@ -141,6 +142,23 @@ public: delete m_LabelTextNoSetLabel; m_LabelTextNoSetLabel = nullptr; } + + void hidePosixPermissions() { + m_permissionEveryone->hide(); + m_permissionOnlyRoot->hide(); + m_labelPermission->hide(); + } + + void showPosixPermissions() { + m_permissionEveryone->show(); + m_permissionOnlyRoot->show(); + m_labelPermission->show(); + } + + bool isPermissionOnlyRoot() const { + return m_permissionOnlyRoot->isVisible() && m_permissionOnlyRoot->isChecked(); + } + void hideBeforeAndAfter() { labelFreeBefore().hide(); spinFreeBefore().hide(); diff --git a/src/gui/sizedialogwidgetbase.ui b/src/gui/sizedialogwidgetbase.ui index 60bedcf..ab88a08 100644 --- a/src/gui/sizedialogwidgetbase.ui +++ b/src/gui/sizedialogwidgetbase.ui @@ -18,22 +18,19 @@ SPDX-License-Identifier: GPL-3.0-or-later - - - - - 3 - 0 - + + + + + 400 + 60 + - - F&ree space before: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - m_SpinFreeBefore + + + 16777215 + 60 + @@ -53,18 +50,8 @@ SPDX-License-Identifier: GPL-3.0-or-later - - - - 0.000000000000000 - - - 999999999.000000000000000 - - - - - + + 0 @@ -72,46 +59,13 @@ SPDX-License-Identifier: GPL-3.0-or-later - File system: + Partition &type: Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - m_ComboFileSystem - - - - - - - Set up encryption for this filesystem with LUKS. You will be asked to provide a passphrase. - - - Encrypt with LUKS - - - - - - - - 0 - 0 - - - - Maximum size: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + m_RadioPrimary @@ -140,7 +94,76 @@ SPDX-License-Identifier: GPL-3.0-or-later - + + + + + 0 + 0 + + + + File system: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + m_ComboFileSystem + + + + + + + + + + + + + + Set up encryption for this filesystem with LUKS. You will be asked to provide a passphrase. + + + Encrypt with LUKS + + + + + + + + + + Logical Volume Name: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + true + + + + + + + Label: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + m_EditLabel + + + + @@ -157,62 +180,7 @@ SPDX-License-Identifier: GPL-3.0-or-later - - - - - 400 - 60 - - - - - 16777215 - 60 - - - - - - - - - - - - - - - - 0 - 0 - - - - Partition &type: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - m_RadioPrimary - - - - - - Label: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - m_EditLabel - - - - @@ -228,7 +196,56 @@ SPDX-License-Identifier: GPL-3.0-or-later - + + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + + + 0 + 0 + + + + Maximum size: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + + + 3 + 0 + + + + F&ree space before: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + m_SpinFreeBefore + + + + @@ -244,7 +261,7 @@ SPDX-License-Identifier: GPL-3.0-or-later - + @@ -263,7 +280,17 @@ SPDX-License-Identifier: GPL-3.0-or-later - + + + + 0.000000000000000 + + + 999999999.000000000000000 + + + + @@ -282,7 +309,7 @@ SPDX-License-Identifier: GPL-3.0-or-later - + 0.000000000000000 @@ -292,6 +319,40 @@ SPDX-License-Identifier: GPL-3.0-or-later + + + + Permissions + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + Allow everyone to write and read on this device + + + Everyone + + + + + + + Allow only root to write and read on this device, you will need to setup per-folder permissions + + + Only Root + + + + + @@ -308,33 +369,6 @@ SPDX-License-Identifier: GPL-3.0-or-later - - - - - - - Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - - - - - - - Logical Volume Name: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - true - - -