From 6946b0db9f34ff515bf56a48d3d922a5af4ce2f7 Mon Sep 17 00:00:00 2001 From: Patrick von Reth Date: Tue, 23 Jun 2015 18:32:57 +0200 Subject: [PATCH] drop defaults from hints --- src/libsnore/application_p.cpp | 1 + src/libsnore/hint.cpp | 9 ++------- src/libsnore/hint.h | 2 +- src/libsnore/notification/notification.h | 15 +++++++++------ src/libsnore/notification/notification_p.cpp | 7 +++++++ src/libsnore/notification/notification_p.h | 2 ++ src/plugins/backends/snoretoast/snoretoast.cpp | 2 +- .../secondary_backends/pushover/pushover.cpp | 4 ++-- src/plugins/secondary_backends/sound/sound.cpp | 2 +- 9 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/libsnore/application_p.cpp b/src/libsnore/application_p.cpp index a6d977c..0a66cac 100644 --- a/src/libsnore/application_p.cpp +++ b/src/libsnore/application_p.cpp @@ -25,6 +25,7 @@ ApplicationData::ApplicationData(const QString &name, const Icon &icon): m_icon(icon) { Q_ASSERT_X(!name.isEmpty(), Q_FUNC_INFO, "invalid name detected"); + m_hint.setValue("pushover-token", "aFB1TPCyZkkr7mubCGEKy5vJEWak9t"); } ApplicationData::~ApplicationData() diff --git a/src/libsnore/hint.cpp b/src/libsnore/hint.cpp index b7bc177..4ba933b 100644 --- a/src/libsnore/hint.cpp +++ b/src/libsnore/hint.cpp @@ -36,14 +36,9 @@ void Hint::setValue(const QString &key, QObject *value) 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()); - if (m_data.contains(key)) { - return m_data.value(key); - } else { - return defaultValue; - } + return m_data.value(k.toLower()); } bool Hint::contains(const QString &key) const diff --git a/src/libsnore/hint.h b/src/libsnore/hint.h index 2988975..9f59b74 100644 --- a/src/libsnore/hint.h +++ b/src/libsnore/hint.h @@ -63,7 +63,7 @@ public: * @param key the key * @param defaultValue the fallback value */ - QVariant value(const QString &key, const QVariant &defaultValue = QVariant()) const; + QVariant value(const QString &key) const; /** * diff --git a/src/libsnore/notification/notification.h b/src/libsnore/notification/notification.h index 3d4bfd3..ba07a02 100644 --- a/src/libsnore/notification/notification.h +++ b/src/libsnore/notification/notification.h @@ -166,14 +166,14 @@ public: const Application &application() const; /** - * - * @return the title + * Returns the title of the notification. + * @param flags the supported markup flags. */ QString title(Utils::MARKUP_FLAGS flags = Utils::NO_MARKUP) const; /** - * - * @return the text body + * Returns the notification text. + * @param flags the supported markup flags. */ QString text(Utils::MARKUP_FLAGS flags = Utils::NO_MARKUP) const; @@ -222,8 +222,11 @@ public: const Notification::CloseReasons &closeReason(); /** - * - * @return hints associated with this notification + * Returns notification specific hints: + * 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(); diff --git a/src/libsnore/notification/notification_p.cpp b/src/libsnore/notification/notification_p.cpp index 2e284d6..c615c8e 100644 --- a/src/libsnore/notification/notification_p.cpp +++ b/src/libsnore/notification/notification_p.cpp @@ -44,6 +44,7 @@ NotificationData::NotificationData(const Snore::Application &application, const { notificationCount++; 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): @@ -59,6 +60,7 @@ Snore::NotificationData::NotificationData(const Notification &old, const QString m_toReplace(old) { notificationCount++; + initHints(); snoreDebug(SNORE_INFO) << "Creating Notification: ActiveNotifications" << notificationCount << "id" << m_id; } @@ -87,3 +89,8 @@ void NotificationData::setTimeoutTimer(QTimer *timer) m_timeoutTimer.reset(timer); } +void NotificationData::initHints() +{ + m_hints.setValue("silent", QVariant::fromValue(false)); +} + diff --git a/src/libsnore/notification/notification_p.h b/src/libsnore/notification/notification_p.h index a1a062b..c70a32b 100644 --- a/src/libsnore/notification/notification_p.h +++ b/src/libsnore/notification/notification_p.h @@ -51,6 +51,8 @@ public: private: Q_DISABLE_COPY(NotificationData) + void initHints(); + uint m_id; uint m_updateID; int m_timeout; diff --git a/src/plugins/backends/snoretoast/snoretoast.cpp b/src/plugins/backends/snoretoast/snoretoast.cpp index 4780486..6a243da 100644 --- a/src/plugins/backends/snoretoast/snoretoast.cpp +++ b/src/plugins/backends/snoretoast/snoretoast.cpp @@ -56,7 +56,7 @@ void SnoreToast::slotNotify(Notification notification) << "-id" << QString::number(notification.id()); //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"; } snoreDebug(SNORE_DEBUG) << "SnoreToast" << arguements; diff --git a/src/plugins/secondary_backends/pushover/pushover.cpp b/src/plugins/secondary_backends/pushover/pushover.cpp index db2992f..99e58a7 100644 --- a/src/plugins/secondary_backends/pushover/pushover.cpp +++ b/src/plugins/secondary_backends/pushover/pushover.cpp @@ -68,7 +68,7 @@ void Pushover::slotNotify(Notification notification) QHttpPart 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"); } else { sound.setBody(value("Sound", LOCAL_SETTING).toString().toUtf8().constData()); @@ -84,7 +84,7 @@ void Pushover::slotNotify(Notification notification) QHttpPart 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); QHttpPart user; diff --git a/src/plugins/secondary_backends/sound/sound.cpp b/src/plugins/secondary_backends/sound/sound.cpp index 187da0a..b5ace52 100644 --- a/src/plugins/secondary_backends/sound/sound.cpp +++ b/src/plugins/secondary_backends/sound/sound.cpp @@ -49,7 +49,7 @@ PluginSettingsWidget *Sound::settingsWidget() void Sound::slotNotificationDisplayed(Snore::Notification notification) { - if (notification.hints().value("silent", false).toBool()) { + if (notification.hints().value("silent").toBool()) { return; }