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

Microblog Library

  • sources
  • kde-4.14
  • kdepimlibs
  • 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 
30 using namespace Microblog;
31 
32 class StatusItem::Private : public QSharedData
33 {
34 public:
35  Private() {}
36  Private( const Private& other ) : QSharedData( other ) {
37  data = other.data;
38  status = other.status;
39  dateTime = other.dateTime;
40  }
41 
42 public:
43  void init();
44  QByteArray data;
45  QHash<QString, QString> status;
46  QDateTime dateTime;
47 };
48 
49 void 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 
84 StatusItem::StatusItem() : d( new Private )
85 {
86 }
87 
88 StatusItem::StatusItem( const QByteArray &data ) : d( new Private )
89 {
90  d->data = data;
91  d->init();
92 }
93 
94 StatusItem::StatusItem( const StatusItem& other ) : d( other.d )
95 {
96 }
97 
98 StatusItem::~StatusItem()
99 {
100 }
101 
102 StatusItem StatusItem::operator=( const StatusItem &other )
103 {
104  if ( &other != this ) {
105  d = other.d;
106  }
107 
108  return *this;
109 }
110 
111 void StatusItem::setData( const QByteArray &data )
112 {
113  d->data = data;
114  d->init();
115 }
116 
117 
118 qlonglong StatusItem::id() const
119 {
120  return d->status.value( QLatin1String("id") ).toLongLong();
121 }
122 
123 QByteArray StatusItem::data() const
124 {
125  return d->data;
126 }
127 
128 QString StatusItem::value( const QString& value ) const
129 {
130  return d->status.value( value );
131 }
132 
133 QStringList StatusItem::keys() const
134 {
135  return d->status.keys();
136 }
137 
138 QString 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 
145 QDateTime StatusItem::date() const
146 {
147  return d->dateTime;
148 }
Microblog::StatusItem::data
QByteArray data() const
Gives the raw xml data of the tweet or dent.
Definition: statusitem.cpp:123
QByteArray
Microblog::StatusItem::operator=
StatusItem operator=(const StatusItem &)
Coparisation operator.
Definition: statusitem.cpp:102
QDomDocument::documentElement
QDomElement documentElement() const
QDomNode
Microblog::StatusItem
This class is a representation of one Dent or Tweet.
Definition: statusitem.h:51
Microblog::StatusItem::keys
QStringList keys() const
Returns all the keys available.
Definition: statusitem.cpp:133
QDomNode::nextSibling
QDomNode nextSibling() const
Microblog::StatusItem::value
QString value(const QString &) const
Returns the value of a certain key.
Definition: statusitem.cpp:128
QDomNode::toElement
QDomElement toElement() const
Microblog::StatusItem::StatusItem
StatusItem()
Constructor.
Definition: statusitem.cpp:84
QDateTime::setTimeSpec
void setTimeSpec(Qt::TimeSpec spec)
QSharedData
Microblog::StatusItem::~StatusItem
~StatusItem()
Destructor.
Definition: statusitem.cpp:98
QDomElement::text
QString text() const
QHash< QString, QString >
QSharedDataPointer::data
T * data()
Microblog::StatusItem::date
QDateTime date() const
Returns the date of the dent or tweet.
Definition: statusitem.cpp:145
QString
QStringList
Microblog::StatusItem::text
QString text() const
Gives the text of the tweet or dent.
Definition: statusitem.cpp:138
QDomDocument
QDateTime::fromString
QDateTime fromString(const QString &string, Qt::DateFormat format)
Microblog::StatusItem::id
qlonglong id() const
Returns the unique id as given by the service.
Definition: statusitem.cpp:118
QDomNode::isNull
bool isNull() const
QDomNode::firstChild
QDomNode firstChild() const
QLatin1String
QByteArray::data
char * data()
QDomElement::tagName
QString tagName() const
QDomElement
Microblog::StatusItem::setData
void setData(const QByteArray &)
The call to set the XML data.
Definition: statusitem.cpp:111
QDateTime
QDomDocument::setContent
bool setContent(const QByteArray &data, bool namespaceProcessing, QString *errorMsg, int *errorLine, int *errorColumn)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:37:30 by doxygen 1.8.7 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 API Reference

Skip menu "kdepimlibs 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

Search



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