Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'notification_visibility' into 'master'
[lipstick] Support public visibility on notification and use on battery ones....

See merge request mer-core/lipstick!129
  • Loading branch information
pvuorela committed Oct 28, 2019
2 parents ec1fe74 + bd97bdd commit 5956e65
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 26 deletions.
1 change: 1 addition & 0 deletions doc/src/notifications.dox
Expand Up @@ -89,6 +89,7 @@
* - \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.
* - \c x-nemo-remote-action-actionname: details of the D-Bus call to be made when the action "actionname" is executed. "actionname" should be listed in the notification's \c actions array. The required format is "serviceName objectPath interface methodName [argument...]", where each argument must be separately encoded by serializing to QDataStream, then encoding the resulting byte sequence to Base64.
* - \c x-nemo-visibility: the confidentiality of the notification. Currently allows "public" to make notification show even on locked device, "private" and "secret" like on Android API might come later if needed.
*
* - The following hints are used by system notifications, and may be excluded from application notifications:
* - \c x-nemo-feedback: a token used to generate a pre-defined feedback event when the notification preview is displayed
Expand Down
2 changes: 1 addition & 1 deletion src/compositor/windowmodel.cpp
Expand Up @@ -70,7 +70,7 @@ QVariant WindowModel::data(const QModelIndex &index, int role) const
return m_items.at(idx);
} else if (role == Qt::UserRole + 2) {
QWaylandSurface *s = c->surfaceForId(m_items.at(idx));
return s?s->processId():0;
return s ? s->processId() : 0;
} else if (role == Qt::UserRole + 3) {
LipstickCompositorWindow *w = static_cast<LipstickCompositorWindow *>(c->windowForId(m_items.at(idx)));
return w->title();
Expand Down
1 change: 1 addition & 0 deletions src/notifications/batterynotifier.cpp
Expand Up @@ -454,6 +454,7 @@ void BatteryNotifier::sendNotification(BatteryNotifier::NotificationType type)
QVariantHash hints;
hints.insert(LipstickNotification::HINT_CATEGORY, info.category);
hints.insert(LipstickNotification::HINT_PREVIEW_BODY, info.message);
hints.insert(LipstickNotification::HINT_VISIBILITY, QLatin1String("public"));
QueuedNotification queuedNotification;
queuedNotification.m_type = type;
queuedNotification.m_id = m_notificationManager->Notify(m_notificationManager->systemApplicationName(),
Expand Down
3 changes: 2 additions & 1 deletion src/notifications/lipsticknotification.cpp
Expand Up @@ -26,6 +26,7 @@ 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_SOUND_FILE = "sound-file";
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 All @@ -48,7 +49,7 @@ const char *LipstickNotification::HINT_MAX_CONTENT_LINES = "x-nemo-max-content-l
const char *LipstickNotification::HINT_RESTORED = "x-nemo-restored";
const char *LipstickNotification::HINT_PROGRESS = "x-nemo-progress";
const char *LipstickNotification::HINT_VIBRA = "x-nemo-vibrate";
const char *LipstickNotification::HINT_SOUND_FILE = "sound-file";
const char *LipstickNotification::HINT_VISIBILITY = "x-nemo-visibility";

LipstickNotification::LipstickNotification(const QString &appName, const QString &disambiguatedAppName, uint id,
const QString &appIcon, const QString &summary, const QString &body,
Expand Down
3 changes: 3 additions & 0 deletions src/notifications/lipsticknotification.h
Expand Up @@ -145,6 +145,9 @@ class LIPSTICK_EXPORT LipstickNotification : public QObject
//! Nemo hint: play vibra feedback
static const char *HINT_VIBRA;

//! Nemo hint: Indicates the confidentiality of the notification
static const char *HINT_VISIBILITY;

/*!
* Creates an object for storing information about a single notification.
*
Expand Down
54 changes: 31 additions & 23 deletions src/notifications/notificationpreviewpresenter.cpp
Expand Up @@ -93,23 +93,7 @@ void NotificationPreviewPresenter::showNextNotification()
setCurrentNotification(0);
} else {
LipstickNotification *notification = m_notificationQueue.takeFirst();

const bool screenLocked = m_screenLock->isScreenLocked() && m_screenLock->displayState() == TouchScreen::DisplayOff;
const bool deviceLocked = m_deviceLock->state() >= NemoDeviceLock::DeviceLock::Locked;
const bool notificationIsCritical = notification->urgency() >= 2 || notification->hints().value(LipstickNotification::HINT_DISPLAY_ON).toBool();

bool show = true;
if (deviceLocked) {
if (!notificationIsCritical) {
show = false;
} else {
show = m_deviceLock->showNotifications();
}
} else if (screenLocked) {
if (!notificationIsCritical) {
show = false;
}
}
bool show = notificationShouldBeShown(notification);

if (!show) {
if (m_deviceLock->state() != NemoDeviceLock::DeviceLock::ManagerLockout) { // Suppress feedback if locked out.
Expand Down Expand Up @@ -201,27 +185,51 @@ void NotificationPreviewPresenter::createWindowIfNecessary()

bool NotificationPreviewPresenter::notificationShouldBeShown(LipstickNotification *notification)
{
if (notification->hidden() || notification->restored() || (notification->previewBody().isEmpty() && notification->previewSummary().isEmpty()))
if (notification->hidden()
|| notification->restored()
|| (notification->previewBody().isEmpty() && notification->previewSummary().isEmpty())) {
return false;
}

if (notification->hasProgress()) {
return false; // would show up constantly as preview
}

const bool screenLocked = m_screenLock->isScreenLocked();
const bool deviceLocked = m_deviceLock->state() >= NemoDeviceLock::DeviceLock::Locked;
const bool notificationIsCritical = notification->urgency() >= 2 || notification->hints().value(LipstickNotification::HINT_DISPLAY_ON).toBool();
const bool notificationIsCritical = notification->urgency() >= 2
|| notification->hints().value(LipstickNotification::HINT_DISPLAY_ON).toBool();
const bool notificationIsPublic = notification->hints().value(LipstickNotification::HINT_VISIBILITY).toString()
.compare(QLatin1String("public"), Qt::CaseInsensitive) == 0;

bool show = true;

if (notificationIsPublic) {
} else if (deviceLocked) {
if (!notificationIsCritical) {
show = false;
} else {
show = m_deviceLock->showNotifications();
}
} else if (screenLocked) {
if (!notificationIsCritical) {
show = false;
}
}

if (!show) {
return false;
}

uint mode = AllNotificationsEnabled;
QWaylandSurface *surface = LipstickCompositor::instance()->surfaceForId(LipstickCompositor::instance()->topmostWindowId());
if (surface != 0) {
mode = surface->windowProperties().value("NOTIFICATION_PREVIEWS_DISABLED", uint(AllNotificationsEnabled)).toUInt();
}

return ((!screenLocked && !deviceLocked) || notificationIsCritical) &&
(mode == AllNotificationsEnabled ||
(mode == ApplicationNotificationsDisabled && notificationIsCritical) ||
(mode == SystemNotificationsDisabled && !notificationIsCritical));
return (mode == AllNotificationsEnabled
|| (mode == ApplicationNotificationsDisabled && notificationIsCritical)
|| (mode == SystemNotificationsDisabled && !notificationIsCritical));
}

void NotificationPreviewPresenter::setCurrentNotification(LipstickNotification *notification)
Expand Down
1 change: 0 additions & 1 deletion src/notifications/notificationpreviewpresenter.h
Expand Up @@ -85,7 +85,6 @@ private slots:
void createWindowIfNecessary();

private:
//! Checks whether the given notification has a preview body and a preview summary.
bool notificationShouldBeShown(LipstickNotification *notification);

//! Sets the given notification as the current notification
Expand Down

0 comments on commit 5956e65

Please sign in to comment.