• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.14.10 API Reference
  • KDE Home
  • Contact Us
 

Microblog Library

  • microblog
statusitem.cpp
1/*
2 Copyright (C) 2009 Omat Holding B.V. <info@omat.nl>
3
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
8
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
18*/
19
20#include "statusitem.h"
21#include <kdebug.h>
22
23#include <QDateTime>
24#include <QDomElement>
25#include <QHash>
26#include <QStringList>
27
28#include <kpimutils/linklocator.h>
29
30using namespace Microblog;
31
32class StatusItem::Private : public QSharedData
33{
34public:
35 Private() {}
36 Private( const Private& other ) : QSharedData( other ) {
37 data = other.data;
38 status = other.status;
39 dateTime = other.dateTime;
40 }
41
42public:
43 void init();
44 QByteArray data;
45 QHash<QString, QString> status;
46 QDateTime dateTime;
47};
48
49void StatusItem::Private::init()
50{
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();
64 }
65 } else {
66 const QString value = node.toElement().text();
67 status[key] = value;
68 }
69 node = node.nextSibling();
70 }
71 //kDebug() << status;
72
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();
77
78 if ( !dateTime.isValid() ) {
79 kDebug() << "Unable to parse" << status.value( QLatin1String("created_at") ).toLower().mid( 4 );
80 }
81 //kDebug() << dateTime;
82}
83
84StatusItem::StatusItem() : d( new Private )
85{
86}
87
88StatusItem::StatusItem( const QByteArray &data ) : d( new Private )
89{
90 d->data = data;
91 d->init();
92}
93
94StatusItem::StatusItem( const StatusItem& other ) : d( other.d )
95{
96}
97
98StatusItem::~StatusItem()
99{
100}
101
102StatusItem StatusItem::operator=( const StatusItem &other )
103{
104 if ( &other != this ) {
105 d = other.d;
106 }
107
108 return *this;
109}
110
111void StatusItem::setData( const QByteArray &data )
112{
113 d->data = data;
114 d->init();
115}
116
117
118qlonglong StatusItem::id() const
119{
120 return d->status.value( QLatin1String("id") ).toLongLong();
121}
122
123QByteArray StatusItem::data() const
124{
125 return d->data;
126}
127
128QString StatusItem::value( const QString& value ) const
129{
130 return d->status.value( value );
131}
132
133QStringList StatusItem::keys() const
134{
135 return d->status.keys();
136}
137
138QString StatusItem::text() const
139{
140 using KPIMUtils::LinkLocator;
141 int flags = LinkLocator::PreserveSpaces | LinkLocator::HighlightText | LinkLocator::ReplaceSmileys;
142 return KPIMUtils::LinkLocator::convertToHtml( d->status.value( QLatin1String("text") ), flags );
143}
144
145QDateTime StatusItem::date() const
146{
147 return d->dateTime;
148}
Microblog::StatusItem
This class is a representation of one Dent or Tweet.
Definition statusitem.h:52
Microblog::StatusItem::data
QByteArray data() const
Gives the raw xml data of the tweet or dent.
Definition statusitem.cpp:123
Microblog::StatusItem::setData
void setData(const QByteArray &)
The call to set the XML data.
Definition statusitem.cpp:111
Microblog::StatusItem::keys
QStringList keys() const
Returns all the keys available.
Definition statusitem.cpp:133
Microblog::StatusItem::operator=
StatusItem operator=(const StatusItem &)
Coparisation operator.
Definition statusitem.cpp:102
Microblog::StatusItem::~StatusItem
~StatusItem()
Destructor.
Definition statusitem.cpp:98
Microblog::StatusItem::id
qlonglong id() const
Returns the unique id as given by the service.
Definition statusitem.cpp:118
Microblog::StatusItem::date
QDateTime date() const
Returns the date of the dent or tweet.
Definition statusitem.cpp:145
Microblog::StatusItem::text
QString text() const
Gives the text of the tweet or dent.
Definition statusitem.cpp:138
Microblog::StatusItem::StatusItem
StatusItem()
Constructor.
Definition statusitem.cpp:84
Microblog::StatusItem::value
QString value(const QString &) const
Returns the value of a certain key.
Definition statusitem.cpp:128
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Wed Jan 24 2024 00:00:00 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Microblog Library

Skip menu "Microblog Library"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Members
  • File List
  • Related Pages

kdepimlibs-4.14.10 API Reference

Skip menu "kdepimlibs-4.14.10 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal