diff --git a/akonadi/itemcopyjob.cpp b/akonadi/itemcopyjob.cpp index 62f75aea6..beb2d184a 100644 --- a/akonadi/itemcopyjob.cpp +++ b/akonadi/itemcopyjob.cpp @@ -1,80 +1,87 @@ /* Copyright (c) 2008 Volker Krause This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "itemcopyjob.h" #include "collection.h" #include "imapset_p.h" #include "job_p.h" using namespace Akonadi; class Akonadi::ItemCopyJobPrivate : public JobPrivate { public: ItemCopyJobPrivate( ItemCopyJob *parent ) : JobPrivate( parent ) { } Item::List mItems; Collection mTarget; }; ItemCopyJob::ItemCopyJob(const Item & item, const Collection & target, QObject * parent) : Job( new ItemCopyJobPrivate( this ), parent ) { Q_D( ItemCopyJob ); d->mItems << item; d->mTarget = target; } ItemCopyJob::ItemCopyJob(const Item::List & items, const Collection & target, QObject * parent) : Job( new ItemCopyJobPrivate( this ), parent ) { Q_D( ItemCopyJob ); d->mItems = items; d->mTarget = target; } ItemCopyJob::~ItemCopyJob() { } +Item::List ItemCopyJob::items() const +{ + Q_D( const ItemCopyJob ); + + return d->mItems; +} + void ItemCopyJob::doStart() { Q_D( ItemCopyJob ); QList ids; foreach ( const Item &item, d->mItems ) ids << item.id(); ImapSet set; set.add( ids ); QByteArray cmd( d->newTag() ); cmd += " COPY "; cmd += set.toImapSequenceSet(); cmd += ' '; cmd += QByteArray::number( d->mTarget.id() ); cmd += '\n'; d->writeData( cmd ); } #include "itemcopyjob.moc" diff --git a/akonadi/itemcopyjob.h b/akonadi/itemcopyjob.h index 09f3ae5fa..ef3789a46 100644 --- a/akonadi/itemcopyjob.h +++ b/akonadi/itemcopyjob.h @@ -1,91 +1,96 @@ /* Copyright (c) 2008 Volker Krause This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef AKONADI_ITEMCOPYJOB_H #define AKONADI_ITEMCOPYJOB_H #include #include namespace Akonadi { class Collection; class ItemCopyJobPrivate; /** * @short Job that copies a set of items to a target collection in the Akonadi storage. * * The job can be used to copy one or several Item objects to another collection. * * Example: * * @code * * Akonadi::Item::List items = ... * Akonadi::Collection collection = ... * * Akonadi::ItemCopyJob *job = new Akonadi::ItemCopyJob( items, collection ); * * if ( job->exec() ) * qDebug() << "Items copied successfully"; * else * qDebug() << "Error occurred"; * * @endcode * * @author Volker Krause */ class AKONADI_EXPORT ItemCopyJob : public Job { Q_OBJECT public: /** * Creates a new item copy job. * * @param item The item to copy. * @param target The target collection. * @param parent The parent object. */ ItemCopyJob( const Item &item, const Collection &target, QObject *parent = 0 ); /** * Creates a new item copy job. * * @param items A list of items to copy. * @param target The target collection. * @param parent The parent object. */ ItemCopyJob( const Item::List &items, const Collection &target, QObject *parent = 0 ); /** * Destroys the item copy job. */ ~ItemCopyJob(); + /** + * Returns the items passed on in the constructor. + */ + Item::List items() const; + protected: void doStart(); private: Q_DECLARE_PRIVATE( ItemCopyJob ) }; } #endif diff --git a/akonadi/itemdeletejob.cpp b/akonadi/itemdeletejob.cpp index 9821fe751..447623b32 100644 --- a/akonadi/itemdeletejob.cpp +++ b/akonadi/itemdeletejob.cpp @@ -1,110 +1,126 @@ /* Copyright (c) 2006 - 2007 Volker Krause This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "itemdeletejob.h" #include "collection.h" #include "collectionselectjob_p.h" #include "item.h" #include "job_p.h" #include "protocolhelper_p.h" #include #include #include #include using namespace Akonadi; class Akonadi::ItemDeleteJobPrivate : public JobPrivate { public: ItemDeleteJobPrivate( ItemDeleteJob *parent ) : JobPrivate( parent ) { } void selectResult( KJob *job ); Q_DECLARE_PUBLIC( ItemDeleteJob ) Item::List mItems; Collection mCollection; }; void ItemDeleteJobPrivate::selectResult( KJob *job ) { if ( job->error() ) return; // KCompositeJob takes care of errors const QByteArray command = newTag() + " " AKONADI_CMD_ITEMDELETE " 1:*\n"; writeData( command ); } ItemDeleteJob::ItemDeleteJob( const Item & item, QObject * parent ) : Job( new ItemDeleteJobPrivate( this ), parent ) { Q_D( ItemDeleteJob ); d->mItems << item; } ItemDeleteJob::ItemDeleteJob(const Item::List& items, QObject* parent) : Job( new ItemDeleteJobPrivate( this ), parent ) { Q_D( ItemDeleteJob ); + d->mItems = items; } ItemDeleteJob::ItemDeleteJob(const Collection& collection, QObject* parent) : Job( new ItemDeleteJobPrivate( this ), parent ) { Q_D( ItemDeleteJob ); + d->mCollection = collection; } ItemDeleteJob::~ItemDeleteJob() { } +Item::List ItemDeleteJob::items() const +{ + Q_D( const ItemDeleteJob ); + + return d->mItems; +} + +Collection ItemDeleteJob::collection() const +{ + Q_D( const ItemDeleteJob ); + + return d->mCollection; +} + void ItemDeleteJob::doStart() { Q_D( ItemDeleteJob ); if ( !d->mItems.isEmpty() ) { QByteArray command = d->newTag(); try { command += ProtocolHelper::itemSetToByteArray( d->mItems, AKONADI_CMD_ITEMDELETE ); } catch ( const std::exception &e ) { setError( Unknown ); setErrorText( QString::fromUtf8( e.what() ) ); emitResult(); return; } command += '\n'; d->writeData( command ); } else { CollectionSelectJob *job = new CollectionSelectJob( d->mCollection, this ); connect( job, SIGNAL(result(KJob*)), SLOT(selectResult(KJob*)) ); addSubjob( job ); } } #include "itemdeletejob.moc" diff --git a/akonadi/itemdeletejob.h b/akonadi/itemdeletejob.h index 70bb9461c..ea7d93a45 100644 --- a/akonadi/itemdeletejob.h +++ b/akonadi/itemdeletejob.h @@ -1,120 +1,130 @@ /* Copyright (c) 2006 Volker Krause This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef AKONADI_ITEMDELETEJOB_H #define AKONADI_ITEMDELETEJOB_H #include "akonadi_export.h" #include #include namespace Akonadi { class Collection; class ItemDeleteJobPrivate; /** * @short Job that deletes items from the Akonadi storage. * * This job removes the given items from the Akonadi storage. * * Example: * * @code * * const Akonadi::Item item = ... * * ItemDeleteJob *job = new ItemDeleteJob( item ); * connect( job, SIGNAL( result( KJob* ) ), this, SLOT( deletionResult( KJob* ) ) ); * * @endcode * * Example: * * @code * * const Akonadi::Item::List items = ... * * ItemDeleteJob *job = new ItemDeleteJob( items ); * connect( job, SIGNAL( result( KJob* ) ), this, SLOT( deletionResult( KJob* ) ) ); * * @endcode * * @author Volker Krause */ class AKONADI_EXPORT ItemDeleteJob : public Job { Q_OBJECT public: /** * Creates a new item delete job that deletes @p item. The item * needs to either have a unique identifier or a remote identifier * set. In the latter case a collection or resource context needs * to be selected (using CollectionSelectJob or ResourceSelectJob). * * @param item The item to delete. * @param parent The parent object. */ explicit ItemDeleteJob( const Item &item, QObject *parent = 0 ); /** * Creates a new item delete job that deletes all items in the list * @p items. These items can be located in any collection. The same * restrictions on item identifiers apply as in the constructor above. * * @param items The items to delete. * @param parent The parent object. * * @since 4.3 */ explicit ItemDeleteJob( const Item::List &items, QObject *parent = 0 ); /** * Creates a new item delete job that deletes all items in the collection * @p collection. The collection needs to have either a unique identifier * or a remote identifier set. In the latter case a resource context * needs to be selected using ResourceSelectJob. * * @param collection The collection which content should be deleted. * @param parent The parent object. * * @since 4.3 */ explicit ItemDeleteJob( const Collection &collection, QObject *parent = 0 ); /** * Destroys the item delete job. */ ~ItemDeleteJob(); + /** + * Returns the items passed on in the constructor. + */ + Item::List items() const; + + /** + * Returns the collection passed on in the constructor. + */ + Collection collection() const; + protected: virtual void doStart(); private: //@cond PRIVATE Q_DECLARE_PRIVATE( ItemDeleteJob ) Q_PRIVATE_SLOT( d_func(), void selectResult( KJob* ) ) //@endcond }; } #endif