use cool new connects

This commit is contained in:
Patrick von Reth 2014-09-20 15:03:56 +02:00
parent 65931bdf9d
commit b331644379
2 changed files with 35 additions and 44 deletions

View File

@ -17,53 +17,47 @@ Toasty::~Toasty()
void Toasty::slotNotify(Notification notification)
{
if (!m_key.isEmpty()) {
QNetworkRequest request(QString("http://api.supertoasty.com/notify/%1").arg(m_key));
QHttpMultiPart *mp = new QHttpMultiPart(QHttpMultiPart::FormDataType);
QHttpPart title;
title.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"title\""));
title.setBody(Snore::toPlainText(notification.title()).toLatin1().constData());
mp->append(title);
QNetworkRequest request(QString("http://api.supertoasty.com/notify/%1").arg(m_key));
QHttpMultiPart *mp = new QHttpMultiPart(QHttpMultiPart::FormDataType);
QHttpPart title;
title.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"title\""));
title.setBody(Snore::toPlainText(notification.title()).toLatin1().constData());
mp->append(title);
QHttpPart text;
text.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"text\""));
text.setBody(Snore::toPlainText(notification.text()).toLatin1().constData());
mp->append(text);
QHttpPart text;
text.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"text\""));
text.setBody(Snore::toPlainText(notification.text()).toLatin1().constData());
mp->append(text);
QHttpPart app;
app.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"sender\""));
app.setBody(notification.application().name().toLatin1().constData());
mp->append(app);
QHttpPart app;
app.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"sender\""));
app.setBody(notification.application().name().toLatin1().constData());
mp->append(app);
QHttpPart icon;
Icon sIcon = notification.icon();
QSize iconSize = notification.icon().image().size();
if (iconSize.height() > 128 || iconSize.width() > 128 ) {
sIcon = sIcon.scaled(QSize(128, 128));
}
icon.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant(QString("form-data; name=\"image\"; filename=\"%1\"").arg(sIcon.localUrl())));
icon.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("image/png"));
QFile *file = new QFile(sIcon.localUrl());
file->open(QIODevice::ReadOnly);
icon.setBodyDevice(file);
mp->append(icon);
QNetworkReply *reply = m_manager.post(request, mp);
mp->setParent(reply);
file->setParent(reply);
connect(reply, SIGNAL(finished()), this, SLOT(slotRequestFinished()));
QHttpPart icon;
Icon sIcon = notification.icon();
QSize iconSize = notification.icon().image().size();
if (iconSize.height() > 128 || iconSize.width() > 128 ) {
sIcon = sIcon.scaled(QSize(128, 128));
}
}
icon.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant(QString("form-data; name=\"image\"; filename=\"%1\"").arg(sIcon.localUrl())));
icon.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("image/png"));
QFile *file = new QFile(sIcon.localUrl());
file->open(QIODevice::ReadOnly);
icon.setBodyDevice(file);
mp->append(icon);
QNetworkReply *reply = m_manager.post(request, mp);
mp->setParent(reply);
file->setParent(reply);
connect(reply, &QNetworkReply::finished, this, [reply](){
snoreDebug(SNORE_DEBUG) << reply->readAll();
reply->close();
reply->deleteLater();
});
void Toasty::slotRequestFinished()
{
QNetworkReply *reply = qobject_cast<QNetworkReply *>(sender());
snoreDebug(SNORE_DEBUG) << reply->readAll();
reply->close();
reply->deleteLater();
}
bool Toasty::initialize(SnoreCore *snore)

View File

@ -19,9 +19,6 @@ public:
public slots:
virtual void slotNotify(Snore::Notification notification) override;
private slots:
void slotRequestFinished();
private:
QString m_key;
QNetworkAccessManager m_manager;