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

0001 /*
0002     SPDX-FileCopyrightText: 2009 Constantin Berzan <exit3219@gmail.com>
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 "specialcollections.h"
0012 #include "transactionsequence.h"
0013 
0014 #include <QVariant>
0015 
0016 #include <memory>
0017 
0018 namespace Akonadi
0019 {
0020 class SpecialCollectionsRequestJobPrivate;
0021 
0022 /**
0023  * @short A job to request SpecialCollections.
0024  *
0025  * Use this job to request the SpecialCollections you need. You can request both
0026  * default SpecialCollections and SpecialCollections in a given resource. The default
0027  * SpecialCollections resource is created when the first default SpecialCollection is
0028  * requested, but if a SpecialCollection in a custom resource is requested, this
0029  * job expects that resource to exist already.
0030  *
0031  * If the folders you requested already exist, this job simply succeeds.
0032  * Otherwise, it creates the required collections and registers them with
0033  * SpecialCollections.
0034  *
0035  * This class is not meant to be used directly but as a base class for type
0036  * specific special collection request jobs.
0037  *
0038  * @author Constantin Berzan <exit3219@gmail.com>
0039  * @since 4.4
0040  */
0041 class AKONADICORE_EXPORT SpecialCollectionsRequestJob : public TransactionSequence
0042 {
0043     Q_OBJECT
0044 
0045 public:
0046     /**
0047      * Destroys the special collections request job.
0048      */
0049     ~SpecialCollectionsRequestJob() override;
0050 
0051     /**
0052      * Requests a special collection of the given @p type in the default resource.
0053      */
0054     void requestDefaultCollection(const QByteArray &type);
0055 
0056     /**
0057      * Requests a special collection of the given @p type in the given resource @p instance.
0058      */
0059     void requestCollection(const QByteArray &type, const AgentInstance &instance);
0060 
0061     /**
0062      * Returns the requested collection.
0063      */
0064     [[nodiscard]] Collection collection() const;
0065 
0066 protected:
0067     /**
0068      * Creates a new special collections request job.
0069      *
0070      * @param collections The SpecialCollections object that shall be used.
0071      * @param parent The parent object.
0072      */
0073     explicit SpecialCollectionsRequestJob(SpecialCollections *collections, QObject *parent = nullptr);
0074 
0075     /**
0076      * Sets the @p type of the resource that shall be created if the requested
0077      * special collection does not exist yet.
0078      */
0079     void setDefaultResourceType(const QString &type);
0080 
0081     /**
0082      * Sets the configuration @p options that shall be applied to the new resource
0083      * that is created if the requested special collection does not exist yet.
0084      */
0085     void setDefaultResourceOptions(const QVariantMap &options);
0086 
0087     /**
0088      * Sets the list of well known special collection @p types.
0089      */
0090     void setTypes(const QList<QByteArray> &types);
0091 
0092     /**
0093      * Sets the @p map of special collection types to display names.
0094      */
0095     void setNameForTypeMap(const QMap<QByteArray, QString> &map);
0096 
0097     /**
0098      * Sets the @p map of special collection types to icon names.
0099      */
0100     void setIconForTypeMap(const QMap<QByteArray, QString> &map);
0101 
0102     /* reimpl */
0103     void doStart() override;
0104     /* reimpl */
0105     void slotResult(KJob *job) override;
0106 
0107 private:
0108     /// @cond PRIVATE
0109     friend class SpecialCollectionsRequestJobPrivate;
0110     friend class DefaultResourceJobPrivate;
0111 
0112     std::unique_ptr<SpecialCollectionsRequestJobPrivate> const d;
0113 
0114     Q_PRIVATE_SLOT(d, void releaseLock())
0115     Q_PRIVATE_SLOT(d, void resourceScanResult(KJob *))
0116     Q_PRIVATE_SLOT(d, void collectionCreateResult(KJob *))
0117     /// @endcond
0118 };
0119 
0120 } // namespace Akonadi