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
00074 d->mItems = items;
00075 }
00076
00077 ItemDeleteJob::ItemDeleteJob(const Collection& collection, QObject* parent)
00078 : Job( new ItemDeleteJobPrivate( this ), parent )
00079 {
00080 Q_D( ItemDeleteJob );
00081
00082 d->mCollection = collection;
00083 }
00084
00085 ItemDeleteJob::~ItemDeleteJob()
00086 {
00087 }
00088
00089 Item::List ItemDeleteJob::deletedItems() const
00090 {
00091 Q_D( const ItemDeleteJob );
00092
00093 return d->mItems;
00094 }
00095
00096 void ItemDeleteJob::doStart()
00097 {
00098 Q_D( ItemDeleteJob );
00099
00100 if ( !d->mItems.isEmpty() ) {
00101 QByteArray command = d->newTag();
00102 try {
00103 command += ProtocolHelper::entitySetToByteArray( d->mItems, AKONADI_CMD_ITEMDELETE );
00104 } catch ( const std::exception &e ) {
00105 setError( Unknown );
00106 setErrorText( QString::fromUtf8( e.what() ) );
00107 emitResult();
00108 return;
00109 }
00110 command += '\n';
00111 d->writeData( command );
00112 } else {
00113 CollectionSelectJob *job = new CollectionSelectJob( d->mCollection, this );
00114 connect( job, SIGNAL( result( KJob* ) ), SLOT( selectResult( KJob* ) ) );
00115 addSubjob( job );
00116 }
00117 }
00118
00119 #include "itemdeletejob.moc"