drop defaults from hints

This commit is contained in:
Patrick von Reth 2015-06-23 18:32:57 +02:00
parent 080d615b1a
commit 6946b0db9f
9 changed files with 26 additions and 18 deletions

View File

@ -25,6 +25,7 @@ ApplicationData::ApplicationData(const QString &name, const Icon &icon):
m_icon(icon) m_icon(icon)
{ {
Q_ASSERT_X(!name.isEmpty(), Q_FUNC_INFO, "invalid name detected"); Q_ASSERT_X(!name.isEmpty(), Q_FUNC_INFO, "invalid name detected");
m_hint.setValue("pushover-token", "aFB1TPCyZkkr7mubCGEKy5vJEWak9t");
} }
ApplicationData::~ApplicationData() ApplicationData::~ApplicationData()

View File

@ -36,14 +36,9 @@ void Hint::setValue(const QString &key, QObject *value)
connect(value, SIGNAL(destroyed()), this, SLOT(slotValueDestroyed()), Qt::DirectConnection); connect(value, SIGNAL(destroyed()), this, SLOT(slotValueDestroyed()), Qt::DirectConnection);
} }
QVariant Hint::value(const QString &k, const QVariant &defaultValue) const QVariant Hint::value(const QString &k) const
{ {
QString key(k.toLower()); return m_data.value(k.toLower());
if (m_data.contains(key)) {
return m_data.value(key);
} else {
return defaultValue;
}
} }
bool Hint::contains(const QString &key) const bool Hint::contains(const QString &key) const

View File

@ -63,7 +63,7 @@ public:
* @param key the key * @param key the key
* @param defaultValue the fallback value * @param defaultValue the fallback value
*/ */
QVariant value(const QString &key, const QVariant &defaultValue = QVariant()) const; QVariant value(const QString &key) const;
/** /**
* *

View File

@ -166,14 +166,14 @@ public:
const Application &application() const; const Application &application() const;
/** /**
* * Returns the title of the notification.
* @return the title * @param flags the supported markup flags.
*/ */
QString title(Utils::MARKUP_FLAGS flags = Utils::NO_MARKUP) const; QString title(Utils::MARKUP_FLAGS flags = Utils::NO_MARKUP) const;
/** /**
* * Returns the notification text.
* @return the text body * @param flags the supported markup flags.
*/ */
QString text(Utils::MARKUP_FLAGS flags = Utils::NO_MARKUP) const; QString text(Utils::MARKUP_FLAGS flags = Utils::NO_MARKUP) const;
@ -222,8 +222,11 @@ public:
const Notification::CloseReasons &closeReason(); const Notification::CloseReasons &closeReason();
/** /**
* * Returns notification specific hints:
* @return hints associated with this notification * Key | Type | Value | Used In
* ------------- | ----------- | ----------- | -----------
* silent | bool | Don't play notification sounds. | Multiple backends.
* sound | QString | Local uri to a sound file. | Secondary Backend Sound.
*/ */
Hint &hints(); Hint &hints();

View File

@ -44,6 +44,7 @@ NotificationData::NotificationData(const Snore::Application &application, const
{ {
notificationCount++; notificationCount++;
snoreDebug(SNORE_INFO) << "Creating Notification: ActiveNotifications" << notificationCount << "id" << m_id; snoreDebug(SNORE_INFO) << "Creating Notification: ActiveNotifications" << notificationCount << "id" << m_id;
initHints();
} }
Snore::NotificationData::NotificationData(const Notification &old, const QString &title, const QString &text, const Icon &icon, int timeout, Notification::Prioritys priority): Snore::NotificationData::NotificationData(const Notification &old, const QString &title, const QString &text, const Icon &icon, int timeout, Notification::Prioritys priority):
@ -59,6 +60,7 @@ Snore::NotificationData::NotificationData(const Notification &old, const QString
m_toReplace(old) m_toReplace(old)
{ {
notificationCount++; notificationCount++;
initHints();
snoreDebug(SNORE_INFO) << "Creating Notification: ActiveNotifications" << notificationCount << "id" << m_id; snoreDebug(SNORE_INFO) << "Creating Notification: ActiveNotifications" << notificationCount << "id" << m_id;
} }
@ -87,3 +89,8 @@ void NotificationData::setTimeoutTimer(QTimer *timer)
m_timeoutTimer.reset(timer); m_timeoutTimer.reset(timer);
} }
void NotificationData::initHints()
{
m_hints.setValue("silent", QVariant::fromValue(false));
}

View File

@ -51,6 +51,8 @@ public:
private: private:
Q_DISABLE_COPY(NotificationData) Q_DISABLE_COPY(NotificationData)
void initHints();
uint m_id; uint m_id;
uint m_updateID; uint m_updateID;
int m_timeout; int m_timeout;

View File

@ -56,7 +56,7 @@ void SnoreToast::slotNotify(Notification notification)
<< "-id" << "-id"
<< QString::number(notification.id()); << QString::number(notification.id());
//TODO: could clash with sound backend //TODO: could clash with sound backend
if (notification.hints().value("silent", true).toBool() || notification.hints().value("sound").isValid()) { if (notification.hints().value("silent").toBool() || notification.hints().value("sound").isValid()) {
arguements << "-silent"; arguements << "-silent";
} }
snoreDebug(SNORE_DEBUG) << "SnoreToast" << arguements; snoreDebug(SNORE_DEBUG) << "SnoreToast" << arguements;

View File

@ -68,7 +68,7 @@ void Pushover::slotNotify(Notification notification)
QHttpPart sound; QHttpPart sound;
sound.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"sound\"")); sound.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"sound\""));
if (notification.hints().value("silent", false).toBool()) { if (notification.hints().value("silent").toBool()) {
sound.setBody("none"); sound.setBody("none");
} else { } else {
sound.setBody(value("Sound", LOCAL_SETTING).toString().toUtf8().constData()); sound.setBody(value("Sound", LOCAL_SETTING).toString().toUtf8().constData());
@ -84,7 +84,7 @@ void Pushover::slotNotify(Notification notification)
QHttpPart token; QHttpPart token;
token.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"token\"")); token.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"token\""));
token.setBody(notification.application().constHints().value("pushover-token","aFB1TPCyZkkr7mubCGEKy5vJEWak9t").toString().toUtf8().constData()); token.setBody(notification.application().constHints().value("pushover-token").toString().toUtf8().constData());
mp->append(token); mp->append(token);
QHttpPart user; QHttpPart user;

View File

@ -49,7 +49,7 @@ PluginSettingsWidget *Sound::settingsWidget()
void Sound::slotNotificationDisplayed(Snore::Notification notification) void Sound::slotNotificationDisplayed(Snore::Notification notification)
{ {
if (notification.hints().value("silent", false).toBool()) { if (notification.hints().value("silent").toBool()) {
return; return;
} }