File indexing completed on 2024-11-24 04:43:05

0001 /*
0002    SPDX-FileCopyrightText: 2014-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "mergecontactshowresulttabwidget.h"
0008 #include "widgets/mergecontactinfowidget.h"
0009 #include <KContacts/Addressee>
0010 
0011 #include "kaddressbookmergelibprivate_debug.h"
0012 #include <QTabBar>
0013 
0014 using namespace KABMergeContacts;
0015 
0016 MergeContactShowResultTabWidget::MergeContactShowResultTabWidget(QWidget *parent)
0017     : QTabWidget(parent)
0018 {
0019     updateTabWidget();
0020 }
0021 
0022 MergeContactShowResultTabWidget::~MergeContactShowResultTabWidget() = default;
0023 
0024 void MergeContactShowResultTabWidget::updateTabWidget()
0025 {
0026     tabBar()->setVisible(count() > 1);
0027 }
0028 
0029 bool MergeContactShowResultTabWidget::tabBarVisible() const
0030 {
0031     return tabBar()->isVisible();
0032 }
0033 
0034 void MergeContactShowResultTabWidget::showMergedContacts(const Akonadi::Item::List &lstItem)
0035 {
0036     clear();
0037     for (const Akonadi::Item &item : lstItem) {
0038         addMergedContact(item, false);
0039     }
0040     updateTabWidget();
0041 }
0042 
0043 void MergeContactShowResultTabWidget::addMergedContact(const Akonadi::Item &item, bool updateTab)
0044 {
0045     if (item.hasPayload<KContacts::Addressee>()) {
0046         const auto address = item.payload<KContacts::Addressee>();
0047         auto infoWidget = new MergeContactInfoWidget;
0048         infoWidget->setContact(item);
0049         addTab(infoWidget, address.name());
0050         if (updateTab) {
0051             updateTabWidget();
0052         }
0053     } else {
0054         qCDebug(KADDRESSBOOKMERGELIBPRIVATE_LOG) << " don't have address";
0055     }
0056 }
0057 
0058 #include "moc_mergecontactshowresulttabwidget.cpp"