aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/MainWindow.cpp2
-rw-r--r--src/gpg/GpgContext.cpp36
-rw-r--r--src/ui/WaitingDialog.cpp8
-rw-r--r--src/ui/main_window/MainWindowSlotFunction.cpp265
-rw-r--r--src/ui/widgets/TextEdit.cpp2
5 files changed, 169 insertions, 144 deletions
diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp
index a59bd01d..35890a47 100644
--- a/src/MainWindow.cpp
+++ b/src/MainWindow.cpp
@@ -29,7 +29,7 @@ MainWindow::MainWindow()
settings(RESOURCE_DIR(appPath) + "/conf/gpgfrontend.ini",
QSettings::IniFormat) {
- auto waitingDialog = new WaitingDialog(this);
+ auto waitingDialog = new WaitingDialog("Loading", this);
auto ctx_thread = QThread::create([&]() { mCtx = new GpgME::GpgContext(); });
diff --git a/src/gpg/GpgContext.cpp b/src/gpg/GpgContext.cpp
index e94ce1ab..028653b7 100644
--- a/src/gpg/GpgContext.cpp
+++ b/src/gpg/GpgContext.cpp
@@ -659,16 +659,16 @@ namespace GpgME {
bool GpgContext::exportSecretKey(const GpgKey &key, QByteArray *outBuffer) {
qDebug() << "Export Secret Key" << key.id;
gpgme_key_t target_key[2] = {
- key.key_refer,
- nullptr
+ key.key_refer,
+ nullptr
};
gpgme_data_t dataOut;
gpgme_data_new(&dataOut);
// export private key to outBuffer
- gpgme_error_t error = gpgme_op_export_keys(mCtx, target_key,GPGME_EXPORT_MODE_SECRET, dataOut);
+ gpgme_error_t error = gpgme_op_export_keys(mCtx, target_key, GPGME_EXPORT_MODE_SECRET, dataOut);
- if(gpgme_err_code(error) != GPG_ERR_NO_ERROR) {
+ if (gpgme_err_code(error) != GPG_ERR_NO_ERROR) {
checkErr(error);
gpgme_data_release(dataOut);
return false;
@@ -734,26 +734,6 @@ namespace GpgME {
return gpgmeError;
}
- /***
- * return type should contain:
- * -> list of sigs
- * -> valid
- * -> decrypted message
- */
- //void GpgContext::decryptVerify(QByteArray in) {
-
- /* gpgme_error_t err;
- gpgme_data_t in, out;
-
- gpgme_decrypt_result_t decrypt_result;
- gpgme_verify_result_t verify_result;
-
- err = gpgme_op_decrypt_verify (mCtx, in, out);
- decrypt_result = gpgme_op_decrypt_result (mCtx);
-
- verify_result = gpgme_op_verify_result (mCtx);
- */
- //}
gpg_error_t
GpgContext::sign(const QVector<GpgKey> &keys, const QByteArray &inBuffer, QByteArray *outBuffer, bool detached,
gpgme_sign_result_t *result) {
@@ -962,7 +942,7 @@ namespace GpgME {
void GpgContext::setSigners(const QVector<GpgKey> &keys) {
gpgme_signers_clear(mCtx);
for (const auto &key : keys) {
- if(checkIfKeyCanSign(key)) {
+ if (checkIfKeyCanSign(key)) {
auto gpgmeError = gpgme_signers_add(mCtx, key.key_refer);
checkErr(gpgmeError);
}
@@ -1180,7 +1160,7 @@ namespace GpgME {
}
}
- if(gpgme_err_code(err) != GPG_ERR_NO_ERROR)
+ if (gpgme_err_code(err) != GPG_ERR_NO_ERROR)
checkErr(err);
if (dataIn) {
@@ -1240,11 +1220,11 @@ namespace GpgME {
return false;
}
- for (const auto& key : keys) {
+ for (const auto &key : keys) {
err = gpgme_data_new(&dataOut);
checkErr(err);
- err = gpgme_op_export(mCtx,key.id.toUtf8().constData(), 0, dataOut);
+ err = gpgme_op_export(mCtx, key.id.toUtf8().constData(), 0, dataOut);
checkErr(err);
read_bytes = gpgme_data_seek(dataOut, 0, SEEK_END);
diff --git a/src/ui/WaitingDialog.cpp b/src/ui/WaitingDialog.cpp
index 8281385a..bc21a17d 100644
--- a/src/ui/WaitingDialog.cpp
+++ b/src/ui/WaitingDialog.cpp
@@ -1,15 +1,19 @@
#include "ui/WaitingDialog.h"
-WaitingDialog::WaitingDialog(QWidget *parent) : QDialog(parent) {
+WaitingDialog::WaitingDialog(const QString &title, QWidget *parent) : QDialog(parent) {
auto *pb = new QProgressBar();
pb->setRange(0, 0);
+ pb->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
auto *layout = new QVBoxLayout();
+ layout->setContentsMargins(0, 0, 0, 0);
+ layout->setSpacing(0);
layout->addWidget(pb);
this->setLayout(layout);
this->setModal(true);
- this->setWindowTitle(tr("Processing"));
+ this->setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint);
+ this->setWindowTitle(title);
this->setFixedSize(240, 42);
this->show();
}
diff --git a/src/ui/main_window/MainWindowSlotFunction.cpp b/src/ui/main_window/MainWindowSlotFunction.cpp
index 36d8f363..21d0af0d 100644
--- a/src/ui/main_window/MainWindowSlotFunction.cpp
+++ b/src/ui/main_window/MainWindowSlotFunction.cpp
@@ -61,9 +61,9 @@ void MainWindow::slotEncrypt() {
thread->start();
- WaitingDialog *dialog = new WaitingDialog(this);
+ auto *dialog = new WaitingDialog(tr("Encrypting"), this);
- while(thread->isRunning()) {
+ while (thread->isRunning()) {
QApplication::processEvents();
}
@@ -118,7 +118,18 @@ void MainWindow::slotSign() {
gpgme_sign_result_t result = nullptr;
- auto error = mCtx->sign(keys, edit->curTextPage()->toPlainText().toUtf8(), tmp, false, &result);
+ gpgme_error_t error;
+ auto thread = QThread::create([&]() {
+ error = mCtx->sign(keys, edit->curTextPage()->toPlainText().toUtf8(), tmp, false, &result);
+ });
+ thread->start();
+
+ auto *dialog = new WaitingDialog(tr("Signing"), this);
+ while (thread->isRunning()) {
+ QApplication::processEvents();
+ }
+ dialog->close();
+
infoBoard->associateTextEdit(edit->curTextPage());
edit->slotFillTextEditWithText(QString::fromUtf8(*tmp));
@@ -156,8 +167,8 @@ void MainWindow::slotDecrypt() {
});
thread->start();
- WaitingDialog *dialog = new WaitingDialog(this);
- while(thread->isRunning()) {
+ auto *dialog = new WaitingDialog(tr("Decrypting"), this);
+ while (thread->isRunning()) {
QApplication::processEvents();
}
@@ -215,11 +226,10 @@ void MainWindow::slotVerify() {
});
thread->start();
- WaitingDialog *dialog = new WaitingDialog(this);
- while(thread->isRunning()) {
+ auto *dialog = new WaitingDialog(tr("Verifying"), this);
+ while (thread->isRunning()) {
QApplication::processEvents();
}
-
dialog->close();
auto resultAnalyse = new VerifyResultAnalyse(mCtx, error, result);
@@ -268,27 +278,27 @@ void MainWindow::slotEncryptSign() {
if (!key_can_sign && !key_can_encr) {
QMessageBox::critical(nullptr,
- tr("Invalid KeyPair"),
- tr("The selected keypair cannot be used for signing and encryption at the same time.<br/>")
- + tr("<br/>For example the Following Key: <br/>") + key.uids.first().uid);
+ tr("Invalid KeyPair"),
+ tr("The selected keypair cannot be used for signing and encryption at the same time.<br/>")
+ + tr("<br/>For example the Following Key: <br/>") + key.uids.first().uid);
return;
}
- if(key_can_sign) can_sign = true;
- if(key_can_encr) can_encr = true;
+ if (key_can_sign) can_sign = true;
+ if (key_can_encr) can_encr = true;
}
- if(!can_encr) {
- QMessageBox::critical(nullptr,
- tr("Incomplete Operation"),
- tr("None of the selected key pairs can provide the encryption function."));
- return;
+ if (!can_encr) {
+ QMessageBox::critical(nullptr,
+ tr("Incomplete Operation"),
+ tr("None of the selected key pairs can provide the encryption function."));
+ return;
}
- if(!can_sign) {
- QMessageBox::warning(nullptr,
- tr("Incomplete Operation"),
- tr("None of the selected key pairs can provide the signature function."));
+ if (!can_sign) {
+ QMessageBox::warning(nullptr,
+ tr("Incomplete Operation"),
+ tr("None of the selected key pairs can provide the signature function."));
}
auto *tmp = new QByteArray();
@@ -300,18 +310,18 @@ void MainWindow::slotEncryptSign() {
gpgme_error_t error;
auto thread = QThread::create([&]() {
error = mCtx->encryptSign(keys, edit->curTextPage()->toPlainText().toUtf8(), tmp, &encr_result,
- &sign_result);
+ &sign_result);
});
thread->start();
- WaitingDialog *dialog = new WaitingDialog(this);
- while(thread->isRunning()) {
+ auto *dialog = new WaitingDialog(tr("Encrypting and Signing"), this);
+ while (thread->isRunning()) {
QApplication::processEvents();
}
dialog->close();
- if(gpgme_err_code(error) == GPG_ERR_NO_ERROR) {
+ if (gpgme_err_code(error) == GPG_ERR_NO_ERROR) {
auto *tmp2 = new QString(*tmp);
edit->slotFillTextEditWithText(*tmp2);
}
@@ -356,8 +366,8 @@ void MainWindow::slotDecryptVerify() {
});
thread->start();
- WaitingDialog *dialog = new WaitingDialog(this);
- while(thread->isRunning()) {
+ WaitingDialog *dialog = new WaitingDialog(tr("Decrypting and Verifying"), this);
+ while (thread->isRunning()) {
QApplication::processEvents();
}
@@ -495,22 +505,26 @@ void MainWindow::slotFileEncrypt() {
}
}
- try {
- gpgme_encrypt_result_t result;
+ gpgme_encrypt_result_t result;
- gpgme_error_t error;
- auto thread = QThread::create([&]() {
+ gpgme_error_t error;
+ bool if_error = false;
+ auto thread = QThread::create([&]() {
+ try {
error = GpgFileOpera::encryptFile(mCtx, keys, path, &result);
- });
- thread->start();
-
- WaitingDialog *dialog = new WaitingDialog(this);
- while(thread->isRunning()) {
- QApplication::processEvents();
+ } catch (const std::runtime_error &e) {
+ if_error = true;
}
+ });
+ thread->start();
- dialog->close();
+ auto *dialog = new WaitingDialog(tr("Encrypting"), this);
+ while (thread->isRunning()) {
+ QApplication::processEvents();
+ }
+ dialog->close();
+ if(!if_error) {
auto resultAnalyse = new EncryptResultAnalyse(error, result);
auto &reportText = resultAnalyse->getResultReport();
infoBoard->associateTabWidget(edit->tabWidget);
@@ -526,11 +540,10 @@ void MainWindow::slotFileEncrypt() {
delete resultAnalyse;
fileTreeView->update();
-
- } catch (const std::runtime_error &e) {
+ } else {
QMessageBox::critical(this, tr("Error"), tr("An error occurred during operation."));
+ return;
}
-
}
void MainWindow::slotFileDecrypt() {
@@ -572,21 +585,27 @@ void MainWindow::slotFileDecrypt() {
return;
}
- try {
- gpgme_decrypt_result_t result;
- gpgme_error_t error;
- auto thread = QThread::create([&]() {
- error = GpgFileOpera::decryptFile(mCtx, path, &result);
- });
- thread->start();
+ gpgme_decrypt_result_t result;
+ gpgme_error_t error;
+ bool if_error = false;
- WaitingDialog *dialog = new WaitingDialog(this);
- while(thread->isRunning()) {
- QApplication::processEvents();
+ auto thread = QThread::create([&]() {
+ try {
+ error = GpgFileOpera::decryptFile(mCtx, path, &result);
+ } catch (const std::runtime_error &e) {
+ if_error = true;
}
+ });
+ thread->start();
- dialog->close();
+ auto *dialog = new WaitingDialog("Decrypting", this);
+ while (thread->isRunning()) {
+ QApplication::processEvents();
+ }
+ dialog->close();
+
+ if(!if_error) {
auto resultAnalyse = new DecryptResultAnalyse(mCtx, error, result);
auto &reportText = resultAnalyse->getResultReport();
infoBoard->associateTabWidget(edit->tabWidget);
@@ -602,7 +621,7 @@ void MainWindow::slotFileDecrypt() {
delete resultAnalyse;
fileTreeView->update();
- } catch (const std::runtime_error &e) {
+ } else {
QMessageBox::critical(this, tr("Error"), tr("An error occurred during operation."));
return;
}
@@ -661,20 +680,27 @@ void MainWindow::slotFileSign() {
}
}
- try {
- gpgme_sign_result_t result;
- gpgme_error_t error;
- auto thread = QThread::create([&]() {
- error = GpgFileOpera::signFile(mCtx, keys, path, &result);
- });
- thread->start();
+ gpgme_sign_result_t result;
+ gpgme_error_t error;
+ bool if_error = false;
- WaitingDialog *dialog = new WaitingDialog(this);
- while(thread->isRunning()) {
- QApplication::processEvents();
+ auto thread = QThread::create([&]() {
+ try {
+ error = GpgFileOpera::signFile(mCtx, keys, path, &result);
+ } catch (const std::runtime_error &e) {
+ if_error = true;
}
+ });
+ thread->start();
- dialog->close();
+ auto *dialog = new WaitingDialog(tr("Signing"), this);
+ while (thread->isRunning()) {
+ QApplication::processEvents();
+ }
+
+ dialog->close();
+
+ if(!if_error) {
auto resultAnalyse = new SignResultAnalyse(error, result);
auto &reportText = resultAnalyse->getResultReport();
@@ -692,8 +718,9 @@ void MainWindow::slotFileSign() {
fileTreeView->update();
- } catch (const std::runtime_error &e) {
+ } else {
QMessageBox::critical(this, tr("Error"), tr("An error occurred during operation."));
+ return;
}
fileTreeView->update();
@@ -709,11 +736,10 @@ void MainWindow::slotFileVerify() {
QString signFilePath, dataFilePath;
- if(fileInfo.suffix() == "gpg") {
+ if (fileInfo.suffix() == "gpg") {
dataFilePath = path;
signFilePath = path;
- }
- else if (fileInfo.suffix() == "sig") {
+ } else if (fileInfo.suffix() == "sig") {
int pos = path.lastIndexOf(QChar('.'));
dataFilePath = path.left(pos);
signFilePath = path;
@@ -743,7 +769,7 @@ void MainWindow::slotFileVerify() {
gpgme_error_t error;
bool if_error = false;
auto thread = QThread::create([&]() {
- try{
+ try {
error = GpgFileOpera::verifyFile(mCtx, dataFilePath, &result);
} catch (const std::runtime_error &e) {
if_error = true;
@@ -751,13 +777,13 @@ void MainWindow::slotFileVerify() {
});
thread->start();
- WaitingDialog *dialog = new WaitingDialog(this);
- while(thread->isRunning()) {
+ auto *dialog = new WaitingDialog(tr("Verifying"), this);
+ while (thread->isRunning()) {
QApplication::processEvents();
}
dialog->close();
- if(!if_error) {
+ if (!if_error) {
auto resultAnalyse = new VerifyResultAnalyse(mCtx, error, result);
auto &reportText = resultAnalyse->getResultReport();
infoBoard->associateTabWidget(edit->tabWidget);
@@ -832,45 +858,51 @@ void MainWindow::slotFileEncryptSign() {
if (!key_can_sign && !key_can_encr) {
QMessageBox::critical(nullptr,
- tr("Invalid KeyPair"),
- tr("The selected keypair cannot be used for signing and encryption at the same time.<br/>")
- + tr("<br/>For example the Following Key: <br/>") + key.uids.first().uid);
+ tr("Invalid KeyPair"),
+ tr("The selected keypair cannot be used for signing and encryption at the same time.<br/>")
+ + tr("<br/>For example the Following Key: <br/>") + key.uids.first().uid);
return;
}
- if(key_can_sign) can_sign = true;
- if(key_can_encr) can_encr = true;
+ if (key_can_sign) can_sign = true;
+ if (key_can_encr) can_encr = true;
}
- if(!can_encr) {
- QMessageBox::critical(nullptr,
- tr("Incomplete Operation"),
- tr("None of the selected key pairs can provide the encryption function."));
- return;
+ if (!can_encr) {
+ QMessageBox::critical(nullptr,
+ tr("Incomplete Operation"),
+ tr("None of the selected key pairs can provide the encryption function."));
+ return;
}
- if(!can_sign) {
- QMessageBox::warning(nullptr,
- tr("Incomplete Operation"),
- tr("None of the selected key pairs can provide the signature function."));
+ if (!can_sign) {
+ QMessageBox::warning(nullptr,
+ tr("Incomplete Operation"),
+ tr("None of the selected key pairs can provide the signature function."));
}
- try {
+ gpgme_encrypt_result_t encr_result = nullptr;
+ gpgme_sign_result_t sign_result = nullptr;
- gpgme_encrypt_result_t encr_result = nullptr;
- gpgme_sign_result_t sign_result = nullptr;
+ gpgme_error_t error;
+ bool if_error = false;
- gpgme_error_t error;
- auto thread = QThread::create([&]() {
+ auto thread = QThread::create([&]() {
+ try {
error = GpgFileOpera::encryptSignFile(mCtx, keys, path, &encr_result, &sign_result);
- });
- thread->start();
-
- WaitingDialog *dialog = new WaitingDialog(this);
- while(thread->isRunning()) {
- QApplication::processEvents();
+ } catch (const std::runtime_error &e) {
+ if_error = true;
}
- dialog->close();
+ });
+ thread->start();
+
+ WaitingDialog *dialog = new WaitingDialog(tr("Encrypting and Signing"), this);
+ while (thread->isRunning()) {
+ QApplication::processEvents();
+ }
+ dialog->close();
+
+ if(!if_error) {
auto resultAnalyseEncr = new EncryptResultAnalyse(error, encr_result);
auto resultAnalyseSign = new SignResultAnalyse(error, sign_result);
@@ -891,8 +923,9 @@ void MainWindow::slotFileEncryptSign() {
fileTreeView->update();
- } catch (std::runtime_error &e) {
+ } else {
QMessageBox::critical(this, tr("Error"), tr("An error occurred during operation."));
+ return;
}
}
@@ -924,22 +957,28 @@ void MainWindow::slotFileDecryptVerify() {
outFileName = path + ".out";
}
- try {
+ gpgme_decrypt_result_t d_result = nullptr;
+ gpgme_verify_result_t v_result = nullptr;
- gpgme_decrypt_result_t d_result = nullptr;
- gpgme_verify_result_t v_result = nullptr;
+ gpgme_error_t error;
+ bool if_error = false;
- gpgme_error_t error;
- auto thread = QThread::create([&]() {
+ auto thread = QThread::create([&]() {
+ try {
error = GpgFileOpera::decryptVerifyFile(mCtx, path, &d_result, &v_result);
- });
- thread->start();
-
- WaitingDialog *dialog = new WaitingDialog(this);
- while(thread->isRunning()) {
- QApplication::processEvents();
+ } catch (const std::runtime_error &e) {
+ if_error = true;
}
- dialog->close();
+ });
+ thread->start();
+
+ auto *dialog = new WaitingDialog(tr("Decrypting and Verifying"), this);
+ while (thread->isRunning()) {
+ QApplication::processEvents();
+ }
+ dialog->close();
+
+ if(!if_error) {
infoBoard->associateFileTreeView(edit->curFilePage());
auto resultAnalyseDecrypt = new DecryptResultAnalyse(mCtx, error, d_result);
@@ -964,7 +1003,7 @@ void MainWindow::slotFileDecryptVerify() {
delete resultAnalyseVerify;
fileTreeView->update();
- } catch (std::runtime_error &e) {
+ } else {
QMessageBox::critical(this, tr("Error"), tr("An error occurred during operation."));
return;
}
diff --git a/src/ui/widgets/TextEdit.cpp b/src/ui/widgets/TextEdit.cpp
index 26cc3834..f06b3a45 100644
--- a/src/ui/widgets/TextEdit.cpp
+++ b/src/ui/widgets/TextEdit.cpp
@@ -132,6 +132,7 @@ void TextEdit::slotInsertTargetTextPage(const QString &pagePtr,
auto *taregtTextPage = qobject_cast<EditorPage *>(it.value());
if (taregtTextPage != nullptr) {
taregtTextPage->getTextPage()->insertPlainText(text);
+ taregtTextPage->getTextPage()->document()->setModified(false);
}
}
}
@@ -164,6 +165,7 @@ void TextEdit::slotReadTargetTextPageDone(const QString &pagePtr) {
tabWidget->setTabText(index,
strippedName(taregtTextPage->getFilePath()));
}
+ taregtTextPage->getTextPage()->document()->setModified(false);
connect(taregtTextPage->getTextPage()->document(),
SIGNAL(modificationChanged(bool)), this,
SLOT(slotShowModified()));