Skip to content

Commit

Permalink
Merge branch 'do_not_disturb' into 'master'
Browse files Browse the repository at this point in the history
Support Do Not Disturb mode. JB#50221

See merge request mer-core/lipstick!151
  • Loading branch information
pvuorela committed Aug 25, 2020
2 parents 4939756 + c2185fd commit 2df81ae
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 21 deletions.
43 changes: 30 additions & 13 deletions src/notifications/notificationfeedbackplayer.cpp
@@ -1,6 +1,7 @@
/***************************************************************************
**
** Copyright (c) 2012 Jolla Ltd.
** Copyright (c) 2012-2019 Jolla Ltd.
** Copyright (c) 2020 Open Mobile Platform LLC.
**
** This file is part of lipstick.
**
Expand All @@ -14,6 +15,8 @@

#include <NgfClient>
#include <QWaylandSurface>
#include <QUrl>

#include "lipstickcompositor.h"
#include "notificationmanager.h"
#include "lipsticknotification.h"
Expand All @@ -33,7 +36,8 @@ enum PreviewMode {
NotificationFeedbackPlayer::NotificationFeedbackPlayer(QObject *parent) :
QObject(parent),
m_ngfClient(new Ngf::Client(this)),
m_minimumPriority(0)
m_minimumPriority(0),
m_doNotDisturbSetting(QLatin1String("/lipstick/do_not_disturb"))
{
connect(NotificationManager::instance(), SIGNAL(notificationRemoved(uint)), this, SLOT(removeNotification(uint)));

Expand Down Expand Up @@ -61,10 +65,10 @@ void NotificationFeedbackPlayer::addNotification(uint id)
// Play the feedback related to the notification if any
const QString feedback = notification->hints().value(LipstickNotification::HINT_FEEDBACK).toString();
const QStringList feedbackItems = feedback.split(QStringLiteral(","), QString::SkipEmptyParts);

if (isEnabled(notification, m_minimumPriority) && !feedbackItems.isEmpty()) {
QMap<QString, QVariant> properties;
if (notification->body().isEmpty() &&
notification->summary().isEmpty()) {
if (notification->body().isEmpty() && notification->summary().isEmpty()) {
properties.insert("media.leds", false);
}
if (notification->hints().value(LipstickNotification::HINT_SUPPRESS_SOUND, false).toBool()) {
Expand All @@ -75,14 +79,21 @@ void NotificationFeedbackPlayer::addNotification(uint id)
properties.insert("media.vibra", false);
}

QString soundFile = notification->hints().value(LipstickNotification::HINT_SOUND_FILE).toString();
if (!soundFile.isEmpty()) {
if (soundFile.startsWith(QStringLiteral("file://")))
soundFile.remove(0, 7);

properties.insert(QStringLiteral("sound.filename"), soundFile);
// Sound is enabled explicitly if sound-file hint is set.
properties.insert(QStringLiteral("sound.enabled"), true);
if (doNotDisturbMode()) {
// no sound or vibra, but led is allowed
properties.insert("media.vibra", false);
properties.insert("media.audio", false);
} else {
QString soundFile = notification->hints().value(LipstickNotification::HINT_SOUND_FILE).toString();
if (!soundFile.isEmpty()) {
if (soundFile.startsWith(QStringLiteral("file://"))) {
soundFile = QUrl(soundFile).toLocalFile();
}

properties.insert(QStringLiteral("sound.filename"), soundFile);
// Sound is enabled explicitly if sound-file hint is set.
properties.insert(QStringLiteral("sound.enabled"), true);
}
}

foreach (const QString &item, feedbackItems) {
Expand All @@ -92,7 +103,8 @@ void NotificationFeedbackPlayer::addNotification(uint id)
}

// vibra played if it's asked regardless of priorities
if (isEnabled(notification, 0) && notification->hints().value(LipstickNotification::HINT_VIBRA, false).toBool()) {
if (!doNotDisturbMode() && isEnabled(notification, 0)
&& notification->hints().value(LipstickNotification::HINT_VIBRA, false).toBool()) {
m_ngfClient->stop("vibra");
m_idToEventId.insert(notification, m_ngfClient->play("vibra", QMap<QString, QVariant>()));
}
Expand Down Expand Up @@ -145,3 +157,8 @@ void NotificationFeedbackPlayer::setMinimumPriority(int minimumPriority)

emit minimumPriorityChanged();
}

bool NotificationFeedbackPlayer::doNotDisturbMode() const
{
return m_doNotDisturbSetting.value().toBool();
}
8 changes: 7 additions & 1 deletion src/notifications/notificationfeedbackplayer.h
@@ -1,6 +1,7 @@
/***************************************************************************
**
** Copyright (c) 2012 Jolla Ltd.
** Copyright (c) 2012-2019 Jolla Ltd.
** Copyright (c) 2020 Open Mobile Platform LLC.
**
** This file is part of lipstick.
**
Expand All @@ -18,6 +19,7 @@
#include "lipstickglobal.h"
#include <QObject>
#include <QHash>
#include <MGConfItem>

class LipstickNotification;
namespace Ngf {
Expand Down Expand Up @@ -51,6 +53,8 @@ class LIPSTICK_EXPORT NotificationFeedbackPlayer : public QObject
*/
void setMinimumPriority(int minimumPriority);

bool doNotDisturbMode() const;

signals:
//! Emitted when the minimum priority of notifications for which a feedback should be played has changed
void minimumPriorityChanged();
Expand Down Expand Up @@ -86,6 +90,8 @@ private slots:
//! The minimum priority of notifications for which a feedback should be played
int m_minimumPriority;

MGConfItem m_doNotDisturbSetting;

friend class NotificationPreviewPresenter;
#ifdef UNIT_TEST
friend class Ut_NotificationFeedbackPlayer;
Expand Down
19 changes: 12 additions & 7 deletions src/notifications/notificationpreviewpresenter.cpp
@@ -1,6 +1,7 @@
/***************************************************************************
**
** Copyright (c) 2012 Jolla Ltd.
** Copyright (c) 2012-2019 Jolla Ltd.
** Copyright (c) 2020 Open Mobile Platform LLC.
**
** This file is part of lipstick.
**
Expand Down Expand Up @@ -156,7 +157,8 @@ void NotificationPreviewPresenter::removeNotification(uint id, bool onlyFromQueu
if (notification != 0) {
m_notificationQueue.removeAll(notification);

// If the notification is currently being shown hide it - the next notification will be shown after the current one has been hidden
// If the notification is currently being shown hide it
// - the next notification will be shown after the current one has been hidden
if (!onlyFromQueue && m_currentNotification == notification) {
m_currentNotification = 0;
emit notificationChanged();
Expand Down Expand Up @@ -241,13 +243,16 @@ void NotificationPreviewPresenter::setCurrentNotification(LipstickNotification *

if (notification) {
// Ask mce to turn the screen on if requested
const bool notificationIsCritical = notification->urgency() >= 2 ||
notification->hints().value(LipstickNotification::HINT_DISPLAY_ON).toBool();
const bool notificationCanUnblank = !notification->hints().value(LipstickNotification::HINT_SUPPRESS_DISPLAY_ON).toBool();
const bool notificationIsCritical = notification->urgency() >= 2;
const bool displayOnRequested = notification->hints().value(LipstickNotification::HINT_DISPLAY_ON).toBool()
&& !m_notificationFeedbackPlayer->doNotDisturbMode();
const bool notificationCanUnblank
= !notification->hints().value(LipstickNotification::HINT_SUPPRESS_DISPLAY_ON).toBool();

if (notificationIsCritical && notificationCanUnblank) {
if ((notificationIsCritical || displayOnRequested) && notificationCanUnblank) {
QString mceIdToAdd = QString("lipstick_notification_") + QString::number(notification->id());
QDBusMessage msg = QDBusMessage::createMethodCall(MCE_SERVICE, MCE_REQUEST_PATH, MCE_REQUEST_IF, MCE_NOTIFICATION_BEGIN);
QDBusMessage msg = QDBusMessage::createMethodCall(MCE_SERVICE, MCE_REQUEST_PATH, MCE_REQUEST_IF,
MCE_NOTIFICATION_BEGIN);
msg.setArguments(QVariantList() << mceIdToAdd << MCE_DURATION << MCE_EXTEND_DURATION);
QDBusConnection::systemBus().asyncCall(msg);
}
Expand Down
5 changes: 5 additions & 0 deletions tests/stubs/notificationfeedbackplayer_stub.h
Expand Up @@ -78,6 +78,7 @@ NotificationFeedbackPlayerStub *gNotificationFeedbackPlayerStub = &gDefaultNotif

// 4. CREATE A PROXY WHICH CALLS THE STUB
NotificationFeedbackPlayer::NotificationFeedbackPlayer(QObject *parent)
: m_doNotDisturbSetting("/lipstick/do_not_disturb")
{
gNotificationFeedbackPlayerStub->NotificationFeedbackPlayerConstructor(parent);
}
Expand Down Expand Up @@ -107,5 +108,9 @@ void NotificationFeedbackPlayer::removeNotification(uint id)
gNotificationFeedbackPlayerStub->removeNotification(id);
}

bool NotificationFeedbackPlayer::doNotDisturbMode() const
{
return false;
}

#endif

0 comments on commit 2df81ae

Please sign in to comment.