qt: daemon now operates in the background thread; added Quit GUI button

This commit is contained in:
hypnosis-i2p 2016-06-17 21:49:49 +08:00
parent 3e912c6198
commit 1b35f68de9
12 changed files with 360 additions and 43 deletions

View file

@ -1,15 +1,54 @@
#include <stdlib.h>
#include "Daemon.h"
#ifndef ANDROID
# include <stdlib.h>
# include "Daemon.h"
#else
# include "qt/i2pd_qt/i2pd_qt_gui.h"
# include <QMessageBox>
# include <QApplication>
# include "DaemonQT.h"
# include "mainwindow.h"
# include <QThread>
#endif
int main( int argc, char* argv[] )
{
if (Daemon.init(argc, argv))
#ifdef ANDROID
//int result = runGUI(argc, argv);
//QMessageBox::information(0,"Debug","runGUI completed");
QApplication app(argc, argv);
qDebug("Initialising the daemon...");
bool daemonInitSuccess = i2p::util::DaemonQt::DaemonQTImpl::init(argc, argv);
if(!daemonInitSuccess) {
QMessageBox::critical(0, "Error", "Daemon init failed");
return 1;
}
qDebug("Initialised, creating the main window...");
MainWindow w;
qDebug("Before main window.show()...");
w.show ();
int result;
{
i2p::util::DaemonQt::Controller daemonQtController;
qDebug("Starting the daemon...");
emit daemonQtController.startDaemon();
qDebug("Starting gui event loop...");
result = app.exec();
//QMessageBox::information(&w, "Debug", "exec finished");
}
i2p::util::DaemonQt::DaemonQTImpl::deinit();
//QMessageBox::information(&w, "Debug", "demon stopped");
//exit(result); //return from main() causes intermittent sigsegv bugs in some Androids. exit() is a workaround for this
qDebug("Exiting the application");
return result;
#else
if (Daemon.init(argc, argv))
{
if (Daemon.start())
Daemon.run ();
Daemon.stop();
}
return EXIT_SUCCESS;
#endif
}
#ifdef _WIN32