File indexing completed on 2024-11-24 04:39:34
0001 /* 0002 This file is part of Akonadi Contact. 0003 0004 SPDX-FileCopyrightText: 2009 Tobias Koenig <tokoe@kde.org> 0005 0006 SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 0009 #pragma once 0010 0011 #include "akonadi-contact-widgets_export.h" 0012 0013 #include <QWidget> 0014 0015 #include <memory> 0016 0017 namespace KContacts 0018 { 0019 class ContactGroup; 0020 } 0021 0022 namespace Akonadi 0023 { 0024 class Collection; 0025 class Item; 0026 class ContactGroupEditorPrivate; 0027 0028 /** 0029 * @short An widget to edit contact groups in Akonadi. 0030 * 0031 * This widget provides a way to create a new contact group or edit 0032 * an existing contact group in Akonadi. 0033 * 0034 * Example for creating a new contact group: 0035 * 0036 * @code 0037 * 0038 * using namespace Akonadi; 0039 * 0040 * ContactGroupEditor *editor = new ContactGroupEditor( Akonadi::ContactGroupEditor::CreateMode, this ); 0041 * 0042 * ... 0043 * 0044 * if ( !editor->saveContactGroup() ) { 0045 * qCDebug(AKONADICONTACT_LOG) << "Unable to save new contact group to storage"; 0046 * return; 0047 * } 0048 * 0049 * @endcode 0050 * 0051 * Example for editing an existing contact group: 0052 * 0053 * @code 0054 * 0055 * const Akonadi::Item contactGroup = ...; 0056 * 0057 * ContactGroupEditor *editor = new ContactGroupEditor( Akonadi::ContactGroupEditor::EditMode, this ); 0058 * editor->loadContactGroup( contactGroup ); 0059 * 0060 * ... 0061 * 0062 * if ( !editor->saveContactGroup() ) { 0063 * qCDebug(AKONADICONTACT_LOG) << "Unable to save changed contact group to storage"; 0064 * return; 0065 * } 0066 * 0067 * @endcode 0068 * 0069 * @author Tobias Koenig <tokoe@kde.org> 0070 * @since 4.4 0071 */ 0072 class AKONADI_CONTACT_WIDGETS_EXPORT ContactGroupEditor : public QWidget 0073 { 0074 Q_OBJECT 0075 0076 public: 0077 /** 0078 * Describes the mode of the contact group editor. 0079 */ 0080 enum Mode { 0081 CreateMode, ///< Creates a new contact group 0082 EditMode ///< Edits an existing contact group 0083 }; 0084 0085 /** 0086 * Creates a new contact group editor. 0087 * 0088 * @param mode The mode of the editor. 0089 * @param parent The parent widget of the editor. 0090 */ 0091 explicit ContactGroupEditor(Mode mode, QWidget *parent = nullptr); 0092 0093 /** 0094 * Destroys the contact group editor. 0095 */ 0096 ~ContactGroupEditor() override; 0097 0098 /** 0099 * Sets a contact @p group that is used as template in create mode. 0100 * The fields of the editor will be prefilled with the content of the group. 0101 * @param group the group to use as template content 0102 */ 0103 void setContactGroupTemplate(const KContacts::ContactGroup &group); 0104 0105 /** 0106 * Sets the @p addressbook which shall be used to store new 0107 * contact groups. 0108 */ 0109 void setDefaultAddressBook(const Akonadi::Collection &addressbook); 0110 0111 void groupNameIsValid(bool isValid); 0112 0113 public Q_SLOTS: 0114 /** 0115 * Loads the contact @p group into the editor. 0116 */ 0117 void loadContactGroup(const Akonadi::Item &group); 0118 0119 /** 0120 * Saves the contact group from the editor back to the storage. 0121 * 0122 * @returns @c true if the contact group has been saved successfully, false otherwise. 0123 */ 0124 bool saveContactGroup(); 0125 0126 Q_SIGNALS: 0127 /** 0128 * This signal is emitted when the contact @p group has been saved back 0129 * to the storage. 0130 */ 0131 void contactGroupStored(const Akonadi::Item &group); 0132 0133 /** 0134 * This signal is emitted when an error occurred during the save. 0135 * @param errorMsg The error message. 0136 */ 0137 void error(const QString &errorMsg); 0138 0139 private: 0140 //@cond PRIVATE 0141 friend class ContactGroupEditorDialog; 0142 0143 std::unique_ptr<ContactGroupEditorPrivate> const d; 0144 0145 Q_DISABLE_COPY(ContactGroupEditor) 0146 //@endcond 0147 }; 0148 }