mirror of
https://gitlab.linphone.org/BC/public/linphone-desktop.git
synced 2026-01-23 06:38:07 +00:00
feat(app):
- supports message received notification - provide a way to test app focus
This commit is contained in:
parent
f181b6d659
commit
bd1b7e727e
10 changed files with 82 additions and 30 deletions
|
|
@ -210,6 +210,7 @@
|
|||
<file>ui/modules/Linphone/Contact/Contact.qml</file>
|
||||
<file>ui/modules/Linphone/Notifications/CallNotification.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/PresenceString.qml</file>
|
||||
<file>ui/modules/Linphone/qmldir</file>
|
||||
|
|
|
|||
|
|
@ -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<QQmlApplicationEngine &>(m_engine);
|
||||
const QQuickWindow *root = qobject_cast<QQuickWindow *>(engine.rootObjects().at(0));
|
||||
return !!root->activeFocusItem();
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void App::initContentApp () {
|
||||
qInfo() << "Initializing core manager...";
|
||||
|
||||
|
|
|
|||
|
|
@ -6,17 +6,31 @@
|
|||
#include <QQmlFileSelector>
|
||||
#include <QSystemTrayIcon>
|
||||
|
||||
#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;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#include <QtDebug>
|
||||
|
||||
#include "../../app/App.hpp"
|
||||
#include "CoreManager.hpp"
|
||||
|
||||
#include "CoreHandlers.hpp"
|
||||
|
|
@ -9,26 +10,31 @@ using namespace std;
|
|||
// =============================================================================
|
||||
|
||||
void CoreHandlers::onAuthenticationRequested (
|
||||
const std::shared_ptr<linphone::Core> &lc,
|
||||
const std::shared_ptr<linphone::AuthInfo> &auth_info,
|
||||
linphone::AuthMethod method
|
||||
const std::shared_ptr<linphone::Core> &,
|
||||
const std::shared_ptr<linphone::AuthInfo> &,
|
||||
linphone::AuthMethod
|
||||
) {
|
||||
qDebug() << "Auth request";
|
||||
}
|
||||
|
||||
void CoreHandlers::onCallStateChanged (
|
||||
const shared_ptr<linphone::Core> &lc,
|
||||
const shared_ptr<linphone::Call> &call,
|
||||
linphone::CallState cstate,
|
||||
const string &message
|
||||
const shared_ptr<linphone::Core> &,
|
||||
const shared_ptr<linphone::Call> &,
|
||||
linphone::CallState,
|
||||
const string &
|
||||
) {
|
||||
qDebug() << "call";
|
||||
}
|
||||
|
||||
void CoreHandlers::onMessageReceived (
|
||||
const shared_ptr<linphone::Core> &lc,
|
||||
const shared_ptr<linphone::Core> &,
|
||||
const shared_ptr<linphone::ChatRoom> &room,
|
||||
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 @@
|
|||
class CoreHandlers : public linphone::CoreListener {
|
||||
public:
|
||||
void onAuthenticationRequested (
|
||||
const std::shared_ptr<linphone::Core> &lc,
|
||||
const std::shared_ptr<linphone::Core> &core,
|
||||
const std::shared_ptr<linphone::AuthInfo> &auth_info,
|
||||
linphone::AuthMethod method
|
||||
) override;
|
||||
|
||||
void onCallStateChanged (
|
||||
const std::shared_ptr<linphone::Core> &lc,
|
||||
const std::shared_ptr<linphone::Core> &core,
|
||||
const std::shared_ptr<linphone::Call> &call,
|
||||
linphone::CallState cstate,
|
||||
const std::string &message
|
||||
) override;
|
||||
|
||||
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::ChatMessage> &message
|
||||
) override;
|
||||
|
|
|
|||
|
|
@ -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<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 &) {
|
||||
QObject *object = createNotification(Notifier::Call);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
#ifndef NOTIFIER_H_
|
||||
#define NOTIFIER_H_
|
||||
|
||||
#include <linphone++/linphone.hh>
|
||||
|
||||
#include <QMutex>
|
||||
#include <QObject>
|
||||
|
||||
|
|
@ -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<linphone::ChatRoom> &room,
|
||||
const std::shared_ptr<linphone::ChatMessage> &message
|
||||
);
|
||||
|
||||
// TODO
|
||||
void showCallMessage (int timeout, const QString &);
|
||||
|
||||
private:
|
||||
QObject *createNotification (NotificationType type);
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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"];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
import QtQuick 2.7
|
||||
|
||||
// =============================================================================
|
||||
|
||||
Notification {
|
||||
Rectangle {
|
||||
color: 'red'
|
||||
|
||||
width: 200
|
||||
height: 100
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue