Add CSS to Twitter stream.
This commit is contained in:
parent
6bc4951236
commit
6862a69383
@ -345,5 +345,6 @@
|
|||||||
<file>providers/itunes.png</file>
|
<file>providers/itunes.png</file>
|
||||||
<file>providers/bbc.png</file>
|
<file>providers/bbc.png</file>
|
||||||
<file>sample.mood</file>
|
<file>sample.mood</file>
|
||||||
|
<file>twitter.css</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
8
data/twitter.css
Normal file
8
data/twitter.css
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
.tweet {
|
||||||
|
background-color: white;
|
||||||
|
margin-bottom: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tweet.alternate {
|
||||||
|
background-color: #f6f6f6;
|
||||||
|
}
|
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
#include "twitterartistinfo.h"
|
#include "twitterartistinfo.h"
|
||||||
|
|
||||||
|
#include <QFile>
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
#include <QXmlStreamWriter>
|
#include <QXmlStreamWriter>
|
||||||
|
|
||||||
@ -34,6 +35,9 @@ const char* TwitterArtistInfo::kTwitterTimelineUrl =
|
|||||||
|
|
||||||
TwitterArtistInfo::TwitterArtistInfo()
|
TwitterArtistInfo::TwitterArtistInfo()
|
||||||
: network_(this) {
|
: network_(this) {
|
||||||
|
QFile file(":twitter.css");
|
||||||
|
file.open(QIODevice::ReadOnly);
|
||||||
|
stylesheet_ = file.readAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TwitterArtistInfo::FetchInfo(int id, const Song& metadata) {
|
void TwitterArtistInfo::FetchInfo(int id, const Song& metadata) {
|
||||||
@ -136,9 +140,13 @@ Entity ParseMentionEntity(const QVariant& m) {
|
|||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const char* kTweetClass = "tweet";
|
||||||
|
static const char* kAlternateClass = "tweet alternate";
|
||||||
|
|
||||||
QString GenerateHtmlForTweetStream(const QVariantList& tweets) {
|
QString GenerateHtmlForTweetStream(const QVariantList& tweets) {
|
||||||
QString html;
|
QString html;
|
||||||
QXmlStreamWriter writer(&html);
|
QXmlStreamWriter writer(&html);
|
||||||
|
bool alt = true;
|
||||||
foreach (const QVariant& v, tweets) {
|
foreach (const QVariant& v, tweets) {
|
||||||
QVariantMap tweet = v.toMap();
|
QVariantMap tweet = v.toMap();
|
||||||
QString text = tweet["text"].toString();
|
QString text = tweet["text"].toString();
|
||||||
@ -165,6 +173,11 @@ QString GenerateHtmlForTweetStream(const QVariantList& tweets) {
|
|||||||
qSort(entities);
|
qSort(entities);
|
||||||
|
|
||||||
writer.writeStartElement("div");
|
writer.writeStartElement("div");
|
||||||
|
if ((alt = !alt)) {
|
||||||
|
writer.writeAttribute("class", kAlternateClass);
|
||||||
|
} else {
|
||||||
|
writer.writeAttribute("class", kTweetClass);
|
||||||
|
}
|
||||||
|
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
foreach (const Entity& e, entities) {
|
foreach (const Entity& e, entities) {
|
||||||
@ -183,7 +196,6 @@ QString GenerateHtmlForTweetStream(const QVariantList& tweets) {
|
|||||||
writer.writeCharacters(text.mid(offset));
|
writer.writeCharacters(text.mid(offset));
|
||||||
|
|
||||||
writer.writeEndElement();
|
writer.writeEndElement();
|
||||||
writer.writeEmptyElement("br");
|
|
||||||
}
|
}
|
||||||
return html;
|
return html;
|
||||||
}
|
}
|
||||||
@ -210,6 +222,7 @@ void TwitterArtistInfo::UserTimelineRequestFinished(
|
|||||||
QString html = GenerateHtmlForTweetStream(result.toList());
|
QString html = GenerateHtmlForTweetStream(result.toList());
|
||||||
|
|
||||||
SongInfoTextView* text_view = new SongInfoTextView;
|
SongInfoTextView* text_view = new SongInfoTextView;
|
||||||
|
text_view->document()->setDefaultStyleSheet(stylesheet_);
|
||||||
text_view->SetHtml(html);
|
text_view->SetHtml(html);
|
||||||
data.contents_ = text_view;
|
data.contents_ = text_view;
|
||||||
|
|
||||||
|
@ -39,6 +39,8 @@ class TwitterArtistInfo : public SongInfoProvider {
|
|||||||
|
|
||||||
NetworkAccessManager network_;
|
NetworkAccessManager network_;
|
||||||
|
|
||||||
|
QString stylesheet_;
|
||||||
|
|
||||||
static const char* kTwitterBucket;
|
static const char* kTwitterBucket;
|
||||||
static const char* kTwitterTimelineUrl;
|
static const char* kTwitterTimelineUrl;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user