aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.cpp
diff options
context:
space:
mode:
authorSaturneric <[email protected]>2021-12-16 18:18:38 +0000
committerSaturneric <[email protected]>2021-12-16 18:18:38 +0000
commit2874ebd5e56a7da7f7e7c96da392199b296d909a (patch)
treee6b78bcbb33282e652cd47df59987fc5932725c7 /src/main.cpp
parentFixed Known Problem. (diff)
downloadGpgFrontend-2874ebd5e56a7da7f7e7c96da392199b296d909a.tar.gz
GpgFrontend-2874ebd5e56a7da7f7e7c96da392199b296d909a.zip
Fixed & Improve.
1. Fixed Known Issues. 2. Improve UI.
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp171
1 files changed, 49 insertions, 122 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 7e46229e..d3e85c68 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -22,6 +22,8 @@
*
*/
+#include <csetjmp>
+#include <csignal>
#include <cstdlib>
#include "GpgFrontendBuildInfo.h"
@@ -29,15 +31,23 @@
#include "gpg/function/GpgKeyGetter.h"
#include "ui/MainWindow.h"
#include "ui/WaitingDialog.h"
-#include "ui/settings/GlobalSettingStation.h"
// Easy Logging Cpp
INITIALIZE_EASYLOGGINGPP
-void init_logging();
-void init_locale();
+// Recover buff
+jmp_buf recover_env;
+
+extern void init_logging();
+extern void init_locale();
+extern void handle_signal(int sig);
int main(int argc, char* argv[]) {
+ // Register Signals
+ signal(SIGSEGV, handle_signal);
+ signal(SIGFPE, handle_signal);
+ signal(SIGILL, handle_signal);
+
// Qt
Q_INIT_RESOURCE(gpgfrontend);
@@ -94,8 +104,6 @@ int main(int argc, char* argv[]) {
QApplication::connect(init_ctx_thread, &QThread::finished, init_ctx_thread,
&QThread::deleteLater);
- init_ctx_thread->start();
-
// Waiting Dialog
auto* waiting_dialog = new QProgressDialog();
waiting_dialog->setMaximum(0);
@@ -119,6 +127,8 @@ int main(int argc, char* argv[]) {
// Show Waiting Dialog
waiting_dialog->show();
waiting_dialog->setFocus();
+
+ init_ctx_thread->start();
while (init_ctx_thread->isRunning()) {
QApplication::processEvents();
}
@@ -132,126 +142,43 @@ int main(int argc, char* argv[]) {
int return_from_event_loop_code;
do {
- try {
- // i18n
- init_locale();
-
- QApplication::setQuitOnLastWindowClosed(true);
-
- auto main_window = std::make_unique<GpgFrontend::UI::MainWindow>();
- main_window->init();
- main_window->show();
- return_from_event_loop_code = QApplication::exec();
-
- } catch (...) {
- QMessageBox::information(nullptr, _("Unhandled Exception Thrown"),
- _("Oops, an unhandled exception was thrown "
- "during the running of the "
- "program, and now it needs to be restarted."));
+ int r = sigsetjmp(recover_env, 1);
+ if (!r) {
+
+ try {
+ // i18n
+ init_locale();
+
+ QApplication::setQuitOnLastWindowClosed(true);
+
+ auto main_window = std::make_unique<GpgFrontend::UI::MainWindow>();
+ main_window->init();
+ main_window->show();
+ return_from_event_loop_code = QApplication::exec();
+
+ } catch (...) {
+ QMessageBox::information(
+ nullptr, _("Unhandled Exception Thrown"),
+ _("Oops, an unhandled exception was thrown "
+ "during the running of the "
+ "program, and now it needs to be restarted. This is not a "
+ "serious problem, it may be the negligence of the programmer, "
+ "please report this problem if you can."));
+ continue;
+ }
+
+ } else {
+ QMessageBox::information(
+ nullptr, _("A serious error has occurred"),
+ _("Oh no! GpgFrontend caught a serious error in the software, so it "
+ "needs to be restarted. If the problem recurs, please manually "
+ "terminate the program and report the problem to the developer."));
+ return_from_event_loop_code = RESTART_CODE;
+ LOG(INFO) << "return_from_event_loop_code" << return_from_event_loop_code;
continue;
}
+ LOG(INFO) << "loop refresh";
} while (return_from_event_loop_code == RESTART_CODE);
return return_from_event_loop_code;
}
-
-void init_logging() {
- using namespace boost::posix_time;
- using namespace boost::gregorian;
-
- ptime now = second_clock::local_time();
-
- el::Loggers::addFlag(el::LoggingFlag::AutoSpacing);
- el::Configurations defaultConf;
- defaultConf.setToDefault();
- el::Loggers::reconfigureLogger("default", defaultConf);
-
- defaultConf.setGlobally(el::ConfigurationType::Format,
- "%datetime %level %func %msg");
-
- auto logfile_path =
- (GpgFrontend::UI::GlobalSettingStation::GetInstance().GetLogDir() /
- to_iso_string(now));
- logfile_path.replace_extension(".log");
- defaultConf.setGlobally(el::ConfigurationType::Filename,
- logfile_path.string());
-
- el::Loggers::reconfigureLogger("default", defaultConf);
-
- LOG(INFO) << _("Logfile Path") << logfile_path;
-}
-
-void init_locale() {
- auto& settings =
- GpgFrontend::UI::GlobalSettingStation::GetInstance().GetUISettings();
-
- if (!settings.exists("general") ||
- settings.lookup("general").getType() != libconfig::Setting::TypeGroup)
- settings.add("general", libconfig::Setting::TypeGroup);
-
- // set system default at first
- auto& general = settings["general"];
- if (!general.exists("lang"))
- general.add("lang", libconfig::Setting::TypeString) = "";
-
- GpgFrontend::UI::GlobalSettingStation::GetInstance().Sync();
-
- LOG(INFO) << "current system locale" << setlocale(LC_ALL, nullptr);
-
- // read from settings file
- std::string lang;
- if (!general.lookupValue("lang", lang)) {
- LOG(ERROR) << _("Could not read properly from configure file");
- };
-
- LOG(INFO) << "lang from settings" << lang;
- LOG(INFO) << "PROJECT_NAME" << PROJECT_NAME;
- LOG(INFO) << "locales path"
- << GpgFrontend::UI::GlobalSettingStation::GetInstance()
- .GetLocaleDir()
- .c_str();
-
-#ifndef WINDOWS
- if (!lang.empty()) {
- std::string lc = lang.empty() ? "" : lang + ".UTF-8";
-
- // set LC_ALL
- auto* locale_name = setlocale(LC_ALL, lc.c_str());
- if (locale_name == nullptr) LOG(WARNING) << "set LC_ALL failed" << lc;
- auto language = getenv("LANGUAGE");
- // set LANGUAGE
- std::string language_env = language == nullptr ? "en" : language;
- language_env.insert(0, lang + ":");
- LOG(INFO) << "language env" << language_env;
- if (setenv("LANGUAGE", language_env.c_str(), 1)) {
- LOG(WARNING) << "set LANGUAGE failed" << language_env;
- };
- }
-#else
- if (!lang.empty()) {
- std::string lc = lang.empty() ? "" : lang;
-
- // set LC_ALL
- auto* locale_name = setlocale(LC_ALL, lc.c_str());
- if (locale_name == nullptr) LOG(WARNING) << "set LC_ALL failed" << lc;
-
- auto language = getenv("LANGUAGE");
- // set LANGUAGE
- std::string language_env = language == nullptr ? "en" : language;
- language_env.insert(0, lang + ":");
- language_env.insert(0, "LANGUAGE=");
- LOG(INFO) << "language env" << language_env;
- if (putenv(language_env.c_str())) {
- LOG(WARNING) << "set LANGUAGE failed" << language_env;
- };
- }
-#endif
-
- bindtextdomain(PROJECT_NAME,
- GpgFrontend::UI::GlobalSettingStation::GetInstance()
- .GetLocaleDir()
- .string()
- .c_str());
- bind_textdomain_codeset(PROJECT_NAME, "utf-8");
- textdomain(PROJECT_NAME);
-}