File indexing completed on 2024-11-24 04:43:05
0001 /* 0002 SPDX-FileCopyrightText: 2015-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "mergecontactselectinformationwidget.h" 0008 #include "widgets/mergecontactselectlistwidget.h" 0009 0010 #include <QVBoxLayout> 0011 0012 using namespace KABMergeContacts; 0013 MergeContactSelectInformationWidget::MergeContactSelectInformationWidget(QWidget *parent) 0014 : QWidget(parent) 0015 { 0016 auto mainLayout = new QVBoxLayout(this); 0017 mainLayout->setContentsMargins({}); 0018 } 0019 0020 MergeContactSelectInformationWidget::~MergeContactSelectInformationWidget() = default; 0021 0022 void MergeContactSelectInformationWidget::setContacts(MergeContacts::ConflictInformations conflictTypes, const Akonadi::Item::List &listItem) 0023 { 0024 for (const Akonadi::Item &item : listItem) { 0025 if (item.hasPayload<KContacts::Addressee>()) { 0026 const auto address = item.payload<KContacts::Addressee>(); 0027 mAddressList.append(address); 0028 } 0029 } 0030 if (conflictTypes & MergeContacts::Birthday) { 0031 addInformationWidget(MergeContacts::Birthday); 0032 } 0033 if (conflictTypes & MergeContacts::Geo) { 0034 addInformationWidget(MergeContacts::Geo); 0035 } 0036 if (conflictTypes & MergeContacts::Photo) { 0037 addInformationWidget(MergeContacts::Photo); 0038 } 0039 if (conflictTypes & MergeContacts::Logo) { 0040 addInformationWidget(MergeContacts::Logo); 0041 } 0042 if (conflictTypes & MergeContacts::Anniversary) { 0043 addInformationWidget(MergeContacts::Anniversary); 0044 } 0045 if (conflictTypes & MergeContacts::Name) { 0046 addInformationWidget(MergeContacts::Name); 0047 } 0048 if (conflictTypes & MergeContacts::NickName) { 0049 addInformationWidget(MergeContacts::NickName); 0050 } 0051 if (conflictTypes & MergeContacts::Blog) { 0052 addInformationWidget(MergeContacts::Blog); 0053 } 0054 if (conflictTypes & MergeContacts::HomePage) { 0055 addInformationWidget(MergeContacts::HomePage); 0056 } 0057 if (conflictTypes & MergeContacts::Organization) { 0058 addInformationWidget(MergeContacts::Organization); 0059 } 0060 if (conflictTypes & MergeContacts::Profession) { 0061 addInformationWidget(MergeContacts::Profession); 0062 } 0063 if (conflictTypes & MergeContacts::Title) { 0064 addInformationWidget(MergeContacts::Title); 0065 } 0066 if (conflictTypes & MergeContacts::Departement) { 0067 addInformationWidget(MergeContacts::Departement); 0068 } 0069 if (conflictTypes & MergeContacts::Office) { 0070 addInformationWidget(MergeContacts::Office); 0071 } 0072 if (conflictTypes & MergeContacts::ManagerName) { 0073 addInformationWidget(MergeContacts::ManagerName); 0074 } 0075 if (conflictTypes & MergeContacts::Assistant) { 0076 addInformationWidget(MergeContacts::Assistant); 0077 } 0078 if (conflictTypes & MergeContacts::FreeBusy) { 0079 addInformationWidget(MergeContacts::FreeBusy); 0080 } 0081 if (conflictTypes & MergeContacts::FamilyName) { 0082 addInformationWidget(MergeContacts::FamilyName); 0083 } 0084 if (conflictTypes & MergeContacts::PartnerName) { 0085 addInformationWidget(MergeContacts::PartnerName); 0086 } 0087 if (conflictTypes & MergeContacts::Keys) { 0088 addInformationWidget(MergeContacts::Keys); 0089 } 0090 } 0091 0092 void MergeContactSelectInformationWidget::addInformationWidget(MergeContacts::ConflictInformation conflictType) 0093 { 0094 auto widget = new MergeContactSelectListWidget; 0095 widget->setContacts(conflictType, mAddressList); 0096 layout()->addWidget(widget); 0097 mListMergeSelectInformation.append(widget); 0098 } 0099 0100 bool MergeContactSelectInformationWidget::verifySelectedInfo() const 0101 { 0102 bool result = true; 0103 for (MergeContactSelectListWidget *listWidget : std::as_const(mListMergeSelectInformation)) { 0104 result = listWidget->verifySelectedInfo(); 0105 if (!result) { 0106 break; 0107 } 0108 } 0109 return result; 0110 } 0111 0112 void MergeContactSelectInformationWidget::createContact(KContacts::Addressee &addr) 0113 { 0114 for (MergeContactSelectListWidget *listWidget : std::as_const(mListMergeSelectInformation)) { 0115 const int selectedContactIndex = listWidget->selectedContact(); 0116 const MergeContacts::ConflictInformation conflictType = listWidget->conflictType(); 0117 if (selectedContactIndex != -1) { 0118 switch (conflictType) { 0119 case MergeContacts::None: 0120 break; 0121 case MergeContacts::Birthday: 0122 addr.setBirthday(mAddressList.at(selectedContactIndex).birthday()); 0123 break; 0124 case MergeContacts::Geo: 0125 addr.setGeo(mAddressList.at(selectedContactIndex).geo()); 0126 break; 0127 case MergeContacts::Photo: 0128 addr.setPhoto(mAddressList.at(selectedContactIndex).photo()); 0129 break; 0130 case MergeContacts::Logo: 0131 addr.setLogo(mAddressList.at(selectedContactIndex).logo()); 0132 break; 0133 case MergeContacts::Anniversary: 0134 addr.setBirthday(mAddressList.at(selectedContactIndex).birthday()); 0135 break; 0136 case MergeContacts::Name: 0137 addr.setName(mAddressList.at(selectedContactIndex).name()); 0138 break; 0139 case MergeContacts::NickName: 0140 addr.setNickName(mAddressList.at(selectedContactIndex).nickName()); 0141 break; 0142 case MergeContacts::Blog: { 0143 const QString newBlog = mAddressList.at(selectedContactIndex).custom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("BlogFeed")); 0144 addr.insertCustom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("BlogFeed"), newBlog); 0145 break; 0146 } 0147 case MergeContacts::HomePage: 0148 addr.setUrl(mAddressList.at(selectedContactIndex).url()); 0149 break; 0150 case MergeContacts::Organization: 0151 addr.setOrganization(mAddressList.at(selectedContactIndex).organization()); 0152 break; 0153 case MergeContacts::Profession: { 0154 const QString newValue = mAddressList.at(selectedContactIndex).custom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("X-Profession")); 0155 addr.insertCustom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("X-Profession"), newValue); 0156 break; 0157 } 0158 case MergeContacts::Title: 0159 addr.setTitle(mAddressList.at(selectedContactIndex).title()); 0160 break; 0161 case MergeContacts::Departement: 0162 addr.setDepartment(mAddressList.at(selectedContactIndex).department()); 0163 break; 0164 case MergeContacts::Office: { 0165 const QString newValue = mAddressList.at(selectedContactIndex).custom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("X-Office")); 0166 addr.insertCustom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("X-Office"), newValue); 0167 break; 0168 } 0169 case MergeContacts::ManagerName: { 0170 const QString newValue = mAddressList.at(selectedContactIndex).custom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("X-ManagersName")); 0171 addr.insertCustom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("X-ManagersName"), newValue); 0172 break; 0173 } 0174 case MergeContacts::Assistant: { 0175 const QString newValue = mAddressList.at(selectedContactIndex).custom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("X-AssistantsName")); 0176 addr.insertCustom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("X-AssistantsName"), newValue); 0177 break; 0178 } 0179 case MergeContacts::FreeBusy: 0180 // TODO 0181 break; 0182 case MergeContacts::FamilyName: 0183 addr.setFamilyName(mAddressList.at(selectedContactIndex).familyName()); 0184 break; 0185 case MergeContacts::PartnerName: { 0186 const QString newValue = mAddressList.at(selectedContactIndex).custom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("X-SpousesName")); 0187 addr.insertCustom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("X-SpousesName"), newValue); 0188 break; 0189 } 0190 case MergeContacts::Keys: 0191 addr.setKeys(mAddressList.at(selectedContactIndex).keys()); 0192 break; 0193 } 0194 } 0195 } 0196 } 0197 0198 #include "moc_mergecontactselectinformationwidget.cpp"