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

0001 /*
0002     SPDX-FileCopyrightText: 2011 Christian Mollekopf <chrigi_1@fastmail.fm>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "akonadicore_export.h"
0010 #include "collection.h"
0011 #include "item.h"
0012 #include "job.h"
0013 
0014 namespace Akonadi
0015 {
0016 class TrashJobPrivate;
0017 
0018 /**
0019  * @short Job that moves items/collection to trash.
0020  *
0021  * This job marks the given entities as trash and moves them to a given trash collection, if available.
0022  *
0023  * Priorities of trash collections are the following:
0024  * 1. keepTrashInCollection()
0025  * 2. setTrashCollection()
0026  * 3. configured collection in TrashSettings
0027  * 4. keep in collection if nothing is configured
0028  *
0029  * If the item is already marked as trash, it will be deleted instead
0030  * only if deleteIfInTrash() is set.
0031  * The entity is marked as trash with the EntityDeletedAttribute.
0032  *
0033  * The restore collection in the EntityDeletedAttribute is set the following way:
0034  * -If entities are not moved to trash -> no restore collection
0035  * -If collection is deleted -> also subentities get collection.parentCollection as restore collection
0036  * -If multiple items are deleted -> all items get their parentCollection as restore collection
0037  *
0038  * Example:
0039  *
0040  * @code
0041  *
0042  * const Akonadi::Item::List items = ...
0043  *
0044  * TrashJob *job = new TrashJob( items );
0045  * connect( job, SIGNAL(result(KJob*)), this, SLOT(deletionResult(KJob*)) );
0046  *
0047  * @endcode
0048  *
0049  * @author Christian Mollekopf <chrigi_1@fastmail.fm>
0050  * @since 4.8
0051  */
0052 class AKONADICORE_EXPORT TrashJob : public Job
0053 {
0054     Q_OBJECT
0055 
0056 public:
0057     /**
0058      * Creates a new trash job that marks @p item as trash, and moves it to the configured trash collection.
0059      *
0060      * If @p keepTrashInCollection is set, the item will not be moved to the configured trash collection.
0061      *
0062      * @param item The item to mark as trash.
0063      * @param parent The parent object.
0064      */
0065     explicit TrashJob(const Item &item, QObject *parent = nullptr);
0066 
0067     /**
0068      * Creates a new trash job that marks all items in the list
0069      * @p items as trash, and moves it to the configured trash collection.
0070      * The items can be in different collections/resources and will still be moved to the correct trash collection.
0071      *
0072      * If @p keepTrashInCollection is set, the item will not be moved to the configured trash collection.
0073      *
0074      * @param items The items to mark as trash.
0075      * @param parent The parent object.
0076      */
0077     explicit TrashJob(const Item::List &items, QObject *parent = nullptr);
0078 
0079     /**
0080      * Creates a new trash job that marks @p collection as trash, and moves it to the configured trash collection.
0081      * The subentities of the collection are also marked as trash.
0082      *
0083      * If @p keepTrashInCollection is set, the item will not be moved to the configured trash collection.
0084      *
0085      * @param collection The collection to mark as trash.
0086      * @param parent The parent object.
0087      */
0088     explicit TrashJob(const Collection &collection, QObject *parent = nullptr);
0089 
0090     ~TrashJob() override;
0091 
0092     /**
0093      * Ignore configured Trash collections and keep all items local
0094      */
0095     void keepTrashInCollection(bool enable);
0096 
0097     /**
0098      * Moves all entities to the give collection
0099      */
0100     void setTrashCollection(const Collection &trashcollection);
0101 
0102     /**
0103      * Delete Items which are already in trash, instead of ignoring them
0104      */
0105     void deleteIfInTrash(bool enable);
0106 
0107     [[nodiscard]] Item::List items() const;
0108 
0109 protected:
0110     void doStart() override;
0111 
0112 private:
0113     /// @cond PRIVATE
0114     Q_DECLARE_PRIVATE(TrashJob)
0115     /// @endcond
0116 };
0117 
0118 }