Commit 64e3c942 authored by Ronan Abhamon's avatar Ronan Abhamon

feat(main): better code

parent 92c948a2
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include <QIcon> #include <QIcon>
#include <QtDebug> #include <QtDebug>
#include "app.hpp" #include "app.hpp"
#define LANGUAGES_PATH ":/languages/" #define LANGUAGES_PATH ":/languages/"
......
...@@ -4,14 +4,11 @@ ...@@ -4,14 +4,11 @@
#include <QApplication> #include <QApplication>
#include <QTranslator> #include <QTranslator>
// TODO: Make it Singleton.
class App : public QApplication { class App : public QApplication {
public: public:
App (int &argc, char **argv); App (int &argc, char **argv);
virtual ~App () {} virtual ~App () {}
private slots:
private: private:
QTranslator m_translator; QTranslator m_translator;
}; };
......
...@@ -12,10 +12,7 @@ ...@@ -12,10 +12,7 @@
// =================================================================== // ===================================================================
int exec (App &app, QQmlApplicationEngine &engine) { void setTrayIcon (QQmlApplicationEngine &engine) {
if (!QSystemTrayIcon::isSystemTrayAvailable())
qWarning() << "System tray not found on this system.";
QQuickWindow *root = qobject_cast<QQuickWindow *>(engine.rootObjects().at(0)); QQuickWindow *root = qobject_cast<QQuickWindow *>(engine.rootObjects().at(0));
QMenu *menu = new QMenu(); QMenu *menu = new QMenu();
QSystemTrayIcon *tray_icon = new QSystemTrayIcon(root); QSystemTrayIcon *tray_icon = new QSystemTrayIcon(root);
...@@ -28,7 +25,7 @@ int exec (App &app, QQmlApplicationEngine &engine) { ...@@ -28,7 +25,7 @@ int exec (App &app, QQmlApplicationEngine &engine) {
root->connect(restore_action, &QAction::triggered, root, &QQuickWindow::showNormal); root->connect(restore_action, &QAction::triggered, root, &QQuickWindow::showNormal);
// trayIcon: Left click actions. // trayIcon: Left click actions.
root->connect(tray_icon, &QSystemTrayIcon::activated, [&root](QSystemTrayIcon::ActivationReason reason) { root->connect(tray_icon, &QSystemTrayIcon::activated, [root](QSystemTrayIcon::ActivationReason reason) {
if (reason == QSystemTrayIcon::Trigger) { if (reason == QSystemTrayIcon::Trigger) {
if (root->visibility() == QWindow::Hidden) if (root->visibility() == QWindow::Hidden)
root->showNormal(); root->showNormal();
...@@ -46,13 +43,6 @@ int exec (App &app, QQmlApplicationEngine &engine) { ...@@ -46,13 +43,6 @@ int exec (App &app, QQmlApplicationEngine &engine) {
tray_icon->setIcon(QIcon(":/imgs/linphone.png")); tray_icon->setIcon(QIcon(":/imgs/linphone.png"));
tray_icon->setToolTip("Linphone"); tray_icon->setToolTip("Linphone");
tray_icon->show(); tray_icon->show();
// Warning: Add global context Notification for all views!
NotificationModel notification;
engine.rootContext()->setContextProperty("Notification", &notification);
// Run.
return app.exec();
} }
int main (int argc, char *argv[]) { int main (int argc, char *argv[]) {
...@@ -62,5 +52,16 @@ int main (int argc, char *argv[]) { ...@@ -62,5 +52,16 @@ int main (int argc, char *argv[]) {
if (engine.rootObjects().isEmpty()) if (engine.rootObjects().isEmpty())
return EXIT_FAILURE; return EXIT_FAILURE;
return exec(app, engine); // Enable TrayIconSystem.
if (!QSystemTrayIcon::isSystemTrayAvailable())
qWarning() << "System tray not found on this system.";
else
setTrayIcon(engine);
// Warning: Add global context Notification for all views!
NotificationModel notification;
engine.rootContext()->setContextProperty("Notification", &notification);
// Run!
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