mirror of https://github.com/PurpleI2P/i2pd.git
Jeff Becker
9 years ago
14 changed files with 342 additions and 92 deletions
@ -1,2 +1,3 @@
@@ -1,2 +1,3 @@
|
||||
/build-i2pd_qt-Android_armeabi_v7a_GCC_4_9_Qt_5_6_0-Debug/ |
||||
/build-i2pd_qt-Desktop_Qt_5_6_0_GCC_64bit-Debug/ |
||||
/build-i2pd_qt-Android_x86_GCC_4_9_Qt_5_6_0-Debug/ |
||||
|
@ -1,64 +1,87 @@
@@ -1,64 +1,87 @@
|
||||
#include <memory> |
||||
#include "mainwindow.h" |
||||
#include <QApplication> |
||||
#include <stdlib.h> |
||||
#include "DaemonQT.h" |
||||
#include "../../Daemon.h" |
||||
#include <QMutex> |
||||
#include <QMutexLocker> |
||||
|
||||
namespace i2p |
||||
{ |
||||
namespace util |
||||
{ |
||||
class DaemonQTImpl: public std::enable_shared_from_this<DaemonQTImpl> |
||||
{ |
||||
public: |
||||
|
||||
DaemonQTImpl (int argc, char* argv[]): |
||||
m_App (argc, argv) |
||||
{ |
||||
} |
||||
|
||||
void Run () |
||||
bool DaemonQT::init(int argc, char* argv[]) |
||||
{ |
||||
MainWindow w; |
||||
w.show (); |
||||
m_App.exec(); |
||||
return Daemon_Singleton::init(argc, argv); |
||||
} |
||||
} |
||||
} |
||||
|
||||
private: |
||||
namespace i2p |
||||
{ |
||||
namespace qt |
||||
{ |
||||
|
||||
void StartDaemon () |
||||
{ |
||||
Daemon.start (); |
||||
void Worker::startDaemon() { |
||||
qDebug("Performing daemon start..."); |
||||
DaemonQTImpl::start(); |
||||
qDebug("Daemon started."); |
||||
emit resultReady(); |
||||
} |
||||
|
||||
void StopDaemon () |
||||
{ |
||||
Daemon.stop (); |
||||
void Worker::restartDaemon() { |
||||
qDebug("Performing daemon restart..."); |
||||
DaemonQTImpl::restart(); |
||||
qDebug("Daemon restarted."); |
||||
emit resultReady(); |
||||
} |
||||
void Worker::stopDaemon() { |
||||
qDebug("Performing daemon stop..."); |
||||
DaemonQTImpl::stop(); |
||||
qDebug("Daemon stopped."); |
||||
emit resultReady(); |
||||
} |
||||
|
||||
bool IsRunning () const |
||||
{ |
||||
return Daemon.running; |
||||
Controller::Controller() { |
||||
Worker *worker = new Worker; |
||||
worker->moveToThread(&workerThread); |
||||
connect(&workerThread, &QThread::finished, worker, &QObject::deleteLater); |
||||
connect(this, &Controller::startDaemon, worker, &Worker::startDaemon); |
||||
connect(this, &Controller::stopDaemon, worker, &Worker::stopDaemon); |
||||
connect(this, &Controller::restartDaemon, worker, &Worker::restartDaemon); |
||||
connect(worker, &Worker::resultReady, this, &Controller::handleResults); |
||||
workerThread.start(); |
||||
} |
||||
Controller::~Controller() { |
||||
qDebug("Closing and waiting for daemon worker thread..."); |
||||
workerThread.quit(); |
||||
workerThread.wait(); |
||||
qDebug("Waiting for daemon worker thread finished."); |
||||
if(DaemonQTImpl::isRunning()) { |
||||
qDebug("Stopping the daemon..."); |
||||
DaemonQTImpl::stop(); |
||||
qDebug("Stopped the daemon."); |
||||
} |
||||
} |
||||
|
||||
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); |
||||
} |
||||
static DaemonQTImpl::runningChangedCallback DaemonQTImpl_runningChanged; |
||||
static bool DaemonQTImpl_running; |
||||
static QMutex* mutex; |
||||
|
||||
void DaemonQT::run () |
||||
{ |
||||
if (m_Impl) |
||||
{ |
||||
m_Impl->Run (); |
||||
m_Impl = nullptr; |
||||
} |
||||
bool DaemonQTImpl::init(int argc, char* argv[]){mutex=new QMutex(QMutex::Recursive);setRunningCallback(0);DaemonQTImpl_running=false;return Daemon.init(argc,argv);} |
||||
void DaemonQTImpl::deinit(){delete mutex;} |
||||
void DaemonQTImpl::start(){QMutexLocker locker(mutex);setRunning(true);Daemon.start();} |
||||
void DaemonQTImpl::stop(){QMutexLocker locker(mutex);Daemon.stop();setRunning(false);} |
||||
void DaemonQTImpl::restart(){QMutexLocker locker(mutex);stop();start();} |
||||
|
||||
void DaemonQTImpl::setRunningCallback(runningChangedCallback cb){DaemonQTImpl_runningChanged=cb;} |
||||
bool DaemonQTImpl::isRunning(){return DaemonQTImpl_running;} |
||||
void DaemonQTImpl::setRunning(bool newValue){ |
||||
bool oldValue = DaemonQTImpl_running; |
||||
if(oldValue!=newValue) { |
||||
DaemonQTImpl_running = newValue; |
||||
if(DaemonQTImpl_runningChanged!=0)DaemonQTImpl_runningChanged(); |
||||
} |
||||
} |
||||
|
||||
} |
||||
} |
||||
|
||||
|
@ -0,0 +1,63 @@
@@ -0,0 +1,63 @@
|
||||
#ifndef DAEMONQT_H |
||||
#define DAEMONQT_H |
||||
|
||||
#include <QObject> |
||||
#include <QThread> |
||||
|
||||
namespace i2p |
||||
{ |
||||
namespace qt |
||||
{ |
||||
class Worker : public QObject |
||||
{ |
||||
Q_OBJECT |
||||
|
||||
public slots: |
||||
void startDaemon(); |
||||
void restartDaemon(); |
||||
void stopDaemon(); |
||||
|
||||
signals: |
||||
void resultReady(); |
||||
}; |
||||
|
||||
class DaemonQTImpl |
||||
{ |
||||
public: |
||||
typedef void (*runningChangedCallback)(); |
||||
|
||||
/**
|
||||
* @brief init |
||||
* @param argc |
||||
* @param argv |
||||
* @return success |
||||
*/ |
||||
bool static init(int argc, char* argv[]); |
||||
void static deinit(); |
||||
void static start(); |
||||
void static stop(); |
||||
void static restart(); |
||||
void static setRunningCallback(runningChangedCallback cb); |
||||
bool static isRunning(); |
||||
private: |
||||
void static setRunning(bool running); |
||||
}; |
||||
|
||||
class Controller : public QObject |
||||
{ |
||||
Q_OBJECT |
||||
QThread workerThread; |
||||
public: |
||||
Controller(); |
||||
~Controller(); |
||||
public slots: |
||||
void handleResults(){} |
||||
signals: |
||||
void startDaemon(); |
||||
void stopDaemon(); |
||||
void restartDaemon(); |
||||
}; |
||||
} |
||||
} |
||||
|
||||
#endif // DAEMONQT_H
|
@ -0,0 +1,24 @@
@@ -0,0 +1,24 @@
|
||||
#if 0 |
||||
#include "i2pd_qt_gui.h" |
||||
#include <QApplication> |
||||
#include <QMessageBox> |
||||
#include "mainwindow.h" |
||||
#include "DaemonQT.h" |
||||
|
||||
int runGUI( int argc, char* argv[] ) { |
||||
QApplication app(argc, argv); |
||||
bool daemonInitSuccess = i2p::util::DaemonQTImpl::init(argc, argv); |
||||
if(!daemonInitSuccess) { |
||||
QMessageBox::critical(0, "Error", "Daemon init failed"); |
||||
return 1; |
||||
} |
||||
MainWindow w; |
||||
w.show (); |
||||
i2p::util::DaemonQTImpl::start(); |
||||
int result = app.exec(); |
||||
//QMessageBox::information(&w, "Debug", "exec finished");
|
||||
i2p::util::DaemonQTImpl::stop(); |
||||
//QMessageBox::information(&w, "Debug", "demon stopped");
|
||||
return result; |
||||
} |
||||
#endif |
@ -0,0 +1,6 @@
@@ -0,0 +1,6 @@
|
||||
#ifndef IQPD_QT_GUI_H |
||||
#define IQPD_QT_GUI_H |
||||
|
||||
int runGUI( int argc, char* argv[] ); |
||||
|
||||
#endif // IQPD_QT_GUI_H
|
@ -1,14 +1,55 @@
@@ -1,14 +1,55 @@
|
||||
#include "mainwindow.h" |
||||
#include "ui_mainwindow.h" |
||||
//#include "ui_mainwindow.h"
|
||||
#include <QMessageBox> |
||||
|
||||
MainWindow::MainWindow(QWidget *parent) : |
||||
QMainWindow(parent), |
||||
ui(new Ui::MainWindow) |
||||
QMainWindow(parent)/*,
|
||||
ui(new Ui::MainWindow)*/ |
||||
{ |
||||
ui->setupUi(this); |
||||
//ui->setupUi(this);
|
||||
if (objectName().isEmpty()) |
||||
setObjectName(QStringLiteral("MainWindow")); |
||||
resize(800, 480); |
||||
centralWidget = new QWidget(this); |
||||
centralWidget->setObjectName(QStringLiteral("centralWidget")); |
||||
verticalLayoutWidget = new QWidget(centralWidget); |
||||
verticalLayoutWidget->setObjectName(QStringLiteral("verticalLayoutWidget")); |
||||
//verticalLayoutWidget->setGeometry(QRect(10, 20, 771, 441));
|
||||
verticalLayout1 = new QVBoxLayout(verticalLayoutWidget); |
||||
verticalLayout1->setSpacing(6); |
||||
verticalLayout1->setContentsMargins(11, 11, 11, 11); |
||||
verticalLayout1->setObjectName(QStringLiteral("verticalLayout1")); |
||||
verticalLayout1->setContentsMargins(0, 0, 0, 0); |
||||
quitButton = new QPushButton(verticalLayoutWidget); |
||||
quitButton->setObjectName(QStringLiteral("quitButton")); |
||||
QSizePolicy sizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); |
||||
sizePolicy.setHorizontalStretch(0); |
||||
sizePolicy.setVerticalStretch(0); |
||||
sizePolicy.setHeightForWidth(quitButton->sizePolicy().hasHeightForWidth()); |
||||
quitButton->setSizePolicy(sizePolicy); |
||||
|
||||
verticalLayout1->addWidget(quitButton); |
||||
|
||||
setCentralWidget(centralWidget); |
||||
|
||||
setWindowTitle(QApplication::translate("MainWindow", "MainWindow", 0)); |
||||
quitButton->setText(QApplication::translate("MainWindow", "Quit", 0)); |
||||
|
||||
QObject::connect(quitButton, SIGNAL(released()), this, SLOT(handleQuitButton())); |
||||
|
||||
//QMetaObject::connectSlotsByName(this);
|
||||
} |
||||
|
||||
void MainWindow::handleQuitButton() { |
||||
qDebug("Quit pressed. Hiding the main window"); |
||||
close(); |
||||
QApplication::instance()->quit(); |
||||
} |
||||
|
||||
MainWindow::~MainWindow() |
||||
{ |
||||
delete ui; |
||||
qDebug("Destroying main window"); |
||||
//QMessageBox::information(0, "Debug", "mw destructor 1");
|
||||
//delete ui;
|
||||
//QMessageBox::information(0, "Debug", "mw destructor 2");
|
||||
} |
||||
|
Loading…
Reference in new issue