From 92c948a2e68130a8fff5dbcef6a8000def77bea3 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Tue, 20 Sep 2016 11:47:21 +0200 Subject: [PATCH] feat(app): `Notification` component is exposed globally in qml --- tests/linphone.pro | 4 +++- tests/src/main.cpp | 20 ++++++++-------- .../models/notification/NotificationModel.cpp | 20 ++++++++++++++++ .../models/notification/NotificationModel.hpp | 23 +++++++++++++++++++ 4 files changed, 57 insertions(+), 10 deletions(-) create mode 100644 tests/src/models/notification/NotificationModel.cpp create mode 100644 tests/src/models/notification/NotificationModel.hpp diff --git a/tests/linphone.pro b/tests/linphone.pro index 3a5a33afc..5bb80b85b 100644 --- a/tests/linphone.pro +++ b/tests/linphone.pro @@ -7,11 +7,13 @@ CONFIG += c++11 SOURCES = \ src/app.cpp \ src/main.cpp \ + src/models/notification/NotificationModel.cpp \ src/models/settings/AccountSettingsModel.cpp \ src/models/settings/SettingsModel.cpp HEADERS = \ - src/app.hpp \ +src/app.hpp \ + src/models/notification/NotificationModel.hpp \ src/models/settings/AccountSettingsModel.hpp \ src/models/settings/SettingsModel.hpp diff --git a/tests/src/main.cpp b/tests/src/main.cpp index e252273a8..b5a6d6ef0 100644 --- a/tests/src/main.cpp +++ b/tests/src/main.cpp @@ -8,6 +8,7 @@ #include #include "app.hpp" +#include "models/notification/NotificationModel.hpp" // =================================================================== @@ -19,15 +20,12 @@ int exec (App &app, QQmlApplicationEngine &engine) { QMenu *menu = new QMenu(); QSystemTrayIcon *tray_icon = new QSystemTrayIcon(root); - // Warning: Add global context trayIcon for all views! - engine.rootContext()->setContextProperty("trayIcon", tray_icon); - // trayIcon: Right click actions. - QAction *quitAction = new QAction(QObject::tr("Quit"), root); - root->connect(quitAction, &QAction::triggered, qApp, &QCoreApplication::quit); + QAction *quit_action = new QAction("Quit", root); + root->connect(quit_action, &QAction::triggered, qApp, &QCoreApplication::quit); - QAction *restoreAction = new QAction(QObject::tr("Restore"), root); - root->connect(restoreAction, &QAction::triggered, root, &QQuickWindow::showNormal); + QAction *restore_action = new QAction("Restore", root); + root->connect(restore_action, &QAction::triggered, root, &QQuickWindow::showNormal); // trayIcon: Left click actions. root->connect(tray_icon, &QSystemTrayIcon::activated, [&root](QSystemTrayIcon::ActivationReason reason) { @@ -40,15 +38,19 @@ int exec (App &app, QQmlApplicationEngine &engine) { }); // Build trayIcon menu. - menu->addAction(restoreAction); + menu->addAction(restore_action); menu->addSeparator(); - menu->addAction(quitAction); + menu->addAction(quit_action); tray_icon->setContextMenu(menu); tray_icon->setIcon(QIcon(":/imgs/linphone.png")); tray_icon->setToolTip("Linphone"); tray_icon->show(); + // Warning: Add global context Notification for all views! + NotificationModel notification; + engine.rootContext()->setContextProperty("Notification", ¬ification); + // Run. return app.exec(); } diff --git a/tests/src/models/notification/NotificationModel.cpp b/tests/src/models/notification/NotificationModel.cpp new file mode 100644 index 000000000..c226f22f9 --- /dev/null +++ b/tests/src/models/notification/NotificationModel.cpp @@ -0,0 +1,20 @@ +#include + +#include "NotificationModel.hpp" + +// =================================================================== + +NotificationModel::NotificationModel (QObject *parent) : + QObject(parent) { +} + +void NotificationModel::showMessage ( + const QString &summary, + const QString &body, + const QString &icon, + int timeout +) { + qDebug() << + "Notification.showMessage(" << summary << ", " << + body << ", " << icon << ", " << timeout << ")"; +} diff --git a/tests/src/models/notification/NotificationModel.hpp b/tests/src/models/notification/NotificationModel.hpp new file mode 100644 index 000000000..6b2a6048d --- /dev/null +++ b/tests/src/models/notification/NotificationModel.hpp @@ -0,0 +1,23 @@ +#ifndef NOTIFICATION_MODEL_H_ +#define NOTIFICATION_MODEL_H_ + +#include + +// =================================================================== + +class NotificationModel : public QObject { + Q_OBJECT + +public: + NotificationModel (QObject *parent = Q_NULLPTR); + +public slots: + void showMessage ( + const QString &summary, + const QString &body, + const QString &icon = "", + int timeout = 10000 + ); +}; + +#endif // NOTIFICATION_MODEL_H_