mirror of
https://gitlab.linphone.org/BC/public/linphone-desktop.git
synced 2026-01-23 22:58:15 +00:00
feat(notifier): supports visible property changed to false
This commit is contained in:
parent
fbfa00a3de
commit
41cab40639
3 changed files with 69 additions and 25 deletions
|
|
@ -1,3 +1,4 @@
|
|||
#include <QQuickWindow>
|
||||
#include <QTimer>
|
||||
#include <QtDebug>
|
||||
|
||||
|
|
@ -13,6 +14,7 @@
|
|||
// Arbitrary hardcoded values.
|
||||
#define NOTIFICATION_SPACING 10
|
||||
#define N_MAX_NOTIFICATIONS 15
|
||||
#define MAX_TIMEOUT 60000
|
||||
|
||||
// ===================================================================
|
||||
|
||||
|
|
@ -71,24 +73,18 @@ Notifier::~Notifier () {
|
|||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
void Notifier::showCallMessage (
|
||||
int timeout,
|
||||
const QString &sip_address
|
||||
) {
|
||||
qDebug() << "Show call notification message. (addr=" <<
|
||||
sip_address << ")";
|
||||
|
||||
QObject *Notifier::createNotification (Notifier::NotificationType type) {
|
||||
m_mutex.lock();
|
||||
|
||||
// Check existing instances.
|
||||
if (m_n_instances >= N_MAX_NOTIFICATIONS) {
|
||||
qWarning() << "Unable to create another notification";
|
||||
m_mutex.unlock();
|
||||
return;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Create instance and set attributes.
|
||||
QObject *object = m_components[Notifier::Call]->create();
|
||||
QObject *object = m_components[type]->create();
|
||||
int offset = getNotificationSize(*object, NOTIFICATION_HEIGHT_PROPERTY);
|
||||
|
||||
if (
|
||||
|
|
@ -97,7 +93,7 @@ void Notifier::showCallMessage (
|
|||
) {
|
||||
delete object;
|
||||
m_mutex.unlock();
|
||||
return;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
m_offset = (offset + m_offset) + NOTIFICATION_SPACING;
|
||||
|
|
@ -105,22 +101,63 @@ void Notifier::showCallMessage (
|
|||
|
||||
m_mutex.unlock();
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
void Notifier::showNotification (QObject *notification, int timeout) {
|
||||
if (timeout > MAX_TIMEOUT) {
|
||||
timeout = MAX_TIMEOUT;
|
||||
}
|
||||
|
||||
// Display notification.
|
||||
QMetaObject::invokeMethod(
|
||||
object, NOTIFICATION_SHOW_METHOD_NAME,
|
||||
notification, NOTIFICATION_SHOW_METHOD_NAME,
|
||||
Qt::DirectConnection
|
||||
);
|
||||
|
||||
// Called explicitly (by a click on notification for example)
|
||||
// or when single shot happen and if notification is visible.
|
||||
QObject::connect(
|
||||
notification->findChild<QQuickWindow *>(),
|
||||
&QQuickWindow::visibleChanged,
|
||||
[this](const bool &value) {
|
||||
qDebug() << "Update notifications counter, hidden notification detected.";
|
||||
|
||||
if (value) {
|
||||
qFatal("A notification cannot be visible twice!");
|
||||
return;
|
||||
}
|
||||
|
||||
m_mutex.lock();
|
||||
|
||||
m_n_instances--;
|
||||
|
||||
if (m_n_instances == 0)
|
||||
m_offset = 0;
|
||||
|
||||
m_mutex.unlock();
|
||||
}
|
||||
);
|
||||
|
||||
// Destroy it after timeout.
|
||||
QTimer::singleShot(timeout, this, [object, this]() {
|
||||
delete object;
|
||||
|
||||
m_mutex.lock();
|
||||
m_n_instances--;
|
||||
|
||||
if (m_n_instances == 0)
|
||||
m_offset = 0;
|
||||
|
||||
m_mutex.unlock();
|
||||
QTimer::singleShot(timeout, this, [notification]() {
|
||||
delete notification;
|
||||
});
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
void Notifier::showCallMessage (
|
||||
int timeout,
|
||||
const QString &sip_address
|
||||
) {
|
||||
qDebug() << "Show call notification message. (addr=" <<
|
||||
sip_address << ")";
|
||||
|
||||
QObject *object = createNotification(Notifier::Call);
|
||||
|
||||
if (!object)
|
||||
return;
|
||||
|
||||
showNotification(object, timeout);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,20 +14,23 @@ public:
|
|||
Notifier (QObject *parent = Q_NULLPTR);
|
||||
virtual ~Notifier ();
|
||||
|
||||
enum Type {
|
||||
enum NotificationType {
|
||||
Call,
|
||||
MaxNbTypes
|
||||
};
|
||||
Q_ENUM(Type);
|
||||
|
||||
public slots:
|
||||
void showCallMessage (int timeout, const QString &sip_address);
|
||||
|
||||
private:
|
||||
QObject *createNotification (NotificationType type);
|
||||
void handleNotificationHidden ();
|
||||
void showNotification (QObject *notification, int timeout);
|
||||
|
||||
QQmlComponent *m_components[MaxNbTypes];
|
||||
|
||||
int m_offset = 0;
|
||||
int m_n_instances = 0;
|
||||
unsigned int m_n_instances = 0;
|
||||
QMutex m_mutex;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ TestCase {
|
|||
|
||||
function test_notificationHeightProperty () {
|
||||
compare(Utils.isInteger(notification.notificationHeight), true)
|
||||
}
|
||||
}
|
||||
|
||||
function test_notificationOffsetProperty () {
|
||||
compare(Utils.isInteger(notification.notificationOffset), true)
|
||||
|
|
@ -22,4 +22,8 @@ TestCase {
|
|||
function test_notificationShowMethod () {
|
||||
compare(Utils.isFunction(notification.show), true)
|
||||
}
|
||||
|
||||
function test_childWindow () {
|
||||
compare(Utils.qmlTypeof(notification.data[0], 'QQuickWindowQmlImpl'), true)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue