File indexing completed on 2024-06-23 05:06:55

0001 /*
0002     SPDX-FileCopyrightText: 2014 Christian Mollekopf <mollekopf@kolabsys.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "akonadicore_export.h"
0010 
0011 #include <QSharedPointer>
0012 
0013 namespace Akonadi
0014 {
0015 class TagFetchScopePrivate;
0016 
0017 /**
0018  * @short Specifies which parts of a tag should be fetched from the Akonadi storage.
0019  *
0020  * @since 4.13
0021  */
0022 class AKONADICORE_EXPORT TagFetchScope
0023 {
0024 public:
0025     /**
0026      * Creates an empty tag fetch scope.
0027      *
0028      * Using an empty scope will only fetch the very basic meta data of tags,
0029      * e.g. local id, remote id and mime type
0030      */
0031     TagFetchScope();
0032 
0033     /**
0034      * Creates a new tag fetch scope from an @p other.
0035      */
0036     TagFetchScope(const TagFetchScope &other);
0037 
0038     /**
0039      * Destroys the tag fetch scope.
0040      */
0041     ~TagFetchScope();
0042 
0043     /**
0044      * Assigns the @p other to this scope and returns a reference to this scope.
0045      */
0046     TagFetchScope &operator=(const TagFetchScope &other);
0047 
0048     /**
0049      * Returns all explicitly fetched attributes.
0050      *
0051      * Undefined if fetchAllAttributes() returns true.
0052      *
0053      * @see fetchAttribute()
0054      */
0055     [[nodiscard]] QSet<QByteArray> attributes() const;
0056 
0057     /**
0058      * Sets whether to fetch tag remote ID.
0059      *
0060      * This option only has effect for Resources.
0061      */
0062     void setFetchRemoteId(bool fetchRemoteId);
0063 
0064     /**
0065      * Returns whether tag remote ID should be fetched.
0066      */
0067     [[nodiscard]] bool fetchRemoteId() const;
0068 
0069     /**
0070      * Sets whether to fetch all attributes.
0071      */
0072     void setFetchAllAttributes(bool fetchAllAttributes);
0073 
0074     /**
0075      * Returns whether to fetch all attributes
0076      */
0077     [[nodiscard]] bool fetchAllAttributes() const;
0078 
0079     /**
0080      * Sets whether the attribute of the given @p type should be fetched.
0081      *
0082      * @param type The attribute type to fetch.
0083      * @param fetch @c true if the attribute should be fetched, @c false otherwise.
0084      */
0085     void fetchAttribute(const QByteArray &type, bool fetch = true);
0086 
0087     /**
0088      * Sets whether the attribute of the requested type should be fetched.
0089      *
0090      * @param fetch @c true if the attribute should be fetched, @c false otherwise.
0091      */
0092     template<typename T>
0093     inline void fetchAttribute(bool fetch = true)
0094     {
0095         T dummy;
0096         fetchAttribute(dummy.type(), fetch);
0097     }
0098 
0099     /**
0100      * Sets whether only the id or the complete tag should be fetched.
0101      *
0102      * The default is @c false.
0103      *
0104      * @since 4.15
0105      */
0106     void setFetchIdOnly(bool fetchIdOnly);
0107 
0108     /**
0109      * Sets whether only the id of the tags should be retrieved or the complete tag.
0110      *
0111      * @see tagFetchScope()
0112      * @since 4.15
0113      */
0114     [[nodiscard]] bool fetchIdOnly() const;
0115 
0116 private:
0117     /// @cond PRIVATE
0118     QSharedPointer<TagFetchScopePrivate> d;
0119     /// @endcond
0120 };
0121 
0122 }
0123 
0124 // Q_DECLARE_METATYPE(Akonadi::TagFetchScope)