Browse Source

Dissect DaemonQT.* into the app launcher and daemon controller

pull/82/head
nonlin-lin-chaos-order-etc-etal 2 years ago
parent
commit
af1d09d0b1
  1. 6
      i2pd_qt.pro
  2. 54
      src/controller/i2pd_daemon_controller.cpp
  3. 6
      src/controller/i2pd_daemon_controller.h
  4. 65
      src/launcher/i2pd_qt_launcher.cpp
  5. 10
      src/launcher/i2pd_qt_launcher.h
  6. 3
      src/mainwindow.cpp
  7. 3
      src/mainwindow.h

6
i2pd_qt.pro

@ -38,7 +38,8 @@ CONFIG(release, debug|release) { @@ -38,7 +38,8 @@ CONFIG(release, debug|release) {
}
SOURCES += \
src/DaemonQT.cpp \
src/launcher/i2pd_qt_launcher.cpp \
src/controller/i2pd_daemon_controller.cpp \
src/MutexWrapperLock.cpp \
src/mainwindow.cpp \
src/ClientTunnelPane.cpp \
@ -67,7 +68,8 @@ SOURCES += \ @@ -67,7 +68,8 @@ SOURCES += \
HEADERS += \
src/ConcurrentHolder.h \
src/DaemonQT.h \
src/launcher/i2pd_qt_launcher.h \
src/controller/i2pd_daemon_controller.h \
src/MutexWrapperLock.h \
src/mainwindow.h \
src/ClientTunnelPane.h \

54
src/DaemonQT.cpp → src/controller/i2pd_daemon_controller.cpp

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
#include <memory>
#include "DaemonQT.h"
#include "controller/i2pd_daemon_controller.h"
#include "Daemon.h"
#include "mainwindow.h"
@ -11,12 +11,8 @@ @@ -11,12 +11,8 @@
#include <QMutexLocker>
#include <QThread>
//#define DEBUG_WITH_DEFAULT_LOGGING (1)
namespace i2p
{
namespace qt
{
namespace i2p {
namespace qt {
Worker::Worker (DaemonQTImpl& daemon):
m_Daemon (daemon)
{
@ -146,50 +142,6 @@ namespace qt @@ -146,50 +142,6 @@ namespace qt
m_RunningChangedCallback();
}
}
int RunQT (int argc, char* argv[])
{
QApplication app(argc, argv);
int result;
{
std::shared_ptr<std::iostream> logstreamptr=
#ifdef DEBUG_WITH_DEFAULT_LOGGING
nullptr
#else
std::make_shared<std::stringstream>()
#endif
;
//TODO move daemon init deinit to a bg thread
DaemonQTImpl daemon;
if(logstreamptr) (*logstreamptr) << "Initialising the daemon..." << std::endl;
bool daemonInitSuccess = daemon.init(argc, argv, logstreamptr);
if(!daemonInitSuccess)
{
QMessageBox::critical(0, "Error", "Daemon init failed");
return 1;
}
LogPrint(eLogDebug, "Initialised, creating the main window...");
MainWindow w(logstreamptr);
LogPrint(eLogDebug, "Before main window.show()...");
w.show ();
{
i2p::qt::Controller daemonQtController(daemon);
w.setI2PController(&daemonQtController);
LogPrint(eLogDebug, "Starting the daemon...");
emit daemonQtController.startDaemon();
//daemon.start ();
LogPrint(eLogDebug, "Starting GUI event loop...");
result = app.exec();
//daemon.stop ();
}
}
//QMessageBox::information(&w, "Debug", "demon stopped");
LogPrint(eLogDebug, "Exiting the application");
return result;
}
}
}

6
src/DaemonQT.h → src/controller/i2pd_daemon_controller.h

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
#ifndef DAEMONQT_H
#define DAEMONQT_H
#ifndef I2PD_DAEMON_CONTROLLER_H
#define I2PD_DAEMON_CONTROLLER_H
#include <memory>
#include <QObject>
@ -85,4 +85,4 @@ namespace qt @@ -85,4 +85,4 @@ namespace qt
}
}
#endif // DAEMONQT_H
#endif // I2PD_DAEMON_CONTROLLER_H

65
src/launcher/i2pd_qt_launcher.cpp

@ -0,0 +1,65 @@ @@ -0,0 +1,65 @@
#include <memory>
#include "launcher/i2pd_qt_launcher.h"
#include "controller/i2pd_daemon_controller.h"
#include "Daemon.h"
#include "mainwindow.h"
#include "Log.h"
#include <QMessageBox>
#include <QApplication>
#include <QMutexLocker>
#include <QThread>
//#define DEBUG_WITH_DEFAULT_LOGGING (1)
namespace i2p {
namespace qt {
//TODO rework for clean MVC
int RunQT (int argc, char* argv[]) {
QApplication app(argc, argv);
int result;
{
std::shared_ptr<std::iostream> logstreamptr =
#ifdef DEBUG_WITH_DEFAULT_LOGGING
nullptr
#else
std::make_shared<std::stringstream>()
#endif
;
//TODO move daemon init deinit to a bg thread
DaemonQTImpl daemon;
if (logstreamptr) (*logstreamptr) << "Initialising the daemon..." << std::endl;
bool daemonInitSuccess = daemon.init(argc, argv, logstreamptr);
if (!daemonInitSuccess) {
QMessageBox::critical(0, "Error", "Daemon init failed");
return 1;
}
LogPrint(eLogDebug, "Initialised, creating the main window...");
MainWindow w(logstreamptr);
LogPrint(eLogDebug, "Before main window.show()...");
w.show ();
{
i2p::qt::Controller daemonQtController(daemon);
w.setI2PController(&daemonQtController);
LogPrint(eLogDebug, "Starting the daemon...");
emit daemonQtController.startDaemon();
//daemon.start ();
LogPrint(eLogDebug, "Starting GUI event loop...");
result = app.exec();
//daemon.stop ();
}
}
//QMessageBox::information(&w, "Debug", "demon stopped");
LogPrint(eLogDebug, "Exiting the application");
return result;
}
}
}

10
src/launcher/i2pd_qt_launcher.h

@ -0,0 +1,10 @@ @@ -0,0 +1,10 @@
#ifndef I2PD_QT_LAUNCHER_H
#define I2PD_QT_LAUNCHER_H
namespace i2p {
namespace qt {
int RunQT (int argc, char* argv[]);
}
}
#endif // I2PD_QT_LAUNCHER_H

3
src/mainwindow.cpp

@ -33,7 +33,8 @@ @@ -33,7 +33,8 @@
# include <QtDebug>
#endif
#include "DaemonQT.h"
#include "controller/i2pd_daemon_controller.h"
#include "SignatureTypeComboboxFactory.h"
#include "logviewermanager.h"

3
src/mainwindow.h

@ -56,7 +56,8 @@ @@ -56,7 +56,8 @@
#include "TunnelsPageUpdateListener.h"
#include "DaemonQT.h"
#include "controller/i2pd_daemon_controller.h"
#include "SignatureTypeComboboxFactory.h"
#include "pagewithbackbutton.h"

Loading…
Cancel
Save