diff options
author | Anne Jan Brouwer <annejan@noprotocol.com> | 2015-05-21 22:06:22 +0200 |
---|---|---|
committer | Anne Jan Brouwer <annejan@noprotocol.com> | 2015-05-21 22:06:22 +0200 |
commit | 2a5b7e26a07bcb53f32c8f4b90ad566a3a3912ff (patch) | |
tree | 098df138ce4dba289cf32106a397f93aa343cd50 | |
parent | bd23531be44730f3b626df27a84134a40e5a65f7 (diff) |
clean wizard interface
-rw-r--r-- | dialog.cpp | 19 | ||||
-rw-r--r-- | dialog.h | 7 | ||||
-rw-r--r-- | mainwindow.cpp | 54 | ||||
-rw-r--r-- | mainwindow.h | 1 | ||||
-rw-r--r-- | util.cpp | 20 |
5 files changed, 94 insertions, 7 deletions
@@ -1,5 +1,6 @@ #include "dialog.h" #include "ui_dialog.h" +#include "mainwindow.h" #include <QDebug> #include <QMessageBox> @@ -7,10 +8,11 @@ * @brief Dialog::Dialog * @param parent */ -Dialog::Dialog(QWidget *parent) : +Dialog::Dialog(MainWindow *parent) : QDialog(parent), ui(new Ui::Dialog) { + mainWindow = parent; ui->setupUi(this); } @@ -353,10 +355,19 @@ void Dialog::addGPGId(bool addGPGId) void Dialog::wizard() { - // got GPG at-least ? - // TODO ^^ + if(!QFile(ui->gpgPath->text()).exists()){ + QMessageBox::critical(this, tr("GnuPG not found"), + tr("Please install GnuPG on your system.\nhttps://www.gnupg.org/download/")); + // TODO REST + } - // TODO have usable gpg id + QStringList names = mainWindow->getSecretKeys(); + //qDebug() << names; + if (names.empty()) { + QMessageBox::critical(this, tr("Secret key not found"), + tr("You can not encrypt :(")); + // TODO have usable gpg id wizrd :P + } QString passStore = ui->storePath->text(); if(!QFile(passStore + ".gpg-id").exists()){ @@ -3,8 +3,12 @@ #include <QDialog> #include <QFileDialog> +#include "mainwindow.h" namespace Ui { + +struct UserInfo; + class Dialog; } @@ -13,7 +17,7 @@ class Dialog : public QDialog Q_OBJECT public: - explicit Dialog(QWidget *parent = 0); + explicit Dialog(MainWindow *parent); ~Dialog(); void setPassPath(QString); void setGitPath(QString); @@ -54,6 +58,7 @@ private: void setGroupBoxState(); QString selectExecutable(); QString selectFolder(); + MainWindow *mainWindow; }; #endif // DIALOG_H diff --git a/mainwindow.cpp b/mainwindow.cpp index 1ebc284c..5dfbbaf8 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -224,7 +224,7 @@ bool MainWindow::checkConfig() { * @brief MainWindow::config */ void MainWindow::config() { - QScopedPointer<Dialog> d(new Dialog()); + QScopedPointer<Dialog> d(new Dialog(this)); d->setModal(true); d->setPassPath(passExecutable); @@ -614,6 +614,11 @@ void MainWindow::on_clearButton_clicked() ui->lineEdit->clear(); } +/** + * @brief MainWindow::getRecipientList + * @param for_file + * @return + */ QStringList MainWindow::getRecipientList(QString for_file) { QDir gpgIdPath(QFileInfo(for_file.startsWith(passStore) ? for_file : passStore + for_file).absoluteDir()); @@ -643,6 +648,13 @@ QStringList MainWindow::getRecipientList(QString for_file) return recipients; } +/** + * @brief MainWindow::getRecipientString + * @param for_file + * @param separator + * @param count + * @return + */ QString MainWindow::getRecipientString(QString for_file, QString separator, int *count) { QString recipients_str; @@ -658,6 +670,11 @@ QString MainWindow::getRecipientString(QString for_file, QString separator, int return recipients_str; } +/** + * @brief MainWindow::setPassword + * @param file + * @param overwrite + */ void MainWindow::setPassword(QString file, bool overwrite) { bool ok; @@ -698,6 +715,9 @@ void MainWindow::setPassword(QString file, bool overwrite) } } +/** + * @brief MainWindow::on_addButton_clicked + */ void MainWindow::on_addButton_clicked() { bool ok; @@ -715,6 +735,9 @@ void MainWindow::on_addButton_clicked() setPassword(file, false); } +/** + * @brief MainWindow::on_deleteButton_clicked + */ void MainWindow::on_deleteButton_clicked() { QString file = getFile(ui->treeView->currentIndex(), usePass); @@ -731,6 +754,9 @@ void MainWindow::on_deleteButton_clicked() } } +/** + * @brief MainWindow::on_editButton_clicked + */ void MainWindow::on_editButton_clicked() { QString file = getFile(ui->treeView->currentIndex(), usePass); @@ -742,6 +768,12 @@ void MainWindow::on_editButton_clicked() setPassword(file, true); } +/** + * @brief MainWindow::listKeys + * @param keystring + * @param secret + * @return + */ QList<UserInfo> MainWindow::listKeys(QString keystring, bool secret) { QList<UserInfo> users; @@ -918,3 +950,23 @@ void MainWindow::updateEnv() env.replaceInStrings(store.first(), "PASSWORD_STORE_DIR=" + passStore); } } + +/** + * @brief MainWindow::getSecretKeys + * @return QStringList keys + */ +QStringList MainWindow::getSecretKeys() +{ + QList<UserInfo> keys = listKeys("", true); + QStringList names; + + if (keys.size() == 0) { + return names; + } + + foreach (const UserInfo &sec, keys) { + names << sec.name; + } + + return names; +} diff --git a/mainwindow.h b/mainwindow.h index 60da42e8..db27403b 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -41,6 +41,7 @@ public: bool checkConfig(); void setApp(SingleApplication* app); void setText(QString); + QStringList getSecretKeys(); private slots: void on_updateButton_clicked(); @@ -8,6 +8,9 @@ QProcessEnvironment Util::_env; bool Util::_envInitialised; +/** + * @brief Util::initialiseEnvironment + */ void Util::initialiseEnvironment() { if (!_envInitialised) { @@ -28,6 +31,10 @@ void Util::initialiseEnvironment() } } +/** + * @brief Util::findPasswordStore + * @return + */ QString Util::findPasswordStore() { QString path; @@ -40,7 +47,11 @@ QString Util::findPasswordStore() return Util::normalizeFolderPath(path); } - +/** + * @brief Util::normalizeFolderPath + * @param path + * @return + */ QString Util::normalizeFolderPath(QString path) { if (!path.endsWith("/") && !path.endsWith(QDir::separator())) { path += '/'; @@ -86,6 +97,13 @@ QString Util::findBinaryInPath(QString binary) return ret; } +/** + * @brief Util::checkConfig + * @param passStore + * @param passExecutable + * @param gpgExecutable + * @return + */ bool Util::checkConfig(QString passStore, QString passExecutable, QString gpgExecutable) { return !QFile(passStore + ".gpg-id").exists() || (!QFile(passExecutable).exists() && !QFile(gpgExecutable).exists()); |