Skip to content

Commit

Permalink
[lipstick] Rework notification icon properties and hints. JB#50444
Browse files Browse the repository at this point in the history
Leave appIcon as the only icon-related property/hint in the API, and
define it as HINT_APP_ICON.

LipstickNotification changes:
- Add HINT_APP_ICON (defined as standardized "app_icon") and
  appIconChanged, and remove setAppIcon() so that it is set
  with hints instead
- Remove previewIcon and deprecate HINT_PREVIEW_ICON
- Remove icon and deprecate HINT_ICON

Notification category .conf changes:
- Use app_icon instead of x-nemo-icon
  • Loading branch information
Bea Lam committed Jul 23, 2020
1 parent 64a3358 commit 6c5d366
Show file tree
Hide file tree
Showing 29 changed files with 93 additions and 151 deletions.
14 changes: 5 additions & 9 deletions doc/src/notifications.dox
Expand Up @@ -80,11 +80,9 @@
* the hints of the notification, unless already defined.
*
* - The service supports the following Nemo specific hints:
* - \c x-nemo-icon: icon ID or path for the notification. This may be a file:// URL, else if the string begins with a / it's interpreted to be an absolute path. Otherwise it's interpreted to be an icon ID, in which case the icon with the given ID is fetched from the theme. This hint is deprecated in favor of the standard \c image-path hint.
* - \c x-nemo-item-count: the number of items represented by this notification. For example, a single notification can represent four missed calls by setting the count to 4.
* - \c x-nemo-priority: the priority of the notification as an integer. Priorities can be used by UI implementations to present notifications in a specific order, for example. If not specified, the priority level will be allocated 50.
* - \c x-nemo-timestamp: the timestamp for the notification. Should be set to the time when the event the notification is related to has occurred, not when the notification itself was sent.
* - \c x-nemo-preview-icon: icon ID or path to use in the preview banner for the notification, if any.
* - \c x-nemo-preview-body: body text to be shown in the preview banner for the notification, if any.
* - \c x-nemo-preview-summary: summary text to be shown in the preview banner for the notification, if any.
* - \c x-nemo-max-content-lines: the maximum number of content lines to display in the events view, inclusive of the summary. If 1, then no body lines will be displayed.
Expand Down Expand Up @@ -120,8 +118,7 @@
* - \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 x-nemo-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-icon should be "icon-preview-chat" to define that the icon with that ID is to be shown on the preview banner
* - \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 @@ -144,9 +141,8 @@
* - \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 x-nemo-icon should be "icon-lock-chat" to define that the icon with that ID is to be shown on the notification area
* - \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-icon should be "icon-preview-chat" to define that the icon with that ID is to be shown on the preview banner
* - \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?"
* - \c x-nemo-timestamp should be set to the time when the latest chat message was sent (or received, depending on the intended application logic)
Expand Down Expand Up @@ -185,7 +181,7 @@
* - \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 x-nemo-preview-icon should be "icon-battery-low" to define that the icon with that ID is to be shown on the preview banner
* - \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 All @@ -205,7 +201,7 @@
* \code
* transient=true
* urgency=2
* x-nemo-preview-icon=icon-battery-low
* app_icon=icon-battery-low
* \endcode
*
* and Notify() is called with the hints dictionary containing the value \c "device"
Expand All @@ -217,7 +213,7 @@
* transient=true
* urgency=2
* x-nemo-preview-body=Charging
* x-nemo-preview-icon=icon-battery-low
* app_icon=icon-battery-low
* \endcode
*
* It is also possible to define the following notification properties in the category
Expand Down
2 changes: 1 addition & 1 deletion src/notificationcategories/device.added.conf
@@ -1,4 +1,4 @@
x-nemo-icon=icon-system-usb
app_icon=icon-system-usb
urgency=2
transient=true
x-nemo-feedback=accessory_connected
2 changes: 1 addition & 1 deletion src/notificationcategories/device.conf
@@ -1,3 +1,3 @@
x-nemo-icon=icon-system-bluetooth-device
app_icon=icon-system-bluetooth-device
urgency=0
transient=true
2 changes: 1 addition & 1 deletion src/notificationcategories/device.error.conf
@@ -1,4 +1,4 @@
x-nemo-icon=icon-system-usb
app_icon=icon-system-usb
urgency=2
transient=true
x-nemo-feedback=general_warning
2 changes: 1 addition & 1 deletion src/notificationcategories/device.removed.conf
@@ -1,4 +1,4 @@
x-nemo-icon=icon-system-usb
app_icon=icon-system-usb
urgency=2
transient=true
x-nemo-suppress-display-on=true
2 changes: 1 addition & 1 deletion src/notificationcategories/network.conf
@@ -1,3 +1,3 @@
x-nemo-icon=icon-system-resources
app_icon=icon-system-resources
urgency=0
transient=true
2 changes: 1 addition & 1 deletion src/notificationcategories/network.connected.conf
@@ -1,3 +1,3 @@
x-nemo-icon=icon-system-resources
app_icon=icon-system-resources
urgency=1
transient=true
2 changes: 1 addition & 1 deletion src/notificationcategories/network.disconnected.conf
@@ -1,3 +1,3 @@
x-nemo-icon=icon-system-resources
app_icon=icon-system-resources
urgency=1
transient=true
2 changes: 1 addition & 1 deletion src/notificationcategories/network.error.conf
@@ -1,3 +1,3 @@
x-nemo-icon=icon-system-resources
app_icon=icon-system-resources
urgency=2
transient=true
@@ -1,3 +1,3 @@
x-nemo-icon=icon-system-charging
app_icon=icon-system-charging
urgency=2
transient=true
@@ -1,4 +1,4 @@
x-nemo-icon=icon-system-battery
app_icon=icon-system-battery
urgency=2
expireTimeout=60000
x-nemo-feedback=general_warning
2 changes: 1 addition & 1 deletion src/notificationcategories/x-nemo.battery.conf
@@ -1,4 +1,4 @@
x-nemo-icon=icon-system-charging
app_icon=icon-system-charging
urgency=2
transient=true
x-nemo-feedback=charging_started
2 changes: 1 addition & 1 deletion src/notificationcategories/x-nemo.battery.enterpsm.conf
@@ -1,4 +1,4 @@
x-nemo-icon=icon-system-battery
app_icon=icon-system-battery
urgency=2
transient=true
x-nemo-feedback=battery_low
2 changes: 1 addition & 1 deletion src/notificationcategories/x-nemo.battery.exitpsm.conf
@@ -1,3 +1,3 @@
x-nemo-icon=icon-system-battery
app_icon=icon-system-battery
urgency=2
transient=true
2 changes: 1 addition & 1 deletion src/notificationcategories/x-nemo.battery.lowbattery.conf
@@ -1,4 +1,4 @@
x-nemo-icon=icon-system-battery
app_icon=icon-system-battery
urgency=2
expireTimeout=60000
x-nemo-feedback=battery_low
@@ -1,3 +1,3 @@
x-nemo-icon=icon-system-battery
app_icon=icon-system-battery
urgency=2
expireTimout=60000
2 changes: 1 addition & 1 deletion src/notificationcategories/x-nemo.battery.recharge.conf
@@ -1,4 +1,4 @@
x-nemo-icon=icon-system-battery
app_icon=icon-system-battery
urgency=2
transient=true
x-nemo-feedback=battery_empty
@@ -1,3 +1,3 @@
x-nemo-icon=icon-system-charging
app_icon=icon-system-charging
urgency=2
expireTimeout=60000
2 changes: 1 addition & 1 deletion src/notificationcategories/x-nemo.battery.shutdown.conf
@@ -1,4 +1,4 @@
x-nemo-icon=icon-system-battery
app_icon=icon-system-battery
urgency=2
transient=true
x-nemo-feedback=battery_empty
2 changes: 1 addition & 1 deletion src/notificationcategories/x-nemo.battery.temperature.conf
@@ -1,4 +1,4 @@
x-nemo-icon=icon-system-warning
app_icon=icon-system-warning
urgency=2
expireTimeout=60000
x-nemo-feedback=general_warning
@@ -1,3 +1,3 @@
x-nemo-icon=icon-m-mobile-network
app_icon=icon-m-mobile-network
urgency=2
transient=true
@@ -1,3 +1,3 @@
x-nemo-icon=icon-m-wlan
app_icon=icon-m-wlan
urgency=2
transient=true
2 changes: 1 addition & 1 deletion src/notificationcategories/x-nemo.device.locked.conf
@@ -1,3 +1,3 @@
x-nemo-icon=icon-system-warning
app_icon=icon-system-warning
urgency=2
transient=true
2 changes: 1 addition & 1 deletion src/notificationcategories/x-nemo.general.warning.conf
@@ -1,3 +1,3 @@
x-nemo-icon=icon-system-warning
app_icon=icon-system-warning
urgency=2
x-nemo-feedback=general_warning
56 changes: 21 additions & 35 deletions src/notifications/lipsticknotification.cpp
@@ -1,6 +1,8 @@

/***************************************************************************
**
** 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 @@ -26,6 +28,7 @@ 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_SOUND_FILE = "sound-file";
const char *LipstickNotification::HINT_APP_ICON = "app_icon";
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";
Expand Down Expand Up @@ -58,7 +61,6 @@ LipstickNotification::LipstickNotification(const QString &appName, const QString
m_appName(appName),
m_disambiguatedAppName(disambiguatedAppName),
m_id(id),
m_appIcon(appIcon),
m_summary(summary),
m_body(body),
m_actions(actions),
Expand All @@ -68,6 +70,9 @@ LipstickNotification::LipstickNotification(const QString &appName, const QString
m_timestamp(hints.value(LipstickNotification::HINT_TIMESTAMP).toDateTime().toMSecsSinceEpoch()),
m_activeProgressTimer(0)
{
if (!appIcon.isEmpty()) {
m_hints.insert(LipstickNotification::HINT_APP_ICON, appIcon);
}
updateHintValues();
}

Expand All @@ -86,7 +91,6 @@ LipstickNotification::LipstickNotification(const LipstickNotification &notificat
m_appName(notification.m_appName),
m_disambiguatedAppName(notification.m_disambiguatedAppName),
m_id(notification.m_id),
m_appIcon(notification.m_appIcon),
m_summary(notification.m_summary),
m_body(notification.m_body),
m_actions(notification.m_actions),
Expand Down Expand Up @@ -126,12 +130,7 @@ uint LipstickNotification::id() const

QString LipstickNotification::appIcon() const
{
return m_appIcon;
}

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

QString LipstickNotification::summary() const
Expand Down Expand Up @@ -182,9 +181,8 @@ QVariantMap LipstickNotification::hintValues() const

void LipstickNotification::setHints(const QVariantHash &hints)
{
QString oldIcon = icon();
QString oldAppIcon = appIcon();
quint64 oldTimestamp = m_timestamp;
QString oldPreviewIcon = previewIcon();
QString oldPreviewSummary = previewSummary();
QString oldPreviewBody = previewBody();
int oldUrgency = urgency();
Expand All @@ -197,19 +195,15 @@ void LipstickNotification::setHints(const QVariantHash &hints)
m_hints = hints;
updateHintValues();

if (oldIcon != icon()) {
emit iconChanged();
if (oldAppIcon != appIcon()) {
emit appIconChanged();
}

m_timestamp = m_hints.value(LipstickNotification::HINT_TIMESTAMP).toDateTime().toMSecsSinceEpoch();
if (oldTimestamp != m_timestamp) {
emit timestampChanged();
}

if (oldPreviewIcon != previewIcon()) {
emit previewIconChanged();
}

if (oldPreviewSummary != previewSummary()) {
emit previewSummaryChanged();
}
Expand Down Expand Up @@ -256,25 +250,11 @@ void LipstickNotification::setExpireTimeout(int expireTimeout)
m_expireTimeout = expireTimeout;
}

QString LipstickNotification::icon() const
{
QString rv(m_hints.value(LipstickNotification::HINT_ICON).toString());
if (rv.isEmpty()) {
rv = m_hints.value(LipstickNotification::HINT_IMAGE_PATH).toString();
}
return rv;
}

QDateTime LipstickNotification::timestamp() const
{
return QDateTime::fromMSecsSinceEpoch(m_timestamp);
}

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

QString LipstickNotification::previewSummary() const
{
return m_hints.value(LipstickNotification::HINT_PREVIEW_SUMMARY).toString();
Expand Down Expand Up @@ -446,10 +426,18 @@ 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(LipstickNotification::HINT_ICON, Qt::CaseInsensitive) != 0 &&

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

if (hint.compare(LipstickNotification::HINT_APP_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 &&
Expand All @@ -474,7 +462,6 @@ 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 @@ -489,7 +476,6 @@ 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

0 comments on commit 6c5d366

Please sign in to comment.