• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.9.4 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 
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 == "user" || key == "sender" || key == "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 + "_-_" + 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( "created_at" ).toLower().mid( 4 ),
74  "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( "created_at" ).toLower().mid( 4 );
80  //kDebug() << dateTime;
81 }
82 
83 StatusItem::StatusItem() : d( new Private )
84 {
85 }
86 
87 StatusItem::StatusItem( const QByteArray &data ) : d( new Private )
88 {
89  d->data = data;
90  d->init();
91 }
92 
93 StatusItem::StatusItem( const StatusItem& other ) : d( other.d )
94 {
95 }
96 
97 StatusItem::~StatusItem()
98 {
99 }
100 
101 StatusItem StatusItem::operator=( const StatusItem &other )
102 {
103  if ( &other != this )
104  d = other.d;
105 
106  return *this;
107 }
108 
109 void StatusItem::setData( const QByteArray &data )
110 {
111  d->data = data;
112  d->init();
113 }
114 
115 
116 qlonglong StatusItem::id() const
117 {
118  return d->status.value( "id" ).toLongLong();
119 }
120 
121 QByteArray StatusItem::data() const
122 {
123  return d->data;
124 }
125 
126 QString StatusItem::value( const QString& value ) const
127 {
128  return d->status.value( value );
129 }
130 
131 QStringList StatusItem::keys() const
132 {
133  return d->status.keys();
134 }
135 
136 QString StatusItem::text() const
137 {
138  using KPIMUtils::LinkLocator;
139  int flags = LinkLocator::PreserveSpaces | LinkLocator::HighlightText | LinkLocator::ReplaceSmileys;
140  return KPIMUtils::LinkLocator::convertToHtml( d->status.value( "text" ), flags );
141 }
142 
143 QDateTime StatusItem::date() const
144 {
145  return d->dateTime;
146 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Tue Dec 11 2012 12:13:34 by doxygen 1.8.1.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Microblog Library

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

kdepimlibs-4.9.4 API Reference

Skip menu "kdepimlibs-4.9.4 API Reference"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • 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