mirror of
https://gitlab.linphone.org/BC/public/linphone-desktop.git
synced 2026-01-24 23:28:09 +00:00
feat(app): use system tray
This commit is contained in:
parent
77f59f13d4
commit
9b78b2e124
6 changed files with 41 additions and 6 deletions
|
|
@ -7,7 +7,7 @@ for filename in $(find languages/ ui/ imgs/ -type f)
|
|||
do
|
||||
extension="${filename##*.}"
|
||||
|
||||
if [[ "${extension}" == @(qml|svg|qm|js) ]]; then
|
||||
if [[ "${extension}" == @(qml|svg|png|qm|js) ]]; then
|
||||
echo " <file>$filename</file>"
|
||||
fi
|
||||
done
|
||||
|
|
|
|||
BIN
tests/imgs/linphone.png
Normal file
BIN
tests/imgs/linphone.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.7 KiB |
|
|
@ -39,6 +39,7 @@
|
|||
<file>imgs/led_disconnected.svg</file>
|
||||
<file>imgs/valid.svg</file>
|
||||
<file>imgs/incoming_call.svg</file>
|
||||
<file>imgs/linphone.png</file>
|
||||
<file>imgs/led_do_not_disturb.svg</file>
|
||||
<file>imgs/lost_incoming_call.svg</file>
|
||||
<file>imgs/conference.svg</file>
|
||||
|
|
|
|||
|
|
@ -1,19 +1,21 @@
|
|||
#include <cstdlib>
|
||||
|
||||
#include <QIcon>
|
||||
#include <QtDebug>
|
||||
|
||||
#include "app.hpp"
|
||||
|
||||
#define LANGUAGES_PATH ":/languages/"
|
||||
|
||||
// ===================================================================
|
||||
|
||||
App::App(int &argc, char **argv) : QGuiApplication(argc, argv) {
|
||||
// Try to enable system translation by default. (else english)
|
||||
App::App (int &argc, char **argv) : QApplication(argc, argv) {
|
||||
// Try to use default locale.
|
||||
if (m_translator.load(QString(LANGUAGES_PATH) + QLocale::system().name()) ||
|
||||
m_translator.load(LANGUAGES_PATH "en")) {
|
||||
this->installTranslator(&m_translator);
|
||||
} else {
|
||||
qWarning() << "No translation found.";
|
||||
}
|
||||
|
||||
this->setWindowIcon(QIcon(":/imgs/linphone.png"));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +1,17 @@
|
|||
#ifndef APP_H_
|
||||
#define APP_H_
|
||||
|
||||
#include <QGuiApplication>
|
||||
#include <QApplication>
|
||||
#include <QTranslator>
|
||||
|
||||
// TODO: Make it Singleton.
|
||||
class App : public QGuiApplication {
|
||||
class App : public QApplication {
|
||||
public:
|
||||
App (int &argc, char **argv);
|
||||
virtual ~App () {}
|
||||
|
||||
private slots:
|
||||
|
||||
private:
|
||||
QTranslator m_translator;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,11 +1,36 @@
|
|||
#include <cstdlib>
|
||||
|
||||
#include <QMenu>
|
||||
#include <QQmlApplicationEngine>
|
||||
#include <QSystemTrayIcon>
|
||||
#include <QtDebug>
|
||||
|
||||
#include "app.hpp"
|
||||
|
||||
// ===================================================================
|
||||
|
||||
void createSystemTrayIcon (QQmlApplicationEngine &engine) {
|
||||
QObject *root = 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);
|
||||
|
||||
QAction *restoreAction = new QAction(QObject::tr("Restore")), root);
|
||||
root->connect(restoreAction, SIGNAL(triggered()), root, SLOT(showNormal()));
|
||||
|
||||
menu->addAction(restoreAction);
|
||||
menu->addSeparator();
|
||||
menu->addAction(quitAction);
|
||||
|
||||
tray_icon->setContextMenu(menu);
|
||||
tray_icon->setIcon(QIcon(":/imgs/linphone.png"));
|
||||
tray_icon->show();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int main (int argc, char *argv[]) {
|
||||
App app(argc, argv);
|
||||
QQmlApplicationEngine engine(QUrl("qrc:/ui/views/mainWindow/mainWindow.qml"));
|
||||
|
|
@ -13,5 +38,10 @@ 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();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue