Add a button to allow the user to select if the partition is open for

everyone
This commit is contained in:
Tomaz Canabrava 2021-12-09 14:10:21 +01:00 committed by Andrius Štikonas
parent 4f17fc5548
commit 6b27467943
3 changed files with 23 additions and 2 deletions

View File

@ -27,6 +27,7 @@
#include <QtGlobal> #include <QtGlobal>
#include <QFontDatabase> #include <QFontDatabase>
#include <QPalette> #include <QPalette>
#include <QCheckBox>
#include <KColorScheme> #include <KColorScheme>
#include <KConfigGroup> #include <KConfigGroup>
@ -54,6 +55,12 @@ NewDialog::NewDialog(QWidget* parent, Device& device, Partition& unallocatedPart
KConfigGroup kcg(KSharedConfig::openConfig(), "newDialog"); KConfigGroup kcg(KSharedConfig::openConfig(), "newDialog");
restoreGeometry(kcg.readEntry<QByteArray>("Geometry", QByteArray())); restoreGeometry(kcg.readEntry<QByteArray>("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"));
QBoxLayout *l = qobject_cast<QBoxLayout*>(layout());
int lCount = l->count();
l->insertWidget(lCount-1, allowEveryone);
} }
NewDialog::~NewDialog() NewDialog::~NewDialog()
@ -284,3 +291,8 @@ void NewDialog::updateOkButtonStatus()
{ {
okButton->setEnabled(isValidPassword() && isValidLVName()); okButton->setEnabled(isValidPassword() && isValidLVName());
} }
bool NewDialog::useUnsecuredPartition() const
{
return m_unsecuredPartition->checkState() == Qt::CheckState::Checked;
}

View File

@ -17,6 +17,7 @@
#include <fs/filesystem.h> #include <fs/filesystem.h>
class Device; class Device;
class QCheckBox;
/** Dialog to create new Partitions. /** Dialog to create new Partitions.
@ -30,6 +31,9 @@ public:
NewDialog(QWidget* parent, Device& device, Partition& unallocatedPartition, PartitionRole::Roles r); NewDialog(QWidget* parent, Device& device, Partition& unallocatedPartition, PartitionRole::Roles r);
~NewDialog(); ~NewDialog();
// returns true if any user can write on the partition.
// has the same effect as running `chmod 777` on it.
bool useUnsecuredPartition() const;
protected: protected:
void accept() override; void accept() override;
void onRoleChanged(bool); void onRoleChanged(bool);
@ -60,6 +64,7 @@ protected:
private: private:
PartitionRole::Roles m_PartitionRoles; PartitionRole::Roles m_PartitionRoles;
bool m_IsValidPassword; bool m_IsValidPassword;
QCheckBox *m_unsecuredPartition;
}; };
#endif #endif

View File

@ -504,10 +504,14 @@ void PartitionManagerWidget::onNewPartition()
Partition* newPartition = NewOperation::createNew(*selectedPartition(), static_cast<FileSystem::Type>(Config::defaultFileSystem())); Partition* newPartition = NewOperation::createNew(*selectedPartition(), static_cast<FileSystem::Type>(Config::defaultFileSystem()));
QPointer<NewDialog> dlg = new NewDialog(this, *selectedDevice(), *newPartition, selectedDevice()->partitionTable()->childRoles(*selectedPartition())); QPointer<NewDialog> dlg = new NewDialog(this, *selectedDevice(), *newPartition, selectedDevice()->partitionTable()->childRoles(*selectedPartition()));
if (dlg->exec() == QDialog::Accepted) if (dlg->exec() == QDialog::Accepted) {
operationStack().push(new NewOperation(*selectedDevice(), newPartition)); operationStack().push(new NewOperation(*selectedDevice(), newPartition));
else if (dlg->useUnsecuredPartition()) {
// operationStac().push(new ChangePermissionOperation("777", *selectedDevice(), newPartition);
}
} else {
delete newPartition; delete newPartition;
}
delete dlg; delete dlg;
} }