• Skip to content
  • Skip to link menu
KDE 4.4 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • Sitemap
  • Contact Us
 

Microblog Library

statusitem.cpp

00001 /*
00002     Copyright (C) 2009 Omat Holding B.V. <info@omat.nl>
00003 
00004     This library is free software; you can redistribute it and/or modify it
00005     under the terms of the GNU Library General Public License as published by
00006     the Free Software Foundation; either version 2 of the License, or (at your
00007     option) any later version.
00008 
00009     This library is distributed in the hope that it will be useful, but WITHOUT
00010     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00011     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00012     License for more details.
00013 
00014     You should have received a copy of the GNU Library General Public License
00015     along with this library; see the file COPYING.LIB.  If not, write to the
00016     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017     02110-1301, USA.
00018 */
00019 
00020 #include "statusitem.h"
00021 #include <kdebug.h>
00022 
00023 #include <QDateTime>
00024 #include <QDomElement>
00025 #include <QHash>
00026 #include <QStringList>
00027 
00028 #include <kpimutils/linklocator.h>
00029 
00030 using namespace Microblog;
00031 
00032 class StatusItem::Private : public QSharedData
00033 {
00034 public:
00035     Private() {}
00036     Private( const Private& other ) : QSharedData( other ) {
00037         data = other.data;
00038         status = other.status;
00039         dateTime = other.dateTime;
00040     }
00041 
00042 public:
00043     void init();
00044     QByteArray data;
00045     QHash<QString,QString> status;
00046     QDateTime dateTime;
00047 };
00048 
00049 void StatusItem::Private::init()
00050 {
00051     QDomDocument document;
00052     document.setContent( data );
00053     QDomElement root = document.documentElement();
00054     QDomNode node = root.firstChild();
00055     while ( !node.isNull() ) {
00056         const QString key = node.toElement().tagName();
00057         if ( key == "user" || key == "sender" || key == "recipient" ) {
00058             QDomNode node2 = node.firstChild();
00059             while ( !node2.isNull() ) {
00060                 const QString key2 = node2.toElement().tagName();
00061                 const QString val2 = node2.toElement().text();
00062                 status[ key + "_-_" + key2 ] = val2;
00063                 node2 = node2.nextSibling();
00064             }
00065         } else {
00066             const QString value = node.toElement().text();
00067             status[key] = value;
00068         }
00069         node = node.nextSibling();
00070     }
00071     //kDebug() << status;
00072 
00073     dateTime = QDateTime::fromString( status.value( "created_at" ).toLower().mid( 4 ),
00074                                       "MMM dd H:mm:ss +0000 yyyy" );
00075     dateTime.setTimeSpec( Qt::UTC );
00076     dateTime = dateTime.toLocalTime();
00077 
00078     if ( !dateTime.isValid() )
00079         kDebug() << "Unable to parse" << status.value( "created_at" ).toLower().mid( 4 );
00080     //kDebug() << dateTime;
00081 }
00082 
00083 StatusItem::StatusItem()  :  d( new Private )
00084 {
00085 }
00086 
00087 StatusItem::StatusItem( const QByteArray &data ) : d( new Private )
00088 {
00089     d->data = data;
00090     d->init();
00091 }
00092 
00093 StatusItem::StatusItem( const StatusItem& other ) : d( other.d )
00094 {
00095 }
00096 
00097 StatusItem::~StatusItem()
00098 {
00099 }
00100 
00101 StatusItem StatusItem::operator=( const StatusItem &other )
00102 {
00103     if ( &other != this )
00104         d = other.d;
00105 
00106     return *this;
00107 }
00108 
00109 void StatusItem::setData( const QByteArray &data )
00110 {
00111     d->data = data;
00112     d->init();
00113 }
00114 
00115 
00116 qlonglong StatusItem::id() const
00117 {
00118     return d->status.value( "id" ).toLongLong();
00119 }
00120 
00121 QByteArray StatusItem::data() const
00122 {
00123     return d->data;
00124 }
00125 
00126 QString StatusItem::value( const QString& value ) const
00127 {
00128     return d->status.value( value );
00129 }
00130 
00131 QStringList StatusItem::keys() const
00132 {
00133     return d->status.keys();
00134 }
00135 
00136 QString StatusItem::text() const
00137 {
00138     using KPIMUtils::LinkLocator;
00139     int flags = LinkLocator::PreserveSpaces | LinkLocator::HighlightText | LinkLocator::ReplaceSmileys;
00140     return KPIMUtils::LinkLocator::convertToHtml( d->status.value( "text" ), flags );
00141 }
00142 
00143 QDateTime StatusItem::date() const
00144 {
00145     return d->dateTime;
00146 }

Microblog Library

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

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kblog
  • kcal
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.6.2-20100208
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal