From d3b1f25bd533d392bb6d6cc8c733dcf737942280 Mon Sep 17 00:00:00 2001 From: Stefan Suhren Date: Fri, 2 Oct 2015 16:32:23 +0200 Subject: Füge DecryptWizard für bessere Nutzerführung ein MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CryptLog.pro | 9 ++-- decryptdatadialog.cpp | 56 ++++++++++++++++++++++++ decryptdatadialog.h | 68 +++++++++++++++++++++++++++++ decryptdatadialog.ui | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++ mainwindow.cpp | 43 ++++++------------- mainwindow.h | 1 + 6 files changed, 261 insertions(+), 32 deletions(-) create mode 100644 decryptdatadialog.cpp create mode 100644 decryptdatadialog.h create mode 100644 decryptdatadialog.ui diff --git a/CryptLog.pro b/CryptLog.pro index 52e5193..6a9c2ec 100644 --- a/CryptLog.pro +++ b/CryptLog.pro @@ -17,17 +17,20 @@ SOURCES += main.cpp\ passworddialog.cpp \ publickeyimportdialog.cpp \ crypt/hybridcrypt.cpp \ - crypt/cryptexception.cpp + crypt/cryptexception.cpp \ + decryptdatadialog.cpp HEADERS += mainwindow.h \ passworddialog.h \ publickeyimportdialog.h \ crypt/hybridcrypt.h \ - crypt/cryptexception.h + crypt/cryptexception.h \ + decryptdatadialog.h FORMS += mainwindow.ui \ passworddialog.ui \ - publickeyimportdialog.ui + publickeyimportdialog.ui \ + decryptdatadialog.ui RESOURCES += \ ressources.qrc diff --git a/decryptdatadialog.cpp b/decryptdatadialog.cpp new file mode 100644 index 0000000..b7d3e2a --- /dev/null +++ b/decryptdatadialog.cpp @@ -0,0 +1,56 @@ +#include "decryptdatadialog.h" +#include "ui_decryptdatadialog.h" + +DecryptDataDialog::DecryptDataDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::DecryptDataDialog) +{ + ui->setupUi(this); +} + +DecryptDataDialog::~DecryptDataDialog() +{ + delete ui; +} + +void DecryptDataDialog::accept() +{ + if (!ui->lineEditFilePath->text().isEmpty()) + { + m_outFile = QFileDialog::getSaveFileName(this, tr("Datei Speichern"), + QDir::homePath(), tr("Alle Dateien")); + + if (!m_outFile.isEmpty()) + { + QDialog::accept(); + } + } + else + { + QMessageBox::information(this, tr("Keine verschlüsselte Datei"), + tr("Bitte wählen Sie eine verschlüsselte Datei aus,\nbevor Sie entschlüsseln.")); + } + +} + +void DecryptDataDialog::on_pushButtonOpenFile_clicked() +{ + QString filename = QFileDialog::getOpenFileName(this, tr("Datei Öffnen"), + QDir::homePath(), + tr("Alle Dateien")); + + if (!filename.isEmpty()) + { + ui->lineEditFilePath->setText(filename); + } +} + +QString DecryptDataDialog::getInFilename() const +{ + return ui->lineEditFilePath->text(); +} + +QString DecryptDataDialog::getOutFileName() const +{ + return m_outFile; +} diff --git a/decryptdatadialog.h b/decryptdatadialog.h new file mode 100644 index 0000000..8faf514 --- /dev/null +++ b/decryptdatadialog.h @@ -0,0 +1,68 @@ +#ifndef DECRYPTDATADIALOG_H +#define DECRYPTDATADIALOG_H + +#include +#include +#include +#include +#include + +namespace Ui { +class DecryptDataDialog; +} + +/** + * @brief Ein Wizard, der durch das Entschlüsseln führt. + */ +class DecryptDataDialog : public QDialog +{ + Q_OBJECT + +public: + /** + * @brief Erzeugt ein neuen DecryptDataDialog, mit dem angegeben Elternfenster. + * @param parent Das Elternfenster, welches überschattet wird. + */ + explicit DecryptDataDialog(QWidget *parent = 0); + ~DecryptDataDialog(); + + /** + * @brief Gibt den Pfad der zu speichernden Datei an. + * @return Der Dateipfad. + */ + QString getOutFileName() const; + + /** + * @brief Gibt den Pfad der zu entschlüsselnden Datei an. + * @return Der Dateipfad. + */ + QString getCipherFilename() const; + +public slots: + /** + * @brief Fängt Fehler nach dem Okay ab. + */ + virtual void accept(); + +private slots: + /** + * @brief Öffnet einen Dateidialog + * für die verschlüsselte Datei. + * Schreibt Dateipfad in lineEditFilePath(ChangeEvent). + */ + void on_pushButtonOpenFile_clicked(); + +private: + /** + * @brief Liefert Zugriff auf die UI. + */ + Ui::DecryptDataDialog *ui; + + /** + * @brief Der Pfad, der zu speichernden Datei. + */ + QString m_outFile; + +}; + +#endif // DECRYPTDATADIALOG_H diff --git a/decryptdatadialog.ui b/decryptdatadialog.ui new file mode 100644 index 0000000..35fa56a --- /dev/null +++ b/decryptdatadialog.ui @@ -0,0 +1,116 @@ + + + DecryptDataDialog + + + + 0 + 0 + 400 + 300 + + + + Dialog + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Verschlüsselte Datei auswählen + + + + + + QLineEdit::Normal + + + true + + + + + + + Datei auswählen + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Save + + + + + + + + + buttonBox + accepted() + DecryptDataDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + DecryptDataDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/mainwindow.cpp b/mainwindow.cpp index 8b888aa..efec3ad 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -17,43 +17,28 @@ void MainWindow::on_pushButtonDecrypt_clicked() { if (hybridcrypt.isUserKeyInitialised()) { - QString inFilename = QFileDialog::getOpenFileName(this, - tr("Verschlüsselte Datei laden"), QDir::homePath(), tr("Alle Dateien")); + DecryptDataDialog decryptDialog; - if (!inFilename.isEmpty()) + if (decryptDialog.exec()) { - - QString outFilename = QFileDialog::getSaveFileName(this, - tr("Entschlüsselte Datei speichern"), QDir::homePath(), tr("Alle Dateien")); - - if (!outFilename.isEmpty()) + try { - try - { - statusBar()->showMessage(tr("Entschlüsselung hat begonnen."), messageTimeout); - hybridcrypt.decrypt(inFilename, outFilename); - statusBar()->showMessage(tr("Entschlüsselung war erfolgreich."), - messageTimeout); + QString inFilename = decryptDialog.getInFilename(); + QString outFilename = decryptDialog.getOutFileName(); - // Zeige entschlüsselte Datei - ui->lineEditFilePath->setText(outFilename); - } - catch (CryptException e) - { - QMessageBox::critical(this, tr("Fehler beim Entschlüsseln"), e.what()); - } + statusBar()->showMessage(tr("Entschlüsselung hat begonnen."), messageTimeout); + hybridcrypt.decrypt(inFilename, outFilename); + statusBar()->showMessage(tr("Entschlüsselung war erfolgreich."), + messageTimeout); + + // Zeige entschlüsselte Datei + ui->lineEditFilePath->setText(outFilename); } - else + catch (CryptException e) { - QMessageBox::warning(this, tr("Keinen Seicherort ausgewählt"), - tr("Sie haben keine Speicherort für die entschlüsselte Datei eingegeben.")); + QMessageBox::critical(this, tr("Fehler beim Entschlüsseln"), e.what()); } } - else - { - QMessageBox::information(this, tr("Kein Datei ausgewählt"), - tr("Sie haben keine Datei eingeben die entschlüsselt werden soll.")); - } } else { diff --git a/mainwindow.h b/mainwindow.h index 4ae6bb9..f7ddaae 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -13,6 +13,7 @@ #include "crypt/hybridcrypt.h" #include "passworddialog.h" #include "publickeyimportdialog.h" +#include "decryptdatadialog.h" namespace Ui { class MainWindow; -- cgit v1.2.3-70-g09d2