diff --git a/Daemon.h b/Daemon.h index 2f7682eb..7467a518 100644 --- a/Daemon.h +++ b/Daemon.h @@ -1,6 +1,7 @@ #ifndef DAEMON_H__ #define DAEMON_H__ +#include #include namespace i2p @@ -32,6 +33,7 @@ namespace i2p #if defined(QT_GUI_LIB) // check if QT #define Daemon i2p::util::DaemonQT::Instance() + class DaemonQTImpl; class DaemonQT: public i2p::util::Daemon_Singleton { public: @@ -43,9 +45,11 @@ namespace i2p } bool init(int argc, char* argv[]); - bool start(); - bool stop(); void run (); + + private: + + std::shared_ptr m_Impl; }; #elif defined(_WIN32) diff --git a/qt/i2pd_qt/DaemonQT.cpp b/qt/i2pd_qt/DaemonQT.cpp index 19a13c6e..41242e3b 100644 --- a/qt/i2pd_qt/DaemonQT.cpp +++ b/qt/i2pd_qt/DaemonQT.cpp @@ -8,32 +8,57 @@ namespace i2p { namespace util { - std::unique_ptr app; + class DaemonQTImpl: public std::enable_shared_from_this + { + public: + + DaemonQTImpl (int argc, char* argv[]): + m_App (argc, argv) + { + } + + void Run () + { + MainWindow w; + w.show (); + m_App.exec(); + } + + private: + + void StartDaemon () + { + Daemon.start (); + } + + void StopDaemon () + { + Daemon.stop (); + } + + bool IsRunning () const + { + return Daemon.running; + } + + private: + + QApplication m_App; + }; + bool DaemonQT::init(int argc, char* argv[]) { - app.reset (new QApplication (argc, argv)); + m_Impl = std::make_shared (argc, argv); return Daemon_Singleton::init(argc, argv); } - bool DaemonQT::start() - { - return Daemon_Singleton::start(); - } - - bool DaemonQT::stop() - { - return Daemon_Singleton::stop(); - } - void DaemonQT::run () { - MainWindow w; - w.show (); - if (app) - { - app->exec(); - app.reset (nullptr); - } + if (m_Impl) + { + m_Impl->Run (); + m_Impl = nullptr; + } } } }