1 /*
2   SPDX-FileCopyrightText: 2009 Tobias Koenig <tokoe@kde.org>
3   SPDX-FileCopyrightText: 2016-2021 Laurent Montel <montel@kde.org>
4 
5   SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7 
8 #pragma once
9 
10 #include "contactlist.h"
11 #include "kaddressbook_importexport_export.h"
12 #include <Akonadi/Item>
13 #include <KContacts/Addressee>
14 
15 #include <QWidget>
16 
17 class QCheckBox;
18 class QItemSelectionModel;
19 class QLabel;
20 class QRadioButton;
21 
22 namespace Akonadi
23 {
24 class Collection;
25 class CollectionComboBox;
26 }
27 
28 namespace KAddressBookImportExport
29 {
30 /**
31  * @short A widget to select a group of contacts.
32  *
33  * @author Tobias Koenig <tokoe@kde.org>
34  */
35 class KADDRESSBOOK_IMPORTEXPORT_EXPORT ContactSelectionWidget : public QWidget
36 {
37     Q_OBJECT
38 
39 public:
40     /**
41      * Creates a new contact selection widget.
42      *
43      * @param selectionModel The model that contains the currently selected contacts.
44      * @param parent The parent widget.
45      */
46     explicit ContactSelectionWidget(QItemSelectionModel *selectionModel, QWidget *parent = nullptr);
47 
48     /**
49      * Sets the @p message text.
50      */
51     void setMessageText(const QString &message);
52 
53     /**
54      * Sets the default addressbook.
55      */
56     void setDefaultAddressBook(const Akonadi::Collection &addressBook);
57 
58     /**
59      * Returns the list of selected contacts.
60      */
61     Q_REQUIRED_RESULT ContactList selectedContacts() const;
62 
63     void setAddGroupContact(bool addGroupContact);
64     Q_REQUIRED_RESULT Akonadi::Item::List selectedItems() const;
65 
66 private:
67     void initGui();
68 
69     Q_REQUIRED_RESULT ContactList collectAllContacts() const;
70     Q_REQUIRED_RESULT ContactList collectSelectedContacts() const;
71     Q_REQUIRED_RESULT ContactList collectAddressBookContacts() const;
72 
73     Q_REQUIRED_RESULT Akonadi::Item::List collectAllItems() const;
74     Q_REQUIRED_RESULT Akonadi::Item::List collectSelectedItems() const;
75     Q_REQUIRED_RESULT Akonadi::Item::List collectAddressBookItems() const;
76 
77     QItemSelectionModel *const mSelectionModel;
78 
79     QLabel *mMessageLabel = nullptr;
80     QRadioButton *mAllContactsButton = nullptr;
81     QRadioButton *mSelectedContactsButton = nullptr;
82     QRadioButton *mAddressBookContactsButton = nullptr;
83     Akonadi::CollectionComboBox *mAddressBookSelection = nullptr;
84     QCheckBox *mAddressBookSelectionRecursive = nullptr;
85     bool mAddContactGroup = false;
86 };
87 }
88