diff --git a/tests/resources.qrc b/tests/resources.qrc
index 37d1c5e4d..1e43911b4 100644
--- a/tests/resources.qrc
+++ b/tests/resources.qrc
@@ -210,6 +210,7 @@
ui/modules/Linphone/Contact/Contact.qml
ui/modules/Linphone/Notifications/CallNotification.qml
ui/modules/Linphone/Notifications/Notification.qml
+ ui/modules/Linphone/Notifications/ReceivedMessageNotification.qml
ui/modules/Linphone/Presence/PresenceLevel.qml
ui/modules/Linphone/Presence/PresenceString.qml
ui/modules/Linphone/qmldir
diff --git a/tests/src/app/App.cpp b/tests/src/app/App.cpp
index db8ac49ef..d73978137 100644
--- a/tests/src/app/App.cpp
+++ b/tests/src/app/App.cpp
@@ -8,7 +8,6 @@
#include "../components/chat/ChatProxyModel.hpp"
#include "../components/contacts/ContactsListProxyModel.hpp"
#include "../components/core/CoreManager.hpp"
-#include "../components/notifier/Notifier.hpp"
#include "../components/settings/AccountSettingsModel.hpp"
#include "../components/timeline/TimelineModel.hpp"
#include "../components/smart-search-bar/SmartSearchBarModel.hpp"
@@ -60,6 +59,14 @@ App::App (int &argc, char **argv) : QApplication(argc, argv) {
// -----------------------------------------------------------------------------
+bool App::hasFocus () const {
+ QQmlApplicationEngine &engine = const_cast(m_engine);
+ const QQuickWindow *root = qobject_cast(engine.rootObjects().at(0));
+ return !!root->activeFocusItem();
+}
+
+// -----------------------------------------------------------------------------
+
void App::initContentApp () {
qInfo() << "Initializing core manager...";
diff --git a/tests/src/app/App.hpp b/tests/src/app/App.hpp
index 6164044e0..f63dee2ad 100644
--- a/tests/src/app/App.hpp
+++ b/tests/src/app/App.hpp
@@ -6,17 +6,31 @@
#include
#include
+#include "../components/notifier/Notifier.hpp"
#include "AvatarProvider.hpp"
#include "DefaultTranslator.hpp"
-class Notifier;
-
// =============================================================================
class App : public QApplication {
Q_OBJECT;
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) {
if (!m_instance) {
// Instance must be exists before content.
@@ -29,14 +43,6 @@ public:
return m_instance;
}
- QQmlEngine *getEngine () {
- return &m_engine;
- }
-
- Q_INVOKABLE QString locale () const {
- return m_locale;
- }
-
private:
App (int &argc, char **argv);
~App () = default;
diff --git a/tests/src/components/core/CoreHandlers.cpp b/tests/src/components/core/CoreHandlers.cpp
index 7fe32faa6..7ae767c58 100644
--- a/tests/src/components/core/CoreHandlers.cpp
+++ b/tests/src/components/core/CoreHandlers.cpp
@@ -1,5 +1,6 @@
#include
+#include "../../app/App.hpp"
#include "CoreManager.hpp"
#include "CoreHandlers.hpp"
@@ -9,26 +10,31 @@ using namespace std;
// =============================================================================
void CoreHandlers::onAuthenticationRequested (
- const std::shared_ptr &lc,
- const std::shared_ptr &auth_info,
- linphone::AuthMethod method
+ const std::shared_ptr &,
+ const std::shared_ptr &,
+ linphone::AuthMethod
) {
qDebug() << "Auth request";
}
void CoreHandlers::onCallStateChanged (
- const shared_ptr &lc,
- const shared_ptr &call,
- linphone::CallState cstate,
- const string &message
+ const shared_ptr &,
+ const shared_ptr &,
+ linphone::CallState,
+ const string &
) {
qDebug() << "call";
}
void CoreHandlers::onMessageReceived (
- const shared_ptr &lc,
+ const shared_ptr &,
const shared_ptr &room,
const shared_ptr &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);
}
diff --git a/tests/src/components/core/CoreHandlers.hpp b/tests/src/components/core/CoreHandlers.hpp
index f8336b4c2..f167a9f17 100644
--- a/tests/src/components/core/CoreHandlers.hpp
+++ b/tests/src/components/core/CoreHandlers.hpp
@@ -8,20 +8,20 @@
class CoreHandlers : public linphone::CoreListener {
public:
void onAuthenticationRequested (
- const std::shared_ptr &lc,
+ const std::shared_ptr &core,
const std::shared_ptr &auth_info,
linphone::AuthMethod method
) override;
void onCallStateChanged (
- const std::shared_ptr &lc,
+ const std::shared_ptr &core,
const std::shared_ptr &call,
linphone::CallState cstate,
const std::string &message
) override;
void onMessageReceived (
- const std::shared_ptr &lc,
+ const std::shared_ptr &core,
const std::shared_ptr &room,
const std::shared_ptr &message
) override;
diff --git a/tests/src/components/notifier/Notifier.cpp b/tests/src/components/notifier/Notifier.cpp
index e55bcfc4e..8f4363006 100644
--- a/tests/src/components/notifier/Notifier.cpp
+++ b/tests/src/components/notifier/Notifier.cpp
@@ -13,7 +13,8 @@
#define NOTIFICATION_HEIGHT_PROPERTY "notificationHeight"
#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.
#define NOTIFICATION_SPACING 10
@@ -54,7 +55,8 @@ Notifier::Notifier (QObject *parent) :
QQmlEngine *engine = App::getInstance()->getEngine();
// 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.
for (int i = 0; i < Notifier::MaxNbTypes; ++i) {
@@ -148,6 +150,17 @@ void Notifier::showNotification (QObject *notification, int timeout) {
// -----------------------------------------------------------------------------
+void Notifier::notifyReceivedMessage (
+ int timeout,
+ const std::shared_ptr &room,
+ const std::shared_ptr &message
+) {
+ QObject *object = createNotification(Notifier::MessageReceived);
+
+ if (object)
+ showNotification(object, timeout);
+}
+
void Notifier::showCallMessage (int timeout, const QString &) {
QObject *object = createNotification(Notifier::Call);
diff --git a/tests/src/components/notifier/Notifier.hpp b/tests/src/components/notifier/Notifier.hpp
index 21ca12ec3..a1c48dd9d 100644
--- a/tests/src/components/notifier/Notifier.hpp
+++ b/tests/src/components/notifier/Notifier.hpp
@@ -1,6 +1,8 @@
#ifndef NOTIFIER_H_
#define NOTIFIER_H_
+#include
+
#include
#include
@@ -17,10 +19,18 @@ public:
enum NotificationType {
Call,
+ MessageReceived,
MaxNbTypes
};
- Q_INVOKABLE void showCallMessage (int timeout, const QString &sip_address);
+ void notifyReceivedMessage (
+ int timeout,
+ const std::shared_ptr &room,
+ const std::shared_ptr &message
+ );
+
+ // TODO
+ void showCallMessage (int timeout, const QString &);
private:
QObject *createNotification (NotificationType type);
diff --git a/tests/src/components/sip-addresses/SipAddressesModel.cpp b/tests/src/components/sip-addresses/SipAddressesModel.cpp
index 31d8a6670..9e16265ef 100644
--- a/tests/src/components/sip-addresses/SipAddressesModel.cpp
+++ b/tests/src/components/sip-addresses/SipAddressesModel.cpp
@@ -213,8 +213,6 @@ void SipAddressesModel::addOrUpdateSipAddress (const QString &sip_address, Conta
m_refs << &m_sip_addresses[sip_address];
endInsertRows();
-
- emit dataChanged(index(row, 0), index(row, 0));
}
void SipAddressesModel::removeContactOfSipAddress (const QString &sip_address) {
diff --git a/tests/src/components/timeline/TimelineModel.cpp b/tests/src/components/timeline/TimelineModel.cpp
index 4bfab2a58..1d83348ee 100644
--- a/tests/src/components/timeline/TimelineModel.cpp
+++ b/tests/src/components/timeline/TimelineModel.cpp
@@ -25,6 +25,5 @@ bool TimelineModel::filterAcceptsRow (int source_row, const QModelIndex &source_
}
bool TimelineModel::lessThan (const QModelIndex &left, const QModelIndex &right) const {
- return sourceModel()->data(left).toMap()["timestamp"].toDateTime().toMSecsSinceEpoch() >
- sourceModel()->data(right).toMap()["timestamp"].toDateTime().toMSecsSinceEpoch();
+ return sourceModel()->data(left).toMap()["timestamp"] > sourceModel()->data(right).toMap()["timestamp"];
}
diff --git a/tests/ui/modules/Linphone/Notifications/ReceivedMessageNotification.qml b/tests/ui/modules/Linphone/Notifications/ReceivedMessageNotification.qml
new file mode 100644
index 000000000..e25e060f0
--- /dev/null
+++ b/tests/ui/modules/Linphone/Notifications/ReceivedMessageNotification.qml
@@ -0,0 +1,12 @@
+import QtQuick 2.7
+
+// =============================================================================
+
+Notification {
+ Rectangle {
+ color: 'red'
+
+ width: 200
+ height: 100
+ }
+}