From f438c2a15ccf3d1780e3310c36e65fedd9e454e4 Mon Sep 17 00:00:00 2001 From: Patrick von Reth Date: Sat, 18 Jan 2014 16:59:22 +0100 Subject: [PATCH] introduced private hints --- src/core/hint.cpp | 26 +++++++++++++++++++ src/core/hint.h | 5 ++++ src/plugins/frontends/snarlnetwork/parser.cpp | 4 +-- .../frontends/snarlnetwork/snarlnetwork.cpp | 4 +-- 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/src/core/hint.cpp b/src/core/hint.cpp index 1473cd1..41e6cac 100644 --- a/src/core/hint.cpp +++ b/src/core/hint.cpp @@ -56,3 +56,29 @@ bool Hint::contains(const QString &key) const // debug << "Snore::Hint(" << hint.m_data << ")" ; // return debug.maybeSpace(); //} + + +void Hint::setPrivateValue(const void *owner, const QString &key, const QVariant &value) +{ + m_privateData[QString("%1-%2").arg(QString::number((quintptr)owner),key)] = value; +} + + +QVariant Hint::privateValue(const void *owner, const QString &k, const QVariant &defaultValue) const +{ + QString key(QString("%1-%2").arg(QString::number((quintptr)owner),k)); + if(m_privateData.contains(key)) + { + return m_privateData[key]; + } + else + { + return defaultValue; + } +} + + +bool Hint::containsPrivateValue(const void *owner, const QString &key) const +{ + return m_privateData.contains(QString("%1-%2").arg(QString::number((quintptr)owner),key)); +} diff --git a/src/core/hint.h b/src/core/hint.h index f276932..dc16463 100644 --- a/src/core/hint.h +++ b/src/core/hint.h @@ -38,9 +38,14 @@ public: void setValue(const QString &key, const QVariant &value); QVariant value(const QString & key, const QVariant & defaultValue = QVariant() ) const; bool contains ( const QString & key ) const; + + void setPrivateValue(const void *owner, const QString &key, const QVariant &value); + QVariant privateValue(const void *owner, const QString & key, const QVariant & defaultValue = QVariant() ) const; + bool containsPrivateValue(const void *owner, const QString & key ) const; private: QVariantHash m_data; + QVariantHash m_privateData; }; diff --git a/src/plugins/frontends/snarlnetwork/parser.cpp b/src/plugins/frontends/snarlnetwork/parser.cpp index 317b81e..e0e1d66 100644 --- a/src/plugins/frontends/snarlnetwork/parser.cpp +++ b/src/plugins/frontends/snarlnetwork/parser.cpp @@ -64,7 +64,7 @@ void Parser::parse(Notification &sNotification,const QString &msg,QTcpSocket* cl QString alertName; QString title; QString text; - QString icon; + Icon icon(":/root/snore.png"); int timeout = Notification::defaultTimeout(); QString key; @@ -138,7 +138,7 @@ void Parser::parse(Notification &sNotification,const QString &msg,QTcpSocket* cl } sNotification = Notification(app,alert,title,text,icon,timeout); sNotification.data()->setSource(snarl); - sNotification.hints().setValue("snarl_clientSocket", qVariantFromValue(client)); + sNotification.hints().setPrivateValue(snarl, "clientSocket", qVariantFromValue(client)); break; } case ADD_CLASS: diff --git a/src/plugins/frontends/snarlnetwork/snarlnetwork.cpp b/src/plugins/frontends/snarlnetwork/snarlnetwork.cpp index 0ffeffe..a9f9add 100644 --- a/src/plugins/frontends/snarlnetwork/snarlnetwork.cpp +++ b/src/plugins/frontends/snarlnetwork/snarlnetwork.cpp @@ -129,9 +129,9 @@ void SnarlNetworkFrontend::handleMessages() void SnarlNetworkFrontend::callback(Notification &sn, const QString msg) { - if(sn.hints().contains("snarl_clientSocket") &&!msg.isEmpty()) + QTcpSocket *client = qvariant_cast(sn.hints().privateValue(this, "clientSocket")); + if(client && !msg.isEmpty()) { - QTcpSocket *client = qvariant_cast(sn.hints().value("snarl_clientSocket")); write(client, QString("%1%2\r\n").arg(msg, QString::number(sn.id()))); } }