Akonadi Contacts

contactgroupeditor.h
1 /*
2  This file is part of Akonadi Contact.
3 
4  SPDX-FileCopyrightText: 2009 Tobias Koenig <[email protected]>
5 
6  SPDX-License-Identifier: LGPL-2.0-or-later
7 */
8 
9 #pragma once
10 
11 #include "akonadi-contact_export.h"
12 
13 #include <QWidget>
14 
15 namespace KContacts
16 {
17 class ContactGroup;
18 }
19 
20 namespace Akonadi
21 {
22 class Collection;
23 class Item;
24 
25 /**
26  * @short An widget to edit contact groups in Akonadi.
27  *
28  * This widget provides a way to create a new contact group or edit
29  * an existing contact group in Akonadi.
30  *
31  * Example for creating a new contact group:
32  *
33  * @code
34  *
35  * using namespace Akonadi;
36  *
37  * ContactGroupEditor *editor = new ContactGroupEditor( Akonadi::ContactGroupEditor::CreateMode, this );
38  *
39  * ...
40  *
41  * if ( !editor->saveContactGroup() ) {
42  * qCDebug(AKONADICONTACT_LOG) << "Unable to save new contact group to storage";
43  * return;
44  * }
45  *
46  * @endcode
47  *
48  * Example for editing an existing contact group:
49  *
50  * @code
51  *
52  * const Akonadi::Item contactGroup = ...;
53  *
54  * ContactGroupEditor *editor = new ContactGroupEditor( Akonadi::ContactGroupEditor::EditMode, this );
55  * editor->loadContactGroup( contactGroup );
56  *
57  * ...
58  *
59  * if ( !editor->saveContactGroup() ) {
60  * qCDebug(AKONADICONTACT_LOG) << "Unable to save changed contact group to storage";
61  * return;
62  * }
63  *
64  * @endcode
65  *
66  * @author Tobias Koenig <[email protected]>
67  * @since 4.4
68  */
69 class AKONADI_CONTACT_EXPORT ContactGroupEditor : public QWidget
70 {
71  Q_OBJECT
72 
73 public:
74  /**
75  * Describes the mode of the contact group editor.
76  */
77  enum Mode {
78  CreateMode, ///< Creates a new contact group
79  EditMode ///< Edits an existing contact group
80  };
81 
82  /**
83  * Creates a new contact group editor.
84  *
85  * @param mode The mode of the editor.
86  * @param parent The parent widget of the editor.
87  */
88  explicit ContactGroupEditor(Mode mode, QWidget *parent = nullptr);
89 
90  /**
91  * Destroys the contact group editor.
92  */
93  ~ContactGroupEditor() override;
94 
95  /**
96  * Sets a contact @p group that is used as template in create mode.
97  * The fields of the editor will be prefilled with the content of the group.
98  * @param group the group to use as template content
99  */
100  void setContactGroupTemplate(const KContacts::ContactGroup &group);
101 
102  /**
103  * Sets the @p addressbook which shall be used to store new
104  * contact groups.
105  */
106  void setDefaultAddressBook(const Akonadi::Collection &addressbook);
107 
108  void groupNameIsValid(bool isValid);
109 
110 public Q_SLOTS:
111  /**
112  * Loads the contact @p group into the editor.
113  */
114  void loadContactGroup(const Akonadi::Item &group);
115 
116  /**
117  * Saves the contact group from the editor back to the storage.
118  *
119  * @returns @c true if the contact group has been saved successfully, false otherwise.
120  */
121  bool saveContactGroup();
122 
123 Q_SIGNALS:
124  /**
125  * This signal is emitted when the contact @p group has been saved back
126  * to the storage.
127  */
128  void contactGroupStored(const Akonadi::Item &group);
129 
130  /**
131  * This signal is emitted when an error occurred during the save.
132  * @param errorMsg The error message.
133  */
134  void error(const QString &errorMsg);
135 
136 private:
137  //@cond PRIVATE
138  friend class ContactGroupEditorDialog;
139 
140  class Private;
141  Private *const d;
142 
143  Q_DISABLE_COPY(ContactGroupEditor)
144  //@endcond
145 };
146 }
147 
Mode
Describes the mode of the contact group editor.
A dialog for creating or editing a contact group in Akonadi.
An widget to edit contact groups in Akonadi.
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Thu Jun 17 2021 23:09:01 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.