aboutsummaryrefslogtreecommitdiffstats
path: root/src/GpgFrontendContext.cpp
diff options
context:
space:
mode:
authorsaturneric <[email protected]>2023-12-15 09:04:59 +0000
committersaturneric <[email protected]>2023-12-15 09:04:59 +0000
commitf5cf83e4b3fdf1e9ae82b00f39e45e189809c419 (patch)
treecc7d9b764b0274cfce5830e22a1ecc23678bd091 /src/GpgFrontendContext.cpp
parentfix: slove issues on memory and add asan support for debug (diff)
downloadGpgFrontend-f5cf83e4b3fdf1e9ae82b00f39e45e189809c419.tar.gz
GpgFrontend-f5cf83e4b3fdf1e9ae82b00f39e45e189809c419.zip
fix: slove some issues on memory and intilizations
Diffstat (limited to 'src/GpgFrontendContext.cpp')
-rw-r--r--src/GpgFrontendContext.cpp39
1 files changed, 20 insertions, 19 deletions
diff --git a/src/GpgFrontendContext.cpp b/src/GpgFrontendContext.cpp
index 5f51975a..461bbeaa 100644
--- a/src/GpgFrontendContext.cpp
+++ b/src/GpgFrontendContext.cpp
@@ -28,36 +28,37 @@
#include "GpgFrontendContext.h"
+#include <qapplication.h>
#include <qcoreapplication.h>
-
-#include <memory>
+#include <qobject.h>
+#include <qthread.h>
#include "core/utils/MemoryUtils.h"
#include "ui/GpgFrontendApplication.h"
namespace GpgFrontend {
-std::shared_ptr<GpgFrontendContext> GpgFrontendContext::global_context =
- nullptr;
-
-auto GpgFrontendContext::CreateInstance(int argc, char** argv)
- -> std::weak_ptr<GpgFrontendContext> {
- global_context = std::make_shared<GpgFrontendContext>();
- global_context->argc = argc;
- global_context->argv = argv;
- return global_context;
+void GpgFrontendContext::InitApplication(bool gui_mode) {
+ if (!gui_mode) {
+ app_ = SecureCreateObject<QCoreApplication>(argc, argv);
+ } else {
+ app_ = SecureCreateObject<QApplication>(argc, argv);
+ }
+ this->load_ui_env = gui_mode;
}
-auto GpgFrontendContext::GetInstance() -> std::weak_ptr<GpgFrontendContext> {
- return global_context;
-}
+auto GpgFrontendContext::GetApp() -> QCoreApplication* { return app_; }
-void GpgFrontendContext::InitCoreApplication() {
- app = SecureCreateUniqueObject<QCoreApplication>(argc, argv);
+auto GpgFrontendContext::GetGuiApp() -> QApplication* {
+ return qobject_cast<QApplication*>(app_);
}
-void GpgFrontendContext::InitGUIApplication() {
- app = SecureCreateUniqueObject<UI::GpgFrontendApplication>(argc, argv);
-}
+GpgFrontendContext::GpgFrontendContext(int argc, char** argv)
+ : argc(argc), argv(argv) {}
+GpgFrontendContext::~GpgFrontendContext() {
+ if (app_ != nullptr) {
+ SecureDestroyObject(app_);
+ }
+}
} // namespace GpgFrontend \ No newline at end of file