aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSaturneric <[email protected]>2021-12-20 06:28:53 +0000
committerSaturneric <[email protected]>2021-12-20 06:28:53 +0000
commitef1b42b53185e4b1ec841ab15bf6272cd2a99473 (patch)
treee19adff5f59579458235161c3a0d4c17e8cd625b
parentPass apple store automatic verification. (diff)
downloadGpgFrontend-ef1b42b53185e4b1ec841ab15bf6272cd2a99473.tar.gz
GpgFrontend-ef1b42b53185e4b1ec841ab15bf6272cd2a99473.zip
Fixed bugs.
1. Not not paint in main thread.
-rw-r--r--src/main.cpp38
-rw-r--r--src/ui/UserInterfaceUtils.cpp9
-rw-r--r--src/ui/UserInterfaceUtils.h2
-rw-r--r--src/ui/function/CtxCheckThread.cpp44
-rw-r--r--src/ui/function/CtxCheckThread.h42
5 files changed, 111 insertions, 24 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 10d54958..ed863f41 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -28,8 +28,8 @@
#include "GpgFrontendBuildInfo.h"
#include "gpg/GpgContext.h"
-#include "gpg/function/GpgKeyGetter.h"
#include "ui/MainWindow.h"
+#include "ui/function/CtxCheckThread.h"
#include "ui/settings/GlobalSettingStation.h"
// Easy Logging Cpp
@@ -78,7 +78,9 @@ int main(int argc, char* argv[]) {
#if !defined(RELEASE) && defined(WINDOWS)
// css
- boost::filesystem::path css_path = GpgFrontend::UI::GlobalSettingStation::GetInstance().GetResourceDir() / "css" / "default.qss";
+ boost::filesystem::path css_path =
+ GpgFrontend::UI::GlobalSettingStation::GetInstance().GetResourceDir() /
+ "css" / "default.qss";
QFile file(css_path.string().c_str());
file.open(QFile::ReadOnly);
QString styleSheet = QLatin1String(file.readAll());
@@ -86,21 +88,7 @@ int main(int argc, char* argv[]) {
file.close();
#endif
- auto* init_ctx_thread = QThread::create([]() {
- // Create & Check Gnupg Context Status
- if (!GpgFrontend::GpgContext::GetInstance().good()) {
- QMessageBox::critical(
- nullptr, _("ENV Loading Failed"),
- _("Gnupg(gpg) is not installed correctly, please follow the "
- "ReadME "
- "instructions in Github to install Gnupg and then open "
- "GpgFrontend."));
- QCoreApplication::quit();
- exit(0);
- }
- // Try fetching key
- GpgFrontend::GpgKeyGetter::GetInstance().FetchKey();
- });
+ auto* init_ctx_thread = new GpgFrontend::UI::CtxCheckThread();
QApplication::connect(init_ctx_thread, &QThread::finished, init_ctx_thread,
&QThread::deleteLater);
@@ -118,9 +106,13 @@ int main(int argc, char* argv[]) {
waiting_dialog_label->setWordWrap(true);
waiting_dialog->setLabel(waiting_dialog_label);
waiting_dialog->resize(420, 120);
+ QApplication::connect(init_ctx_thread, &QThread::finished, [=]() {
+ waiting_dialog->finished(0);
+ waiting_dialog->deleteLater();
+ });
QApplication::connect(waiting_dialog, &QProgressDialog::canceled, [=]() {
LOG(INFO) << "cancel clicked";
- init_ctx_thread->terminate();
+ if (init_ctx_thread->isRunning()) init_ctx_thread->terminate();
QCoreApplication::quit();
exit(0);
});
@@ -130,11 +122,10 @@ int main(int argc, char* argv[]) {
waiting_dialog->setFocus();
init_ctx_thread->start();
- while (init_ctx_thread->isRunning()) {
- QApplication::processEvents();
- }
- waiting_dialog->finished(0);
- waiting_dialog->deleteLater();
+ QEventLoop loop;
+ QApplication::connect(init_ctx_thread, &QThread::finished, &loop,
+ &QEventLoop::quit);
+ loop.exec();
/**
* internationalisation. loop to restart main window
@@ -149,7 +140,6 @@ int main(int argc, char* argv[]) {
int r = setjmp(recover_env);
#endif
if (!r) {
-
try {
// i18n
init_locale();
diff --git a/src/ui/UserInterfaceUtils.cpp b/src/ui/UserInterfaceUtils.cpp
index 0931a179..581eabda 100644
--- a/src/ui/UserInterfaceUtils.cpp
+++ b/src/ui/UserInterfaceUtils.cpp
@@ -151,6 +151,15 @@ CommonUtils* CommonUtils::GetInstance() {
CommonUtils::CommonUtils() : QWidget(nullptr) {
connect(this, SIGNAL(signalKeyStatusUpdated()), SignalStation::GetInstance(),
SIGNAL(KeyDatabaseRefresh()));
+ connect(this, &CommonUtils::signalGnupgNotInstall, this, []() {
+ QMessageBox::critical(
+ nullptr, _("ENV Loading Failed"),
+ _("Gnupg(gpg) is not installed correctly, please follow the "
+ "ReadME "
+ "instructions in Github to install Gnupg and then open "
+ "GpgFrontend."));
+ QCoreApplication::quit();
+ });
}
void CommonUtils::slotImportKeys(QWidget* parent,
diff --git a/src/ui/UserInterfaceUtils.h b/src/ui/UserInterfaceUtils.h
index be114b0a..76b6ce0d 100644
--- a/src/ui/UserInterfaceUtils.h
+++ b/src/ui/UserInterfaceUtils.h
@@ -75,6 +75,8 @@ class CommonUtils : public QWidget {
signals:
void signalKeyStatusUpdated();
+ void signalGnupgNotInstall();
+
public slots:
void slotImportKeys(QWidget* parent, const std::string& in_buffer);
diff --git a/src/ui/function/CtxCheckThread.cpp b/src/ui/function/CtxCheckThread.cpp
new file mode 100644
index 00000000..cd184910
--- /dev/null
+++ b/src/ui/function/CtxCheckThread.cpp
@@ -0,0 +1,44 @@
+/**
+ * This file is part of GpgFrontend.
+ *
+ * GpgFrontend 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Foobar 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 Foobar. If not, see <https://www.gnu.org/licenses/>.
+ *
+ * The initial version of the source code is inherited from gpg4usb-team.
+ * Their source code version also complies with GNU General Public License.
+ *
+ * The source code version of this software was modified and released
+ * by Saturneric<[email protected]><[email protected]> starting on May 12, 2021.
+ *
+ */
+
+#include "CtxCheckThread.h"
+
+#include "gpg/GpgContext.h"
+#include "gpg/function/GpgKeyGetter.h"
+#include "ui/UserInterfaceUtils.h"
+
+GpgFrontend::UI::CtxCheckThread::CtxCheckThread() : QThread(nullptr) {
+ connect(this, &CtxCheckThread::signalGnupgNotInstall,
+ CommonUtils::GetInstance(), &CommonUtils::signalGnupgNotInstall);
+}
+
+void GpgFrontend::UI::CtxCheckThread::run() {
+ // Create & Check Gnupg Context Status
+ if (!GpgContext::GetInstance().good()) {
+ emit signalGnupgNotInstall();
+ }
+ // Try fetching key
+ else
+ GpgFrontend::GpgKeyGetter::GetInstance().FetchKey();
+}
diff --git a/src/ui/function/CtxCheckThread.h b/src/ui/function/CtxCheckThread.h
new file mode 100644
index 00000000..74bdb491
--- /dev/null
+++ b/src/ui/function/CtxCheckThread.h
@@ -0,0 +1,42 @@
+/**
+ * This file is part of GpgFrontend.
+ *
+ * GpgFrontend 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Foobar 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 Foobar. If not, see <https://www.gnu.org/licenses/>.
+ *
+ * The initial version of the source code is inherited from gpg4usb-team.
+ * Their source code version also complies with GNU General Public License.
+ *
+ * The source code version of this software was modified and released
+ * by Saturneric<[email protected]><[email protected]> starting on May 12, 2021.
+ *
+ */
+
+#ifndef GPGFRONTEND_CTXCHECKTRHEAD_H
+#define GPGFRONTEND_CTXCHECKTRHEAD_H
+#include "ui/GpgFrontendUI.h"
+namespace GpgFrontend::UI {
+class CtxCheckThread : public QThread {
+ Q_OBJECT
+ public:
+ CtxCheckThread();
+
+ signals:
+ void signalGnupgNotInstall();
+
+ protected:
+ void run() override;
+};
+} // namespace GpgFrontend::UI
+
+#endif // GPGFRONTEND_CTXCHECKTRHEAD_H