diff options
author | Anne Jan Brouwer <brouwer@annejan.com> | 2015-07-07 01:01:36 +0200 |
---|---|---|
committer | Anne Jan Brouwer <brouwer@annejan.com> | 2015-07-07 01:01:36 +0200 |
commit | b13216157165c801ba493588df0a409178db9519 (patch) | |
tree | 33335ff738663a87d4bcb8cfbd1120cd23a7e378 | |
parent | a023c49a2b3f80f08abd42aa14c065f736493e76 (diff) |
anti-collission measures
-rw-r--r-- | mainwindow.cpp | 29 | ||||
-rw-r--r-- | mainwindow.h | 3 |
2 files changed, 29 insertions, 3 deletions
diff --git a/mainwindow.cpp b/mainwindow.cpp index 3b61d131..d9afc336 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -789,8 +789,12 @@ QString MainWindow::getRecipientString(QString for_file, QString separator, int * @param file * @param overwrite */ -void MainWindow::setPassword(QString file, bool overwrite) +void MainWindow::setPassword(QString file, bool overwrite, bool isNew = false) { + if (!isNew && lastDecrypt.isEmpty()) { + // warn? + return; + } bool ok; #if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0) QString newValue = QInputDialog::getMultiLineText(this, tr("New Value"), @@ -847,7 +851,7 @@ void MainWindow::on_addButton_clicked() file += ".gpg"; } lastDecrypt = ""; - setPassword(file, false); + setPassword(file, false, true); } /** @@ -937,6 +941,21 @@ void MainWindow::on_editButton_clicked() } /** + * @brief MainWindow::qSleep + * @param ms + */\ +void MainWindow::qSleep(int ms) +{ +#ifdef Q_OS_WIN + Sleep(uint(ms)); +#else + struct timespec ts = { ms / 1000, (ms % 1000) * 1000 * 1000 }; + nanosleep(&ts, NULL); +#endif +} + + +/** * @brief MainWindow::listKeys * @param keystring * @param secret @@ -944,6 +963,9 @@ void MainWindow::on_editButton_clicked() */ QList<UserInfo> MainWindow::listKeys(QString keystring, bool secret) { + while (!process->atEnd() || !execQueue->isEmpty()) { + qSleep(100); + } QList<UserInfo> users; currentAction = GPG_INTERNAL; QString listopt = secret ? "--list-secret-keys " : "--list-keys "; @@ -1336,6 +1358,9 @@ void MainWindow::addFolder() */ void MainWindow::editPassword() { + while (!process->atEnd() || !execQueue->isEmpty()) { + qSleep(100); + } // TODO move to editbutton stuff possibly? currentDir = getDir(ui->treeView->currentIndex(), false); lastDecrypt = "Could not decrypt"; diff --git a/mainwindow.h b/mainwindow.h index 163e626e..ff234afd 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -71,6 +71,7 @@ private slots: void showContextMenu(const QPoint& pos); void addFolder(); void editPassword(); + void qSleep(int); private: QApplication *QtPass; @@ -121,7 +122,7 @@ private: QModelIndex firstFile(QModelIndex parentIndex); QString getDir(const QModelIndex &, bool); QString getFile(const QModelIndex &, bool); - void setPassword(QString, bool); + void setPassword(QString, bool, bool); QSettings &getSettings(); QList<UserInfo> listKeys(QString keystring = "", bool secret = false); QStringList getRecipientList(QString for_file); |