mirror of
https://gitlab.linphone.org/BC/public/linphone-desktop.git
synced 2026-02-07 15:08:24 +00:00
feat(app): provide a custom notifier
This commit is contained in:
parent
cf6eecbdb5
commit
4d91eb4a85
6 changed files with 25 additions and 53 deletions
|
|
@ -34,7 +34,7 @@ set(SOURCES
|
|||
src/components/contacts/ContactsListModel.cpp
|
||||
src/components/contacts/ContactsListProxyModel.cpp
|
||||
src/components/linphone/LinphoneCore.cpp
|
||||
src/components/notification/Notification.cpp
|
||||
src/components/notifier/Notifier.cpp
|
||||
src/components/settings/AccountSettingsModel.cpp
|
||||
src/components/settings/SettingsModel.cpp
|
||||
src/components/timeline/TimelineModel.cpp
|
||||
|
|
@ -49,7 +49,7 @@ set(HEADERS
|
|||
src/components/contacts/ContactsListModel.hpp
|
||||
src/components/contacts/ContactsListProxyModel.hpp
|
||||
src/components/linphone/LinphoneCore.hpp
|
||||
src/components/notification/Notification.hpp
|
||||
src/components/notifier/Notifier.hpp
|
||||
src/components/presence/Presence.hpp
|
||||
src/components/settings/AccountSettingsModel.hpp
|
||||
src/components/settings/SettingsModel.hpp
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
#include <QDesktopWidget>
|
||||
#include <QMenu>
|
||||
#include <QQmlComponent>
|
||||
#include <QQmlContext>
|
||||
|
|
@ -57,9 +56,6 @@ void App::initContentApp () {
|
|||
qWarning("System tray not found on this system.");
|
||||
else
|
||||
setTrayIcon();
|
||||
|
||||
// Set notification attr.
|
||||
setNotificationAttributes();
|
||||
}
|
||||
|
||||
void App::registerTypes () {
|
||||
|
|
@ -100,8 +96,8 @@ void App::addContextProperties () {
|
|||
// Other.
|
||||
context->setContextProperty("LinphoneCore", LinphoneCore::getInstance());
|
||||
|
||||
m_notification = new Notification();
|
||||
context->setContextProperty("Notification", m_notification);
|
||||
m_notifier = new Notifier();
|
||||
context->setContextProperty("Notifier", m_notifier);
|
||||
}
|
||||
|
||||
void App::setTrayIcon () {
|
||||
|
|
@ -137,22 +133,3 @@ void App::setTrayIcon () {
|
|||
m_system_tray_icon->setToolTip("Linphone");
|
||||
m_system_tray_icon->show();
|
||||
}
|
||||
|
||||
void App::setNotificationAttributes () {
|
||||
if (!m_system_tray_icon) {
|
||||
return;
|
||||
}
|
||||
|
||||
QDesktopWidget *desktop = QApplication::desktop();
|
||||
|
||||
QRect icon_rect = m_system_tray_icon->geometry();
|
||||
QRect screen_rect = desktop->screenGeometry();
|
||||
|
||||
int x = icon_rect.x() / 2 + icon_rect.width() / 2;
|
||||
int y = icon_rect.y() / 2 + icon_rect.height() / 2;
|
||||
|
||||
Qt::Edges edge = (x < screen_rect.width() / 2) ? Qt::LeftEdge : Qt::RightEdge;
|
||||
edge |= (y < screen_rect.height() / 2) ? Qt::TopEdge : Qt::BottomEdge;
|
||||
|
||||
m_notification->setEdge(edge);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
#include <QSystemTrayIcon>
|
||||
#include <QTranslator>
|
||||
|
||||
#include "../components/notification/Notification.hpp"
|
||||
#include "../components/notifier/Notifier.hpp"
|
||||
|
||||
// ===================================================================
|
||||
|
||||
|
|
@ -37,14 +37,12 @@ private:
|
|||
void addContextProperties ();
|
||||
void setTrayIcon ();
|
||||
|
||||
void setNotificationAttributes ();
|
||||
|
||||
QQmlApplicationEngine m_engine;
|
||||
QQmlFileSelector *m_file_selector = nullptr;
|
||||
QSystemTrayIcon *m_system_tray_icon = nullptr;
|
||||
QTranslator m_translator;
|
||||
|
||||
Notification *m_notification = nullptr;
|
||||
Notifier *m_notifier = nullptr;
|
||||
|
||||
static App *m_instance;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
#include <QtDebug>
|
||||
|
||||
#include "../../app/App.hpp"
|
||||
#include "Notification.hpp"
|
||||
#include "Notifier.hpp"
|
||||
|
||||
#define NOTIFICATION_SHOW_METHOD_NAME "show"
|
||||
|
||||
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
// Helpers.
|
||||
inline int getNotificationSize (const QObject &object, const char *property) {
|
||||
QVariant variant = object.property(property);
|
||||
QVariant variant(object.property(property));
|
||||
bool so_far_so_good;
|
||||
|
||||
int size = variant.toInt(&so_far_so_good);
|
||||
|
|
@ -44,17 +44,17 @@ bool setProperty (QObject &object, const char *property, const T &value) {
|
|||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
Notification::Notification (QObject *parent) :
|
||||
Notifier::Notifier (QObject *parent) :
|
||||
QObject(parent) {
|
||||
QQmlEngine *engine = App::getInstance()->getEngine();
|
||||
|
||||
// Build components.
|
||||
m_components[Notification::Call] = new QQmlComponent(
|
||||
m_components[Notifier::Call] = new QQmlComponent(
|
||||
engine, QUrl("qrc:/ui/modules/Linphone/Notifications/CallNotification.qml")
|
||||
);
|
||||
|
||||
// Check errors.
|
||||
for (int i = 0; i < Notification::MaxNbTypes; i++) {
|
||||
for (int i = 0; i < Notifier::MaxNbTypes; i++) {
|
||||
QQmlComponent &component = *m_components[i];
|
||||
if (component.isError()) {
|
||||
qWarning() << "Errors found in `Notification` component "
|
||||
|
|
@ -64,14 +64,14 @@ Notification::Notification (QObject *parent) :
|
|||
}
|
||||
}
|
||||
|
||||
Notification::~Notification () {
|
||||
for (int i = 0; i < Notification::MaxNbTypes; i++)
|
||||
Notifier::~Notifier () {
|
||||
for (int i = 0; i < Notifier::MaxNbTypes; i++)
|
||||
delete m_components[i];
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
void Notification::showCallMessage (
|
||||
void Notifier::showCallMessage (
|
||||
int timeout,
|
||||
const QString &sip_address
|
||||
) {
|
||||
|
|
@ -88,12 +88,12 @@ void Notification::showCallMessage (
|
|||
}
|
||||
|
||||
// Create instance and set attributes.
|
||||
QObject *object = m_components[Notification::Call]->create();
|
||||
QObject *object = m_components[Notifier::Call]->create();
|
||||
int offset = getNotificationSize(*object, NOTIFICATION_HEIGHT_PROPERTY);
|
||||
|
||||
if (
|
||||
offset == -1 ||
|
||||
!::setProperty(*object, NOTIFICATION_EDGE_PROPERTY_NAME, m_edge) ||
|
||||
!::setProperty(*object, NOTIFICATION_EDGE_PROPERTY_NAME, Qt::TopEdge | Qt::RightEdge) ||
|
||||
!::setProperty(*object, NOTIFICATION_OFFSET_PROPERTY_NAME, m_offset)
|
||||
) {
|
||||
delete object;
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
#ifndef NOTIFICATION_H_
|
||||
#define NOTIFICATION_H_
|
||||
#ifndef NOTIFIER_H_
|
||||
#define NOTIFIER_H_
|
||||
|
||||
#include <QMutex>
|
||||
#include <QObject>
|
||||
|
|
@ -7,12 +7,12 @@
|
|||
|
||||
// ===================================================================
|
||||
|
||||
class Notification : public QObject {
|
||||
class Notifier : public QObject {
|
||||
Q_OBJECT;
|
||||
|
||||
public:
|
||||
Notification (QObject *parent = Q_NULLPTR);
|
||||
virtual ~Notification ();
|
||||
Notifier (QObject *parent = Q_NULLPTR);
|
||||
virtual ~Notifier ();
|
||||
|
||||
enum Type {
|
||||
Call,
|
||||
|
|
@ -20,15 +20,12 @@ public:
|
|||
};
|
||||
Q_ENUM(Type);
|
||||
|
||||
void setEdge (Qt::Edges edge) {
|
||||
m_edge = edge;
|
||||
}
|
||||
|
||||
public slots:
|
||||
void showCallMessage (int timeout, const QString &sip_address);
|
||||
|
||||
private:
|
||||
Qt::Edges m_edge = Qt::RightEdge | Qt::TopEdge;
|
||||
void computePositions ();
|
||||
|
||||
QQmlComponent *m_components[MaxNbTypes];
|
||||
|
||||
int m_offset = 0;
|
||||
|
|
@ -36,4 +33,4 @@ private:
|
|||
QMutex m_mutex;
|
||||
};
|
||||
|
||||
#endif // NOTIFICATION_H_
|
||||
#endif // NOTIFIER_H_
|
||||
|
|
@ -36,7 +36,7 @@ ColumnLayout {
|
|||
})
|
||||
}
|
||||
|
||||
spacing: Notification.showCallMessage(5000, "toto@toto.com") || 0
|
||||
spacing: Notifier.showCallMessage(5000, "toto@toto.com") || 0
|
||||
|
||||
// -----------------------------------------------------------------
|
||||
// Search Bar & actions.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue