introduced private hints

This commit is contained in:
Patrick von Reth 2014-01-18 16:59:22 +01:00
parent d25d387e13
commit f438c2a15c
4 changed files with 35 additions and 4 deletions

View File

@ -56,3 +56,29 @@ bool Hint::contains(const QString &key) const
// debug << "Snore::Hint(" << hint.m_data << ")" ; // debug << "Snore::Hint(" << hint.m_data << ")" ;
// return debug.maybeSpace(); // 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));
}

View File

@ -39,8 +39,13 @@ public:
QVariant value(const QString & key, const QVariant & defaultValue = QVariant() ) const; QVariant value(const QString & key, const QVariant & defaultValue = QVariant() ) const;
bool contains ( const QString & key ) 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: private:
QVariantHash m_data; QVariantHash m_data;
QVariantHash m_privateData;
}; };

View File

@ -64,7 +64,7 @@ void Parser::parse(Notification &sNotification,const QString &msg,QTcpSocket* cl
QString alertName; QString alertName;
QString title; QString title;
QString text; QString text;
QString icon; Icon icon(":/root/snore.png");
int timeout = Notification::defaultTimeout(); int timeout = Notification::defaultTimeout();
QString key; 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 = Notification(app,alert,title,text,icon,timeout);
sNotification.data()->setSource(snarl); sNotification.data()->setSource(snarl);
sNotification.hints().setValue("snarl_clientSocket", qVariantFromValue(client)); sNotification.hints().setPrivateValue(snarl, "clientSocket", qVariantFromValue(client));
break; break;
} }
case ADD_CLASS: case ADD_CLASS:

View File

@ -129,9 +129,9 @@ void SnarlNetworkFrontend::handleMessages()
void SnarlNetworkFrontend::callback(Notification &sn, const QString msg) void SnarlNetworkFrontend::callback(Notification &sn, const QString msg)
{ {
if(sn.hints().contains("snarl_clientSocket") &&!msg.isEmpty()) QTcpSocket *client = qvariant_cast<QTcpSocket*>(sn.hints().privateValue(this, "clientSocket"));
if(client && !msg.isEmpty())
{ {
QTcpSocket *client = qvariant_cast<QTcpSocket*>(sn.hints().value("snarl_clientSocket"));
write(client, QString("%1%2\r\n").arg(msg, QString::number(sn.id()))); write(client, QString("%1%2\r\n").arg(msg, QString::number(sn.id())));
} }
} }