Commit 5956e65f authored by pvuorela's avatar pvuorela

Merge branch 'notification_visibility' into 'master'

[lipstick] Support public visibility on notification and use on battery ones....

See merge request !129
parents ec1fe740 bd97bdd3
......@@ -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
......
......@@ -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();
......
......@@ -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(),
......
......@@ -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";
......@@ -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,
......
......@@ -145,6 +145,9 @@ public:
//! 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.
*
......
......@@ -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.
......@@ -201,8 +185,11 @@ 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
......@@ -210,7 +197,29 @@ bool NotificationPreviewPresenter::notificationShouldBeShown(LipstickNotificatio
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());
......@@ -218,10 +227,9 @@ bool NotificationPreviewPresenter::notificationShouldBeShown(LipstickNotificatio
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)
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment