File indexing completed on 2024-06-16 04:50:12

0001 /*
0002     SPDX-FileCopyrightText: 2007 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 "collection.h"
0011 #include "job.h"
0012 
0013 namespace Akonadi
0014 {
0015 class CollectionPathResolverPrivate;
0016 
0017 /**
0018  * @internal
0019  *
0020  * Converts between collection id and collection path.
0021  *
0022  * While it is generally recommended to use collection ids, it can
0023  * be necessary in some cases (eg. a command line client) to use the
0024  * collection path instead. Use this class to get a collection id
0025  * from a collection path.
0026  *
0027  * @author Volker Krause <vkrause@kde.org>
0028  */
0029 class AKONADICORE_EXPORT CollectionPathResolver : public Job
0030 {
0031     Q_OBJECT
0032 
0033 public:
0034     /**
0035      * Creates a new collection path resolver to convert a path into a id.
0036      *
0037      * Equivalent to calling CollectionPathResolver(path, Collection:root(), parent)
0038      *
0039      * @param path The collection path.
0040      * @param parent The parent object.
0041      */
0042     explicit CollectionPathResolver(const QString &path, QObject *parent = nullptr);
0043 
0044     /**
0045      * Create a new collection path resolver to convert a path into an id.
0046      *
0047      * The @p path is resolved relatively to @p parentCollection. This can be
0048      * useful for resource, which now the root collection.
0049      *
0050      * @param path The collection path.
0051      * @param parentCollection Collection relatively to which the path will be resolved.
0052      * @param parent The parent object.
0053      *
0054      * @since 4.14
0055      */
0056     explicit CollectionPathResolver(const QString &path, const Collection &parentCollection, QObject *parent = nullptr);
0057 
0058     /**
0059      * Creates a new collection path resolver to determine the path of
0060      * the given collection.
0061      *
0062      * @param collection The collection.
0063      * @param parent The parent object.
0064      */
0065     explicit CollectionPathResolver(const Collection &collection, QObject *parent = nullptr);
0066 
0067     /**
0068      * Destroys the collection path resolver.
0069      */
0070     ~CollectionPathResolver() override;
0071 
0072     /**
0073      * Returns the collection id. Only valid after the job succeeded.
0074      */
0075     [[nodiscard]] Collection::Id collection() const;
0076 
0077     /**
0078      * Returns the collection path. Only valid after the job succeeded.
0079      */
0080     [[nodiscard]] QString path() const;
0081 
0082     /**
0083      * Returns the path delimiter for collections.
0084      */
0085     [[nodiscard]] static QString pathDelimiter();
0086 
0087 protected:
0088     void doStart() override;
0089 
0090 private:
0091     Q_DECLARE_PRIVATE(CollectionPathResolver)
0092 };
0093 
0094 }