mirror of
https://github.com/clementine-player/Clementine
synced 2024-12-17 12:02:48 +01:00
Nicer generation of tweet HTML.
This commit is contained in:
parent
7c522ee306
commit
919a88976b
@ -99,6 +99,7 @@ void TwitterArtistInfo::UserTimelineRequestFinished(QNetworkReply* reply, const
|
|||||||
data.title_ = QString("Twitter (%1)").arg(twitter_id);
|
data.title_ = QString("Twitter (%1)").arg(twitter_id);
|
||||||
|
|
||||||
QString html;
|
QString html;
|
||||||
|
QXmlStreamWriter writer(&html);
|
||||||
QVariantList tweets = result.toList();
|
QVariantList tweets = result.toList();
|
||||||
foreach (const QVariant& v, tweets) {
|
foreach (const QVariant& v, tweets) {
|
||||||
QVariantMap tweet = v.toMap();
|
QVariantMap tweet = v.toMap();
|
||||||
@ -106,6 +107,9 @@ void TwitterArtistInfo::UserTimelineRequestFinished(QNetworkReply* reply, const
|
|||||||
|
|
||||||
QVariantMap entities = tweet["entities"].toMap();
|
QVariantMap entities = tweet["entities"].toMap();
|
||||||
QVariantList urls = entities["urls"].toList();
|
QVariantList urls = entities["urls"].toList();
|
||||||
|
|
||||||
|
writer.writeStartElement("div");
|
||||||
|
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
foreach (const QVariant& u, urls) {
|
foreach (const QVariant& u, urls) {
|
||||||
QVariantMap url = u.toMap();
|
QVariantMap url = u.toMap();
|
||||||
@ -113,20 +117,17 @@ void TwitterArtistInfo::UserTimelineRequestFinished(QNetworkReply* reply, const
|
|||||||
int start_index = indices[0].toInt();
|
int start_index = indices[0].toInt();
|
||||||
int end_index = indices[1].toInt();
|
int end_index = indices[1].toInt();
|
||||||
|
|
||||||
QString replacement;
|
writer.writeCharacters(text.mid(offset, start_index));
|
||||||
QXmlStreamWriter writer(&replacement);
|
offset = end_index;
|
||||||
|
|
||||||
writer.writeStartElement("a");
|
writer.writeStartElement("a");
|
||||||
writer.writeAttribute("href", url["expanded_url"].toString());
|
writer.writeAttribute("href", url["expanded_url"].toString());
|
||||||
writer.writeCharacters(url["display_url"].toString());
|
writer.writeCharacters(url["display_url"].toString());
|
||||||
writer.writeEndElement();
|
writer.writeEndElement();
|
||||||
|
|
||||||
text.replace(start_index + offset, end_index - start_index, replacement);
|
|
||||||
offset += replacement.size();
|
|
||||||
}
|
}
|
||||||
|
writer.writeCharacters(text.mid(offset));
|
||||||
|
|
||||||
html += "<div>";
|
writer.writeEndElement();
|
||||||
html += text;
|
|
||||||
html += "</div>";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SongInfoTextView* text_view = new SongInfoTextView;
|
SongInfoTextView* text_view = new SongInfoTextView;
|
||||||
|
Loading…
Reference in New Issue
Block a user