File indexing completed on 2024-11-24 04:39:36

0001 /*
0002    SPDX-FileCopyrightText: 2012-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 #include "selectcomponentpage.h"
0007 #include "ui_selectcomponentpage.h"
0008 
0009 SelectComponentPage::SelectComponentPage(QWidget *parent)
0010     : QWidget(parent)
0011     , ui(new Ui::SelectComponentPage)
0012 {
0013     ui->setupUi(this);
0014     connect(ui->everything, &QCheckBox::clicked, this, &SelectComponentPage::slotEverythingClicked);
0015     connect(ui->addressbooks, &QCheckBox::clicked, this, &SelectComponentPage::slotComponentClicked);
0016     connect(ui->filters, &QCheckBox::clicked, this, &SelectComponentPage::slotComponentClicked);
0017     connect(ui->mails, &QCheckBox::clicked, this, &SelectComponentPage::slotComponentClicked);
0018     connect(ui->settings, &QCheckBox::clicked, this, &SelectComponentPage::slotComponentClicked);
0019     connect(ui->calendars, &QCheckBox::clicked, this, &SelectComponentPage::slotComponentClicked);
0020 }
0021 
0022 SelectComponentPage::~SelectComponentPage()
0023 {
0024     delete ui;
0025 }
0026 
0027 void SelectComponentPage::slotComponentClicked()
0028 {
0029     const bool componentSelected = (ui->addressbooks->isChecked() || ui->filters->isChecked() || ui->mails->isChecked() || ui->settings->isChecked()
0030                                     || ui->calendars->isChecked() || ui->everything->isChecked());
0031     Q_EMIT atLeastOneComponentSelected(componentSelected);
0032 }
0033 
0034 void SelectComponentPage::slotEverythingClicked(bool clicked)
0035 {
0036     ui->addressbooks->setEnabled(!clicked && (mOptions & LibImportWizard::AbstractImporter::AddressBooks));
0037     ui->filters->setEnabled(!clicked && (mOptions & LibImportWizard::AbstractImporter::Filters));
0038     ui->mails->setEnabled(!clicked && (mOptions & LibImportWizard::AbstractImporter::Mails));
0039     ui->settings->setEnabled(!clicked && (mOptions & LibImportWizard::AbstractImporter::Settings));
0040     ui->calendars->setEnabled(!clicked && (mOptions & LibImportWizard::AbstractImporter::Calendars));
0041     slotComponentClicked();
0042 }
0043 
0044 void SelectComponentPage::setEnabledComponent(LibImportWizard::AbstractImporter::TypeSupportedOptions options)
0045 {
0046     mOptions = options;
0047     slotEverythingClicked(ui->everything->isChecked());
0048 }
0049 
0050 LibImportWizard::AbstractImporter::TypeSupportedOptions SelectComponentPage::selectedComponents() const
0051 {
0052     if (ui->everything->isChecked()) {
0053         return mOptions;
0054     } else {
0055         LibImportWizard::AbstractImporter::TypeSupportedOptions newOptions;
0056         if (ui->addressbooks->isChecked()) {
0057             newOptions |= LibImportWizard::AbstractImporter::AddressBooks;
0058         }
0059         if (ui->filters->isChecked()) {
0060             newOptions |= LibImportWizard::AbstractImporter::Filters;
0061         }
0062         if (ui->mails->isChecked()) {
0063             newOptions |= LibImportWizard::AbstractImporter::Mails;
0064         }
0065         if (ui->settings->isChecked()) {
0066             newOptions |= LibImportWizard::AbstractImporter::Settings;
0067         }
0068         if (ui->calendars->isChecked()) {
0069             newOptions |= LibImportWizard::AbstractImporter::Calendars;
0070         }
0071 
0072         return newOptions;
0073     }
0074 }
0075 
0076 #include "moc_selectcomponentpage.cpp"