Commit 4d91eb4a authored by Ronan Abhamon's avatar Ronan Abhamon

feat(app): provide a custom notifier

parent cf6eecbd
...@@ -34,7 +34,7 @@ set(SOURCES ...@@ -34,7 +34,7 @@ set(SOURCES
src/components/contacts/ContactsListModel.cpp src/components/contacts/ContactsListModel.cpp
src/components/contacts/ContactsListProxyModel.cpp src/components/contacts/ContactsListProxyModel.cpp
src/components/linphone/LinphoneCore.cpp src/components/linphone/LinphoneCore.cpp
src/components/notification/Notification.cpp src/components/notifier/Notifier.cpp
src/components/settings/AccountSettingsModel.cpp src/components/settings/AccountSettingsModel.cpp
src/components/settings/SettingsModel.cpp src/components/settings/SettingsModel.cpp
src/components/timeline/TimelineModel.cpp src/components/timeline/TimelineModel.cpp
...@@ -49,7 +49,7 @@ set(HEADERS ...@@ -49,7 +49,7 @@ set(HEADERS
src/components/contacts/ContactsListModel.hpp src/components/contacts/ContactsListModel.hpp
src/components/contacts/ContactsListProxyModel.hpp src/components/contacts/ContactsListProxyModel.hpp
src/components/linphone/LinphoneCore.hpp src/components/linphone/LinphoneCore.hpp
src/components/notification/Notification.hpp src/components/notifier/Notifier.hpp
src/components/presence/Presence.hpp src/components/presence/Presence.hpp
src/components/settings/AccountSettingsModel.hpp src/components/settings/AccountSettingsModel.hpp
src/components/settings/SettingsModel.hpp src/components/settings/SettingsModel.hpp
......
#include <QDesktopWidget>
#include <QMenu> #include <QMenu>
#include <QQmlComponent> #include <QQmlComponent>
#include <QQmlContext> #include <QQmlContext>
...@@ -57,9 +56,6 @@ void App::initContentApp () { ...@@ -57,9 +56,6 @@ void App::initContentApp () {
qWarning("System tray not found on this system."); qWarning("System tray not found on this system.");
else else
setTrayIcon(); setTrayIcon();
// Set notification attr.
setNotificationAttributes();
} }
void App::registerTypes () { void App::registerTypes () {
...@@ -100,8 +96,8 @@ void App::addContextProperties () { ...@@ -100,8 +96,8 @@ void App::addContextProperties () {
// Other. // Other.
context->setContextProperty("LinphoneCore", LinphoneCore::getInstance()); context->setContextProperty("LinphoneCore", LinphoneCore::getInstance());
m_notification = new Notification(); m_notifier = new Notifier();
context->setContextProperty("Notification", m_notification); context->setContextProperty("Notifier", m_notifier);
} }
void App::setTrayIcon () { void App::setTrayIcon () {
...@@ -137,22 +133,3 @@ void App::setTrayIcon () { ...@@ -137,22 +133,3 @@ void App::setTrayIcon () {
m_system_tray_icon->setToolTip("Linphone"); m_system_tray_icon->setToolTip("Linphone");
m_system_tray_icon->show(); 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 @@ ...@@ -7,7 +7,7 @@
#include <QSystemTrayIcon> #include <QSystemTrayIcon>
#include <QTranslator> #include <QTranslator>
#include "../components/notification/Notification.hpp" #include "../components/notifier/Notifier.hpp"
// =================================================================== // ===================================================================
...@@ -37,14 +37,12 @@ private: ...@@ -37,14 +37,12 @@ private:
void addContextProperties (); void addContextProperties ();
void setTrayIcon (); void setTrayIcon ();
void setNotificationAttributes ();
QQmlApplicationEngine m_engine; QQmlApplicationEngine m_engine;
QQmlFileSelector *m_file_selector = nullptr; QQmlFileSelector *m_file_selector = nullptr;
QSystemTrayIcon *m_system_tray_icon = nullptr; QSystemTrayIcon *m_system_tray_icon = nullptr;
QTranslator m_translator; QTranslator m_translator;
Notification *m_notification = nullptr; Notifier *m_notifier = nullptr;
static App *m_instance; static App *m_instance;
}; };
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#include <QtDebug> #include <QtDebug>
#include "../../app/App.hpp" #include "../../app/App.hpp"
#include "Notification.hpp" #include "Notifier.hpp"
#define NOTIFICATION_SHOW_METHOD_NAME "show" #define NOTIFICATION_SHOW_METHOD_NAME "show"
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
// Helpers. // Helpers.
inline int getNotificationSize (const QObject &object, const char *property) { inline int getNotificationSize (const QObject &object, const char *property) {
QVariant variant = object.property(property); QVariant variant(object.property(property));
bool so_far_so_good; bool so_far_so_good;
int size = variant.toInt(&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) { ...@@ -44,17 +44,17 @@ bool setProperty (QObject &object, const char *property, const T &value) {
// ------------------------------------------------------------------- // -------------------------------------------------------------------
Notification::Notification (QObject *parent) : Notifier::Notifier (QObject *parent) :
QObject(parent) { QObject(parent) {
QQmlEngine *engine = App::getInstance()->getEngine(); QQmlEngine *engine = App::getInstance()->getEngine();
// Build components. // Build components.
m_components[Notification::Call] = new QQmlComponent( m_components[Notifier::Call] = new QQmlComponent(
engine, QUrl("qrc:/ui/modules/Linphone/Notifications/CallNotification.qml") engine, QUrl("qrc:/ui/modules/Linphone/Notifications/CallNotification.qml")
); );
// Check errors. // Check errors.
for (int i = 0; i < Notification::MaxNbTypes; i++) { for (int i = 0; i < Notifier::MaxNbTypes; i++) {
QQmlComponent &component = *m_components[i]; QQmlComponent &component = *m_components[i];
if (component.isError()) { if (component.isError()) {
qWarning() << "Errors found in `Notification` component " qWarning() << "Errors found in `Notification` component "
...@@ -64,14 +64,14 @@ Notification::Notification (QObject *parent) : ...@@ -64,14 +64,14 @@ Notification::Notification (QObject *parent) :
} }
} }
Notification::~Notification () { Notifier::~Notifier () {
for (int i = 0; i < Notification::MaxNbTypes; i++) for (int i = 0; i < Notifier::MaxNbTypes; i++)
delete m_components[i]; delete m_components[i];
} }
// ------------------------------------------------------------------- // -------------------------------------------------------------------
void Notification::showCallMessage ( void Notifier::showCallMessage (
int timeout, int timeout,
const QString &sip_address const QString &sip_address
) { ) {
...@@ -88,12 +88,12 @@ void Notification::showCallMessage ( ...@@ -88,12 +88,12 @@ void Notification::showCallMessage (
} }
// Create instance and set attributes. // 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); int offset = getNotificationSize(*object, NOTIFICATION_HEIGHT_PROPERTY);
if ( if (
offset == -1 || 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) !::setProperty(*object, NOTIFICATION_OFFSET_PROPERTY_NAME, m_offset)
) { ) {
delete object; delete object;
......
#ifndef NOTIFICATION_H_ #ifndef NOTIFIER_H_
#define NOTIFICATION_H_ #define NOTIFIER_H_
#include <QMutex> #include <QMutex>
#include <QObject> #include <QObject>
...@@ -7,12 +7,12 @@ ...@@ -7,12 +7,12 @@
// =================================================================== // ===================================================================
class Notification : public QObject { class Notifier : public QObject {
Q_OBJECT; Q_OBJECT;
public: public:
Notification (QObject *parent = Q_NULLPTR); Notifier (QObject *parent = Q_NULLPTR);
virtual ~Notification (); virtual ~Notifier ();
enum Type { enum Type {
Call, Call,
...@@ -20,15 +20,12 @@ public: ...@@ -20,15 +20,12 @@ public:
}; };
Q_ENUM(Type); Q_ENUM(Type);
void setEdge (Qt::Edges edge) {
m_edge = edge;
}
public slots: public slots:
void showCallMessage (int timeout, const QString &sip_address); void showCallMessage (int timeout, const QString &sip_address);
private: private:
Qt::Edges m_edge = Qt::RightEdge | Qt::TopEdge; void computePositions ();
QQmlComponent *m_components[MaxNbTypes]; QQmlComponent *m_components[MaxNbTypes];
int m_offset = 0; int m_offset = 0;
...@@ -36,4 +33,4 @@ private: ...@@ -36,4 +33,4 @@ private:
QMutex m_mutex; QMutex m_mutex;
}; };
#endif // NOTIFICATION_H_ #endif // NOTIFIER_H_
...@@ -36,7 +36,7 @@ ColumnLayout { ...@@ -36,7 +36,7 @@ ColumnLayout {
}) })
} }
spacing: Notification.showCallMessage(5000, "toto@toto.com") || 0 spacing: Notifier.showCallMessage(5000, "toto@toto.com") || 0
// ----------------------------------------------------------------- // -----------------------------------------------------------------
// Search Bar & actions. // Search Bar & actions.
......
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