File indexing completed on 2024-11-17 04:40:41

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 <QDialog>
0014 
0015 #include <memory>
0016 
0017 namespace Akonadi
0018 {
0019 class Item;
0020 class Collection;
0021 class ContactGroupEditor;
0022 class ContactGroupEditorDialogPrivate;
0023 
0024 /**
0025  * @short A dialog for creating or editing a contact group in Akonadi.
0026  *
0027  * This dialog provides a way to create a new contact group or edit
0028  * an existing contact group in Akonadi.
0029  *
0030  * Example for creating a new contact group:
0031  *
0032  * @code
0033  *
0034  * using namespace Akonadi;
0035  *
0036  * ContactGroupEditorDialog *dlg = new ContactGroupEditorDialog( ContactGroupEditorDialog::CreateMode, this );
0037  * connect( dlg, SIGNAL(contactGroupStored(Akonadi::Item)),
0038  *          this, SLOT(contactGroupStored(Akonadi::Item)) );
0039  * dlg->show();
0040  *
0041  * @endcode
0042  *
0043  * Example for editing an existing contact group:
0044  *
0045  * @code
0046  *
0047  * using namespace Akonadi;
0048  *
0049  * const Item contactGroup = ...;
0050  *
0051  * ContactGroupEditorDialog *dlg = new ContactGroupEditorDialog( ContactGroupEditorDialog::EditMode, this );
0052  * connect( dlg, SIGNAL(contactGroupStored(Akonadi::Item)),
0053  *          this, SLOT(contactGroupStored(Akonadi::Item)) );
0054  * dlg->setContactGroup( contactGroup );
0055  * dlg->show();
0056  *
0057  * @endcode
0058  *
0059  * @author Tobias Koenig <tokoe@kde.org>
0060  * @since 4.4
0061  */
0062 class AKONADI_CONTACT_WIDGETS_EXPORT ContactGroupEditorDialog : public QDialog
0063 {
0064     Q_OBJECT
0065 
0066 public:
0067     /**
0068      * Describes the mode of the contact group editor.
0069      */
0070     enum Mode {
0071         CreateMode, ///< Creates a new contact group
0072         EditMode ///< Edits an existing contact group
0073     };
0074 
0075     /**
0076      * Creates a new contact group editor dialog.
0077      *
0078      * @param mode The mode of the dialog.
0079      * @param parent The parent widget of the dialog.
0080      */
0081     explicit ContactGroupEditorDialog(Mode mode, QWidget *parent = nullptr);
0082 
0083     /**
0084      * Destroys the contact group editor dialog.
0085      */
0086     ~ContactGroupEditorDialog() override;
0087 
0088     /**
0089      * Sets the contact @p group to edit when in EditMode.
0090      */
0091     void setContactGroup(const Akonadi::Item &group);
0092 
0093     /**
0094      * Sets the @p addressbook that shall be selected as default
0095      * for storage in create mode.
0096      */
0097     void setDefaultAddressBook(const Akonadi::Collection &addressbook);
0098 
0099     /**
0100      * Returns the ContactGroupEditor that is used by the dialog.
0101      */
0102     [[nodiscard]] ContactGroupEditor *editor() const;
0103 
0104     void reject() override;
0105 Q_SIGNALS:
0106     /**
0107      * This signal is emitted whenever a contact group was updated or stored.
0108      *
0109      * @param group The contact group.
0110      */
0111     void contactGroupStored(const Akonadi::Item &group);
0112 
0113 private:
0114     AKONADI_CONTACT_WIDGETS_NO_EXPORT void slotAccepted();
0115 
0116     //@cond PRIVATE
0117     std::unique_ptr<ContactGroupEditorDialogPrivate> const d;
0118     //@endcond
0119 };
0120 }