akonadi
collectioncreatejob.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "collectioncreatejob.h"
00021 #include "imapparser_p.h"
00022 #include "protocolhelper.h"
00023
00024 #include "job_p.h"
00025
00026 #include <kdebug.h>
00027
00028 using namespace Akonadi;
00029
00030 class Akonadi::CollectionCreateJobPrivate : public JobPrivate
00031 {
00032 public:
00033 CollectionCreateJobPrivate( CollectionCreateJob *parent )
00034 : JobPrivate( parent )
00035 {
00036 }
00037
00038 Collection mCollection;
00039 };
00040
00041 CollectionCreateJob::CollectionCreateJob( const Collection &collection, QObject * parent )
00042 : Job( new CollectionCreateJobPrivate( this ), parent )
00043 {
00044 Q_D( CollectionCreateJob );
00045
00046 d->mCollection = collection;
00047 }
00048
00049 CollectionCreateJob::~CollectionCreateJob( )
00050 {
00051 }
00052
00053 void CollectionCreateJob::doStart( )
00054 {
00055 Q_D( CollectionCreateJob );
00056
00057 QByteArray command = d->newTag() + " CREATE \"" + d->mCollection.name().toUtf8() + "\" ";
00058 command += QByteArray::number( d->mCollection.parent() );
00059 command += " (";
00060 if ( !d->mCollection.contentMimeTypes().isEmpty() )
00061 {
00062 QList<QByteArray> cList;
00063 foreach( const QString &s, d->mCollection.contentMimeTypes() ) cList << s.toLatin1();
00064 command += "MIMETYPE (" + ImapParser::join( cList, QByteArray(" ") ) + ')';
00065 }
00066 command += " REMOTEID \"" + d->mCollection.remoteId().toUtf8() + '"';
00067 foreach ( Attribute* attr, d->mCollection.attributes() )
00068 command += ' ' + attr->type() + ' ' + ImapParser::quote( attr->serialized() );
00069 command += ' ' + ProtocolHelper::cachePolicyToByteArray( d->mCollection.cachePolicy() );
00070 command += ")\n";
00071 d->writeData( command );
00072 emitWriteFinished();
00073 }
00074
00075 Collection CollectionCreateJob::collection() const
00076 {
00077 Q_D( const CollectionCreateJob );
00078
00079 return d->mCollection;
00080 }
00081
00082 void CollectionCreateJob::doHandleResponse(const QByteArray & tag, const QByteArray & data)
00083 {
00084 Q_D( CollectionCreateJob );
00085
00086 if ( tag == "*" ) {
00087 Collection col;
00088 ProtocolHelper::parseCollection( data, col );
00089 if ( !col.isValid() )
00090 return;
00091
00092 col.setParent( d->mCollection.parent() );
00093 col.setName( d->mCollection.name() );
00094 col.setRemoteId( d->mCollection.remoteId() );
00095 d->mCollection = col;
00096 } else {
00097 Job::doHandleResponse( tag, data );
00098 }
00099 }
00100
00101 #include "collectioncreatejob.moc"