File indexing completed on 2024-11-10 04:40:30

0001 /*
0002     SPDX-FileCopyrightText: 2008 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "akonadicore_export.h"
0010 #include "item.h"
0011 #include "job.h"
0012 namespace Akonadi
0013 {
0014 class Collection;
0015 class ItemMoveJobPrivate;
0016 
0017 /**
0018  * @short Job that moves an item into a different collection in the Akonadi storage.
0019  *
0020  * This job takes an item and moves it to a collection in the Akonadi storage.
0021  *
0022  * @code
0023  *
0024  * Akonadi::Item item = ...
0025  * Akonadi::Collection collection = ...
0026  *
0027  * Akonadi::ItemMoveJob *job = new Akonadi::ItemMoveJob( item, collection );
0028  * connect( job, SIGNAL(result(KJob*)), this, SLOT(moveResult(KJob*)) );
0029  *
0030  * @endcode
0031  *
0032  * @author Volker Krause <vkrause@kde.org>
0033  */
0034 class AKONADICORE_EXPORT ItemMoveJob : public Job
0035 {
0036     Q_OBJECT
0037 
0038 public:
0039     /**
0040      * Move the given item into the given collection.
0041      *
0042      * @param item The item to move.
0043      * @param destination The destination collection.
0044      * @param parent The parent object.
0045      */
0046     ItemMoveJob(const Item &item, const Collection &destination, QObject *parent = nullptr);
0047 
0048     /**
0049      * Move the given items into @p destination.
0050      *
0051      * @param items A list of items to move.
0052      * @param destination The destination collection.
0053      * @param parent The parent object.
0054      */
0055     ItemMoveJob(const Item::List &items, const Collection &destination, QObject *parent = nullptr);
0056 
0057     /**
0058      * Move the given items from @p source to @p destination.
0059      *
0060      * @internal If the items are identified only by RID, then you MUST use this
0061      * constructor to specify the source collection, otherwise the job will fail.
0062      * RID-based moves are only allowed to resources.
0063      *
0064      * @since 4.14
0065      */
0066     ItemMoveJob(const Item::List &items, const Collection &source, const Collection &destination, QObject *parent = nullptr);
0067 
0068     /**
0069      * Destroys the item move job.
0070      */
0071     ~ItemMoveJob() override;
0072 
0073     /**
0074      * Returns the destination collection.
0075      *
0076      * @since 4.7
0077      */
0078     [[nodiscard]] Collection destinationCollection() const;
0079 
0080     /**
0081      * Returns the list of items that where passed in the constructor.
0082      *
0083      * @since 4.7
0084      */
0085     [[nodiscard]] Akonadi::Item::List items() const;
0086 
0087 protected:
0088     void doStart() override;
0089     bool doHandleResponse(qint64 tag, const Protocol::CommandPtr &response) override;
0090 
0091 private:
0092     Q_DECLARE_PRIVATE(ItemMoveJob)
0093 };
0094 
0095 }