diff --git a/src/daemon/trayicon.cpp b/src/daemon/trayicon.cpp index 7988559..41c75a8 100644 --- a/src/daemon/trayicon.cpp +++ b/src/daemon/trayicon.cpp @@ -35,8 +35,8 @@ using namespace Snore; TrayIcon::TrayIcon(): m_trayIcon(new QSystemTrayIcon(QIcon(":/root/snore.png"))) { - SnoreCorePrivate::instance()->defaultApplication().hints().setValue("use-markup", QVariant::fromValue(true)); - SnoreCorePrivate::instance()->defaultApplication().hints().setValue("tray-icon", m_trayIcon); + SnoreCorePrivate::instance()->defaultApplication().hints().setValue("use-markup", true); + SnoreCorePrivate::instance()->defaultApplication().hints().setValue("tray-icon", QVariant::fromValue(QPointer(m_trayIcon))); } void TrayIcon::initConextMenu() diff --git a/src/libsnore/application.h b/src/libsnore/application.h index 6ffe000..bb75c0c 100644 --- a/src/libsnore/application.h +++ b/src/libsnore/application.h @@ -106,7 +106,7 @@ public: * use-markup | Enable markup support for title and message, strings must be html escaped.| Many Backends. * desktop-entry | The name of the desktop enty associated with the application. | Used for The freedesktop backend. * windows-app-id | The app id associated with the application. | Needed for the Windows 8 backend [See MSDN Documentation](http://msdn.microsoft.com/en-us/library/windows/apps/dd378459.aspx). - * tray-icon | A pointer to a QSystemTray item. | Needed for the System Tray Backend. + * tray-icon | A QPointer item. | Needed for the System Tray Backend. * pushover-token | The token associated with your application. | Needed to associate pushover notification with your application, to register your application visit [Pushover](https://pushover.net/apps/build). */ Hint &hints(); diff --git a/src/libsnore/hint.cpp b/src/libsnore/hint.cpp index 4ba933b..b45cae0 100644 --- a/src/libsnore/hint.cpp +++ b/src/libsnore/hint.cpp @@ -29,18 +29,16 @@ void Hint::setValue(const QString &key, const QVariant &value) m_data.insert(key.toLower(), value); } -void Hint::setValue(const QString &key, QObject *value) -{ - m_data.insert(key.toLower(), qVariantFromValue(value)); - value->setProperty("hint_key", key.toLower()); - connect(value, SIGNAL(destroyed()), this, SLOT(slotValueDestroyed()), Qt::DirectConnection); -} - QVariant Hint::value(const QString &k) const { return m_data.value(k.toLower()); } +QVariant Hint::take(const QString &key) +{ + return m_data.take(key.toLower()); +} + bool Hint::contains(const QString &key) const { return m_data.contains(key.toLower()); @@ -52,23 +50,10 @@ void Hint::setPrivateValue(const void *owner, const QString &key, const QVariant m_privateData.insert(pk, value); } -void Hint::setPrivateValue(const void *owner, const QString &key, QObject *value) const -{ - QPair pk((quintptr)owner, key.toLower()); - m_privateData.insert(pk, qVariantFromValue(value)); - value->setProperty("hint_key", key.toLower()); - value->setProperty("hint_owner", (quintptr)owner); - connect(value, SIGNAL(destroyed()), this, SLOT(slotValueDestroyed()), Qt::DirectConnection); -} - -QVariant Hint::privateValue(const void *owner, const QString &k, const QVariant &defaultValue) const +QVariant Hint::privateValue(const void *owner, const QString &k) const { QPair key((quintptr)owner, k.toLower()); - if (m_privateData.contains(key)) { - return m_privateData.value(key); - } else { - return defaultValue; - } + return m_privateData.value(key); } bool Hint::containsPrivateValue(const void *owner, const QString &key) const @@ -77,16 +62,10 @@ bool Hint::containsPrivateValue(const void *owner, const QString &key) const return m_privateData.contains(pk); } -void Hint::slotValueDestroyed() +QVariant Hint::takePrivateValue(const void *owner, const QString &key) { - QObject *o = sender(); - QString key = o->property("hint_key").toString(); - if (!o->property("hint_owner").isNull()) { - QPair pk(o->property("hint_owner").value(), key); - m_privateData.remove(pk); - } else { - m_data.remove(key); - } + QPair pk((quintptr)owner, key.toLower()); + return m_privateData.take(pk); } QDebug operator<<(QDebug debug, const Snore::Hint &hint) diff --git a/src/libsnore/hint.h b/src/libsnore/hint.h index 9f59b74..8d54e79 100644 --- a/src/libsnore/hint.h +++ b/src/libsnore/hint.h @@ -38,9 +38,8 @@ namespace Snore * The keys are case insensitive. */ -class SNORE_EXPORT Hint : public QObject +class SNORE_EXPORT Hint { - Q_OBJECT public: Hint(); @@ -51,20 +50,20 @@ public: */ void setValue(const QString &key, const QVariant &value); - /** - * Sets the value for the key - * @param key the key - * @param value the value - */ - void setValue(const QString &key, QObject *value); /** - * The associated value of the key if present, returns the default value otherwise. + * The associated value of the key. * @param key the key - * @param defaultValue the fallback value */ QVariant value(const QString &key) const; + + /** + * The associated value of the key. + * @param key the key + */ + QVariant take(const QString &key); + /** * * @param key the key @@ -81,20 +80,11 @@ public: void setPrivateValue(const void *owner, const QString &key, const QVariant &value) const; /** - * Sets the value for the key depending on the owner + * The associated value of the key if present. * @param owner the owner * @param key the key - * @param value the value */ - void setPrivateValue(const void *owner, const QString &key, QObject *value) const; - - /** - * The associated value of the key if present, returns the default value otherwise. - * @param owner the owner - * @param key the key - * @param defaultValue the fallback value - */ - QVariant privateValue(const void *owner, const QString &key, const QVariant &defaultValue = QVariant()) const; + QVariant privateValue(const void *owner, const QString &key) const; /** * @@ -104,8 +94,15 @@ public: */ bool containsPrivateValue(const void *owner, const QString &key) const; -private slots: - void slotValueDestroyed(); + + + /** + * The associated value of the key if present. + * @param owner the owner + * @param key the key + * @return whether the key is set + */ + QVariant takePrivateValue(const void *owner, const QString &key); private: QVariantHash m_data; diff --git a/src/libsnore/notification/notification_p.cpp b/src/libsnore/notification/notification_p.cpp index e98c47b..7fc9338 100644 --- a/src/libsnore/notification/notification_p.cpp +++ b/src/libsnore/notification/notification_p.cpp @@ -41,7 +41,8 @@ NotificationData::NotificationData(const Snore::Application &application, const m_text(text), m_icon(icon), m_priority(priority), - m_closeReason(Notification::NONE) + m_closeReason(Notification::NONE), + m_hints(m_application.constHints()) { notificationCount++; snoreDebug(SNORE_INFO) << "Creating Notification: ActiveNotifications" << notificationCount << "id" << m_id; @@ -59,6 +60,7 @@ Snore::NotificationData::NotificationData(const Notification &old, const QString m_icon(icon), m_priority(priority), m_closeReason(Notification::NONE), + m_hints(m_application.constHints()), m_toReplace(old) { notificationCount++; @@ -94,11 +96,11 @@ void NotificationData::setTimeoutTimer(QTimer *timer) QString NotificationData::resolveMarkup(const QString &string, Utils::MARKUP_FLAGS flags) { - if(!m_application.constHints().value("use-markup").toBool()) { + if(!m_hints.value("use-markup").toBool()) { if(flags == Utils::NO_MARKUP){ return string; } else { - return string.toHtmlEscaped(); + return Utils::normalizeMarkup(string.toHtmlEscaped(), flags); } } else { return Utils::normalizeMarkup(string, flags); diff --git a/src/libsnore/utils.cpp b/src/libsnore/utils.cpp index ef15cba..79a70df 100644 --- a/src/libsnore/utils.cpp +++ b/src/libsnore/utils.cpp @@ -88,7 +88,6 @@ QString Utils::normalizeMarkup(QString string, MARKUP_FLAGS tags) } QMutexLocker lock(&mutex); - if (~tags & Utils::BREAK) { static QRegExp br("
"); string = string.replace(br, "\n"); diff --git a/src/plugins/backends/trayicon/trayiconnotifer.cpp b/src/plugins/backends/trayicon/trayiconnotifer.cpp index c589fae..24e4653 100644 --- a/src/plugins/backends/trayicon/trayiconnotifer.cpp +++ b/src/plugins/backends/trayicon/trayiconnotifer.cpp @@ -59,7 +59,7 @@ void TrayIconNotifer::slotDeregisterApplication(const Application &application) QSystemTrayIcon *TrayIconNotifer::trayIcon(const Application &app) { if (app.constHints().contains("tray-icon")) { - return app.constHints().value("tray-icon").value(); + return app.constHints().value("tray-icon").value>(); } return nullptr; } diff --git a/src/plugins/frontends/pushover/pushover_frontend.cpp b/src/plugins/frontends/pushover/pushover_frontend.cpp index cdb1807..5fc8adb 100644 --- a/src/plugins/frontends/pushover/pushover_frontend.cpp +++ b/src/plugins/frontends/pushover/pushover_frontend.cpp @@ -228,10 +228,6 @@ void PushoverFrontend::getMessages() SnoreCore::instance().registerApplication(app); } - if(notification.value("html").toInt() == 1) { - app.hints().setValue("use-markup", QVariant::fromValue(true)) ; - } - Notification n(app, *app.alerts().begin(), notification.value("title").toString(), notification.value("message").toString(), app.icon(), Notification::defaultTimeout(), static_cast(notification.value("priority").toInt())); @@ -239,6 +235,9 @@ void PushoverFrontend::getMessages() n.hints().setValue("receipt", notification.value("receipt").toString()); n.hints().setValue("acked", notification.value("acked").toInt()); } + if(notification.value("html").toInt() == 1) { + n.hints().setValue("use-markup", true) ; + } SnoreCore::instance().broadcastNotification(n); } if(latestID != -1){ diff --git a/src/plugins/frontends/snarlnetwork/parser.cpp b/src/plugins/frontends/snarlnetwork/parser.cpp index 4e2e81f..915d258 100644 --- a/src/plugins/frontends/snarlnetwork/parser.cpp +++ b/src/plugins/frontends/snarlnetwork/parser.cpp @@ -25,6 +25,7 @@ #include #include +#include using namespace Snore; @@ -116,7 +117,7 @@ void Parser::parse(Notification &sNotification, const QString &msg, QTcpSocket * break; } sNotification = Notification(app, alert, title, text, icon, timeout); - sNotification.hints().setPrivateValue(snarl, "clientSocket", client); + sNotification.hints().setPrivateValue(snarl, "clientSocket", QVariant::fromValue(QPointer(client))); break; } case ADD_CLASS: diff --git a/src/plugins/frontends/snarlnetwork/snarlnetwork.cpp b/src/plugins/frontends/snarlnetwork/snarlnetwork.cpp index 2e6a9fb..f17105d 100644 --- a/src/plugins/frontends/snarlnetwork/snarlnetwork.cpp +++ b/src/plugins/frontends/snarlnetwork/snarlnetwork.cpp @@ -22,6 +22,7 @@ #include #include +#include #include using namespace Snore; @@ -117,8 +118,12 @@ void SnarlNetworkFrontend::handleMessages() void SnarlNetworkFrontend::callback(Notification &sn, const QString msg) { if (sn.hints().containsPrivateValue(this, "clientSocket")) { - QTcpSocket *client = qobject_cast(sn.hints().privateValue(this, "clientSocket").value()); - write(client, QString("%1%2\r\n").arg(msg, QString::number(sn.id()))); + QTcpSocket *client = sn.hints().privateValue(this, "clientSocket").value>(); + if(client){ + write(client, QString("%1%2\r\n").arg(msg, QString::number(sn.id()))); + }else{ + sn.hints().takePrivateValue(this, "clientSocket"); + } } }