Commit bd1b7e72 authored by Ronan Abhamon's avatar Ronan Abhamon

feat(app):

  - supports message received notification
  - provide a way to test app focus
parent f181b6d6
...@@ -210,6 +210,7 @@ ...@@ -210,6 +210,7 @@
<file>ui/modules/Linphone/Contact/Contact.qml</file> <file>ui/modules/Linphone/Contact/Contact.qml</file>
<file>ui/modules/Linphone/Notifications/CallNotification.qml</file> <file>ui/modules/Linphone/Notifications/CallNotification.qml</file>
<file>ui/modules/Linphone/Notifications/Notification.qml</file> <file>ui/modules/Linphone/Notifications/Notification.qml</file>
<file>ui/modules/Linphone/Notifications/ReceivedMessageNotification.qml</file>
<file>ui/modules/Linphone/Presence/PresenceLevel.qml</file> <file>ui/modules/Linphone/Presence/PresenceLevel.qml</file>
<file>ui/modules/Linphone/Presence/PresenceString.qml</file> <file>ui/modules/Linphone/Presence/PresenceString.qml</file>
<file>ui/modules/Linphone/qmldir</file> <file>ui/modules/Linphone/qmldir</file>
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include "../components/chat/ChatProxyModel.hpp" #include "../components/chat/ChatProxyModel.hpp"
#include "../components/contacts/ContactsListProxyModel.hpp" #include "../components/contacts/ContactsListProxyModel.hpp"
#include "../components/core/CoreManager.hpp" #include "../components/core/CoreManager.hpp"
#include "../components/notifier/Notifier.hpp"
#include "../components/settings/AccountSettingsModel.hpp" #include "../components/settings/AccountSettingsModel.hpp"
#include "../components/timeline/TimelineModel.hpp" #include "../components/timeline/TimelineModel.hpp"
#include "../components/smart-search-bar/SmartSearchBarModel.hpp" #include "../components/smart-search-bar/SmartSearchBarModel.hpp"
...@@ -60,6 +59,14 @@ App::App (int &argc, char **argv) : QApplication(argc, argv) { ...@@ -60,6 +59,14 @@ App::App (int &argc, char **argv) : QApplication(argc, argv) {
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
bool App::hasFocus () const {
QQmlApplicationEngine &engine = const_cast<QQmlApplicationEngine &>(m_engine);
const QQuickWindow *root = qobject_cast<QQuickWindow *>(engine.rootObjects().at(0));
return !!root->activeFocusItem();
}
// -----------------------------------------------------------------------------
void App::initContentApp () { void App::initContentApp () {
qInfo() << "Initializing core manager..."; qInfo() << "Initializing core manager...";
......
...@@ -6,17 +6,31 @@ ...@@ -6,17 +6,31 @@
#include <QQmlFileSelector> #include <QQmlFileSelector>
#include <QSystemTrayIcon> #include <QSystemTrayIcon>
#include "../components/notifier/Notifier.hpp"
#include "AvatarProvider.hpp" #include "AvatarProvider.hpp"
#include "DefaultTranslator.hpp" #include "DefaultTranslator.hpp"
class Notifier;
// ============================================================================= // =============================================================================
class App : public QApplication { class App : public QApplication {
Q_OBJECT; Q_OBJECT;
public: public:
QQmlEngine *getEngine () {
return &m_engine;
}
Notifier *getNotifier () const {
return m_notifier;
}
bool hasFocus () const;
Q_INVOKABLE QString locale () const {
return m_locale;
}
static void init (int &argc, char **argv) { static void init (int &argc, char **argv) {
if (!m_instance) { if (!m_instance) {
// Instance must be exists before content. // Instance must be exists before content.
...@@ -29,14 +43,6 @@ public: ...@@ -29,14 +43,6 @@ public:
return m_instance; return m_instance;
} }
QQmlEngine *getEngine () {
return &m_engine;
}
Q_INVOKABLE QString locale () const {
return m_locale;
}
private: private:
App (int &argc, char **argv); App (int &argc, char **argv);
~App () = default; ~App () = default;
......
#include <QtDebug> #include <QtDebug>
#include "../../app/App.hpp"
#include "CoreManager.hpp" #include "CoreManager.hpp"
#include "CoreHandlers.hpp" #include "CoreHandlers.hpp"
...@@ -9,26 +10,31 @@ using namespace std; ...@@ -9,26 +10,31 @@ using namespace std;
// ============================================================================= // =============================================================================
void CoreHandlers::onAuthenticationRequested ( void CoreHandlers::onAuthenticationRequested (
const std::shared_ptr<linphone::Core> &lc, const std::shared_ptr<linphone::Core> &,
const std::shared_ptr<linphone::AuthInfo> &auth_info, const std::shared_ptr<linphone::AuthInfo> &,
linphone::AuthMethod method linphone::AuthMethod
) { ) {
qDebug() << "Auth request"; qDebug() << "Auth request";
} }
void CoreHandlers::onCallStateChanged ( void CoreHandlers::onCallStateChanged (
const shared_ptr<linphone::Core> &lc, const shared_ptr<linphone::Core> &,
const shared_ptr<linphone::Call> &call, const shared_ptr<linphone::Call> &,
linphone::CallState cstate, linphone::CallState,
const string &message const string &
) { ) {
qDebug() << "call"; qDebug() << "call";
} }
void CoreHandlers::onMessageReceived ( void CoreHandlers::onMessageReceived (
const shared_ptr<linphone::Core> &lc, const shared_ptr<linphone::Core> &,
const shared_ptr<linphone::ChatRoom> &room, const shared_ptr<linphone::ChatRoom> &room,
const shared_ptr<linphone::ChatMessage> &message const shared_ptr<linphone::ChatMessage> &message
) { ) {
CoreManager::getInstance()->getSipAddressesModel()->handleReceivedMessage(room, message); CoreManager *core = CoreManager::getInstance();
core->getSipAddressesModel()->handleReceivedMessage(room, message);
const App *app = App::getInstance();
if (!app->hasFocus())
app->getNotifier()->notifyReceivedMessage(10000, room, message);
} }
...@@ -8,20 +8,20 @@ ...@@ -8,20 +8,20 @@
class CoreHandlers : public linphone::CoreListener { class CoreHandlers : public linphone::CoreListener {
public: public:
void onAuthenticationRequested ( void onAuthenticationRequested (
const std::shared_ptr<linphone::Core> &lc, const std::shared_ptr<linphone::Core> &core,
const std::shared_ptr<linphone::AuthInfo> &auth_info, const std::shared_ptr<linphone::AuthInfo> &auth_info,
linphone::AuthMethod method linphone::AuthMethod method
) override; ) override;
void onCallStateChanged ( void onCallStateChanged (
const std::shared_ptr<linphone::Core> &lc, const std::shared_ptr<linphone::Core> &core,
const std::shared_ptr<linphone::Call> &call, const std::shared_ptr<linphone::Call> &call,
linphone::CallState cstate, linphone::CallState cstate,
const std::string &message const std::string &message
) override; ) override;
void onMessageReceived ( void onMessageReceived (
const std::shared_ptr<linphone::Core> &lc, const std::shared_ptr<linphone::Core> &core,
const std::shared_ptr<linphone::ChatRoom> &room, const std::shared_ptr<linphone::ChatRoom> &room,
const std::shared_ptr<linphone::ChatMessage> &message const std::shared_ptr<linphone::ChatMessage> &message
) override; ) override;
......
...@@ -13,7 +13,8 @@ ...@@ -13,7 +13,8 @@
#define NOTIFICATION_HEIGHT_PROPERTY "notificationHeight" #define NOTIFICATION_HEIGHT_PROPERTY "notificationHeight"
#define NOTIFICATION_OFFSET_PROPERTY_NAME "notificationOffset" #define NOTIFICATION_OFFSET_PROPERTY_NAME "notificationOffset"
#define QML_NOTIFICATION_PATH "qrc:/ui/modules/Linphone/Notifications/CallNotification.qml" #define QML_CALL_NOTIFICATION_PATH "qrc:/ui/modules/Linphone/Notifications/CallNotification.qml"
#define QML_MESSAGE_RECEIVED_NOTIFICATION_PATH "qrc:/ui/modules/Linphone/Notifications/ReceivedMessageNotification.qml"
// Arbitrary hardcoded values. // Arbitrary hardcoded values.
#define NOTIFICATION_SPACING 10 #define NOTIFICATION_SPACING 10
...@@ -54,7 +55,8 @@ Notifier::Notifier (QObject *parent) : ...@@ -54,7 +55,8 @@ Notifier::Notifier (QObject *parent) :
QQmlEngine *engine = App::getInstance()->getEngine(); QQmlEngine *engine = App::getInstance()->getEngine();
// Build components. // Build components.
m_components[Notifier::Call] = new QQmlComponent(engine, QUrl(QML_NOTIFICATION_PATH)); m_components[Notifier::Call] = new QQmlComponent(engine, QUrl(QML_CALL_NOTIFICATION_PATH));
m_components[Notifier::MessageReceived] = new QQmlComponent(engine, QUrl(QML_MESSAGE_RECEIVED_NOTIFICATION_PATH));
// Check errors. // Check errors.
for (int i = 0; i < Notifier::MaxNbTypes; ++i) { for (int i = 0; i < Notifier::MaxNbTypes; ++i) {
...@@ -148,6 +150,17 @@ void Notifier::showNotification (QObject *notification, int timeout) { ...@@ -148,6 +150,17 @@ void Notifier::showNotification (QObject *notification, int timeout) {
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void Notifier::notifyReceivedMessage (
int timeout,
const std::shared_ptr<linphone::ChatRoom> &room,
const std::shared_ptr<linphone::ChatMessage> &message
) {
QObject *object = createNotification(Notifier::MessageReceived);
if (object)
showNotification(object, timeout);
}
void Notifier::showCallMessage (int timeout, const QString &) { void Notifier::showCallMessage (int timeout, const QString &) {
QObject *object = createNotification(Notifier::Call); QObject *object = createNotification(Notifier::Call);
......
#ifndef NOTIFIER_H_ #ifndef NOTIFIER_H_
#define NOTIFIER_H_ #define NOTIFIER_H_
#include <linphone++/linphone.hh>
#include <QMutex> #include <QMutex>
#include <QObject> #include <QObject>
...@@ -17,10 +19,18 @@ public: ...@@ -17,10 +19,18 @@ public:
enum NotificationType { enum NotificationType {
Call, Call,
MessageReceived,
MaxNbTypes MaxNbTypes
}; };
Q_INVOKABLE void showCallMessage (int timeout, const QString &sip_address); void notifyReceivedMessage (
int timeout,
const std::shared_ptr<linphone::ChatRoom> &room,
const std::shared_ptr<linphone::ChatMessage> &message
);
// TODO
void showCallMessage (int timeout, const QString &);
private: private:
QObject *createNotification (NotificationType type); QObject *createNotification (NotificationType type);
......
...@@ -213,8 +213,6 @@ void SipAddressesModel::addOrUpdateSipAddress (const QString &sip_address, Conta ...@@ -213,8 +213,6 @@ void SipAddressesModel::addOrUpdateSipAddress (const QString &sip_address, Conta
m_refs << &m_sip_addresses[sip_address]; m_refs << &m_sip_addresses[sip_address];
endInsertRows(); endInsertRows();
emit dataChanged(index(row, 0), index(row, 0));
} }
void SipAddressesModel::removeContactOfSipAddress (const QString &sip_address) { void SipAddressesModel::removeContactOfSipAddress (const QString &sip_address) {
......
...@@ -25,6 +25,5 @@ bool TimelineModel::filterAcceptsRow (int source_row, const QModelIndex &source_ ...@@ -25,6 +25,5 @@ bool TimelineModel::filterAcceptsRow (int source_row, const QModelIndex &source_
} }
bool TimelineModel::lessThan (const QModelIndex &left, const QModelIndex &right) const { bool TimelineModel::lessThan (const QModelIndex &left, const QModelIndex &right) const {
return sourceModel()->data(left).toMap()["timestamp"].toDateTime().toMSecsSinceEpoch() > return sourceModel()->data(left).toMap()["timestamp"] > sourceModel()->data(right).toMap()["timestamp"];
sourceModel()->data(right).toMap()["timestamp"].toDateTime().toMSecsSinceEpoch();
} }
import QtQuick 2.7
// =============================================================================
Notification {
Rectangle {
color: 'red'
width: 200
height: 100
}
}
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