Hook up new LUKS functionality from KPMcore.

Add decrypt action to actionCollection and context menu.
Wrap very long lines.
Replace NULL with nullptr, TODO: do this everywhere.
This commit is contained in:
Teo Mrnjavac 2015-08-14 17:57:27 +02:00
parent 6e1ff468d3
commit 65ffb182c5
4 changed files with 167 additions and 81 deletions

View File

@ -1,5 +1,6 @@
/************************************************************************* /*************************************************************************
* Copyright (C) 2008, 2009, 2010, 2012 by Volker Lanz <vl@fidra.de> * * Copyright (C) 2008, 2009, 2010, 2012 by Volker Lanz <vl@fidra.de> *
* Copyright (C) 2015 by Teo Mrnjavac <teo@kde.org> *
* * * *
* This program is free software; you can redistribute it and/or * * This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as * * modify it under the terms of the GNU General Public License as *
@ -46,6 +47,7 @@
#include <kpmcore/fs/filesystem.h> #include <kpmcore/fs/filesystem.h>
#include <kpmcore/fs/filesystemfactory.h> #include <kpmcore/fs/filesystemfactory.h>
#include <kpmcore/fs/luks.h>
#include <kpmcore/util/helpers.h> #include <kpmcore/util/helpers.h>
#include "util/guihelpers.h" #include "util/guihelpers.h"
@ -154,14 +156,14 @@ void MainWindow::closeEvent(QCloseEvent* event)
void MainWindow::changeEvent(QEvent* event) void MainWindow::changeEvent(QEvent* event)
{ {
if ((event->type() == QEvent::ActivationChange || event->type() == QEvent::WindowStateChange) && event->spontaneous() && isActiveWindow()) { if ((event->type() == QEvent::ActivationChange || event->type() == QEvent::WindowStateChange) && event->spontaneous() && isActiveWindow()) {
QWidget* w = NULL; QWidget* w = nullptr;
if (applyProgressDialog().isVisible()) if (applyProgressDialog().isVisible())
w = &applyProgressDialog(); w = &applyProgressDialog();
else if (scanProgressDialog().isVisible()) else if (scanProgressDialog().isVisible())
w = &scanProgressDialog(); w = &scanProgressDialog();
if (w != NULL) { if (w != nullptr) {
w->activateWindow(); w->activateWindow();
w->raise(); w->raise();
w->setFocus(); w->setFocus();
@ -303,6 +305,12 @@ void MainWindow::setupActions()
mountPartition->setToolTip(i18nc("@info:tooltip", "Mount or unmount partition")); mountPartition->setToolTip(i18nc("@info:tooltip", "Mount or unmount partition"));
mountPartition->setStatusTip(i18nc("@info:status", "Mount or unmount a partition.")); mountPartition->setStatusTip(i18nc("@info:status", "Mount or unmount a partition."));
QAction* decryptPartition = actionCollection()->addAction(QStringLiteral("decryptPartition"), &pmWidget(), SLOT(onDecryptPartition()));
decryptPartition->setEnabled(false);
decryptPartition->setText(i18nc("@action:inmenu", "Unlock"));
decryptPartition->setToolTip(i18nc("@info:tooltip", "Unlock or lock encrypted partition"));
decryptPartition->setStatusTip(i18nc("@info:status", "Unlock or lock encrypted partition."));
QAction* checkPartition = actionCollection()->addAction(QStringLiteral("checkPartition"), &pmWidget(), SLOT(onCheckPartition())); QAction* checkPartition = actionCollection()->addAction(QStringLiteral("checkPartition"), &pmWidget(), SLOT(onCheckPartition()));
checkPartition->setEnabled(false); checkPartition->setEnabled(false);
checkPartition->setText(i18nc("@action:inmenu", "Check")); checkPartition->setText(i18nc("@action:inmenu", "Check"));
@ -387,41 +395,87 @@ void MainWindow::saveConfig() const
void MainWindow::enableActions() void MainWindow::enableActions()
{ {
actionCollection()->action(QStringLiteral("createNewPartitionTable"))->setEnabled(CreatePartitionTableOperation::canCreate(pmWidget().selectedDevice())); actionCollection()->action(QStringLiteral("createNewPartitionTable"))
actionCollection()->action(QStringLiteral("exportPartitionTable"))->setEnabled(pmWidget().selectedDevice() && pmWidget().selectedDevice()->partitionTable() && operationStack().size() == 0); ->setEnabled(CreatePartitionTableOperation::canCreate(pmWidget().selectedDevice()));
actionCollection()->action(QStringLiteral("importPartitionTable"))->setEnabled(CreatePartitionTableOperation::canCreate(pmWidget().selectedDevice())); actionCollection()->action(QStringLiteral("exportPartitionTable"))
actionCollection()->action(QStringLiteral("smartStatusDevice"))->setEnabled(pmWidget().selectedDevice() != NULL && pmWidget().selectedDevice()->smartStatus().isValid()); ->setEnabled(pmWidget().selectedDevice() &&
actionCollection()->action(QStringLiteral("propertiesDevice"))->setEnabled(pmWidget().selectedDevice() != NULL); pmWidget().selectedDevice()->partitionTable() &&
operationStack().size() == 0);
actionCollection()->action(QStringLiteral("importPartitionTable"))
->setEnabled(CreatePartitionTableOperation::canCreate(pmWidget().selectedDevice()));
actionCollection()->action(QStringLiteral("smartStatusDevice"))
->setEnabled(pmWidget().selectedDevice() != nullptr &&
pmWidget().selectedDevice()->smartStatus().isValid());
actionCollection()->action(QStringLiteral("propertiesDevice"))
->setEnabled(pmWidget().selectedDevice() != nullptr);
actionCollection()->action(QStringLiteral("undoOperation"))->setEnabled(operationStack().size() > 0); actionCollection()->action(QStringLiteral("undoOperation"))
actionCollection()->action(QStringLiteral("clearAllOperations"))->setEnabled(operationStack().size() > 0); ->setEnabled(operationStack().size() > 0);
actionCollection()->action(QStringLiteral("applyAllOperations"))->setEnabled(operationStack().size() > 0 && (geteuid() == 0 || Config::allowApplyOperationsAsNonRoot())); actionCollection()->action(QStringLiteral("clearAllOperations"))
->setEnabled(operationStack().size() > 0);
actionCollection()->action(QStringLiteral("applyAllOperations"))
->setEnabled(operationStack().size() > 0 && (geteuid() == 0 ||
Config::allowApplyOperationsAsNonRoot()));
const bool readOnly = pmWidget().selectedDevice() == NULL || const bool readOnly = pmWidget().selectedDevice() == nullptr ||
pmWidget().selectedDevice()->partitionTable() == NULL || pmWidget().selectedDevice()->partitionTable() == nullptr ||
pmWidget().selectedDevice()->partitionTable()->isReadOnly(); pmWidget().selectedDevice()->partitionTable()->isReadOnly();
const Partition* part = pmWidget().selectedPartition(); const Partition* part = pmWidget().selectedPartition();
actionCollection()->action(QStringLiteral("newPartition"))->setEnabled(!readOnly && NewOperation::canCreateNew(part)); actionCollection()->action(QStringLiteral("newPartition"))
const bool canResize = ResizeOperation::canGrow(part) || ResizeOperation::canShrink(part) || ResizeOperation::canMove(part); ->setEnabled(!readOnly && NewOperation::canCreateNew(part));
actionCollection()->action(QStringLiteral("resizePartition"))->setEnabled(!readOnly && canResize);
actionCollection()->action(QStringLiteral("copyPartition"))->setEnabled(CopyOperation::canCopy(part));
actionCollection()->action(QStringLiteral("deletePartition"))->setEnabled(!readOnly && DeleteOperation::canDelete(part));
actionCollection()->action(QStringLiteral("shredPartition"))->setEnabled(!readOnly && DeleteOperation::canDelete(part));
actionCollection()->action(QStringLiteral("pastePartition"))->setEnabled(!readOnly && CopyOperation::canPaste(part, pmWidget().clipboardPartition()));
actionCollection()->action(QStringLiteral("propertiesPartition"))->setEnabled(part != NULL);
actionCollection()->action(QStringLiteral("editMountPoint"))->setEnabled(part && !part->isMounted()); const bool canResize = ResizeOperation::canGrow(part) ||
actionCollection()->action(QStringLiteral("mountPartition"))->setEnabled(part && (part->canMount() || part->canUnmount())); ResizeOperation::canShrink(part) ||
ResizeOperation::canMove(part);
actionCollection()->action(QStringLiteral("resizePartition"))
->setEnabled(!readOnly && canResize);
if (part != NULL) actionCollection()->action(QStringLiteral("copyPartition"))
actionCollection()->action(QStringLiteral("mountPartition"))->setText(part->isMounted() ? part->fileSystem().unmountTitle() : part->fileSystem().mountTitle()); ->setEnabled(CopyOperation::canCopy(part));
actionCollection()->action(QStringLiteral("deletePartition"))
->setEnabled(!readOnly && DeleteOperation::canDelete(part));
actionCollection()->action(QStringLiteral("shredPartition"))
->setEnabled(!readOnly && DeleteOperation::canDelete(part));
actionCollection()->action(QStringLiteral("pastePartition"))
->setEnabled(!readOnly && CopyOperation::canPaste(part, pmWidget().clipboardPartition()));
actionCollection()->action(QStringLiteral("propertiesPartition"))
->setEnabled(part != nullptr);
actionCollection()->action(QStringLiteral("checkPartition"))->setEnabled(!readOnly && CheckOperation::canCheck(part)); actionCollection()->action(QStringLiteral("editMountPoint"))
->setEnabled(part && !part->isMounted());
actionCollection()->action(QStringLiteral("backupPartition"))->setEnabled(BackupOperation::canBackup(part)); actionCollection()->action(QStringLiteral("mountPartition"))
actionCollection()->action(QStringLiteral("restorePartition"))->setEnabled(RestoreOperation::canRestore(part)); ->setEnabled(part &&
(part->canMount() || part->canUnmount()));
if (part != nullptr)
actionCollection()->action(QStringLiteral("mountPartition"))
->setText(part->isMounted() ?
part->fileSystem().unmountTitle() :
part->fileSystem().mountTitle());
actionCollection()->action(QStringLiteral("decryptPartition"))
->setEnabled(part &&
(part->fileSystem().type() == FileSystem::Luks) &&
(dynamic_cast<const FS::luks&>(part->fileSystem()).canCryptOpen(part->partitionPath()) ||
dynamic_cast<const FS::luks&>(part->fileSystem()).canCryptClose(part->partitionPath())));
if (part && part->fileSystem().type() == FileSystem::Luks)
{
const FS::luks& luksFs = dynamic_cast<const FS::luks&>(part->fileSystem());
actionCollection()->action(QStringLiteral("decryptPartition"))
->setText(luksFs.isCryptOpen() ?
luksFs.cryptCloseTitle() :
luksFs.cryptOpenTitle());
}
actionCollection()->action(QStringLiteral("checkPartition"))
->setEnabled(!readOnly && CheckOperation::canCheck(part));
actionCollection()->action(QStringLiteral("backupPartition"))
->setEnabled(BackupOperation::canBackup(part));
actionCollection()->action(QStringLiteral("restorePartition"))
->setEnabled(RestoreOperation::canRestore(part));
} }
void MainWindow::on_m_ApplyProgressDialog_finished() void MainWindow::on_m_ApplyProgressDialog_finished()
@ -496,10 +550,10 @@ void MainWindow::on_m_ListDevices_contextMenuRequested(const QPoint& pos)
void MainWindow::on_m_PartitionManagerWidget_contextMenuRequested(const QPoint& pos) void MainWindow::on_m_PartitionManagerWidget_contextMenuRequested(const QPoint& pos)
{ {
QMenu* menu = NULL; QMenu* menu = nullptr;
if (pmWidget().selectedPartition() == NULL) { if (pmWidget().selectedPartition() == nullptr) {
if (pmWidget().selectedDevice() != NULL) if (pmWidget().selectedDevice() != nullptr)
menu = static_cast<QMenu*>(guiFactory()->container(QStringLiteral("device"), this)); menu = static_cast<QMenu*>(guiFactory()->container(QStringLiteral("device"), this));
} else } else
menu = static_cast<QMenu*>(guiFactory()->container(QStringLiteral("partition"), this)); menu = static_cast<QMenu*>(guiFactory()->container(QStringLiteral("partition"), this));
@ -603,7 +657,7 @@ void MainWindow::onSelectedDeviceMenuTriggered(bool)
QAction* action = qobject_cast<QAction*>(sender()); QAction* action = qobject_cast<QAction*>(sender());
QMenu* devicesMenu = static_cast<QMenu*>(guiFactory()->container(QStringLiteral("selectedDevice"), this)); QMenu* devicesMenu = static_cast<QMenu*>(guiFactory()->container(QStringLiteral("selectedDevice"), this));
if (action == NULL || action->parent() != devicesMenu) if (action == nullptr || action->parent() != devicesMenu)
return; return;
foreach(QAction * entry, devicesMenu->findChildren<QAction*>()) foreach(QAction * entry, devicesMenu->findChildren<QAction*>())
@ -678,8 +732,8 @@ void MainWindow::onUndoOperation()
// it's possible the undo killed the partition in the clipboard. if there's a partition in the clipboard, try // it's possible the undo killed the partition in the clipboard. if there's a partition in the clipboard, try
// to find a device for it (OperationStack::findDeviceForPartition() only compares pointers, so an invalid // to find a device for it (OperationStack::findDeviceForPartition() only compares pointers, so an invalid
// pointer is not a problem). if no device is found, the pointer must be dangling, so clear the clipboard. // pointer is not a problem). if no device is found, the pointer must be dangling, so clear the clipboard.
if (pmWidget().clipboardPartition() != NULL && operationStack().findDeviceForPartition(pmWidget().clipboardPartition()) == NULL) if (pmWidget().clipboardPartition() != nullptr && operationStack().findDeviceForPartition(pmWidget().clipboardPartition()) == nullptr)
pmWidget().setClipboardPartition(NULL); pmWidget().setClipboardPartition(nullptr);
pmWidget().updatePartitions(); pmWidget().updatePartitions();
enableActions(); enableActions();
@ -704,7 +758,7 @@ void MainWindow::onCreateNewPartitionTable()
{ {
Q_ASSERT(pmWidget().selectedDevice()); Q_ASSERT(pmWidget().selectedDevice());
if (pmWidget().selectedDevice() == NULL) { if (pmWidget().selectedDevice() == nullptr) {
qWarning() << "selected device is null."; qWarning() << "selected device is null.";
return; return;
} }
@ -751,7 +805,7 @@ void MainWindow::onImportPartitionTable()
QRegExp rxMagic(QStringLiteral("^##|v(\\d+)|##")); QRegExp rxMagic(QStringLiteral("^##|v(\\d+)|##"));
quint32 lineNo = 0; quint32 lineNo = 0;
bool haveMagic = false; bool haveMagic = false;
PartitionTable* ptable = NULL; PartitionTable* ptable = nullptr;
PartitionTable::TableType tableType = PartitionTable::unknownTableType; PartitionTable::TableType tableType = PartitionTable::unknownTableType;
while (!(line = file.readLine()).isEmpty()) { while (!(line = file.readLine()).isEmpty()) {
@ -771,7 +825,7 @@ void MainWindow::onImportPartitionTable()
continue; continue;
if (rxType.indexIn(QString::fromUtf8(line.constData())) != -1) { if (rxType.indexIn(QString::fromUtf8(line.constData())) != -1) {
if (ptable != NULL) { if (ptable != nullptr) {
KMessageBox::error(this, i18nc("@info", "Found more than one partition table type in import file (line %1).", lineNo), i18nc("@title:window", "Error While Importing Partition Table")); KMessageBox::error(this, i18nc("@info", "Found more than one partition table type in import file (line %1).", lineNo), i18nc("@title:window", "Error While Importing Partition Table"));
return; return;
} }
@ -793,7 +847,7 @@ void MainWindow::onImportPartitionTable()
} else if (rxAlign.indexIn(QString::fromUtf8(line.constData())) != -1) { } else if (rxAlign.indexIn(QString::fromUtf8(line.constData())) != -1) {
// currently ignored // currently ignored
} else if (rxPartition.indexIn(QString::fromUtf8(line.constData())) != -1) { } else if (rxPartition.indexIn(QString::fromUtf8(line.constData())) != -1) {
if (ptable == NULL) { if (ptable == nullptr) {
KMessageBox::error(this, i18nc("@info", "Found partition but no partition table type (line %1).", lineNo), i18nc("@title:window", "Error While Importing Partition Table")); KMessageBox::error(this, i18nc("@info", "Found partition but no partition table type (line %1).", lineNo), i18nc("@title:window", "Error While Importing Partition Table"));
return; return;
} }
@ -835,7 +889,7 @@ void MainWindow::onImportPartitionTable()
return; return;
} }
if (parent == NULL) { if (parent == nullptr) {
KMessageBox::error(this, i18nc("@info the partition is NOT a device path, just a number", "No parent partition or partition table found for partition %1 (line %2).", num, lineNo), i18nc("@title:window", "Error While Importing Partition Table")); KMessageBox::error(this, i18nc("@info the partition is NOT a device path, just a number", "No parent partition or partition table found for partition %1 (line %2).", num, lineNo), i18nc("@title:window", "Error While Importing Partition Table"));
return; return;
} }
@ -847,7 +901,7 @@ void MainWindow::onImportPartitionTable()
FileSystem* fs = FileSystemFactory::create(FileSystem::typeForName(fsName), firstSector, lastSector); FileSystem* fs = FileSystemFactory::create(FileSystem::typeForName(fsName), firstSector, lastSector);
if (fs == NULL) { if (fs == nullptr) {
KMessageBox::error(this, i18nc("@info the partition is NOT a device path, just a number", "Could not create file system \"%1\" for partition %2 (line %3).", fsName, num, lineNo), i18nc("@title:window", "Error While Importing Partition Table")); KMessageBox::error(this, i18nc("@info the partition is NOT a device path, just a number", "Could not create file system \"%1\" for partition %2 (line %3).", fsName, num, lineNo), i18nc("@title:window", "Error While Importing Partition Table"));
return; return;
} }
@ -977,7 +1031,7 @@ void MainWindow::onPropertiesDevice(const QString&)
static QStringList checkSupportInNode(const PartitionNode* parent) static QStringList checkSupportInNode(const PartitionNode* parent)
{ {
if (parent == NULL) if (parent == nullptr)
return QStringList(); return QStringList();
QStringList rval; QStringList rval;
@ -985,7 +1039,7 @@ static QStringList checkSupportInNode(const PartitionNode* parent)
foreach(const PartitionNode * node, parent->children()) { foreach(const PartitionNode * node, parent->children()) {
const Partition* p = dynamic_cast<const Partition*>(node); const Partition* p = dynamic_cast<const Partition*>(node);
if (p == NULL) if (p == nullptr)
continue; continue;
if (node->children().size() > 0) if (node->children().size() > 0)

View File

@ -62,6 +62,7 @@
<separator/> <separator/>
<Action name="editMountPoint"/> <Action name="editMountPoint"/>
<Action name="mountPartition"/> <Action name="mountPartition"/>
<Action name="decryptPartition"/>
<separator/> <separator/>
<Action name="checkPartition"/> <Action name="checkPartition"/>
<separator/> <separator/>

View File

@ -1,5 +1,6 @@
/************************************************************************* /*************************************************************************
* Copyright (C) 2008-2010 by Volker Lanz <vl@fidra.de> * * Copyright (C) 2008-2010 by Volker Lanz <vl@fidra.de> *
* Copyright (C) 2015 by Teo Mrnjavac <teo@kde.org> *
* * * *
* This program is free software; you can redistribute it and/or * * This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as * * modify it under the terms of the GNU General Public License as *
@ -29,6 +30,7 @@
#include <kpmcore/core/partitiontable.h> #include <kpmcore/core/partitiontable.h>
#include <kpmcore/fs/filesystemfactory.h> #include <kpmcore/fs/filesystemfactory.h>
#include <kpmcore/fs/luks.h>
#include <kpmcore/gui/partwidget.h> #include <kpmcore/gui/partwidget.h>
@ -81,9 +83,9 @@ private:
PartitionManagerWidget::PartitionManagerWidget(QWidget* parent) : PartitionManagerWidget::PartitionManagerWidget(QWidget* parent) :
QWidget(parent), QWidget(parent),
Ui::PartitionManagerWidgetBase(), Ui::PartitionManagerWidgetBase(),
m_OperationStack(NULL), m_OperationStack(nullptr),
m_SelectedDevice(NULL), m_SelectedDevice(nullptr),
m_ClipboardPartition(NULL) m_ClipboardPartition(nullptr)
{ {
setupUi(this); setupUi(this);
@ -152,17 +154,17 @@ void PartitionManagerWidget::setupConnections()
void PartitionManagerWidget::clear() void PartitionManagerWidget::clear()
{ {
setSelectedDevice(NULL); setSelectedDevice(nullptr);
setClipboardPartition(NULL); setClipboardPartition(nullptr);
treePartitions().clear(); treePartitions().clear();
partTableWidget().clear(); partTableWidget().clear();
} }
void PartitionManagerWidget::setSelectedPartition(const Partition* p) void PartitionManagerWidget::setSelectedPartition(const Partition* p)
{ {
if (p == NULL) { if (p == nullptr) {
treePartitions().setCurrentItem(NULL); treePartitions().setCurrentItem(nullptr);
emit selectedPartitionChanged(NULL); emit selectedPartitionChanged(nullptr);
updatePartitions(); updatePartitions();
} else } else
partTableWidget().setActivePartition(p); partTableWidget().setActivePartition(p);
@ -170,8 +172,8 @@ void PartitionManagerWidget::setSelectedPartition(const Partition* p)
Partition* PartitionManagerWidget::selectedPartition() Partition* PartitionManagerWidget::selectedPartition()
{ {
if (selectedDevice() == NULL || selectedDevice()->partitionTable() == NULL || partTableWidget().activeWidget() == NULL) if (selectedDevice() == nullptr || selectedDevice()->partitionTable() == nullptr || partTableWidget().activeWidget() == nullptr)
return NULL; return nullptr;
// The active partition we get from the part table widget is const; we need non-const. // The active partition we get from the part table widget is const; we need non-const.
// So take the first sector and find the partition in the selected device's // So take the first sector and find the partition in the selected device's
@ -190,13 +192,13 @@ void PartitionManagerWidget::setSelectedDevice(const QString& device_node)
return; return;
} }
setSelectedDevice(NULL); setSelectedDevice(nullptr);
} }
void PartitionManagerWidget::setSelectedDevice(Device* d) void PartitionManagerWidget::setSelectedDevice(Device* d)
{ {
m_SelectedDevice = d; m_SelectedDevice = d;
setSelectedPartition(NULL); setSelectedPartition(nullptr);
} }
static QTreeWidgetItem* createTreeWidgetItem(const Partition& p) static QTreeWidgetItem* createTreeWidgetItem(const Partition& p)
@ -234,7 +236,7 @@ static QTreeWidgetItem* createTreeWidgetItem(const Partition& p)
void PartitionManagerWidget::updatePartitions() void PartitionManagerWidget::updatePartitions()
{ {
if (selectedDevice() == NULL) if (selectedDevice() == nullptr)
return; return;
treePartitions().clear(); treePartitions().clear();
@ -256,7 +258,7 @@ void PartitionManagerWidget::updatePartitions()
treePartitions().addTopLevelItem(deviceItem); treePartitions().addTopLevelItem(deviceItem);
if (selectedDevice()->partitionTable() != NULL) { if (selectedDevice()->partitionTable() != nullptr) {
foreach(const Partition * p, selectedDevice()->partitionTable()->children()) { foreach(const Partition * p, selectedDevice()->partitionTable()->children()) {
QTreeWidgetItem* item = createTreeWidgetItem(*p); QTreeWidgetItem* item = createTreeWidgetItem(*p);
@ -281,18 +283,18 @@ void PartitionManagerWidget::on_m_TreePartitions_currentItemChanged(QTreeWidgetI
{ {
if (current) { if (current) {
const PartitionTreeWidgetItem* ptwItem = dynamic_cast<PartitionTreeWidgetItem*>(current); const PartitionTreeWidgetItem* ptwItem = dynamic_cast<PartitionTreeWidgetItem*>(current);
partTableWidget().setActivePartition(ptwItem ? ptwItem->partition() : NULL); partTableWidget().setActivePartition(ptwItem ? ptwItem->partition() : nullptr);
} else } else
partTableWidget().setActiveWidget(NULL); partTableWidget().setActiveWidget(nullptr);
} }
void PartitionManagerWidget::on_m_TreePartitions_itemDoubleClicked(QTreeWidgetItem* item, int) void PartitionManagerWidget::on_m_TreePartitions_itemDoubleClicked(QTreeWidgetItem* item, int)
{ {
if (item == treePartitions().topLevelItem(0)) { if (item == treePartitions().topLevelItem(0)) {
if (selectedDevice() != NULL) if (selectedDevice() != nullptr)
emit deviceDoubleClicked(selectedDevice()); emit deviceDoubleClicked(selectedDevice());
} else { } else {
if (selectedPartition() != NULL) if (selectedPartition() != nullptr)
emit partitionDoubleClicked(selectedPartition()); emit partitionDoubleClicked(selectedPartition());
} }
} }
@ -304,9 +306,9 @@ void PartitionManagerWidget::onHeaderContextMenu(const QPoint& p)
void PartitionManagerWidget::on_m_PartTableWidget_itemSelectionChanged(PartWidget* item) void PartitionManagerWidget::on_m_PartTableWidget_itemSelectionChanged(PartWidget* item)
{ {
if (item == NULL) { if (item == nullptr) {
treePartitions().setCurrentItem(NULL); treePartitions().setCurrentItem(nullptr);
emit selectedPartitionChanged(NULL); emit selectedPartitionChanged(nullptr);
return; return;
} }
@ -376,12 +378,12 @@ void PartitionManagerWidget::onMountPartition()
Q_ASSERT(p); Q_ASSERT(p);
if (p == NULL) { if (p == nullptr) {
qWarning() << "no partition selected"; qWarning() << "no partition selected";
return; return;
} }
Report report(NULL); Report report(nullptr);
if (p->canMount()) { if (p->canMount()) {
if (!p->mount(report)) if (!p->mount(report))
@ -396,7 +398,7 @@ void PartitionManagerWidget::onMountPartition()
Q_ASSERT(parent); Q_ASSERT(parent);
if (parent != NULL) if (parent != nullptr)
parent->checkChildrenMounted(); parent->checkChildrenMounted();
else else
qWarning() << "parent is null"; qWarning() << "parent is null";
@ -405,13 +407,40 @@ void PartitionManagerWidget::onMountPartition()
updatePartitions(); updatePartitions();
} }
void PartitionManagerWidget::onDecryptPartition()
{
Partition* p = selectedPartition();
Q_ASSERT(p);
if (p == nullptr) {
qWarning() << "no partition selected";
return;
}
if (p->fileSystem().type() != FileSystem::Luks)
return;
FS::luks& luksFs = dynamic_cast<FS::luks&>(p->fileSystem());
if (luksFs.canCryptOpen(p->partitionPath())) {
if (!luksFs.cryptOpen(p->partitionPath()))
KMessageBox::detailedSorry(this, xi18nc("@info", "The encrypted file system on partition <filename>%1</filename> could not be unlocked.", p->deviceNode()), QString(), i18nc("@title:window", "Could Not Unlock Encrypted File System."));
} else if (luksFs.canCryptClose(p->partitionPath())) {
if (!luksFs.cryptClose(p->partitionPath()))
KMessageBox::detailedSorry(this, xi18nc("@info", "The encrypted file system on partition <filename>%1</filename> could not be locked.", p->deviceNode()), QString(), i18nc("@title:window", "Could Not Lock Encrypted File System."));
}
updatePartitions();
}
void PartitionManagerWidget::onEditMountPoint() void PartitionManagerWidget::onEditMountPoint()
{ {
Partition* p = selectedPartition(); Partition* p = selectedPartition();
Q_ASSERT(p); Q_ASSERT(p);
if (p == NULL) if (p == nullptr)
return; return;
QPointer<EditMountPointDialog> dlg = new EditMountPointDialog(this, *p); QPointer<EditMountPointDialog> dlg = new EditMountPointDialog(this, *p);
@ -444,14 +473,14 @@ void PartitionManagerWidget::onNewPartition()
Q_ASSERT(selectedDevice()); Q_ASSERT(selectedDevice());
Q_ASSERT(selectedPartition()); Q_ASSERT(selectedPartition());
if (selectedDevice() == NULL || selectedPartition() == NULL) { if (selectedDevice() == nullptr || selectedPartition() == nullptr) {
qWarning() << "selected device: " << selectedDevice() << ", selected partition: " << selectedPartition(); qWarning() << "selected device: " << selectedDevice() << ", selected partition: " << selectedPartition();
return; return;
} }
Q_ASSERT(selectedDevice()->partitionTable()); Q_ASSERT(selectedDevice()->partitionTable());
if (selectedDevice()->partitionTable() == NULL) { if (selectedDevice()->partitionTable() == nullptr) {
qWarning() << "partition table on selected device is null"; qWarning() << "partition table on selected device is null";
return; return;
} }
@ -475,7 +504,7 @@ void PartitionManagerWidget::onDeletePartition(bool shred)
Q_ASSERT(selectedDevice()); Q_ASSERT(selectedDevice());
Q_ASSERT(selectedPartition()); Q_ASSERT(selectedPartition());
if (selectedDevice() == NULL || selectedPartition() == NULL) { if (selectedDevice() == nullptr || selectedPartition() == nullptr) {
qWarning() << "selected device: " << selectedDevice() << ", selected partition: " << selectedPartition(); qWarning() << "selected device: " << selectedDevice() << ", selected partition: " << selectedPartition();
return; return;
} }
@ -483,7 +512,7 @@ void PartitionManagerWidget::onDeletePartition(bool shred)
if (selectedPartition()->roles().has(PartitionRole::Logical)) { if (selectedPartition()->roles().has(PartitionRole::Logical)) {
Q_ASSERT(selectedPartition()->parent()); Q_ASSERT(selectedPartition()->parent());
if (selectedPartition()->parent() == NULL) { if (selectedPartition()->parent() == nullptr) {
qWarning() << "parent of selected partition is null."; qWarning() << "parent of selected partition is null.";
return; return;
} }
@ -510,7 +539,7 @@ void PartitionManagerWidget::onDeletePartition(bool shred)
KStandardGuiItem::cancel(), QStringLiteral("reallyDeleteClipboardPartition")) == KMessageBox::Cancel) KStandardGuiItem::cancel(), QStringLiteral("reallyDeleteClipboardPartition")) == KMessageBox::Cancel)
return; return;
setClipboardPartition(NULL); setClipboardPartition(nullptr);
} }
if (shred && Config::shredSource() == Config::EnumShredSource::random) if (shred && Config::shredSource() == Config::EnumShredSource::random)
@ -531,14 +560,14 @@ void PartitionManagerWidget::onResizePartition()
Q_ASSERT(selectedDevice()); Q_ASSERT(selectedDevice());
Q_ASSERT(selectedPartition()); Q_ASSERT(selectedPartition());
if (selectedDevice() == NULL || selectedPartition() == NULL) { if (selectedDevice() == nullptr || selectedPartition() == nullptr) {
qWarning() << "selected device: " << selectedDevice() << ", selected partition: " << selectedPartition(); qWarning() << "selected device: " << selectedDevice() << ", selected partition: " << selectedPartition();
return; return;
} }
Q_ASSERT(selectedDevice()->partitionTable()); Q_ASSERT(selectedDevice()->partitionTable());
if (selectedDevice()->partitionTable() == NULL) { if (selectedDevice()->partitionTable() == nullptr) {
qWarning() << "partition table on selected device is null"; qWarning() << "partition table on selected device is null";
return; return;
} }
@ -576,7 +605,7 @@ void PartitionManagerWidget::onCopyPartition()
{ {
Q_ASSERT(selectedPartition()); Q_ASSERT(selectedPartition());
if (selectedPartition() == NULL) { if (selectedPartition() == nullptr) {
qWarning() << "selected partition: " << selectedPartition(); qWarning() << "selected partition: " << selectedPartition();
return; return;
} }
@ -590,12 +619,12 @@ void PartitionManagerWidget::onPastePartition()
Q_ASSERT(selectedDevice()); Q_ASSERT(selectedDevice());
Q_ASSERT(selectedPartition()); Q_ASSERT(selectedPartition());
if (selectedDevice() == NULL || selectedPartition() == NULL) { if (selectedDevice() == nullptr || selectedPartition() == nullptr) {
qWarning() << "selected device: " << selectedDevice() << ", selected partition: " << selectedPartition(); qWarning() << "selected device: " << selectedDevice() << ", selected partition: " << selectedPartition();
return; return;
} }
if (clipboardPartition() == NULL) { if (clipboardPartition() == nullptr) {
qWarning() << "no partition in the clipboard."; qWarning() << "no partition in the clipboard.";
return; return;
} }
@ -607,7 +636,7 @@ void PartitionManagerWidget::onPastePartition()
Q_ASSERT(dSource); Q_ASSERT(dSource);
if (dSource == NULL) { if (dSource == nullptr) {
qWarning() << "source partition is null."; qWarning() << "source partition is null.";
return; return;
} }
@ -625,7 +654,7 @@ bool PartitionManagerWidget::showInsertDialog(Partition& insertedPartition, qint
Q_ASSERT(selectedDevice()); Q_ASSERT(selectedDevice());
Q_ASSERT(selectedPartition()); Q_ASSERT(selectedPartition());
if (selectedDevice() == NULL || selectedPartition() == NULL) { if (selectedDevice() == nullptr || selectedPartition() == nullptr) {
qWarning() << "selected device: " << selectedDevice() << ", selected partition: " << selectedPartition(); qWarning() << "selected device: " << selectedDevice() << ", selected partition: " << selectedPartition();
return false; return false;
} }
@ -681,7 +710,7 @@ void PartitionManagerWidget::onCheckPartition()
Q_ASSERT(selectedDevice()); Q_ASSERT(selectedDevice());
Q_ASSERT(selectedPartition()); Q_ASSERT(selectedPartition());
if (selectedDevice() == NULL || selectedPartition() == NULL) { if (selectedDevice() == nullptr || selectedPartition() == nullptr) {
qWarning() << "selected device: " << selectedDevice() << ", selected partition: " << selectedPartition(); qWarning() << "selected device: " << selectedDevice() << ", selected partition: " << selectedPartition();
return; return;
} }
@ -694,7 +723,7 @@ void PartitionManagerWidget::onBackupPartition()
Q_ASSERT(selectedDevice()); Q_ASSERT(selectedDevice());
Q_ASSERT(selectedPartition()); Q_ASSERT(selectedPartition());
if (selectedDevice() == NULL || selectedPartition() == NULL) { if (selectedDevice() == nullptr || selectedPartition() == nullptr) {
qWarning() << "selected device: " << selectedDevice() << ", selected partition: " << selectedPartition(); qWarning() << "selected device: " << selectedDevice() << ", selected partition: " << selectedPartition();
return; return;
} }
@ -714,7 +743,7 @@ void PartitionManagerWidget::onRestorePartition()
Q_ASSERT(selectedDevice()); Q_ASSERT(selectedDevice());
Q_ASSERT(selectedPartition()); Q_ASSERT(selectedPartition());
if (selectedDevice() == NULL || selectedPartition() == NULL) { if (selectedDevice() == nullptr || selectedPartition() == nullptr) {
qWarning() << "selected device: " << selectedDevice() << ", selected partition: " << selectedPartition(); qWarning() << "selected device: " << selectedDevice() << ", selected partition: " << selectedPartition();
return; return;
} }

View File

@ -1,5 +1,6 @@
/************************************************************************* /*************************************************************************
* Copyright (C) 2008-2010 by Volker Lanz <vl@fidra.de> * * Copyright (C) 2008-2010 by Volker Lanz <vl@fidra.de> *
* Copyright (C) 2015 by Teo Mrnjavac <teo@kde.org> *
* * * *
* This program is free software; you can redistribute it and/or * * This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as * * modify it under the terms of the GNU General Public License as *
@ -69,6 +70,7 @@ public Q_SLOTS:
void onEditMountPoint(); void onEditMountPoint();
void onMountPartition(); void onMountPartition();
void onDecryptPartition();
void onCheckPartition(); void onCheckPartition();