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

0001 /*
0002     SPDX-FileCopyrightText: 2008 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "agenttype.h"
0010 #include "akonadicore_export.h"
0011 
0012 #include <KJob>
0013 
0014 #include <memory>
0015 
0016 namespace Akonadi
0017 {
0018 class AgentInstance;
0019 class AgentInstanceCreateJobPrivate;
0020 
0021 /**
0022  * @short Job for creating new agent instances.
0023  *
0024  * This class encapsulates the procedure of creating a new agent instance
0025  * and optionally configuring it immediately.
0026  *
0027  * @code
0028  *
0029  * MyClass::MyClass( QWidget *parent )
0030  *   : QWidget( parent )
0031  * {
0032  *   // Get agent type object
0033  *   Akonadi::AgentType type = Akonadi::AgentManager::self()->type( "akonadi_vcard_resource" );
0034  *
0035  *   Akonadi::AgentInstanceCreateJob *job = new Akonadi::AgentInstanceCreateJob( type );
0036  *   connect( job, SIGNAL(result(KJob*)),
0037  *            this, SLOT(slotCreated(KJob*)) );
0038  *
0039  *   // use this widget as parent for the config dialog
0040  *   job->configure( this );
0041  *
0042  *   job->start();
0043  * }
0044  *
0045  * ...
0046  *
0047  * void MyClass::slotCreated( KJob *job )
0048  * {
0049  *   Akonadi::AgentInstanceCreateJob *createJob = static_cast<Akonadi::AgentInstanceCreateJob*>( job );
0050  *
0051  *   qDebug() << "Created agent instance:" << createJob->instance().identifier();
0052  * }
0053  *
0054  * @endcode
0055  *
0056  * @author Volker Krause <vkrause@kde.org>
0057  */
0058 class AKONADICORE_EXPORT AgentInstanceCreateJob : public KJob
0059 {
0060     Q_OBJECT
0061 
0062 public:
0063     /**
0064      * Creates a new agent instance create job.
0065      *
0066      * @param type The type of the agent to create.
0067      * @param parent The parent object.
0068      */
0069     explicit AgentInstanceCreateJob(const AgentType &type, QObject *parent = nullptr);
0070 
0071     /**
0072      * Creates a new agent instance create job.
0073      *
0074      * @param typeId The identifier of type of the agent to create.
0075      * @param parent The parent object.
0076      * @since 4.5
0077      */
0078     explicit AgentInstanceCreateJob(const QString &typeId, QObject *parent = nullptr);
0079 
0080     /**
0081      * Destroys the agent instance create job.
0082      */
0083     ~AgentInstanceCreateJob() override;
0084 
0085     /**
0086      * Setup the job to show agent configuration dialog once the agent instance
0087      * has been successfully started.
0088      * @param parent The parent window for the configuration dialog.
0089      */
0090     void configure(QWidget *parent = nullptr);
0091 
0092     /**
0093      * Returns the AgentInstance object of the newly created agent instance.
0094      */
0095     [[nodiscard]] AgentInstance instance() const;
0096 
0097     /**
0098      * Starts the instance creation.
0099      */
0100     void start() override;
0101 
0102 private:
0103     /// @cond PRIVATE
0104     friend class Akonadi::AgentInstanceCreateJobPrivate;
0105     std::unique_ptr<AgentInstanceCreateJobPrivate> const d;
0106     /// @endcond
0107 };
0108 
0109 }