mirror of
https://gitlab.linphone.org/BC/public/linphone-desktop.git
synced 2026-01-23 14:48:15 +00:00
feat(app): close main window reduce app in notifications area
This commit is contained in:
parent
be082fa20f
commit
93c4aeea5f
2 changed files with 29 additions and 21 deletions
|
|
@ -2,6 +2,7 @@ QT = core gui quick widgets quickcontrols2
|
|||
|
||||
TARGET = linphone
|
||||
TEMPLATE = app
|
||||
CONFIG += c++11
|
||||
|
||||
SOURCES = \
|
||||
src/app.cpp \
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <QMenu>
|
||||
#include <QQmlApplicationEngine>
|
||||
#include <QQuickView>
|
||||
#include <QSystemTrayIcon>
|
||||
#include <QtDebug>
|
||||
|
||||
|
|
@ -9,26 +10,37 @@
|
|||
|
||||
// ===================================================================
|
||||
|
||||
void createSystemTrayIcon (QQmlApplicationEngine &engine) {
|
||||
QObject *root = engine.rootObjects().at(0);
|
||||
QMenu *menu = new QMenu();
|
||||
QSystemTrayIcon *tray_icon = new QSystemTrayIcon(root);
|
||||
int exec (App &app, QQmlApplicationEngine &engine) {
|
||||
if (!QSystemTrayIcon::isSystemTrayAvailable())
|
||||
qWarning() << "System tray not found on this system.";
|
||||
else {
|
||||
QQuickWindow *root = qobject_cast<QQuickWindow *>(engine.rootObjects().at(0));
|
||||
QMenu *menu = new QMenu();
|
||||
QSystemTrayIcon *tray_icon = new QSystemTrayIcon(root);
|
||||
|
||||
QAction *quitAction = new QAction(QObject::tr("Quit"), root);
|
||||
root->connect(quitAction, &QAction::triggered, qApp, &QCoreApplication::quit);
|
||||
// Right click actions.
|
||||
QAction *quitAction = new QAction(QObject::tr("Quit"), root);
|
||||
root->connect(quitAction, &QAction::triggered, qApp, &QCoreApplication::quit);
|
||||
|
||||
QAction *restoreAction = new QAction(QObject::tr("Restore"), root);
|
||||
root->connect(restoreAction, SIGNAL(triggered()), root, SLOT(showNormal()));
|
||||
QAction *restoreAction = new QAction(QObject::tr("Restore"), root);
|
||||
root->connect(restoreAction, &QAction::triggered, root, &QQuickWindow::showNormal);
|
||||
|
||||
menu->addAction(restoreAction);
|
||||
menu->addSeparator();
|
||||
menu->addAction(quitAction);
|
||||
// Left click action.
|
||||
root->connect(tray_icon, &QSystemTrayIcon::activated, [&root](QSystemTrayIcon::ActivationReason reason) {
|
||||
if (reason == QSystemTrayIcon::DoubleClick)
|
||||
root->showNormal();
|
||||
});
|
||||
|
||||
tray_icon->setContextMenu(menu);
|
||||
tray_icon->setIcon(QIcon(":/imgs/linphone.png"));
|
||||
tray_icon->show();
|
||||
menu->addAction(restoreAction);
|
||||
menu->addSeparator();
|
||||
menu->addAction(quitAction);
|
||||
|
||||
return;
|
||||
tray_icon->setContextMenu(menu);
|
||||
tray_icon->setIcon(QIcon(":/imgs/linphone.png"));
|
||||
tray_icon->show();
|
||||
}
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
|
||||
int main (int argc, char *argv[]) {
|
||||
|
|
@ -38,10 +50,5 @@ int main (int argc, char *argv[]) {
|
|||
if (engine.rootObjects().isEmpty())
|
||||
return EXIT_FAILURE;
|
||||
|
||||
if (!QSystemTrayIcon::isSystemTrayAvailable())
|
||||
qWarning() << "System tray not found on this system.";
|
||||
else
|
||||
createSystemTrayIcon(engine);
|
||||
|
||||
return app.exec();
|
||||
return exec(app, engine);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue