akonadi
itemdeletejob.cpp
00001 /* 00002 Copyright (c) 2006 - 2007 Volker Krause <vkrause@kde.org> 00003 00004 This library is free software; you can redistribute it and/or modify it 00005 under the terms of the GNU Library General Public License as published by 00006 the Free Software Foundation; either version 2 of the License, or (at your 00007 option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, but WITHOUT 00010 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00011 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00012 License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to the 00016 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 00017 02110-1301, USA. 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; // KCompositeJob takes care of errors 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"
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Tue May 8 2012 00:00:44 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2012 The KDE developers.
Generated on Tue May 8 2012 00:00:44 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.