File indexing completed on 2024-12-22 04:55:32

0001 /*
0002   SPDX-FileCopyrightText: 2009 Tobias Koenig <tokoe@kde.org>
0003   SPDX-FileCopyrightText: 2015-2024 Laurent Montel <montel@kde.org>
0004 
0005   SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #include "contactselectiondialog.h"
0009 #include "contactselectionwidget.h"
0010 
0011 #include <KLocalizedString>
0012 #include <QDialogButtonBox>
0013 #include <QPushButton>
0014 #include <QVBoxLayout>
0015 
0016 using namespace KAddressBookImportExport;
0017 
0018 ContactSelectionDialog::ContactSelectionDialog(QItemSelectionModel *selectionModel, bool allowToSelectTypeToExport, QWidget *parent)
0019     : QDialog(parent)
0020     , mSelectionWidget(new ContactSelectionWidget(selectionModel, this))
0021 {
0022     setWindowTitle(i18nc("@title:window", "Select Contacts"));
0023     auto mainLayout = new QVBoxLayout(this);
0024 
0025     if (allowToSelectTypeToExport) {
0026         mainLayout->addWidget(mSelectionWidget);
0027         mVCardExport = new ExportSelectionWidget(this);
0028         mainLayout->addWidget(mVCardExport);
0029     } else {
0030         mainLayout->addWidget(mSelectionWidget);
0031     }
0032 
0033     auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
0034     QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
0035     okButton->setDefault(true);
0036     okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
0037     connect(buttonBox, &QDialogButtonBox::accepted, this, &ContactSelectionDialog::accept);
0038     connect(buttonBox, &QDialogButtonBox::rejected, this, &ContactSelectionDialog::reject);
0039     mainLayout->addWidget(buttonBox);
0040 }
0041 
0042 void ContactSelectionDialog::setMessageText(const QString &message)
0043 {
0044     mSelectionWidget->setMessageText(message);
0045 }
0046 
0047 void ContactSelectionDialog::setDefaultAddressBook(const Akonadi::Collection &addressBook)
0048 {
0049     mSelectionWidget->setDefaultAddressBook(addressBook);
0050 }
0051 
0052 Akonadi::Item::List ContactSelectionDialog::selectedItems() const
0053 {
0054     return mSelectionWidget->selectedItems();
0055 }
0056 
0057 ContactList ContactSelectionDialog::selectedContacts() const
0058 {
0059     return mSelectionWidget->selectedContacts();
0060 }
0061 
0062 ExportSelectionWidget::ExportFields ContactSelectionDialog::exportType() const
0063 {
0064     if (mVCardExport) {
0065         return mVCardExport->exportType();
0066     } else {
0067         return ExportSelectionWidget::None;
0068     }
0069 }
0070 
0071 void ContactSelectionDialog::setAddGroupContact(bool addGroupContact)
0072 {
0073     mSelectionWidget->setAddGroupContact(addGroupContact);
0074 }
0075 
0076 #include "moc_contactselectiondialog.cpp"