Akonadi

agentconfigurationbase.h
1/*
2 SPDX-FileCopyrightText: 2018 Daniel Vrátil <dvratil@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#pragma once
8
9#include "agentconfigurationfactorybase.h"
10#include "akonadicore_export.h"
11
12#include <KSharedConfig>
13#include <QObject>
14
15#include <memory>
16
17class KAboutData;
18
19namespace Akonadi
20{
21class AgentConfigurationBasePrivate;
22
23/**
24 * @brief Base class for configuration UI for Akonadi agents
25 *
26 * Each agent that has a graphical configuration should subclass this class
27 * and create its configuration UI there.
28 *
29 * The subclass must reimplement load() and save() virtual methods which
30 * are called automatically. The load() method is called on start to initialize
31 * widgets (thus subclasses don't need to call it themselves) or when user
32 * clicks a "Reset" button. The save() method is called whenever user decides to
33 * save changes.
34 *
35 * Since each Akonadi agent instance has its own configuration file whose
36 * location and name is opaque to the implementation, config() method can be
37 * used to get access to the current configuration object.
38 *
39 * The widget will not run in the same process as the Akonadi agent, thus all
40 * communication with the resource (if needed) should be done over DBus. The
41 * identifier of the instance currently being configured is accessible from the
42 * identifier() method.
43 *
44 * There is no need to signal back to the resource when configuration is changed.
45 * When save() is called and the dialog is destroyed, Akonadi will automatically
46 * call AgentBase::reconfigure() in the respective Akonadi agent instance.
47 *
48 * It is guaranteed that only a single instance of the configuration dialog for
49 * given agent will be opened at the same time.
50 *
51 * Subclasses of ConfigurationBase must be registered as Akonadi plugins using
52 * AKONADI_AGENTCONFIG_FACTORY macro.
53 *
54 * The metadata JSON file then must contain the following values:
55 * @code
56 * {
57 * "X-Akonadi-PluginType": "AgentConfig",
58 * "X-Akonadi-Library": "exampleresourceconfig",
59 * "X-Akonadi-AgentConfig-Type": "akonadi_example_resource"
60 * }
61 * @endcode
62 *
63 * The @p X-Akonadi-Library value must match the name of the plugin binary without
64 * the (optional) "lib" prefix and file extension. The @p X-Akonadi-AgentConfig-Type
65 * value must match the name of the @p X-Akonadi-Identifier value from the agent's
66 * desktop file.
67 *
68 * The plugin binary should be installed into pim<version>/akonadi/config subdirectory in one
69 * of the paths search by QCoreApplication::libraryPaths().
70 */
71
72class AKONADICORE_EXPORT AgentConfigurationBase : public QObject
73{
75public:
76 enum StandardButton {
77 None = 0,
78 Ok = 1,
79 Cancel = 2,
80 Apply = 4,
81 Help = 8,
82 };
83 Q_ENUM(StandardButton)
84 Q_DECLARE_FLAGS(StandardButtons, StandardButton)
85 Q_FLAG(StandardButtons)
86
87 /**
88 * Creates a new AgentConfigurationBase objects.
89 *
90 * The @p parentWidget should be used as a parent widget for the configuration
91 * widgets.
92 *
93 * Subclasses must provide a constructor with this exact signature.
94 */
95 explicit AgentConfigurationBase(const KSharedConfigPtr &config, QWidget *parentWidget, const QVariantList &args);
96
97 ~AgentConfigurationBase() override;
98
99 /**
100 * Reimplement to load settings from the configuration object into widgets.
101 *
102 * @warning Always call the base class implementation at the beginning of
103 * your overridden method!
104 *
105 * @see config(), save()
106 */
107 virtual void load();
108
109 /**
110 * Reimplement to save new settings into the configuration object.
111 *
112 * Return true if the configuration has been successfully saved and should
113 * be applied to the agent, return false otherwise.
114 *
115 * @warning Always remember call the base class implementation at the end
116 * of your overridden method!
117 *
118 * @see config(), load()
119 */
120 virtual bool save() const;
121
122 /**
123 * Returns about data for the currently configured component.
124 *
125 * May return a null pointer.
126 */
127 KAboutData *aboutData() const;
128
129 /**
130 * Reimplement to restore dialog size.
131 */
132 virtual QSize restoreDialogSize() const;
133
134 /**
135 * Reimplement to save dialog size.
136 */
137 virtual void saveDialogSize(const QSize &size);
138
139 virtual StandardButtons standardButtons() const;
140
141 struct ActivitySettings {
142 bool enabled = false;
143 QStringList activities;
144 };
145
146 /**
147 * @brief saveActivitiesSettings
148 * @param activities
149 * save activities settings
150 */
151 void saveActivitiesSettings(const ActivitySettings &activities) const;
152
153 /**
154 * @brief restoreActivitiesSettings
155 * @return activities settings
156 */
157 [[nodiscard]] ActivitySettings restoreActivitiesSettings() const;
158
159protected:
160 QWidget *parentWidget() const;
161
162 /**
163 * Returns KConfig object belonging to the current Akonadi agent instance.
164 */
165 KSharedConfigPtr config() const;
166
167 /**
168 * Returns identifier of the Akonadi agent instance currently being configured.
169 */
170 [[nodiscard]] QString identifier() const;
171
172 /**
173 * When KAboutData is provided the dialog will also contain KHelpMenu with
174 * access to user help etc.
175 */
177
179 void enableOkButton(bool enabled);
180
181private:
182 friend class AgentConfigurationBasePrivate;
183 std::unique_ptr<AgentConfigurationBasePrivate> const d;
184};
185
186} // namespace
187
188Q_DECLARE_OPERATORS_FOR_FLAGS(Akonadi::AgentConfigurationBase::StandardButtons)
AgentConfigurationBase(const KSharedConfigPtr &config, QWidget *parentWidget, const QVariantList &args)
Creates a new AgentConfigurationBase objects.
virtual QSize restoreDialogSize() const
Reimplement to restore dialog size.
ActivitySettings restoreActivitiesSettings() const
restoreActivitiesSettings
virtual void saveDialogSize(const QSize &size)
Reimplement to save dialog size.
QString identifier() const
Returns identifier of the Akonadi agent instance currently being configured.
void setKAboutData(const KAboutData &aboutData)
When KAboutData is provided the dialog will also contain KHelpMenu with access to user help etc.
void saveActivitiesSettings(const ActivitySettings &activities) const
saveActivitiesSettings
KAboutData * aboutData() const
Returns about data for the currently configured component.
virtual void load()
Reimplement to load settings from the configuration object into widgets.
virtual bool save() const
Reimplement to save new settings into the configuration object.
KSharedConfigPtr config() const
Returns KConfig object belonging to the current Akonadi agent instance.
Helper integration between Akonadi and Qt.
QObject(QObject *parent)
Q_ENUM(...)
Q_FLAG(...)
Q_OBJECTQ_OBJECT
Q_SIGNALSQ_SIGNALS
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Mar 28 2025 11:53:20 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.