mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2024-11-16 00:12:43 +00:00
Merge pull request #539 from hypnosis-i2p/openssl
added tray icon to linux and windows versions
This commit is contained in:
commit
0d229175cd
1
qt/i2pd_qt/.gitignore
vendored
Normal file
1
qt/i2pd_qt/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
i2pd_qt.pro.user*
|
5
qt/i2pd_qt/i2pd.qrc
Normal file
5
qt/i2pd_qt/i2pd.qrc
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<!DOCTYPE RCC><RCC version="1.0">
|
||||||
|
<qresource prefix="/">
|
||||||
|
<file>images/icon.png</file>
|
||||||
|
</qresource>
|
||||||
|
</RCC>
|
@ -202,3 +202,13 @@ message("Using Linux settings")
|
|||||||
LIBS += -lcrypto -lssl -lboost_system -lboost_date_time -lboost_filesystem -lboost_program_options -lpthread -lminiupnpc
|
LIBS += -lcrypto -lssl -lboost_system -lboost_date_time -lboost_filesystem -lboost_program_options -lpthread -lminiupnpc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
!android:!symbian:!maemo5:!simulator {
|
||||||
|
message("Build with a system tray icon")
|
||||||
|
# see also http://doc.qt.io/qt-4.8/qt-desktop-systray-systray-pro.html for example on wince*
|
||||||
|
#sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS i2pd_qt.pro resources images
|
||||||
|
RESOURCES = i2pd.qrc
|
||||||
|
QT += xml
|
||||||
|
#INSTALLS += sources
|
||||||
|
}
|
||||||
|
|
||||||
|
BIN
qt/i2pd_qt/images/icon.png
Normal file
BIN
qt/i2pd_qt/images/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 8.5 KiB |
@ -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();
|
||||||
|
@ -12,6 +12,11 @@
|
|||||||
#include <QtWidgets/QPushButton>
|
#include <QtWidgets/QPushButton>
|
||||||
#include <QtWidgets/QVBoxLayout>
|
#include <QtWidgets/QVBoxLayout>
|
||||||
#include <QtWidgets/QWidget>
|
#include <QtWidgets/QWidget>
|
||||||
|
#ifndef ANDROID
|
||||||
|
#include <QSystemTrayIcon>
|
||||||
|
#include <QCloseEvent>
|
||||||
|
#include <QMenu>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class MainWindow;
|
class MainWindow;
|
||||||
@ -25,17 +30,43 @@ public:
|
|||||||
explicit MainWindow(QWidget *parent = 0);
|
explicit MainWindow(QWidget *parent = 0);
|
||||||
~MainWindow();
|
~MainWindow();
|
||||||
|
|
||||||
|
//#ifndef ANDROID
|
||||||
|
// void setVisible(bool visible);
|
||||||
|
//#endif
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void handleQuitButton();
|
void handleQuitButton();
|
||||||
void handleGracefulQuitButton();
|
void handleGracefulQuitButton();
|
||||||
void handleGracefulQuitTimerEvent();
|
void handleGracefulQuitTimerEvent();
|
||||||
|
#ifndef ANDROID
|
||||||
|
void setIcon();
|
||||||
|
void iconActivated(QSystemTrayIcon::ActivationReason reason);
|
||||||
|
void toggleVisibilitySlot();
|
||||||
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
#ifndef ANDROID
|
||||||
|
void createActions();
|
||||||
|
void createTrayIcon();
|
||||||
|
#endif
|
||||||
|
|
||||||
QWidget *centralWidget;
|
QWidget *centralWidget;
|
||||||
QWidget *verticalLayoutWidget;
|
QWidget *verticalLayoutWidget;
|
||||||
QVBoxLayout *verticalLayout1;
|
QVBoxLayout *verticalLayout1;
|
||||||
QPushButton *quitButton;
|
QPushButton *quitButton;
|
||||||
QPushButton *gracefulQuitButton;
|
QPushButton *gracefulQuitButton;
|
||||||
|
|
||||||
|
#ifndef ANDROID
|
||||||
|
bool quitting;
|
||||||
|
QAction *toggleWindowVisibleAction;
|
||||||
|
QSystemTrayIcon *trayIcon;
|
||||||
|
QMenu *trayIconMenu;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
protected:
|
||||||
|
#ifndef ANDROID
|
||||||
|
void closeEvent(QCloseEvent *event);
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
Loading…
Reference in New Issue
Block a user