Akonadi

agentinstancecreatejob.h
1/*
2 SPDX-FileCopyrightText: 2008 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#pragma once
8
9#include "agenttype.h"
10#include "akonadicore_export.h"
11
12#include <KJob>
13
14#include <memory>
15
16namespace Akonadi
17{
18class AgentInstance;
19class AgentInstanceCreateJobPrivate;
20
21/**
22 * @short Job for creating new agent instances.
23 *
24 * This class encapsulates the procedure of creating a new agent instance
25 * and optionally configuring it immediately.
26 *
27 * Example:
28 *
29 * @code
30 * using namespace Qt::StringLiterals;
31 *
32 * MyClass::MyClass(QWidget *parent)
33 * : QWidget(parent)
34 * {
35 * // Get agent type object
36 * Akonadi::AgentType type = Akonadi::AgentManager::self()->type(u"akonadi_vcard_resource"_s);
37 *
38 * auto job = new Akonadi::AgentInstanceCreateJob(type);
39 *
40 * // Open configuration dialog once created
41 * connect(job, &Akonadi::AgentInstanceCreateJob::result, this, [this, job](KJob *) {
42 * if (job->error()) {
43 * return;
44 * }
45 * auto configureDialog = new Akonadi::AgentConfigurationDialog(job->instance(), this);
46 * configureDialog->setAttribute(Qt::WA_DeleteOnClose);
47 * connect(configureDialog, &QDialog::rejected, this, [instance = job->instance()] {
48 * Akonadi::AgentManager::self()->removeInstance(instance);
49 * });
50 * configureDialog->show();
51 * });
52 *
53 * job->start();
54 * }
55 *
56 * ...
57 *
58 * void MyClass::slotCreated(KJob *job)
59 * {
60 * auto createJob = static_cast<Akonadi::AgentInstanceCreateJob*>(job);
61 *
62 * qDebug() << "Created agent instance:" << createJob->instance().identifier();
63 * }
64 * @endcode
65 *
66 * @note This is a KJob not an Akonadi::Job, so it won't auto-start!
67 *
68 * @author Volker Krause <vkrause@kde.org>
69 */
70class AKONADICORE_EXPORT AgentInstanceCreateJob : public KJob
71{
73
74public:
75 /**
76 * Creates a new agent instance create job.
77 *
78 * @param type The type of the agent to create.
79 * @param parent The parent object.
80 */
81 explicit AgentInstanceCreateJob(const AgentType &type, QObject *parent = nullptr);
82
83 /**
84 * Creates a new agent instance create job.
85 *
86 * @param typeId The identifier of type of the agent to create.
87 * @param parent The parent object.
88 * @since 4.5
89 */
90 explicit AgentInstanceCreateJob(const QString &typeId, QObject *parent = nullptr);
91
92 /**
93 * Destroys the agent instance create job.
94 */
96
97 /**
98 * Returns the AgentInstance object of the newly created agent instance.
99 */
100 [[nodiscard]] AgentInstance instance() const;
101
102 /**
103 * Starts the instance creation.
104 */
105 void start() override;
106
107private:
108 /// @cond PRIVATE
109 friend class Akonadi::AgentInstanceCreateJobPrivate;
110 std::unique_ptr<AgentInstanceCreateJobPrivate> const d;
111 /// @endcond
112};
113
114}
~AgentInstanceCreateJob() override
Destroys the agent instance create job.
AgentInstanceCreateJob(const AgentType &type, QObject *parent=nullptr)
Creates a new agent instance create job.
AgentInstance instance() const
Returns the AgentInstance object of the newly created agent instance.
A representation of an agent instance.
A representation of an agent type.
KJob(QObject *parent=nullptr)
Q_SCRIPTABLE Q_NOREPLY void start()
Helper integration between Akonadi and Qt.
QObject(QObject *parent)
Q_OBJECTQ_OBJECT
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Mar 28 2025 11:53:21 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.