void SnorePlugin::Freedesktop::slotNotify(Snore::Notification noti) { if (noti.data()->sourceAndTargetAreSimilar(this)) { return; } QStringList actions; foreach(int k, noti.actions().keys()) { actions << QString::number(k) << noti.actions()[k].name(); } QVariantMap hints; FreedesktopImageHint image(noti.icon().pixmap(QSize(128, 128)).toImage()); hints.insert(QStringLiteral("image_data"), QVariant::fromValue(image)); char urgency = 1; if (noti.priority() < 0) { urgency = 0; } else if (noti.priority() > 2) { urgency = 2; } hints.insert(QStringLiteral("urgency"), urgency); if (noti.application().constHints().contains("desktop-entry")) { hints.insert(QStringLiteral("desktop-entry"), noti.application().constHints().value("desktop-entry")); } hints.insert(QStringLiteral("suppress-sound"), noti.constHints().value("silent").toBool()); uint updateId = 0; if (noti.isUpdate()) { updateId = noti.old().hints().privateValue(this, "id").toUInt(); m_dbusIdMap.take(updateId); } QString title = noti.application().name() + QLatin1String(" - ") + noti.title(m_supportsRichtext ? Snore::Utils::AllMarkup : Snore::Utils::NoMarkup); QString body(noti.text(m_supportsRichtext ? Snore::Utils::AllMarkup : Snore::Utils::NoMarkup)); //TODO: add app icon hint? QDBusPendingReply<uint> id = m_interface->Notify(noti.application().name(), updateId, QString(), title, body, actions, hints, noti.isSticky() ? -1 : noti.timeout() * 1000); id.waitForFinished(); noti.hints().setPrivateValue(this, "id", id.value()); m_dbusIdMap[id.value()] = noti; slotNotificationDisplayed(noti); qCDebug(SNORE) << noti.id() << "|" << id.value(); }
void Toasty::slotNotify(Snore::Notification notification) { QString key = settingsValue(ToastyConstants::DeviceID).toString(); if (key.isEmpty()) { return; } QNetworkRequest request(QUrl::fromUserInput(QLatin1String("http://api.supertoasty.com/notify/") + key)); QHttpMultiPart *mp = new QHttpMultiPart(QHttpMultiPart::FormDataType); QHttpPart title; title.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant(QLatin1String("form-data; name=\"title\""))); title.setBody(notification.title().toUtf8().constData()); mp->append(title); QHttpPart text; text.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant(QLatin1String("form-data; name=\"text\""))); text.setBody(notification.text().toUtf8().constData()); mp->append(text); QHttpPart app; app.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant(QLatin1String("form-data; name=\"sender\""))); app.setBody(notification.application().name().toUtf8().constData()); mp->append(app); QHttpPart icon; icon.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant(QLatin1String("form-data; name=\"image\"; filename=\"") + notification.icon().localUrl(QSize(128, 128)) + QLatin1Char('"'))); icon.setHeader(QNetworkRequest::ContentTypeHeader, QVariant(QLatin1String("image/png"))); QFile *file = new QFile(notification.icon().localUrl(QSize(128, 128))); 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, [reply]() { qCDebug(SNORE) << reply->error(); qCDebug(SNORE) << reply->readAll(); reply->close(); reply->deleteLater(); }); }