Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[lipstick] Add progress hint for notifications. Contributes to JB#31692
Passed as x-nemo-progress.
  • Loading branch information
pvuorela committed Dec 12, 2017
1 parent d9b6219 commit 3bf722d
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
22 changes: 22 additions & 0 deletions src/notifications/lipsticknotification.cpp
Expand Up @@ -46,6 +46,7 @@ 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";
const char *LipstickNotification::HINT_PROGRESS = "x-nemo-progress";

LipstickNotification::LipstickNotification(const QString &appName, const QString &disambiguatedAppName, uint id,
const QString &appIcon, const QString &summary, const QString &body,
Expand Down Expand Up @@ -185,6 +186,8 @@ void LipstickNotification::setHints(const QVariantHash &hints)
int oldItemCount = itemCount();
int oldPriority = m_priority;
QString oldCategory = category();
qreal oldProgress = progress();
bool oldHasProgress = hasProgress();

m_hints = hints;
updateHintValues();
Expand Down Expand Up @@ -227,6 +230,14 @@ void LipstickNotification::setHints(const QVariantHash &hints)
emit categoryChanged();
}

if (oldHasProgress != hasProgress()) {
emit hasProgressChanged();
}

if (oldProgress != progress()) {
emit progressChanged();
}

emit hintsChanged();
}

Expand Down Expand Up @@ -376,6 +387,16 @@ bool LipstickNotification::restored() const
return m_hints.value(LipstickNotification::HINT_RESTORED).toBool();
}

qreal LipstickNotification::progress() const
{
return m_hints.value(LipstickNotification::HINT_PROGRESS).toReal();
}

bool LipstickNotification::hasProgress() const
{
return m_hints.contains(LipstickNotification::HINT_PROGRESS);
}

quint64 LipstickNotification::internalTimestamp() const
{
return m_timestamp;
Expand Down Expand Up @@ -404,6 +425,7 @@ void LipstickNotification::updateHintValues()
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.compare(LipstickNotification::HINT_PROGRESS, Qt::CaseInsensitive) &&
!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
12 changes: 12 additions & 0 deletions src/notifications/lipsticknotification.h
Expand Up @@ -52,6 +52,8 @@ class LIPSTICK_EXPORT LipstickNotification : public QObject
Q_PROPERTY(QString origin READ origin CONSTANT)
Q_PROPERTY(QString owner READ owner CONSTANT)
Q_PROPERTY(int maxContentLines READ maxContentLines CONSTANT)
Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged)
Q_PROPERTY(bool hasProgress READ hasProgress NOTIFY hasProgressChanged)

public:
//! Standard hint: The urgency level.
Expand Down Expand Up @@ -133,6 +135,9 @@ class LIPSTICK_EXPORT LipstickNotification : public QObject
//! Internal, shouldn't be expected or allowed from d-bus
static const char *HINT_RESTORED;

//! Nemo hint: progress percentage between 0 and 1, negative for indeterminate
static const char *HINT_PROGRESS;

/*!
* Creates an object for storing information about a single notification.
*
Expand Down Expand Up @@ -254,6 +259,10 @@ class LIPSTICK_EXPORT LipstickNotification : public QObject
//! Returns true if the notification has been restored since it was last modified
bool restored() const;

qreal progress() const;

bool hasProgress() const;

//! \internal
quint64 internalTimestamp() const;

Expand Down Expand Up @@ -320,6 +329,9 @@ class LIPSTICK_EXPORT LipstickNotification : public QObject
//! Sent when the user removability has been modified
void userRemovableChanged();

void hasProgressChanged();
void progressChanged();

private:
void updateHintValues();

Expand Down
9 changes: 6 additions & 3 deletions src/notifications/notificationmanager.cpp
Expand Up @@ -1054,17 +1054,20 @@ void NotificationManager::invokeAction(const QString &action)
}

for (int actionIndex = 0; actionIndex < notification->actions().count() / 2; actionIndex++) {
// Actions are sent over as a list of pairs. Each even element in the list (starting at index 0) represents the identifier for the action. Each odd element in the list is the localized string that will be displayed to the user.
// Actions are sent over as a list of pairs. Each even element in the list (starting at index 0) represents
// the identifier for the action. Each odd element in the list is the localized string that will be displayed to the user.
if (notification->actions().at(actionIndex * 2) == action) {
NOTIFICATIONS_DEBUG("INVOKE ACTION:" << action << id);

emit ActionInvoked(id, action);
}
}

// Unless marked as resident, we should remove the notification now
// Unless marked as resident, we should remove the notification now.
// progress notifications expected to update real soon so there is no point of automatically removing.
const QVariant resident(notification->hints().value(LipstickNotification::HINT_RESIDENT));
if (!resident.isValid() || resident.toBool() == false) {
if ((resident.isValid() && resident.toBool() == false)
|| (!resident.isValid() && !notification->hasProgress())) {
removeNotificationIfUserRemovable(id);
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/notifications/notificationpreviewpresenter.cpp
Expand Up @@ -209,6 +209,10 @@ bool NotificationPreviewPresenter::notificationShouldBeShown(LipstickNotificatio
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();
Expand Down

0 comments on commit 3bf722d

Please sign in to comment.