20 #include "statusitem.h"
24 #include <QDomElement>
26 #include <QStringList>
28 #include <kpimutils/linklocator.h>
30 using namespace Microblog;
32 class StatusItem::Private :
public QSharedData
36 Private(
const Private& other ) : QSharedData( other ) {
38 status = other.status;
39 dateTime = other.dateTime;
45 QHash<QString, QString> status;
49 void StatusItem::Private::init()
51 QDomDocument document;
52 document.setContent( data );
53 QDomElement root = document.documentElement();
54 QDomNode node = root.firstChild();
55 while ( !node.isNull() ) {
56 const QString key = node.toElement().tagName();
57 if ( key == QLatin1String(
"user") || key == QLatin1String(
"sender") || key == QLatin1String(
"recipient") ) {
58 QDomNode node2 = node.firstChild();
59 while ( !node2.isNull() ) {
60 const QString key2 = node2.toElement().tagName();
61 const QString val2 = node2.toElement().text();
62 status[ key + QLatin1String(
"_-_") + key2 ] = val2;
63 node2 = node2.nextSibling();
66 const QString value = node.toElement().text();
69 node = node.nextSibling();
73 dateTime = QDateTime::fromString( status.value( QLatin1String(
"created_at") ).toLower().mid( 4 ),
74 QLatin1String(
"MMM dd H:mm:ss +0000 yyyy") );
75 dateTime.setTimeSpec( Qt::UTC );
76 dateTime = dateTime.toLocalTime();
78 if ( !dateTime.isValid() ) {
79 kDebug() <<
"Unable to parse" << status.value( QLatin1String(
"created_at") ).toLower().mid( 4 );
104 if ( &other !=
this ) {
120 return d->status.value( QLatin1String(
"id") ).toLongLong();
130 return d->status.value( value );
135 return d->status.keys();
140 using KPIMUtils::LinkLocator;
141 int flags = LinkLocator::PreserveSpaces | LinkLocator::HighlightText | LinkLocator::ReplaceSmileys;
142 return KPIMUtils::LinkLocator::convertToHtml( d->status.value( QLatin1String(
"text") ), flags );
QByteArray data() const
Gives the raw xml data of the tweet or dent.
StatusItem operator=(const StatusItem &)
Coparisation operator.
This class is a representation of one Dent or Tweet.
QStringList keys() const
Returns all the keys available.
QString value(const QString &) const
Returns the value of a certain key.
QDateTime date() const
Returns the date of the dent or tweet.
QString text() const
Gives the text of the tweet or dent.
qlonglong id() const
Returns the unique id as given by the service.
void setData(const QByteArray &)
The call to set the XML data.