akonadi
collectionselectjob.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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"