|
|
@ -3,10 +3,14 @@ |
|
|
|
#include <QMessageBox> |
|
|
|
#include <QMessageBox> |
|
|
|
#include <QTimer> |
|
|
|
#include <QTimer> |
|
|
|
#include "../../RouterContext.h" |
|
|
|
#include "../../RouterContext.h" |
|
|
|
|
|
|
|
#ifndef ANDROID |
|
|
|
|
|
|
|
#include <QtDebug> |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
MainWindow::MainWindow(QWidget *parent) : |
|
|
|
MainWindow::MainWindow(QWidget *parent) : |
|
|
|
QMainWindow(parent)/*,
|
|
|
|
QMainWindow(parent)/*,
|
|
|
|
ui(new Ui::MainWindow)*/ |
|
|
|
ui(new Ui::MainWindow)*/, |
|
|
|
|
|
|
|
quitting(false) |
|
|
|
{ |
|
|
|
{ |
|
|
|
//ui->setupUi(this);
|
|
|
|
//ui->setupUi(this);
|
|
|
|
if (objectName().isEmpty()) |
|
|
|
if (objectName().isEmpty()) |
|
|
@ -41,18 +45,91 @@ MainWindow::MainWindow(QWidget *parent) : |
|
|
|
|
|
|
|
|
|
|
|
setCentralWidget(centralWidget); |
|
|
|
setCentralWidget(centralWidget); |
|
|
|
|
|
|
|
|
|
|
|
setWindowTitle(QApplication::translate("MainWindow", "MainWindow", 0)); |
|
|
|
setWindowTitle(QApplication::translate("MainWindow", "i2pd", 0)); |
|
|
|
quitButton->setText(QApplication::translate("MainWindow", "Quit", 0)); |
|
|
|
quitButton->setText(QApplication::translate("MainWindow", "Quit", 0)); |
|
|
|
gracefulQuitButton->setText(QApplication::translate("MainWindow", "Graceful Quit", 0)); |
|
|
|
gracefulQuitButton->setText(QApplication::translate("MainWindow", "Graceful Quit", 0)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef ANDROID |
|
|
|
|
|
|
|
createActions(); |
|
|
|
|
|
|
|
createTrayIcon(); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
QObject::connect(quitButton, SIGNAL(released()), this, SLOT(handleQuitButton())); |
|
|
|
QObject::connect(quitButton, SIGNAL(released()), this, SLOT(handleQuitButton())); |
|
|
|
QObject::connect(gracefulQuitButton, SIGNAL(released()), this, SLOT(handleGracefulQuitButton())); |
|
|
|
QObject::connect(gracefulQuitButton, SIGNAL(released()), this, SLOT(handleGracefulQuitButton())); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef ANDROID |
|
|
|
|
|
|
|
QObject::connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), |
|
|
|
|
|
|
|
this, SLOT(iconActivated(QSystemTrayIcon::ActivationReason))); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setIcon(); |
|
|
|
|
|
|
|
trayIcon->show(); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
//QMetaObject::connectSlotsByName(this);
|
|
|
|
//QMetaObject::connectSlotsByName(this);
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef ANDROID |
|
|
|
|
|
|
|
void MainWindow::createActions() { |
|
|
|
|
|
|
|
toggleWindowVisibleAction = new QAction(tr("&Toggle the window"), this); |
|
|
|
|
|
|
|
connect(toggleWindowVisibleAction, SIGNAL(triggered()), this, SLOT(toggleVisibilitySlot())); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//quitAction = new QAction(tr("&Quit"), this);
|
|
|
|
|
|
|
|
//connect(quitAction, SIGNAL(triggered()), QApplication::instance(), SLOT(quit()));
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MainWindow::toggleVisibilitySlot() { |
|
|
|
|
|
|
|
setVisible(!isVisible()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MainWindow::createTrayIcon() { |
|
|
|
|
|
|
|
trayIconMenu = new QMenu(this); |
|
|
|
|
|
|
|
trayIconMenu->addAction(toggleWindowVisibleAction); |
|
|
|
|
|
|
|
//trayIconMenu->addSeparator();
|
|
|
|
|
|
|
|
//trayIconMenu->addAction(quitAction);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
trayIcon = new QSystemTrayIcon(this); |
|
|
|
|
|
|
|
trayIcon->setContextMenu(trayIconMenu); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MainWindow::setIcon() { |
|
|
|
|
|
|
|
QIcon icon(":/images/icon.png"); |
|
|
|
|
|
|
|
trayIcon->setIcon(icon); |
|
|
|
|
|
|
|
setWindowIcon(icon); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
trayIcon->setToolTip(QApplication::translate("MainWindow", "i2pd", 0)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MainWindow::iconActivated(QSystemTrayIcon::ActivationReason reason) { |
|
|
|
|
|
|
|
switch (reason) { |
|
|
|
|
|
|
|
case QSystemTrayIcon::Trigger: |
|
|
|
|
|
|
|
case QSystemTrayIcon::DoubleClick: |
|
|
|
|
|
|
|
case QSystemTrayIcon::MiddleClick: |
|
|
|
|
|
|
|
setVisible(!isVisible()); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
qDebug() << "MainWindow::iconActivated(): unknown reason: " << reason << endl; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MainWindow::closeEvent(QCloseEvent *event) { |
|
|
|
|
|
|
|
if(quitting){ QMainWindow::closeEvent(event); return; } |
|
|
|
|
|
|
|
if (trayIcon->isVisible()) { |
|
|
|
|
|
|
|
QMessageBox::information(this, tr("i2pd"), |
|
|
|
|
|
|
|
tr("The program will keep running in the " |
|
|
|
|
|
|
|
"system tray. To gracefully terminate the program, " |
|
|
|
|
|
|
|
"choose <b>Graceful Quit</b> at the main i2pd window.")); |
|
|
|
|
|
|
|
hide(); |
|
|
|
|
|
|
|
event->ignore(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
void MainWindow::handleQuitButton() { |
|
|
|
void MainWindow::handleQuitButton() { |
|
|
|
qDebug("Quit pressed. Hiding the main window"); |
|
|
|
qDebug("Quit pressed. Hiding the main window"); |
|
|
|
|
|
|
|
#ifndef ANDROID |
|
|
|
|
|
|
|
quitting=true; |
|
|
|
|
|
|
|
#endif |
|
|
|
close(); |
|
|
|
close(); |
|
|
|
QApplication::instance()->quit(); |
|
|
|
QApplication::instance()->quit(); |
|
|
|
} |
|
|
|
} |
|
|
@ -69,6 +146,9 @@ void MainWindow::handleGracefulQuitButton() { |
|
|
|
|
|
|
|
|
|
|
|
void MainWindow::handleGracefulQuitTimerEvent() { |
|
|
|
void MainWindow::handleGracefulQuitTimerEvent() { |
|
|
|
qDebug("Hiding the main window"); |
|
|
|
qDebug("Hiding the main window"); |
|
|
|
|
|
|
|
#ifndef ANDROID |
|
|
|
|
|
|
|
quitting=true; |
|
|
|
|
|
|
|
#endif |
|
|
|
close(); |
|
|
|
close(); |
|
|
|
qDebug("Performing quit"); |
|
|
|
qDebug("Performing quit"); |
|
|
|
QApplication::instance()->quit(); |
|
|
|
QApplication::instance()->quit(); |
|
|
|