aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/before_exit.cpp6
-rw-r--r--src/core/GpgCoreInit.cpp6
-rw-r--r--src/init.cpp8
-rw-r--r--src/ui/GpgFrontendUIInit.cpp9
-rw-r--r--src/ui/main_window/MainWindowUI.cpp23
-rw-r--r--src/ui/widgets/TextEdit.cpp32
-rw-r--r--src/ui/widgets/TextEdit.h2
7 files changed, 40 insertions, 46 deletions
diff --git a/src/before_exit.cpp b/src/before_exit.cpp
index 3b0989fa..caf61db1 100644
--- a/src/before_exit.cpp
+++ b/src/before_exit.cpp
@@ -32,7 +32,11 @@
* @brief Actions performed before exiting the application
*
*/
-void before_exit() {
+void before_exit() {
SPDLOG_INFO("called");
+
+ // Under VisualStudio, this must be called before main finishes to workaround
+ // a known VS issue
+ spdlog::drop_all();
spdlog::shutdown();
}
diff --git a/src/core/GpgCoreInit.cpp b/src/core/GpgCoreInit.cpp
index ee42579d..ad4e395d 100644
--- a/src/core/GpgCoreInit.cpp
+++ b/src/core/GpgCoreInit.cpp
@@ -68,10 +68,14 @@ void InitLoggingSystem() {
#ifdef DEBUG
core_logger->set_level(spdlog::level::trace);
-#else
+#else
core_logger->set_level(spdlog::level::info);
#endif
+ // flush policy
+ core_logger->flush_on(spdlog::level::err);
+ spdlog::flush_every(std::chrono::seconds(5));
+
// register it as default logger
spdlog::set_default_logger(core_logger);
}
diff --git a/src/init.cpp b/src/init.cpp
index 7e6a76cc..46440750 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -48,16 +48,20 @@ void init_logging_system() {
// logger
auto main_logger = std::make_shared<spdlog::async_logger>(
- "core", begin(sinks), end(sinks), spdlog::thread_pool());
+ "main", begin(sinks), end(sinks), spdlog::thread_pool());
main_logger->set_pattern(
"[%H:%M:%S.%e] [T:%t] [%=4n] %^[%=8l]%$ [%s:%#] [%!] -> %v (+%ius)");
#ifdef DEBUG
main_logger->set_level(spdlog::level::trace);
-#else
+#else
core_logger->set_level(spdlog::level::info);
#endif
+ // flush policy
+ main_logger->flush_on(spdlog::level::err);
+ spdlog::flush_every(std::chrono::seconds(5));
+
// register it as default logger
spdlog::set_default_logger(main_logger);
}
diff --git a/src/ui/GpgFrontendUIInit.cpp b/src/ui/GpgFrontendUIInit.cpp
index 8beecea9..210d1088 100644
--- a/src/ui/GpgFrontendUIInit.cpp
+++ b/src/ui/GpgFrontendUIInit.cpp
@@ -150,7 +150,7 @@ void init_logging_system() {
// logger
auto ui_logger = std::make_shared<spdlog::async_logger>(
- "core", begin(sinks), end(sinks), spdlog::thread_pool());
+ "ui", begin(sinks), end(sinks), spdlog::thread_pool());
ui_logger->set_pattern(
"[%H:%M:%S.%e] [T:%t] [%=4n] %^[%=8l]%$ [%s:%#] [%!] -> %v (+%ius)");
@@ -160,6 +160,13 @@ void init_logging_system() {
core_logger->set_level(spdlog::level::info);
#endif
+ // flush policy
+ ui_logger->flush_on(spdlog::level::err);
+ spdlog::flush_every(std::chrono::seconds(5));
+
+ // register it
+ spdlog::register_logger(ui_logger);
+
// register it as default logger
spdlog::set_default_logger(ui_logger);
}
diff --git a/src/ui/main_window/MainWindowUI.cpp b/src/ui/main_window/MainWindowUI.cpp
index 77bf2e14..452061cf 100644
--- a/src/ui/main_window/MainWindowUI.cpp
+++ b/src/ui/main_window/MainWindowUI.cpp
@@ -260,13 +260,14 @@ void MainWindow::create_actions() {
reload_components_act_->setIcon(QIcon(":configure.png"));
reload_components_act_->setToolTip(_("Reload All GnuPG's Components"));
connect(reload_components_act_, &QAction::triggered, this, [=]() {
- if (GpgFrontend::GpgAdvancedOperator::GetInstance()
- .ReloadGpgComponents()) {
- QMessageBox::information(this, _("Successful Operation"),
- _("Reload all the GnuPG's components successfully"));
+ if (GpgFrontend::GpgAdvancedOperator::GetInstance().ReloadGpgComponents()) {
+ QMessageBox::information(
+ this, _("Successful Operation"),
+ _("Reload all the GnuPG's components successfully"));
} else {
- QMessageBox::critical(this, _("Failed Operation"),
- _("Failed to reload all or one of the GnuPG's component(s)"));
+ QMessageBox::critical(
+ this, _("Failed Operation"),
+ _("Failed to reload all or one of the GnuPG's component(s)"));
}
});
@@ -276,11 +277,13 @@ void MainWindow::create_actions() {
connect(restart_components_act_, &QAction::triggered, this, [=]() {
if (GpgFrontend::GpgAdvancedOperator::GetInstance()
.RestartGpgComponents()) {
- QMessageBox::information(this, _("Successful Operation"),
- _("Restart all the GnuPG's components successfully"));
+ QMessageBox::information(
+ this, _("Successful Operation"),
+ _("Restart all the GnuPG's components successfully"));
} else {
- QMessageBox::critical(this, _("Failed Operation"),
- _("Failed to restart all or one of the GnuPG's component(s)"));
+ QMessageBox::critical(
+ this, _("Failed Operation"),
+ _("Failed to restart all or one of the GnuPG's component(s)"));
}
});
diff --git a/src/ui/widgets/TextEdit.cpp b/src/ui/widgets/TextEdit.cpp
index c4754b3b..d8c4605d 100644
--- a/src/ui/widgets/TextEdit.cpp
+++ b/src/ui/widgets/TextEdit.cpp
@@ -79,7 +79,7 @@ void TextEdit::SlotNewFileTab() const {
page->SlotGoPath();
}
-void TextEdit::SlotOpenFile(QString& path) {
+void TextEdit::SlotOpenFile(const QString& path) {
QFile file(path);
SPDLOG_INFO("path: {}", path.toStdString());
auto result = file.open(QIODevice::ReadOnly | QIODevice::Text);
@@ -112,35 +112,7 @@ void TextEdit::SlotOpen() {
QFileDialog::getOpenFileNames(this, _("Open file"), QDir::currentPath());
for (const auto& file_name : file_names) {
if (!file_name.isEmpty()) {
- QFile file(file_name);
-
- if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
- auto* page = new PlainTextEditorPage(file_name);
-
- QTextStream in(&file);
- QApplication::setOverrideCursor(Qt::WaitCursor);
- page->GetTextPage()->setPlainText(in.readAll());
- page->SetFilePath(file_name);
- QTextDocument* document = page->GetTextPage()->document();
- document->setModified(false);
-
- tab_widget_->addTab(page, stripped_name(file_name));
- tab_widget_->setCurrentIndex(tab_widget_->count() - 1);
- QApplication::restoreOverrideCursor();
- page->GetTextPage()->setFocus();
- connect(page->GetTextPage()->document(),
- &QTextDocument::modificationChanged, this,
- &TextEdit::SlotShowModified);
- // enableAction(true)
- file.close();
- } else {
- QMessageBox::warning(
- this, _("Warning"),
- (boost::format(_("Cannot read file %1%:\n%2%.")) %
- file_name.toStdString() % file.errorString().toStdString())
- .str()
- .c_str());
- }
+ SlotOpenFile(file_name);
}
}
}
diff --git a/src/ui/widgets/TextEdit.h b/src/ui/widgets/TextEdit.h
index cb32bfb2..6398cf34 100644
--- a/src/ui/widgets/TextEdit.h
+++ b/src/ui/widgets/TextEdit.h
@@ -153,7 +153,7 @@ class TextEdit : public QWidget {
/**
* @details Adds a new tab with opening file by path
*/
- void SlotOpenFile(QString& path);
+ void SlotOpenFile(const QString& path);
/**
* @details Adds a new tab with the given title and opens given html file.