Browse Source

separate DaemonQT and DaemonQTImpl

pull/520/head
orignal 9 years ago
parent
commit
eb96edbd31
  1. 8
      Daemon.h
  2. 51
      qt/i2pd_qt/DaemonQT.cpp

8
Daemon.h

@ -1,6 +1,7 @@
#ifndef DAEMON_H__ #ifndef DAEMON_H__
#define DAEMON_H__ #define DAEMON_H__
#include <memory>
#include <string> #include <string>
namespace i2p namespace i2p
@ -32,6 +33,7 @@ namespace i2p
#if defined(QT_GUI_LIB) // check if QT #if defined(QT_GUI_LIB) // check if QT
#define Daemon i2p::util::DaemonQT::Instance() #define Daemon i2p::util::DaemonQT::Instance()
class DaemonQTImpl;
class DaemonQT: public i2p::util::Daemon_Singleton class DaemonQT: public i2p::util::Daemon_Singleton
{ {
public: public:
@ -43,9 +45,11 @@ namespace i2p
} }
bool init(int argc, char* argv[]); bool init(int argc, char* argv[]);
bool start();
bool stop();
void run (); void run ();
private:
std::shared_ptr<DaemonQTImpl> m_Impl;
}; };
#elif defined(_WIN32) #elif defined(_WIN32)

51
qt/i2pd_qt/DaemonQT.cpp

@ -8,31 +8,56 @@ namespace i2p
{ {
namespace util namespace util
{ {
std::unique_ptr<QApplication> app; class DaemonQTImpl: public std::enable_shared_from_this<DaemonQTImpl>
bool DaemonQT::init(int argc, char* argv[])
{ {
app.reset (new QApplication (argc, argv)); public:
return Daemon_Singleton::init(argc, argv);
DaemonQTImpl (int argc, char* argv[]):
m_App (argc, argv)
{
}
void Run ()
{
MainWindow w;
w.show ();
m_App.exec();
}
private:
void StartDaemon ()
{
Daemon.start ();
} }
bool DaemonQT::start() void StopDaemon ()
{ {
return Daemon_Singleton::start(); Daemon.stop ();
} }
bool DaemonQT::stop() bool IsRunning () const
{ {
return Daemon_Singleton::stop(); return Daemon.running;
}
private:
QApplication m_App;
};
bool DaemonQT::init(int argc, char* argv[])
{
m_Impl = std::make_shared<DaemonQTImpl> (argc, argv);
return Daemon_Singleton::init(argc, argv);
} }
void DaemonQT::run () void DaemonQT::run ()
{ {
MainWindow w; if (m_Impl)
w.show ();
if (app)
{ {
app->exec(); m_Impl->Run ();
app.reset (nullptr); m_Impl = nullptr;
} }
} }
} }

Loading…
Cancel
Save