Commit 92c948a2 authored by Ronan's avatar Ronan
Browse files

feat(app): `Notification` component is exposed globally in qml

parent bd7a4a2b
......@@ -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
......
......@@ -8,6 +8,7 @@
#include <QtDebug>
#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", &notification);
// Run.
return app.exec();
}
......
#include <QtDebug>
#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 << ")";
}
#ifndef NOTIFICATION_MODEL_H_
#define NOTIFICATION_MODEL_H_
#include <QObject>
// ===================================================================
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_
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