akonadi
collectionstatisticsjob.cpp
00001 /* 00002 Copyright (c) 2006 - 2007 Volker Krause <vkrause@kde.org> 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 "collectionstatisticsjob.h" 00021 00022 #include "collection.h" 00023 #include "collectionstatistics.h" 00024 #include "imapparser_p.h" 00025 #include "job_p.h" 00026 00027 #include <kdebug.h> 00028 00029 using namespace Akonadi; 00030 00031 class Akonadi::CollectionStatisticsJobPrivate : public JobPrivate 00032 { 00033 public: 00034 CollectionStatisticsJobPrivate( CollectionStatisticsJob *parent ) 00035 : JobPrivate( parent ) 00036 { 00037 } 00038 00039 Collection mCollection; 00040 CollectionStatistics mStatistics; 00041 }; 00042 00043 CollectionStatisticsJob::CollectionStatisticsJob( const Collection &collection, QObject * parent ) 00044 : Job( new CollectionStatisticsJobPrivate( this ), parent ) 00045 { 00046 Q_D( CollectionStatisticsJob ); 00047 00048 d->mCollection = collection; 00049 } 00050 00051 CollectionStatisticsJob::~CollectionStatisticsJob() 00052 { 00053 } 00054 00055 void CollectionStatisticsJob::doStart( ) 00056 { 00057 Q_D( CollectionStatisticsJob ); 00058 00059 d->writeData( d->newTag() + " STATUS " + QByteArray::number( d->mCollection.id() ) + " (MESSAGES UNSEEN SIZE)\n" ); 00060 } 00061 00062 void CollectionStatisticsJob::doHandleResponse( const QByteArray & tag, const QByteArray & data ) 00063 { 00064 Q_D( CollectionStatisticsJob ); 00065 00066 if ( tag == "*" ) { 00067 QByteArray token; 00068 int current = ImapParser::parseString( data, token ); 00069 if ( token == "STATUS" ) { 00070 // folder path 00071 current = ImapParser::parseString( data, token, current ); 00072 // result list 00073 QList<QByteArray> list; 00074 current = ImapParser::parseParenthesizedList( data, list, current ); 00075 for ( int i = 0; i < list.count() - 1; i += 2 ) { 00076 if ( list[i] == "MESSAGES" ) { 00077 d->mStatistics.setCount( list[i+1].toLongLong() ); 00078 } else if ( list[i] == "UNSEEN" ) { 00079 d->mStatistics.setUnreadCount( list[i+1].toLongLong() ); 00080 } else if ( list[i] == "SIZE" ) { 00081 d->mStatistics.setSize( list[i+1].toLongLong() ); 00082 } else { 00083 kDebug() << "Unknown STATUS response: " << list[i]; 00084 } 00085 } 00086 00087 d->mCollection.setStatistics( d->mStatistics ); 00088 return; 00089 } 00090 } 00091 kDebug() << "Unhandled response: " << tag << data; 00092 } 00093 00094 Collection CollectionStatisticsJob::collection() const 00095 { 00096 Q_D( const CollectionStatisticsJob ); 00097 00098 return d->mCollection; 00099 } 00100 00101 CollectionStatistics Akonadi::CollectionStatisticsJob::statistics() const 00102 { 00103 Q_D( const CollectionStatisticsJob ); 00104 00105 return d->mStatistics; 00106 } 00107 00108 #include "collectionstatisticsjob.moc"
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Aug 27 2012 22:09:21 by doxygen 1.7.5 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Aug 27 2012 22:09:21 by doxygen 1.7.5 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.