akonadi
collectionselectjob.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 "collectionselectjob.h" 00021 00022 #include "job_p.h" 00023 00024 #include <QtCore/QDebug> 00025 00026 using namespace Akonadi; 00027 00028 class Akonadi::CollectionSelectJobPrivate : public JobPrivate 00029 { 00030 public: 00031 CollectionSelectJobPrivate( CollectionSelectJob *parent ) 00032 : JobPrivate( parent ), 00033 mUnseen( -1 ), 00034 mSilent( true ) 00035 { 00036 } 00037 00038 Collection mCollection; 00039 int mUnseen; 00040 bool mSilent; 00041 }; 00042 00043 CollectionSelectJob::CollectionSelectJob( const Collection &collection, QObject *parent ) 00044 : Job( new CollectionSelectJobPrivate( this ), parent ) 00045 { 00046 Q_D( CollectionSelectJob ); 00047 00048 d->mCollection = collection; 00049 } 00050 00051 CollectionSelectJob::~CollectionSelectJob( ) 00052 { 00053 } 00054 00055 void CollectionSelectJob::doStart( ) 00056 { 00057 Q_D( CollectionSelectJob ); 00058 00059 QByteArray command( d->newTag() + " SELECT " ); 00060 if ( d->mSilent ) 00061 command += "SILENT "; 00062 d->writeData( command + QByteArray::number( d->mCollection.id() ) + '\n' ); 00063 } 00064 00065 void CollectionSelectJob::doHandleResponse( const QByteArray & tag, const QByteArray & data ) 00066 { 00067 Q_D( CollectionSelectJob ); 00068 00069 if ( tag == "*" ) { 00070 if ( data.startsWith( "OK [UNSEEN" ) ) { 00071 int begin = data.indexOf( ' ', 4 ); 00072 int end = data.indexOf( ']' ); 00073 QByteArray number = data.mid( begin + 1, end - begin - 1 ); 00074 d->mUnseen = number.toInt(); 00075 return; 00076 } 00077 } 00078 } 00079 00080 int CollectionSelectJob::unseen( ) const 00081 { 00082 Q_D( const CollectionSelectJob ); 00083 00084 return d->mUnseen; 00085 } 00086 00087 void CollectionSelectJob::setRetrieveStatus(bool status) 00088 { 00089 Q_D( CollectionSelectJob ); 00090 00091 d->mSilent = !status; 00092 } 00093 00094 00095 #include "collectionselectjob.moc"