Commit 9b78b2e1 authored by Ronan's avatar Ronan
Browse files

feat(app): use system tray

parent 77f59f13
......@@ -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
......
......@@ -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>
......
#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"));
}
#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;
};
......
#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();
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment