QJsonObject Setting::toJsonObject() const { QJsonObject setting; setting.insert("kind", kind()); setting.insert("etag", eTag()); setting.insert("id", id()); setting.insert("value", value()); return setting; }
QString QGitHubReleaseAPIPrivate::embedImages(QString &b) const { #if QT_VERSION >= QT_VERSION_CHECK(4, 5, 0) QRegExp emjRex(":([_a-zA-Z0-9]+):"); QRegExp imgRex("<[^<]*img[^>]*src\\s*=\\s*\"([^\"]*)\"[^>]*>"); Emoji *emoji = 0L; int idx = -1; while((idx = b.indexOf(emjRex, idx + 1)) != -1) { const QString emjKey(emjRex.cap(1)); if(!emoji) { QEventLoop emjLoop; QObject::connect((emoji = new Emoji(eTag())), SIGNAL(available()), &emjLoop, SLOT(quit())); if(!emoji->entries()) emjLoop.exec(); } const QUrl &emjUrl(emoji->getUrl(emjKey)); if(emjUrl.isValid()) { b.replace(idx, emjKey.length() + 2, "<img width=\"16\" height=\"16\" alt=\"" + emjKey + "\" src=\"" + emjUrl.toString() + "\">"); } idx += emjKey.length() + 1; } delete emoji; idx = -1; while((idx = b.indexOf(imgRex, idx + 1)) != -1) { const QUrl url = QUrl(imgRex.cap(1)); if(url.isValid()) { const QImage img = QImage::fromData(downloadFile(url)); if(!img.isNull()) { QByteArray ba; QBuffer buf(&ba); buf.open(QIODevice::WriteOnly); img.save(&buf, "PNG"); ba.squeeze(); b.replace(imgRex.pos(1), imgRex.cap(1).length(), QString("data:image/png;base64,%1"). arg(ba.toBase64().constData())); } } } #endif b.append("<hr /><p>Release information provided by " \ "<em>QGitHubReleaseAPI " PROJECTVERSION "</em> © 2015 " \ "Heiko Schäfer <<a href=\"mailto:[email protected]?" \ "subject=QGitHubReleaseAPI%20" PROJECTVERSION "\">[email protected]</a>>"); #ifdef HAVE_MKDIO_H if(m_type == QGitHubReleaseAPI::RAW) { b.append(QString("<br />Markdown rendered with <em>libmarkdown %1</em>"). arg(markdown_version)); } #endif return b.append("</p>"); }