mirror of
https://gitlab.linphone.org/BC/public/linphone-desktop.git
synced 2026-01-29 09:49:20 +00:00
feat(app): Notification component is exposed globally in qml
This commit is contained in:
parent
bd7a4a2b85
commit
92c948a2e6
4 changed files with 57 additions and 10 deletions
|
|
@ -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", ¬ification);
|
||||
|
||||
// Run.
|
||||
return app.exec();
|
||||
}
|
||||
|
|
|
|||
20
tests/src/models/notification/NotificationModel.cpp
Normal file
20
tests/src/models/notification/NotificationModel.cpp
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
#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 << ")";
|
||||
}
|
||||
23
tests/src/models/notification/NotificationModel.hpp
Normal file
23
tests/src/models/notification/NotificationModel.hpp
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
#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_
|
||||
Loading…
Add table
Reference in a new issue