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