Incidenceeditor

editoritemmanager.h
1/*
2 SPDX-FileCopyrightText: 2010 Bertjan Broeksema <broeksema@kde.org>
3 SPDX-FileCopyrightText: 2010 Klaralvdalens Datakonsult AB, a KDAB Group company <info@kdab.net>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#pragma once
9
10#include <Akonadi/Collection>
11#include <Akonadi/IncidenceChanger>
12#include <QObject>
13
14#include <memory>
15
16namespace Akonadi
17{
18class Item;
19}
20
21class KJob;
22
23namespace IncidenceEditorNG
24{
25class ItemEditorUi;
26class ItemEditorPrivate;
27
28/**
29 * Helper class for creating dialogs that let the user create and edit the payload
30 * of Akonadi items (e.g. events, contacts, etc). This class supports editing of
31 * one item at a time and handles all Akonadi specific logic like Item creation,
32 * Item modifying and monitoring of changes to the item during editing.
33 */
34// template <typename PayloadT>
36{
38public:
39 enum ItipPrivacy { ItipPrivacyPlain = 0, ItipPrivacySign = 1, ItipPrivacyEncrypt = 2 };
40 Q_DECLARE_FLAGS(ItipPrivacyFlags, ItipPrivacy)
41
42 /**
43 * Creates an ItemEditor for a new Item.
44 * Receives an option IncidenceChanger, so you can share the undo/redo stack with your
45 * application.
46 */
47 explicit EditorItemManager(ItemEditorUi *ui, Akonadi::IncidenceChanger *changer = nullptr);
48
49 /**
50 * Destructs the ItemEditor. Unsaved changes will get lost at this point.
51 */
53
54 enum ItemState {
55 AfterSave, /**< Returns the last saved item */
56 BeforeSave /**< Returns an item with the original payload before the last save call */
57 };
58
59 /**
60 * Returns the last saved item with payload or an invalid item when save is
61 * not called yet.
62 */
63 [[nodiscard]] Akonadi::Item item(ItemState state = AfterSave) const;
64
65 /**
66 * Loads the @param item into the editor. The item passed must be
67 * a valid item.
68 */
69 void load(const Akonadi::Item &item);
70
71 /**
72 * Saves the new or modified item. This method does nothing when the
73 * ui is not dirty.
74 */
75 void save(ItipPrivacyFlags itipPrivacy = ItipPrivacyPlain);
76
78 Create, /**< A new item was created */
79 Modify, /**< An existing item was modified */
80 None, /**< Nothing happened. */
81 Move, /**< An existing item was moved to another collection */
82 MoveAndModify /**< An existing item was moved to another collection and modified */
83 };
84
85 void setIsCounterProposal(bool isCounterProposal);
86
88 void itemSaveFinished(IncidenceEditorNG::EditorItemManager::SaveAction action);
89
90 void itemSaveFailed(IncidenceEditorNG::EditorItemManager::SaveAction action, const QString &message);
91
92 void revertFinished();
93 void revertFailed(const QString &message);
94
95private:
96 std::unique_ptr<ItemEditorPrivate> const d_ptr;
97 Q_DECLARE_PRIVATE(ItemEditor)
98 Q_DISABLE_COPY(EditorItemManager)
99};
100
101class ItemEditorUi
102{
103public:
104 enum RejectReason {
105 ItemFetchFailed, ///> Either the fetchjob failed or no items where returned
106 ItemHasInvalidPayload, ///> The fetched item has an invalid payload
107 ItemMoveFailed ///> Item move failed
108 };
109
110 virtual ~ItemEditorUi();
111
112 /**
113 * Returns whether or not the identifier set contains payload identifiers that
114 * are displayed/editable in the Gui.
115 */
116 virtual bool containsPayloadIdentifiers(const QSet<QByteArray> &partIdentifiers) const = 0;
117
118 /**
119 * Returns whether or not @param item has a payload type that is supported by
120 * the gui.
121 */
122 virtual bool hasSupportedPayload(const Akonadi::Item &item) const = 0;
123
124 /**
125 * Returns whether or not the values in the ui differ from the original (i.e.
126 * either an empty or a loaded item). This method <em>only</em> involves
127 * payload fields. I.e. if only the collection in which the item should be
128 * stored has changed, this method should return false.
129 */
130 virtual bool isDirty() const = 0;
131
132 /**
133 * Returns whether or not the values in the ui are valid. This method can also
134 * be used to update the ui if necessary. The default implementation returns
135 * true, so if the ui doesn't need validation there is no need to reimplement
136 * this method.
137 */
138 virtual bool isValid() const;
139
140 /**
141 * Fills the ui with the values of the payload of @param item. The item is
142 * guaranteed to have a payload.
143 */
144 virtual void load(const Akonadi::Item &item) = 0;
145
146 /**
147 * Stores the values of the ui into the payload of @param item and returns the
148 * item with an updated payload. The returned item must have a valid mimetype
149 * too.
150 */
151 virtual Akonadi::Item save(const Akonadi::Item &item) = 0;
152
153 /**
154 * Returns the currently selected collection in which the item will be stored.
155 */
156 virtual Akonadi::Collection selectedCollection() const = 0;
157
158 /**
159 * This function is called if for some reason the creation or editing of the
160 * item cannot be continued. The implementing class must abort editing at
161 * this point.
162 */
163 virtual void reject(RejectReason reason, const QString &errorMessage = QString()) = 0;
164};
165}
166
Helper class for creating dialogs that let the user create and edit the payload of Akonadi items (e....
~EditorItemManager() override
Destructs the ItemEditor.
void load(const Akonadi::Item &item)
Loads the.
void save(ItipPrivacyFlags itipPrivacy=ItipPrivacyPlain)
Saves the new or modified item.
EditorItemManager(ItemEditorUi *ui, Akonadi::IncidenceChanger *changer=nullptr)
Creates an ItemEditor for a new Item.
@ Modify
An existing item was modified.
@ MoveAndModify
An existing item was moved to another collection and modified.
@ Move
An existing item was moved to another collection.
Akonadi::Item item(ItemState state=AfterSave) const
Returns the last saved item with payload or an invalid item when save is not called yet.
@ AfterSave
Returns the last saved item.
@ BeforeSave
Returns an item with the original payload before the last save call.
Q_OBJECTQ_OBJECT
Q_SIGNALSQ_SIGNALS
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jul 26 2024 11:52:44 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.