File indexing completed on 2024-06-23 05:06:47
0001 /* 0002 SPDX-FileCopyrightText: 2008 Kevin Krammer <kevin.krammer@gmx.at> 0003 SPDX-FileCopyrightText: 2009 Volker Krause <vkrause@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #pragma once 0009 0010 #include "akonadicore_export.h" 0011 0012 #include <QSet> 0013 #include <QSharedDataPointer> 0014 0015 #include <QStringList> 0016 0017 namespace Akonadi 0018 { 0019 class CollectionFetchScopePrivate; 0020 0021 /** 0022 * @short Specifies which parts of a collection should be fetched from the Akonadi storage. 0023 * 0024 * When collections are fetched from the server either by using CollectionFetchJob 0025 * explicitly or when it is being used internally by other classes, e.g. Akonadi::Monitor, 0026 * the scope of the fetch operation can be tailored to the application's current needs. 0027 * 0028 * Note that CollectionFetchScope always includes fetching collection attributes. 0029 * 0030 * There are two supported ways of changing the currently active CollectionFetchScope 0031 * of classes: 0032 * - in-place: modify the CollectionFetchScope object the other class holds as a member 0033 * - replace: replace the other class' member with a new scope object 0034 * 0035 * Example: modifying a CollectionFetchJob's scope @c in-place 0036 * @code 0037 * Akonadi::CollectionFetchJob *job = new Akonadi::CollectionFetchJob( collection ); 0038 * job->fetchScope().setIncludeUnsubscribed( true ); 0039 * @endcode 0040 * 0041 * Example: @c replacing a CollectionFetchJob's scope 0042 * @code 0043 * Akonadi::CollectionFetchScope scope; 0044 * scope.setIncludeUnsubscribed( true ); 0045 * 0046 * Akonadi::CollectionFetchJob *job = new Akonadi::CollectionFetchJob( collection ); 0047 * job->setFetchScope( scope ); 0048 * @endcode 0049 * 0050 * This class is implicitly shared. 0051 * 0052 * @author Volker Krause <vkrause@kde.org> 0053 * @since 4.4 0054 */ 0055 class AKONADICORE_EXPORT CollectionFetchScope 0056 { 0057 public: 0058 /** 0059 * Describes the ancestor retrieval depth. 0060 */ 0061 enum AncestorRetrieval { 0062 None, ///< No ancestor retrieval at all (the default) 0063 Parent, ///< Only retrieve the immediate parent collection 0064 All ///< Retrieve all ancestors, up to Collection::root() 0065 }; 0066 0067 /** 0068 * Creates an empty collection fetch scope. 0069 * 0070 * Using an empty scope will only fetch the very basic meta data of collections, 0071 * e.g. local id, remote id and content mimetypes. 0072 */ 0073 CollectionFetchScope(); 0074 0075 /** 0076 * Creates a new collection fetch scope from an @p other. 0077 */ 0078 CollectionFetchScope(const CollectionFetchScope &other); 0079 0080 /** 0081 * Destroys the collection fetch scope. 0082 */ 0083 ~CollectionFetchScope(); 0084 0085 /** 0086 * Assigns the @p other to this scope and returns a reference to this scope. 0087 */ 0088 CollectionFetchScope &operator=(const CollectionFetchScope &other); 0089 0090 /** 0091 * Describes the list filter 0092 * 0093 * @since 4.14 0094 */ 0095 enum ListFilter { 0096 NoFilter, ///< No filtering, retrieve all collections 0097 Display, ///< Only retrieve collections for display, taking the local preference and enabled into account. 0098 Sync, ///< Only retrieve collections for synchronization, taking the local preference and enabled into account. 0099 Index, ///< Only retrieve collections for indexing, taking the local preference and enabled into account. 0100 Enabled ///< Only retrieve enabled collections, ignoring the local preference. 0101 }; 0102 0103 /** 0104 * Sets a filter for the collections to be listed. 0105 * 0106 * Note that collections that do not match the filter are included if required to complete the tree. 0107 * 0108 * @since 4.14 0109 */ 0110 void setListFilter(ListFilter); 0111 0112 /** 0113 * Returns the list filter. 0114 * 0115 * @see setListFilter() 0116 * @since 4.14 0117 */ 0118 [[nodiscard]] ListFilter listFilter() const; 0119 0120 /** 0121 * Returns whether collection statistics should be included in the retrieved results. 0122 * 0123 * @see setIncludeStatistics() 0124 */ 0125 [[nodiscard]] bool includeStatistics() const; 0126 0127 /** 0128 * Sets whether collection statistics should be included in the retrieved results. 0129 * 0130 * @param include @c true to include collection statistics, @c false otherwise (the default). 0131 */ 0132 void setIncludeStatistics(bool include); 0133 0134 /** 0135 * Returns the resource identifier that is used as filter. 0136 * 0137 * @see setResource() 0138 */ 0139 [[nodiscard]] QString resource() const; 0140 0141 /** 0142 * Sets a resource filter, that is only collections owned by the specified resource are 0143 * retrieved. 0144 * 0145 * @param resource The resource identifier. 0146 */ 0147 void setResource(const QString &resource); 0148 0149 /** 0150 * Sets a content mimetypes filter, that is only collections that contain at least one of the 0151 * given mimetypes (or their parents) are retrieved. 0152 * 0153 * @param mimeTypes A list of mime types 0154 */ 0155 void setContentMimeTypes(const QStringList &mimeTypes); 0156 0157 /** 0158 * Returns the content mimetypes filter. 0159 * 0160 * @see setContentMimeTypes() 0161 */ 0162 [[nodiscard]] QStringList contentMimeTypes() const; 0163 0164 /** 0165 * Sets how many levels of ancestor collections should be included in the retrieval. 0166 * 0167 * Only the ID and the remote ID of the ancestor collections are fetched. If 0168 * you want more information about the ancestor collections, like their name, 0169 * you will need to do an additional CollectionFetchJob for them. 0170 * 0171 * @param ancestorDepth The desired ancestor retrieval depth. 0172 */ 0173 void setAncestorRetrieval(AncestorRetrieval ancestorDepth); 0174 0175 /** 0176 * Returns the ancestor retrieval depth. 0177 * 0178 * @see setAncestorRetrieval() 0179 */ 0180 [[nodiscard]] AncestorRetrieval ancestorRetrieval() const; 0181 0182 /** 0183 * Sets the fetch scope for ancestor retrieval. 0184 * 0185 * @see setAncestorRetrieval() 0186 */ 0187 void setAncestorFetchScope(const CollectionFetchScope &scope); 0188 0189 /** 0190 * Returns the fetch scope for ancestor retrieval. 0191 */ 0192 [[nodiscard]] CollectionFetchScope ancestorFetchScope() const; 0193 0194 /** 0195 * Returns the fetch scope for ancestor retrieval. 0196 */ 0197 CollectionFetchScope &ancestorFetchScope(); 0198 0199 /** 0200 * Returns all explicitly fetched attributes. 0201 * 0202 * @see fetchAttribute() 0203 */ 0204 [[nodiscard]] QSet<QByteArray> attributes() const; 0205 0206 /** 0207 * Sets whether the attribute of the given @p type should be fetched. 0208 * 0209 * @param type The attribute type to fetch. 0210 * @param fetch @c true if the attribute should be fetched, @c false otherwise. 0211 */ 0212 void fetchAttribute(const QByteArray &type, bool fetch = true); 0213 0214 /** 0215 * Sets whether the attribute of the requested type should be fetched. 0216 * 0217 * @param fetch @c true if the attribute should be fetched, @c false otherwise. 0218 */ 0219 template<typename T> 0220 inline void fetchAttribute(bool fetch = true) 0221 { 0222 T dummy; 0223 fetchAttribute(dummy.type(), fetch); 0224 } 0225 0226 /** 0227 * Sets whether only the id or the complete tag should be fetched. 0228 * 0229 * The default is @c false. 0230 * 0231 * @since 4.15 0232 */ 0233 void setFetchIdOnly(bool fetchIdOnly); 0234 0235 /** 0236 * Sets whether only the id of the tags should be retrieved or the complete tag. 0237 * 0238 * @see tagFetchScope() 0239 * @since 4.15 0240 */ 0241 [[nodiscard]] bool fetchIdOnly() const; 0242 0243 /** 0244 * Ignore retrieval errors while fetching collections, and always deliver what is available. 0245 * 0246 * This flag is useful to fetch a list of collections, where some might no longer be available. 0247 * 0248 * @since KF6 0249 */ 0250 void setIgnoreRetrievalErrors(bool enabled); 0251 0252 /** 0253 * Returns whether retrieval errors should be ignored. 0254 * 0255 * @see setIgnoreRetrievalErrors() 0256 * @since KF6 0257 */ 0258 [[nodiscard]] bool ignoreRetrievalErrors() const; 0259 0260 /** 0261 * Returns @c true if there is nothing to fetch. 0262 */ 0263 [[nodiscard]] bool isEmpty() const; 0264 0265 private: 0266 /// @cond PRIVATE 0267 QSharedDataPointer<CollectionFetchScopePrivate> d; 0268 /// @endcond 0269 }; 0270 0271 }