introduced private hints
This commit is contained in:
parent
d25d387e13
commit
f438c2a15c
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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<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())));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue