diff --git a/src/fs/luks.cpp b/src/fs/luks.cpp index fd43e93..acf74a7 100644 --- a/src/fs/luks.cpp +++ b/src/fs/luks.cpp @@ -20,6 +20,8 @@ #include "fs/luks.h" +#include "gui/decryptluksdialog.h" + #include "util/capacity.h" #include "util/externalcommand.h" @@ -84,11 +86,37 @@ namespace FS return 3 * Capacity::unitFactor(Capacity::Byte, Capacity::MiB); } + QString luks::mountTitle() const + { + return i18nc("@title:menu", "Decrypt"); + } + QString luks::unmountTitle() const { return i18nc("@title:menu", "Deactivate"); } + bool luks::mount(const QString& deviceNode) + { + QPointer dlg = new DecryptLuksDialog(deviceNode); + + if (dlg->exec() == KDialog::Accepted) + { + std::vector commands; + commands.push_back("echo"); + commands.push_back("cryptsetup"); + std::vector args; + args.push_back(QStringList() << dlg->luksPassphrase().text()); + args.push_back(QStringList() << "luksOpen" << deviceNode << dlg->luksName().text()); + ExternalCommand cmd(commands, args); + delete dlg; + return cmd.run(-1) && cmd.exitCode() == 0; + } + + delete dlg; + return false; + } + bool luks::unmount(const QString& deviceNode) { ExternalCommand cmd("cryptsetup", QStringList() << "luksClose" << mapperName(deviceNode)); diff --git a/src/fs/luks.h b/src/fs/luks.h index a1f863b..0061479 100644 --- a/src/fs/luks.h +++ b/src/fs/luks.h @@ -63,9 +63,12 @@ namespace FS virtual QString readUUID(const QString& deviceNode) const; virtual bool updateUUID(Report& report, const QString& deviceNode) const; + virtual bool canMount(const QString&) const { return true; }; virtual bool canUnmount(const QString&) const { return true; }; + virtual bool mount(const QString& deviceNode); virtual bool unmount(const QString& deviceNode); + virtual QString mountTitle() const; virtual QString unmountTitle() const; static QString mapperName (const QString& deviceNode); diff --git a/src/gui/decryptluksdialog.cpp b/src/gui/decryptluksdialog.cpp new file mode 100644 index 0000000..fab685a --- /dev/null +++ b/src/gui/decryptluksdialog.cpp @@ -0,0 +1,39 @@ +/*************************************************************************** + * Copyright (C) 2013 by Andrius Štikonas * + * * + * 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 2 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, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#include "gui/decryptluksdialog.h" +#include "gui/decryptluksdialogwidget.h" + +#include "core/device.h" +#include "core/partitiontable.h" + +#include +#include + +#include + +DecryptLuksDialog::DecryptLuksDialog(/*QWidget* parent, */const QString& deviceNode) : +// KDialog(parent), + m_DialogWidget(new DecryptLuksDialogWidget(this)), + m_DeviceNode(deviceNode) +{ + setMainWidget(&widget()); + setCaption(i18nc("@title:window", "Decrypt LUKS partition on %1", this->deviceNode())); + setButtonText(KDialog::Ok, i18nc("@action:button", "&Decrypt")); +} diff --git a/src/gui/decryptluksdialog.h b/src/gui/decryptluksdialog.h new file mode 100644 index 0000000..9d55087 --- /dev/null +++ b/src/gui/decryptluksdialog.h @@ -0,0 +1,55 @@ +/*************************************************************************** + * Copyright (C) 2013 by Andrius Štikonas * + * * + * 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 2 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, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#if !defined(DECRYPTLUKSDIALOG__H) + +#define DECRYPTLUKSDIALOG__H + +#include "gui/decryptluksdialogwidget.h" + +#include + +class Device; + +class DecryptLuksDialog : public KDialog +{ + Q_OBJECT + + public: + DecryptLuksDialog(/*QWidget* parent, */const QString& deviceNode); + + protected: + DecryptLuksDialogWidget& widget() { return *m_DialogWidget; } + const DecryptLuksDialogWidget& widget() const { return *m_DialogWidget; } + const QString& deviceNode() const { return m_DeviceNode; } + + private: + DecryptLuksDialogWidget* m_DialogWidget; + const QString& m_DeviceNode; + + public: + KLineEdit& luksName() { return widget().luksName(); } + const KLineEdit& luksName() const { return widget().luksName(); } + + KLineEdit& luksPassphrase() { return widget().luksPassphrase(); } + const KLineEdit& luksPassphrase() const { return widget().luksPassphrase(); } +}; + + +#endif diff --git a/src/gui/decryptluksdialogwidget.cpp b/src/gui/decryptluksdialogwidget.cpp new file mode 100644 index 0000000..f1bc93f --- /dev/null +++ b/src/gui/decryptluksdialogwidget.cpp @@ -0,0 +1,26 @@ +/*************************************************************************** + * Copyright (C) 2013 by Andrius Štikonas * + * * + * 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 2 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, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#include "gui/decryptluksdialogwidget.h" + +DecryptLuksDialogWidget::DecryptLuksDialogWidget(QWidget* parent) : + QWidget(parent) +{ + setupUi(this); +} diff --git a/src/gui/decryptluksdialogwidget.h b/src/gui/decryptluksdialogwidget.h new file mode 100644 index 0000000..5e6d625 --- /dev/null +++ b/src/gui/decryptluksdialogwidget.h @@ -0,0 +1,46 @@ +/*************************************************************************** + * Copyright (C) 2013 by Andrius Štikonas * + * * + * 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 2 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, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#if !defined(DECRYPTLUKSDIALOGWIDGET__H) + +#define DECRYPTLUKSDIALOGWIDGET__H + +#include "ui_decryptluksdialogwidgetbase.h" + +#include +#include + +#include + +class DecryptLuksDialogWidget : public QWidget, public Ui::DecryptLuksDialogWidgetBase +{ + Q_OBJECT + + public: + DecryptLuksDialogWidget(QWidget* parent); + + public: + KLineEdit& luksName() { return *m_LineEditName; } + const KLineEdit& luksName() const { return *m_LineEditName; } + + KLineEdit& luksPassphrase() { return *m_LineEditPassphrase; } + const KLineEdit& luksPassphrase() const { return *m_LineEditPassphrase; } +}; + +#endif diff --git a/src/gui/decryptluksdialogwidgetbase.ui b/src/gui/decryptluksdialogwidgetbase.ui new file mode 100644 index 0000000..3ca4dc3 --- /dev/null +++ b/src/gui/decryptluksdialogwidgetbase.ui @@ -0,0 +1,78 @@ + + + DecryptLuksDialogWidgetBase + + + + 0 + 0 + 377 + 122 + + + + + 10 + + + + + + + &Name: + + + m_LineEditName + + + + + + + + + + &Passphrase: + + + m_LineEditPassphrase + + + + + + + true + + + + + + + + + Qt::Vertical + + + QSizePolicy::MinimumExpanding + + + + 20 + 20 + + + + + + + + + KLineEdit + QLineEdit +
klineedit.h
+
+
+ + +