Skip to content

Commit

Permalink
Merge branch 'explicit_app_name' into 'master'
Browse files Browse the repository at this point in the history
Explicit notification app name

See merge request mer-core/lipstick!157
  • Loading branch information
pvuorela committed Sep 28, 2020
2 parents fc665e3 + e3d8367 commit f2286a2
Show file tree
Hide file tree
Showing 11 changed files with 169 additions and 133 deletions.
5 changes: 1 addition & 4 deletions doc/src/notifications.dox
Expand Up @@ -110,7 +110,6 @@
* - \c hints should contain the following:
* - \c category should be "im.received" to categorize the notification to be related to an instant message
* - \c urgency should be 1 (normal) since chat messages are not specifically low or high priority
* - \c app_icon should be "icon-lock-chat" to define that the icon with that ID is to be shown on the notification area
* - \c x-nemo-preview-summary should match the summary text ("John Doe") in order to show it also on the preview banner
* - \c x-nemo-preview-body should match the body text ("Hi!") in order to show it also on the preview banner
* - \c x-nemo-timestamp should be set to the time when the chat message was sent (or received, depending on the intended application logic)
Expand All @@ -133,7 +132,6 @@
* - \c hints should contain the following:
* - \c category should be "im.received" to categorize the notification to be related to an instant message
* - \c urgency should be 1 (normal) since chat messages are not specifically low or high priority
* - \c app_icon should be "icon-lock-chat" to define that the icon with that ID is to be shown on the notification area
* - \c x-nemo-item-count should be 2 to make the notification represent two chat messages
* - \c x-nemo-preview-summary should contain a brief description about the notification to be shown on the preview banner, like "John Doe"
* - \c x-nemo-preview-body should contain informative text about the notification to be shown on the preview banner, like "Are you there?"
Expand Down Expand Up @@ -165,15 +163,14 @@
* When calling Notify() to a display a transient notification, the parameters should be set as follows:
* - \c app_name should be a string identifying the sender application, such as the name of its binary, for example. "batterynotifier"
* - \c replaces_id should be 0 since the notification is a new one and not related to any existing notification
* - \c app_icon should be left empty; it will not be used in this scenario
* - \c app_icon should be "icon-battery-low" to define that the icon with that ID is to be shown on the preview banner
* - \c summary should be left empty for nothing to be shown in the events view
* - \c body should be left empty for nothing to be shown in the events view
* - \c actions should be left empty
* - \c hints should contain the following:
* - \c category should be "device" to categorize the notification to be related to the device
* - \c urgency should be 2 (critical) to show the notification over the lock screen
* - \c transient should be true to automatically close the notification after display
* - \c app_icon should be "icon-battery-low" to define that the icon with that ID is to be shown on the preview banner
* - \c x-nemo-preview-body should be "Battery low" in order to show it on the preview banner
* - \c expire_timeout should be -1 to let the notification manager choose an appropriate expiration time
*
Expand Down
134 changes: 89 additions & 45 deletions src/notifications/lipsticknotification.cpp
Expand Up @@ -35,7 +35,6 @@ const char *LipstickNotification::HINT_IMAGE_PATH = "image-path";
const char *LipstickNotification::HINT_IMAGE_DATA = "image-data";
const char *LipstickNotification::HINT_SUPPRESS_SOUND = "suppress-sound";
const char *LipstickNotification::HINT_SOUND_FILE = "sound-file";
const char *LipstickNotification::HINT_APP_ICON = "app_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";
Expand All @@ -55,53 +54,56 @@ const char *LipstickNotification::HINT_PROGRESS = "x-nemo-progress";
const char *LipstickNotification::HINT_VIBRA = "x-nemo-vibrate";
const char *LipstickNotification::HINT_VISIBILITY = "x-nemo-visibility";

LipstickNotification::LipstickNotification(const QString &appName, const QString &disambiguatedAppName, uint id,
LipstickNotification::LipstickNotification(const QString &appName, const QString &explicitAppName,
const QString &disambiguatedAppName, uint id,
const QString &appIcon, const QString &summary, const QString &body,
const QStringList &actions, const QVariantHash &hints, int expireTimeout,
QObject *parent) :
QObject(parent),
m_appName(appName),
m_disambiguatedAppName(disambiguatedAppName),
m_id(id),
m_summary(summary),
m_body(body),
m_actions(actions),
m_hints(hints),
m_expireTimeout(expireTimeout),
m_priority(hints.value(LipstickNotification::HINT_PRIORITY).toInt()),
m_timestamp(hints.value(LipstickNotification::HINT_TIMESTAMP).toDateTime().toMSecsSinceEpoch()),
m_activeProgressTimer(0)
{
if (!appIcon.isEmpty()) {
m_hints.insert(LipstickNotification::HINT_APP_ICON, appIcon);
}
QObject *parent)
: QObject(parent),
m_appName(appName),
m_explicitAppName(explicitAppName),
m_disambiguatedAppName(disambiguatedAppName),
m_id(id),
m_appIcon(appIcon),
m_summary(summary),
m_body(body),
m_actions(actions),
m_hints(hints),
m_expireTimeout(expireTimeout),
m_priority(hints.value(LipstickNotification::HINT_PRIORITY).toInt()),
m_timestamp(hints.value(LipstickNotification::HINT_TIMESTAMP).toDateTime().toMSecsSinceEpoch()),
m_activeProgressTimer(0)
{
updateHintValues();
}

LipstickNotification::LipstickNotification(QObject *parent) :
QObject(parent),
m_id(0),
m_expireTimeout(-1),
m_priority(0),
m_timestamp(0),
m_activeProgressTimer(0)
LipstickNotification::LipstickNotification(QObject *parent)
: QObject(parent),
m_id(0),
m_expireTimeout(-1),
m_priority(0),
m_timestamp(0),
m_activeProgressTimer(0)
{
}

LipstickNotification::LipstickNotification(const LipstickNotification &notification) :
QObject(notification.parent()),
m_appName(notification.m_appName),
m_disambiguatedAppName(notification.m_disambiguatedAppName),
m_id(notification.m_id),
m_summary(notification.m_summary),
m_body(notification.m_body),
m_actions(notification.m_actions),
m_hints(notification.m_hints),
m_hintValues(notification.m_hintValues),
m_expireTimeout(notification.m_expireTimeout),
m_priority(notification.m_priority),
m_timestamp(notification.m_timestamp),
m_activeProgressTimer(0) // not caring for d-bus serialization
LipstickNotification::LipstickNotification(const LipstickNotification &notification)
: QObject(notification.parent()),
m_appName(notification.m_appName),
m_explicitAppName(notification.m_explicitAppName),
m_disambiguatedAppName(notification.m_disambiguatedAppName),
m_id(notification.m_id),
m_appIcon(notification.m_appIcon),
m_appIconOrigin(notification.m_appIconOrigin),
m_summary(notification.m_summary),
m_body(notification.m_body),
m_actions(notification.m_actions),
m_hints(notification.m_hints),
m_hintValues(notification.m_hintValues),
m_expireTimeout(notification.m_expireTimeout),
m_priority(notification.m_priority),
m_timestamp(notification.m_timestamp),
m_activeProgressTimer(0) // not caring for d-bus serialization
{
}

Expand All @@ -110,6 +112,11 @@ QString LipstickNotification::appName() const
return m_appName;
}

QString LipstickNotification::explicitAppName() const
{
return m_explicitAppName;
}

QString LipstickNotification::disambiguatedAppName() const
{
return m_disambiguatedAppName;
Expand All @@ -120,6 +127,11 @@ void LipstickNotification::setAppName(const QString &appName)
m_appName = appName;
}

void LipstickNotification::setExplicitAppName(const QString &appName)
{
m_explicitAppName = appName;
}

void LipstickNotification::setDisambiguatedAppName(const QString &disambiguatedAppName)
{
m_disambiguatedAppName = disambiguatedAppName;
Expand All @@ -132,7 +144,33 @@ uint LipstickNotification::id() const

QString LipstickNotification::appIcon() const
{
return m_hints.value(LipstickNotification::HINT_APP_ICON).toString();
return m_appIcon;
}

void LipstickNotification::setAppIcon(const QString &appIcon, int source)
{
bool iconChanged = false;
bool sourceChanged = false;

if (appIcon != m_appIcon) {
m_appIcon = appIcon;
}

if (source != m_appIconOrigin) {
m_appIconOrigin = source;
}

if (iconChanged) {
emit appIconChanged();
}
if (sourceChanged) {
emit appIconOriginChanged();
}
}

int LipstickNotification::appIconOrigin() const
{
return m_appIconOrigin;
}

QString LipstickNotification::summary() const
Expand Down Expand Up @@ -194,6 +232,7 @@ void LipstickNotification::setHints(const QVariantHash &hints)
QString oldCategory = category();
qreal oldProgress = progress();
bool oldHasProgress = hasProgress();
bool oldIsTransient = isTransient();

m_hints = hints;
updateHintValues();
Expand Down Expand Up @@ -244,6 +283,10 @@ void LipstickNotification::setHints(const QVariantHash &hints)
emit progressChanged();
}

if (oldIsTransient != isTransient()) {
emit isTransientChanged();
}

emit hintsChanged();
}

Expand Down Expand Up @@ -432,16 +475,15 @@ void LipstickNotification::updateHintValues()

if (hint == HINT_ICON) {
qWarning() << "Notification sets deprecated hint" << HINT_ICON
<< "to" << it.value() << ", use" << LipstickNotification::HINT_APP_ICON << "or"
<< "to" << it.value() << ", use app_icon parameter or"
<< LipstickNotification::HINT_IMAGE_PATH << "instead";
} else if (hint == HINT_PREVIEW_ICON) {
qWarning() << "Notification sets deprecated hint" << HINT_PREVIEW_ICON
<< "to" << it.value() << ", use" << LipstickNotification::HINT_APP_ICON << "or"
<< "to" << it.value() << ", use app_icon parameter or"
<< LipstickNotification::HINT_IMAGE_PATH << "instead";
}

if (hint.compare(LipstickNotification::HINT_APP_ICON, Qt::CaseInsensitive) != 0 &&
hint.compare(LipstickNotification::HINT_TIMESTAMP, Qt::CaseInsensitive) != 0 &&
if (hint.compare(LipstickNotification::HINT_TIMESTAMP, 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_SUB_TEXT, Qt::CaseInsensitive) != 0 &&
Expand All @@ -464,6 +506,7 @@ QDBusArgument &operator<<(QDBusArgument &argument, const LipstickNotification &n
argument.beginStructure();
argument << notification.m_appName;
argument << notification.m_id;
argument << notification.m_appIcon;
argument << notification.m_summary;
argument << notification.m_body;
argument << notification.m_actions;
Expand All @@ -478,6 +521,7 @@ const QDBusArgument &operator>>(const QDBusArgument &argument, LipstickNotificat
argument.beginStructure();
argument >> notification.m_appName;
argument >> notification.m_id;
argument >> notification.m_appIcon;
argument >> notification.m_summary;
argument >> notification.m_body;
argument >> notification.m_actions;
Expand Down
26 changes: 21 additions & 5 deletions src/notifications/lipsticknotification.h
Expand Up @@ -30,10 +30,13 @@ class QDBusArgument;
class LIPSTICK_EXPORT LipstickNotification : public QObject
{
Q_OBJECT
Q_ENUMS(InformationOrigin)
Q_PROPERTY(QString appName READ appName CONSTANT)
Q_PROPERTY(QString explicitAppName READ explicitAppName CONSTANT)
Q_PROPERTY(QString disambiguatedAppName READ disambiguatedAppName CONSTANT)
Q_PROPERTY(uint id READ id CONSTANT)
Q_PROPERTY(QString appIcon READ appIcon NOTIFY appIconChanged)
Q_PROPERTY(int appIconOrigin READ appIconOrigin NOTIFY appIconOriginChanged)
Q_PROPERTY(QString summary READ summary NOTIFY summaryChanged)
Q_PROPERTY(QString body READ body NOTIFY bodyChanged)
Q_PROPERTY(QStringList actions READ actions CONSTANT)
Expand All @@ -52,9 +55,11 @@ class LIPSTICK_EXPORT LipstickNotification : public QObject
Q_PROPERTY(QString owner READ owner CONSTANT)
Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged)
Q_PROPERTY(bool hasProgress READ hasProgress NOTIFY hasProgressChanged)
Q_PROPERTY(bool isTransient READ isTransient NOTIFY isTransientChanged)

public:
enum Urgency { Low = 0, Normal = 1, Critical = 2 };
enum InformationOrigin { ExplicitValue, CategoryValue, InferredValue };

//! Standard hint: The urgency level.
static const char *HINT_URGENCY;
Expand All @@ -80,9 +85,6 @@ class LIPSTICK_EXPORT LipstickNotification : public QObject
//! Standard hint: If set, override possible audible feedback sound.
static const char *HINT_SOUND_FILE;

//! Standard hint: Icon ID of the application sending the notification.
static const char *HINT_APP_ICON;

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

Expand Down Expand Up @@ -142,6 +144,7 @@ class LIPSTICK_EXPORT LipstickNotification : public QObject
* Creates an object for storing information about a single notification.
*
* \param appName name of the application sending the notification
* \param explicitAppName name explicitly set on the received notification
* \param disambiguatedAppName name of the application, decorated to disambiguate names from android and native applications
* \param id the ID of the notification
* \param appIcon icon ID of the application sending the notification
Expand All @@ -152,8 +155,9 @@ class LIPSTICK_EXPORT LipstickNotification : public QObject
* \param expireTimeout expiration timeout for the notification
* \param parent the parent QObject
*/
LipstickNotification(const QString &appName, const QString &disambiguatedAppName, uint id, const QString &appIcon,
const QString &summary, const QString &body, const QStringList &actions, const QVariantHash &hints,
LipstickNotification(const QString &appName, const QString &explicitAppName, const QString &disambiguatedAppName,
uint id, const QString &appIcon, const QString &summary, const QString &body,
const QStringList &actions, const QVariantHash &hints,
int expireTimeout, QObject *parent = 0);

/*!
Expand All @@ -165,17 +169,22 @@ class LIPSTICK_EXPORT LipstickNotification : public QObject

//! Returns the name of the application sending the notification
QString appName() const;
QString explicitAppName() const;
QString disambiguatedAppName() const;

//! Sets the name of the application sending the notification
void setAppName(const QString &appName);
void setExplicitAppName(const QString &appName);
void setDisambiguatedAppName(const QString &disambiguatedAppName);

//! Returns the ID of the notification
uint id() const;

//! Returns the icon ID of the application sending the notification
QString appIcon() const;
void setAppIcon(const QString &appIcon, int source = ExplicitValue);

int appIconOrigin() const;

//! Returns the summary text for the notification
QString summary() const;
Expand Down Expand Up @@ -295,6 +304,7 @@ class LIPSTICK_EXPORT LipstickNotification : public QObject

//! Sent when the app icon has been modified
void appIconChanged();
void appIconOriginChanged();

//! Sent when the timestamp has changed
void timestampChanged();
Expand Down Expand Up @@ -326,16 +336,22 @@ class LIPSTICK_EXPORT LipstickNotification : public QObject
void hasProgressChanged();
void progressChanged();

void isTransientChanged();

private:
void updateHintValues();

//! Name of the application sending the notification
QString m_appName;
QString m_explicitAppName;
QString m_disambiguatedAppName;

//! The ID of the notification
uint m_id;

QString m_appIcon;
int m_appIconOrigin = ExplicitValue;

//! Summary text for the notification
QString m_summary;

Expand Down

0 comments on commit f2286a2

Please sign in to comment.