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

0001 /*
0002     SPDX-FileCopyrightText: 2006 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 "job.h"
0011 
0012 namespace Akonadi
0013 {
0014 class Collection;
0015 class CollectionCreateJobPrivate;
0016 
0017 /**
0018  * @short Job that creates a new collection in the Akonadi storage.
0019  *
0020  * This job creates a new collection with all the set properties.
0021  * You have to use setParentCollection() to define the collection the
0022  * new collection shall be located in.
0023  *
0024  * @code
0025  *
0026  * // create a new top-level collection
0027  * Akonadi::Collection collection;
0028  * collection.setParentCollection( Collection::root() );
0029  * collection.setName( "Events" );
0030  * collection.setContentMimeTypes( QStringList( "text/calendar" ) );
0031  *
0032  * Akonadi::CollectionCreateJob *job = new Akonadi::CollectionCreateJob( collection );
0033  * connect( job, SIGNAL(result(KJob*)), this, SLOT(createResult(KJob*)) );
0034  *
0035  * @endcode
0036  *
0037  * @author Volker Krause <vkrause@kde.org>
0038  */
0039 class AKONADICORE_EXPORT CollectionCreateJob : public Job
0040 {
0041     Q_OBJECT
0042 public:
0043     /**
0044      * Creates a new collection create job.
0045      *
0046      * @param collection The new collection. @p collection must have a parent collection
0047      * set with a unique identifier. If a resource context is specified in the current session
0048      * (that is you are using it within Akonadi::ResourceBase), the parent collection can be
0049      * identified by its remote identifier as well.
0050      * @param parent The parent object.
0051      */
0052     explicit CollectionCreateJob(const Collection &collection, QObject *parent = nullptr);
0053 
0054     /**
0055      * Destroys the collection create job.
0056      */
0057     ~CollectionCreateJob() override;
0058 
0059     /**
0060      * Returns the created collection if the job was executed successfully.
0061      */
0062     [[nodiscard]] Collection collection() const;
0063 
0064 protected:
0065     void doStart() override;
0066     bool doHandleResponse(qint64 tag, const Protocol::CommandPtr &response) override;
0067 
0068 private:
0069     Q_DECLARE_PRIVATE(CollectionCreateJob)
0070 };
0071 
0072 }