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

KDE's Doxygen guidelines are available online.