Skip to content

Commit

Permalink
Move notification hints from NotificationManager to LipstickNotification
Browse files Browse the repository at this point in the history
Gets rid of duplicated declarations in tests. Adding a new hint to
NotificationManager broke build.
  • Loading branch information
pvuorela committed Nov 28, 2017
1 parent bfa018e commit d9b6219
Show file tree
Hide file tree
Showing 21 changed files with 341 additions and 393 deletions.
5 changes: 3 additions & 2 deletions src/notifications/batterynotifier.cpp
Expand Up @@ -19,6 +19,7 @@
#include <QDebug>
#include "lowbatterynotifier.h"
#include "notificationmanager.h"
#include "lipsticknotification.h"
#include "batterynotifier.h"
#include <contextproperty.h>

Expand Down Expand Up @@ -249,8 +250,8 @@ void BatteryNotifier::sendNotification(BatteryNotifier::NotificationID id)

NotificationManager *manager = NotificationManager::instance();
QVariantHash hints;
hints.insert(NotificationManager::HINT_CATEGORY, info.category);
hints.insert(NotificationManager::HINT_PREVIEW_BODY, info.message);
hints.insert(LipstickNotification::HINT_CATEGORY, info.category);
hints.insert(LipstickNotification::HINT_PREVIEW_BODY, info.message);
QueuedNotification queued;
queued.number = manager->Notify(qApp->applicationName(), 0, info.icon,
QString(), QString(), QStringList(), hints, -1);
Expand Down
105 changes: 66 additions & 39 deletions src/notifications/lipsticknotification.cpp
Expand Up @@ -20,6 +20,33 @@
#include <QDataStream>
#include <QtDebug>

const char *LipstickNotification::HINT_URGENCY = "urgency";
const char *LipstickNotification::HINT_CATEGORY = "category";
const char *LipstickNotification::HINT_TRANSIENT = "transient";
const char *LipstickNotification::HINT_RESIDENT = "resident";
const char *LipstickNotification::HINT_IMAGE_PATH = "image-path";
const char *LipstickNotification::HINT_SUPPRESS_SOUND = "suppress-sound";
const char *LipstickNotification::HINT_ICON = "x-nemo-icon";
const char *LipstickNotification::HINT_ITEM_COUNT = "x-nemo-item-count";
const char *LipstickNotification::HINT_PRIORITY = "x-nemo-priority";
const char *LipstickNotification::HINT_TIMESTAMP = "x-nemo-timestamp";
const char *LipstickNotification::HINT_PREVIEW_ICON = "x-nemo-preview-icon";
const char *LipstickNotification::HINT_PREVIEW_BODY = "x-nemo-preview-body";
const char *LipstickNotification::HINT_PREVIEW_SUMMARY = "x-nemo-preview-summary";
const char *LipstickNotification::HINT_REMOTE_ACTION_PREFIX = "x-nemo-remote-action-";
const char *LipstickNotification::HINT_REMOTE_ACTION_ICON_PREFIX = "x-nemo-remote-action-icon-";
const char *LipstickNotification::HINT_USER_REMOVABLE = "x-nemo-user-removable";
const char *LipstickNotification::HINT_FEEDBACK = "x-nemo-feedback";
const char *LipstickNotification::HINT_HIDDEN = "x-nemo-hidden";
const char *LipstickNotification::HINT_DISPLAY_ON = "x-nemo-display-on";
const char *LipstickNotification::HINT_SUPPRESS_DISPLAY_ON = "x-nemo-suppress-display-on";
const char *LipstickNotification::HINT_LED_DISABLED_WITHOUT_BODY_AND_SUMMARY = "x-nemo-led-disabled-without-body-and-summary";
const char *LipstickNotification::HINT_ORIGIN = "x-nemo-origin";
const char *LipstickNotification::HINT_ORIGIN_PACKAGE = "x-nemo-origin-package";
const char *LipstickNotification::HINT_OWNER = "x-nemo-owner";
const char *LipstickNotification::HINT_MAX_CONTENT_LINES = "x-nemo-max-content-lines";
const char *LipstickNotification::HINT_RESTORED = "x-nemo-restored";

LipstickNotification::LipstickNotification(const QString &appName, const QString &disambiguatedAppName, uint id,
const QString &appIcon, const QString &summary, const QString &body,
const QStringList &actions, const QVariantHash &hints, int expireTimeout,
Expand All @@ -34,8 +61,8 @@ LipstickNotification::LipstickNotification(const QString &appName, const QString
m_actions(actions),
m_hints(hints),
m_expireTimeout(expireTimeout),
m_priority(hints.value(NotificationManager::HINT_PRIORITY).toInt()),
m_timestamp(hints.value(NotificationManager::HINT_TIMESTAMP).toDateTime().toMSecsSinceEpoch())
m_priority(hints.value(LipstickNotification::HINT_PRIORITY).toInt()),
m_timestamp(hints.value(LipstickNotification::HINT_TIMESTAMP).toDateTime().toMSecsSinceEpoch())
{
updateHintValues();
}
Expand Down Expand Up @@ -166,7 +193,7 @@ void LipstickNotification::setHints(const QVariantHash &hints)
emit iconChanged();
}

m_timestamp = m_hints.value(NotificationManager::HINT_TIMESTAMP).toDateTime().toMSecsSinceEpoch();
m_timestamp = m_hints.value(LipstickNotification::HINT_TIMESTAMP).toDateTime().toMSecsSinceEpoch();
if (oldTimestamp != m_timestamp) {
emit timestampChanged();
}
Expand All @@ -191,7 +218,7 @@ void LipstickNotification::setHints(const QVariantHash &hints)
emit itemCountChanged();
}

m_priority = m_hints.value(NotificationManager::HINT_PRIORITY).toInt();
m_priority = m_hints.value(LipstickNotification::HINT_PRIORITY).toInt();
if (oldPriority != m_priority) {
emit priorityChanged();
}
Expand All @@ -215,9 +242,9 @@ void LipstickNotification::setExpireTimeout(int expireTimeout)

QString LipstickNotification::icon() const
{
QString rv(m_hints.value(NotificationManager::HINT_ICON).toString());
QString rv(m_hints.value(LipstickNotification::HINT_ICON).toString());
if (rv.isEmpty()) {
rv = m_hints.value(NotificationManager::HINT_IMAGE_PATH).toString();
rv = m_hints.value(LipstickNotification::HINT_IMAGE_PATH).toString();
}
return rv;
}
Expand All @@ -229,27 +256,27 @@ QDateTime LipstickNotification::timestamp() const

QString LipstickNotification::previewIcon() const
{
return m_hints.value(NotificationManager::HINT_PREVIEW_ICON).toString();
return m_hints.value(LipstickNotification::HINT_PREVIEW_ICON).toString();
}

QString LipstickNotification::previewSummary() const
{
return m_hints.value(NotificationManager::HINT_PREVIEW_SUMMARY).toString();
return m_hints.value(LipstickNotification::HINT_PREVIEW_SUMMARY).toString();
}

QString LipstickNotification::previewBody() const
{
return m_hints.value(NotificationManager::HINT_PREVIEW_BODY).toString();
return m_hints.value(LipstickNotification::HINT_PREVIEW_BODY).toString();
}

int LipstickNotification::urgency() const
{
return m_hints.value(NotificationManager::HINT_URGENCY).toInt();
return m_hints.value(LipstickNotification::HINT_URGENCY).toInt();
}

int LipstickNotification::itemCount() const
{
return m_hints.value(NotificationManager::HINT_ITEM_COUNT).toInt();
return m_hints.value(LipstickNotification::HINT_ITEM_COUNT).toInt();
}

int LipstickNotification::priority() const
Expand All @@ -259,17 +286,17 @@ int LipstickNotification::priority() const

QString LipstickNotification::category() const
{
return m_hints.value(NotificationManager::HINT_CATEGORY).toString();
return m_hints.value(LipstickNotification::HINT_CATEGORY).toString();
}

bool LipstickNotification::isUserRemovable() const
{
return m_hints.value(NotificationManager::HINT_USER_REMOVABLE, QVariant(true)).toBool();
return m_hints.value(LipstickNotification::HINT_USER_REMOVABLE, QVariant(true)).toBool();
}

bool LipstickNotification::hidden() const
{
return m_hints.value(NotificationManager::HINT_HIDDEN, QVariant(false)).toBool();
return m_hints.value(LipstickNotification::HINT_HIDDEN, QVariant(false)).toBool();
}

QVariantList LipstickNotification::remoteActions() const
Expand All @@ -285,9 +312,9 @@ QVariantList LipstickNotification::remoteActions() const
++it;
}

const QString hint(m_hints.value(NotificationManager::HINT_REMOTE_ACTION_PREFIX + name).toString());
const QString hint(m_hints.value(LipstickNotification::HINT_REMOTE_ACTION_PREFIX + name).toString());
if (!hint.isEmpty()) {
const QString icon(m_hints.value(NotificationManager::HINT_REMOTE_ACTION_ICON_PREFIX + name).toString());
const QString icon(m_hints.value(LipstickNotification::HINT_REMOTE_ACTION_ICON_PREFIX + name).toString());

QVariantMap vm;
vm.insert(QStringLiteral("name"), name);
Expand Down Expand Up @@ -331,22 +358,22 @@ QVariantList LipstickNotification::remoteActions() const

QString LipstickNotification::origin() const
{
return m_hints.value(NotificationManager::HINT_ORIGIN).toString();
return m_hints.value(LipstickNotification::HINT_ORIGIN).toString();
}

QString LipstickNotification::owner() const
{
return m_hints.value(NotificationManager::HINT_OWNER).toString();
return m_hints.value(LipstickNotification::HINT_OWNER).toString();
}

int LipstickNotification::maxContentLines() const
{
return m_hints.value(NotificationManager::HINT_MAX_CONTENT_LINES).toInt();
return m_hints.value(LipstickNotification::HINT_MAX_CONTENT_LINES).toInt();
}

bool LipstickNotification::restored() const
{
return m_hints.value(NotificationManager::HINT_RESTORED).toBool();
return m_hints.value(LipstickNotification::HINT_RESTORED).toBool();
}

quint64 LipstickNotification::internalTimestamp() const
Expand All @@ -362,23 +389,23 @@ void LipstickNotification::updateHintValues()
for ( ; it != end; ++it) {
// Filter out the hints that are represented by other properties
const QString &hint(it.key());
if (hint.compare(NotificationManager::HINT_ICON, Qt::CaseInsensitive) != 0 &&
hint.compare(NotificationManager::HINT_IMAGE_PATH, Qt::CaseInsensitive) != 0 &&
hint.compare(NotificationManager::HINT_TIMESTAMP, Qt::CaseInsensitive) != 0 &&
hint.compare(NotificationManager::HINT_PREVIEW_ICON, Qt::CaseInsensitive) != 0 &&
hint.compare(NotificationManager::HINT_PREVIEW_SUMMARY, Qt::CaseInsensitive) != 0 &&
hint.compare(NotificationManager::HINT_PREVIEW_BODY, Qt::CaseInsensitive) != 0 &&
hint.compare(NotificationManager::HINT_URGENCY, Qt::CaseInsensitive) != 0 &&
hint.compare(NotificationManager::HINT_ITEM_COUNT, Qt::CaseInsensitive) != 0 &&
hint.compare(NotificationManager::HINT_PRIORITY, Qt::CaseInsensitive) != 0 &&
hint.compare(NotificationManager::HINT_CATEGORY, Qt::CaseInsensitive) != 0 &&
hint.compare(NotificationManager::HINT_USER_REMOVABLE, Qt::CaseInsensitive) != 0 &&
hint.compare(NotificationManager::HINT_HIDDEN, Qt::CaseInsensitive) != 0 &&
hint.compare(NotificationManager::HINT_ORIGIN, Qt::CaseInsensitive) != 0 &&
hint.compare(NotificationManager::HINT_OWNER, Qt::CaseInsensitive) != 0 &&
hint.compare(NotificationManager::HINT_MAX_CONTENT_LINES, Qt::CaseInsensitive) != 0 &&
!hint.startsWith(NotificationManager::HINT_REMOTE_ACTION_PREFIX, Qt::CaseInsensitive) &&
!hint.startsWith(NotificationManager::HINT_REMOTE_ACTION_ICON_PREFIX, Qt::CaseInsensitive)) {
if (hint.compare(LipstickNotification::HINT_ICON, Qt::CaseInsensitive) != 0 &&
hint.compare(LipstickNotification::HINT_IMAGE_PATH, Qt::CaseInsensitive) != 0 &&
hint.compare(LipstickNotification::HINT_TIMESTAMP, Qt::CaseInsensitive) != 0 &&
hint.compare(LipstickNotification::HINT_PREVIEW_ICON, Qt::CaseInsensitive) != 0 &&
hint.compare(LipstickNotification::HINT_PREVIEW_SUMMARY, Qt::CaseInsensitive) != 0 &&
hint.compare(LipstickNotification::HINT_PREVIEW_BODY, Qt::CaseInsensitive) != 0 &&
hint.compare(LipstickNotification::HINT_URGENCY, Qt::CaseInsensitive) != 0 &&
hint.compare(LipstickNotification::HINT_ITEM_COUNT, Qt::CaseInsensitive) != 0 &&
hint.compare(LipstickNotification::HINT_PRIORITY, Qt::CaseInsensitive) != 0 &&
hint.compare(LipstickNotification::HINT_CATEGORY, Qt::CaseInsensitive) != 0 &&
hint.compare(LipstickNotification::HINT_USER_REMOVABLE, Qt::CaseInsensitive) != 0 &&
hint.compare(LipstickNotification::HINT_HIDDEN, Qt::CaseInsensitive) != 0 &&
hint.compare(LipstickNotification::HINT_ORIGIN, Qt::CaseInsensitive) != 0 &&
hint.compare(LipstickNotification::HINT_OWNER, Qt::CaseInsensitive) != 0 &&
hint.compare(LipstickNotification::HINT_MAX_CONTENT_LINES, Qt::CaseInsensitive) != 0 &&
!hint.startsWith(LipstickNotification::HINT_REMOTE_ACTION_PREFIX, Qt::CaseInsensitive) &&
!hint.startsWith(LipstickNotification::HINT_REMOTE_ACTION_ICON_PREFIX, Qt::CaseInsensitive)) {
m_hintValues.insert(hint, it.value());
}
}
Expand Down Expand Up @@ -412,8 +439,8 @@ const QDBusArgument &operator>>(const QDBusArgument &argument, LipstickNotificat
argument >> notification.m_expireTimeout;
argument.endStructure();

notification.m_priority = notification.m_hints.value(NotificationManager::HINT_PRIORITY).toInt();
notification.m_timestamp = notification.m_hints.value(NotificationManager::HINT_TIMESTAMP).toDateTime().toMSecsSinceEpoch();
notification.m_priority = notification.m_hints.value(LipstickNotification::HINT_PRIORITY).toInt();
notification.m_timestamp = notification.m_hints.value(LipstickNotification::HINT_TIMESTAMP).toDateTime().toMSecsSinceEpoch();
notification.updateHintValues();

return argument;
Expand Down
79 changes: 79 additions & 0 deletions src/notifications/lipsticknotification.h
Expand Up @@ -54,6 +54,85 @@ class LIPSTICK_EXPORT LipstickNotification : public QObject
Q_PROPERTY(int maxContentLines READ maxContentLines CONSTANT)

public:
//! Standard hint: The urgency level.
static const char *HINT_URGENCY;

//! Standard hint: The type of notification this is.
static const char *HINT_CATEGORY;

//! Standard hint: If true, the notification should be removed after display.
static const char *HINT_TRANSIENT;

//! Standard hint: If true, the notification should not be removed after activation.
static const char *HINT_RESIDENT;

//! Standard hint: Icon of the notification: either a file:// URL, an absolute path, or a token to be satisfied by the 'theme' image provider.
static const char *HINT_IMAGE_PATH;

//! Standard hint: If true, audible feedback should be should be suppressed during notification feedback.
static const char *HINT_SUPPRESS_SOUND;

//! Nemo hint: Icon of the notification. Might take precedence over appIcon depending on platform implementation.
static const char *HINT_ICON;

//! Nemo hint: Item count represented by the notification.
static const char *HINT_ITEM_COUNT;

//! Nemo hint: Priority level of the notification.
static const char *HINT_PRIORITY;

//! Nemo hint: Timestamp of the notification.
static const char *HINT_TIMESTAMP;

//! Nemo hint: Icon of the preview of the notification.
static const char *HINT_PREVIEW_ICON;

//! Nemo hint: Body text of the preview of the notification.
static const char *HINT_PREVIEW_BODY;

//! Nemo hint: Summary text of the preview of the notification.
static const char *HINT_PREVIEW_SUMMARY;

//! Nemo hint: Remote action of the notification. Prefix only: the action identifier is to be appended.
static const char *HINT_REMOTE_ACTION_PREFIX;

//! Nemo hint: Icon for the remote action of the notification. Prefix only: the action identifier is to be appended.
static const char *HINT_REMOTE_ACTION_ICON_PREFIX;

//! Nemo hint: User removability of the notification.
static const char *HINT_USER_REMOVABLE;

//! Nemo hint: Feedback of the notification.
static const char *HINT_FEEDBACK;

//! Nemo hint: Whether the notification is hidden.
static const char *HINT_HIDDEN;

//! Nemo hint: Whether to turn the screen on when displaying preview
static const char *HINT_DISPLAY_ON;

//! Nemo hint: Even if priority suggests it, do not turn display on
static const char *HINT_SUPPRESS_DISPLAY_ON;

//! Nemo hint: Whether to disable LED feedbacks when there is no body and summary
static const char *HINT_LED_DISABLED_WITHOUT_BODY_AND_SUMMARY;

//! Nemo hint: Indicates the origin of the notification
static const char *HINT_ORIGIN;

//! Nemo hint: Indicates the Android package name from which this notification originates
static const char *HINT_ORIGIN_PACKAGE;

//! Nemo hint: Indicates the identifer of the owner for notification
static const char *HINT_OWNER;

//! Nemo hint: Specifies the maximum number of content lines to display (including summary)
static const char *HINT_MAX_CONTENT_LINES;

//! Nemo hint: Indicates that this notification has been restored from persistent storage since the last update.
//! Internal, shouldn't be expected or allowed from d-bus
static const char *HINT_RESTORED;

/*!
* Creates an object for storing information about a single notification.
*
Expand Down
9 changes: 5 additions & 4 deletions src/notifications/notificationfeedbackplayer.cpp
Expand Up @@ -17,6 +17,7 @@
#include <QWaylandSurface>
#include "lipstickcompositor.h"
#include "notificationmanager.h"
#include "lipsticknotification.h"
#include "notificationfeedbackplayer.h"

namespace {
Expand Down Expand Up @@ -58,16 +59,16 @@ void NotificationFeedbackPlayer::addNotification(uint id)
}

// Play the feedback related to the notification if any
const QString feedback = notification->hints().value(NotificationManager::HINT_FEEDBACK).toString();
const QString feedback = notification->hints().value(LipstickNotification::HINT_FEEDBACK).toString();
const QStringList feedbackItems = feedback.split(QStringLiteral(","), QString::SkipEmptyParts);
if (!feedbackItems.isEmpty()) {
QMap<QString, QVariant> properties;
if (notification->hints().value(NotificationManager::HINT_LED_DISABLED_WITHOUT_BODY_AND_SUMMARY, true).toBool() &&
if (notification->hints().value(LipstickNotification::HINT_LED_DISABLED_WITHOUT_BODY_AND_SUMMARY, true).toBool() &&
notification->body().isEmpty() &&
notification->summary().isEmpty()) {
properties.insert("media.leds", false);
}
if (notification->hints().value(NotificationManager::HINT_SUPPRESS_SOUND, false).toBool()) {
if (notification->hints().value(LipstickNotification::HINT_SUPPRESS_SOUND, false).toBool()) {
properties.insert("media.audio", false);
}

Expand Down Expand Up @@ -118,7 +119,7 @@ bool NotificationFeedbackPlayer::isEnabled(LipstickNotification *notification)

int urgency = notification->urgency();
int priority = notification->priority();
int notificationIsCritical = urgency >= 2 || notification->hints().value(NotificationManager::HINT_DISPLAY_ON).toBool();
int notificationIsCritical = urgency >= 2 || notification->hints().value(LipstickNotification::HINT_DISPLAY_ON).toBool();

return !(urgency < 2 && priority < m_minimumPriority) &&
(mode == AllNotificationsEnabled ||
Expand Down

0 comments on commit d9b6219

Please sign in to comment.