akonadi
itemdeletejob.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "itemdeletejob.h"
00021
00022 #include "collection.h"
00023 #include "collectionselectjob_p.h"
00024 #include "item.h"
00025 #include "job_p.h"
00026 #include "protocolhelper_p.h"
00027
00028 #include <akonadi/private/imapparser_p.h>
00029 #include <akonadi/private/imapset_p.h>
00030 #include <akonadi/private/protocol_p.h>
00031
00032 #include <KLocale>
00033
00034 using namespace Akonadi;
00035
00036 class Akonadi::ItemDeleteJobPrivate : public JobPrivate
00037 {
00038 public:
00039 ItemDeleteJobPrivate( ItemDeleteJob *parent )
00040 : JobPrivate( parent )
00041 {
00042 }
00043
00044 void selectResult( KJob *job );
00045
00046 Q_DECLARE_PUBLIC( ItemDeleteJob )
00047
00048 Item::List mItems;
00049 Collection mCollection;
00050 };
00051
00052 void ItemDeleteJobPrivate::selectResult( KJob *job )
00053 {
00054 if ( job->error() )
00055 return;
00056
00057 const QByteArray command = newTag() + " " AKONADI_CMD_ITEMDELETE " 1:*\n";
00058 writeData( command );
00059 }
00060
00061 ItemDeleteJob::ItemDeleteJob( const Item & item, QObject * parent )
00062 : Job( new ItemDeleteJobPrivate( this ), parent )
00063 {
00064 Q_D( ItemDeleteJob );
00065
00066 d->mItems << item;
00067 }
00068
00069 ItemDeleteJob::ItemDeleteJob(const Item::List& items, QObject* parent)
00070 : Job( new ItemDeleteJobPrivate( this ), parent )
00071 {
00072 Q_D( ItemDeleteJob );
00073 d->mItems = items;
00074 }
00075
00076 ItemDeleteJob::ItemDeleteJob(const Collection& collection, QObject* parent)
00077 : Job( new ItemDeleteJobPrivate( this ), parent )
00078 {
00079 Q_D( ItemDeleteJob );
00080 d->mCollection = collection;
00081 }
00082
00083 ItemDeleteJob::~ItemDeleteJob()
00084 {
00085 }
00086
00087 void ItemDeleteJob::doStart()
00088 {
00089 Q_D( ItemDeleteJob );
00090
00091 if ( !d->mItems.isEmpty() ) {
00092 QByteArray command = d->newTag();
00093 try {
00094 command += ProtocolHelper::itemSetToByteArray( d->mItems, AKONADI_CMD_ITEMDELETE );
00095 } catch ( const std::exception &e ) {
00096 setError( Unknown );
00097 setErrorText( QString::fromUtf8( e.what() ) );
00098 emitResult();
00099 return;
00100 }
00101 command += '\n';
00102 d->writeData( command );
00103 } else {
00104 CollectionSelectJob *job = new CollectionSelectJob( d->mCollection, this );
00105 connect( job, SIGNAL(result(KJob*)), SLOT(selectResult(KJob*)) );
00106 addSubjob( job );
00107 }
00108 }
00109
00110 #include "itemdeletejob.moc"