File indexing completed on 2025-01-05 04:49:19

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 "vcardexportselectionwidget.h"
0008 
0009 #include <KLocalizedString>
0010 
0011 #include <KConfig>
0012 #include <KConfigGroup>
0013 #include <QCheckBox>
0014 #include <QGridLayout>
0015 #include <QGroupBox>
0016 
0017 VCardExportSelectionWidget::VCardExportSelectionWidget(QWidget *parent)
0018     : QWidget(parent)
0019 {
0020     auto mainLayout = new QVBoxLayout(this);
0021     mainLayout->setContentsMargins({});
0022     auto gbox = new QGroupBox(i18nc("@title:group", "Fields to be exported"), this);
0023     mainLayout->addWidget(gbox);
0024     auto layout = new QGridLayout;
0025     gbox->setLayout(layout);
0026     gbox->setFlat(true);
0027     layout->addWidget(gbox, 0, 0, 1, 2);
0028 
0029     mPrivateBox = new QCheckBox(i18nc("@option:check", "Private fields"), this);
0030     mPrivateBox->setToolTip(i18nc("@info:tooltip", "Export private fields"));
0031     mPrivateBox->setWhatsThis(i18nc("@info:whatsthis",
0032                                     "Check this box if you want to export the contact's "
0033                                     "private fields to the vCard output file."));
0034     layout->addWidget(mPrivateBox, 1, 0);
0035 
0036     mBusinessBox = new QCheckBox(i18nc("@option:check", "Business fields"), this);
0037     mBusinessBox->setToolTip(i18nc("@info:tooltip", "Export business fields"));
0038     mBusinessBox->setWhatsThis(i18nc("@info:whatsthis",
0039                                      "Check this box if you want to export the contact's "
0040                                      "business fields to the vCard output file."));
0041     layout->addWidget(mBusinessBox, 2, 0);
0042 
0043     mOtherBox = new QCheckBox(i18nc("@option:check", "Other fields"), this);
0044     mOtherBox->setToolTip(i18nc("@info:tooltip", "Export other fields"));
0045     mOtherBox->setWhatsThis(i18nc("@info:whatsthis",
0046                                   "Check this box if you want to export the contact's "
0047                                   "other fields to the vCard output file."));
0048     layout->addWidget(mOtherBox, 3, 0);
0049 
0050     mEncryptionKeys = new QCheckBox(i18nc("@option:check", "Encryption keys"), this);
0051     mEncryptionKeys->setToolTip(i18nc("@info:tooltip", "Export encryption keys"));
0052     mEncryptionKeys->setWhatsThis(i18nc("@info:whatsthis",
0053                                         "Check this box if you want to export the contact's "
0054                                         "encryption keys to the vCard output file."));
0055     layout->addWidget(mEncryptionKeys, 1, 1);
0056 
0057     mPictureBox = new QCheckBox(i18nc("@option:check", "Pictures"), this);
0058     mPictureBox->setToolTip(i18nc("@info:tooltip", "Export pictures"));
0059     mPictureBox->setWhatsThis(i18nc("@info:whatsthis",
0060                                     "Check this box if you want to export the contact's "
0061                                     "picture to the vCard output file."));
0062     layout->addWidget(mPictureBox, 2, 1);
0063 
0064     gbox = new QGroupBox(i18nc("@title:group", "Export options"), this);
0065     gbox->setFlat(true);
0066     mainLayout->addWidget(gbox);
0067     auto gbLayout = new QHBoxLayout;
0068     gbox->setLayout(gbLayout);
0069 
0070     mDisplayNameBox = new QCheckBox(i18nc("@option:check", "Display name as full name"), this);
0071     mDisplayNameBox->setToolTip(i18nc("@info:tooltip", "Export display name as full name"));
0072     mDisplayNameBox->setWhatsThis(i18nc("@info:whatsthis",
0073                                         "Check this box if you want to export the contact's display name "
0074                                         "in the vCard's full name field.  This may be required to get the "
0075                                         "name shown correctly in GMail or Android."));
0076     gbLayout->addWidget(mDisplayNameBox);
0077 
0078     readSettings();
0079 }
0080 
0081 VCardExportSelectionWidget::~VCardExportSelectionWidget()
0082 {
0083     writeSettings();
0084 }
0085 
0086 void VCardExportSelectionWidget::readSettings()
0087 {
0088     KConfig config(QStringLiteral("kaddressbookrc"));
0089     const KConfigGroup group(&config, QStringLiteral("XXPortVCard"));
0090 
0091     mPrivateBox->setChecked(group.readEntry("ExportPrivateFields", true));
0092     mBusinessBox->setChecked(group.readEntry("ExportBusinessFields", true));
0093     mOtherBox->setChecked(group.readEntry("ExportOtherFields", true));
0094     mEncryptionKeys->setChecked(group.readEntry("ExportEncryptionKeys", true));
0095     mPictureBox->setChecked(group.readEntry("ExportPictureFields", true));
0096     mDisplayNameBox->setChecked(group.readEntry("ExportDisplayName", false));
0097 }
0098 
0099 void VCardExportSelectionWidget::writeSettings()
0100 {
0101     KConfig config(QStringLiteral("kaddressbookrc"));
0102     KConfigGroup group(&config, QStringLiteral("XXPortVCard"));
0103 
0104     group.writeEntry("ExportPrivateFields", mPrivateBox->isChecked());
0105     group.writeEntry("ExportBusinessFields", mBusinessBox->isChecked());
0106     group.writeEntry("ExportOtherFields", mOtherBox->isChecked());
0107     group.writeEntry("ExportEncryptionKeys", mEncryptionKeys->isChecked());
0108     group.writeEntry("ExportPictureFields", mPictureBox->isChecked());
0109     group.writeEntry("ExportDisplayName", mDisplayNameBox->isChecked());
0110 }
0111 
0112 VCardExportSelectionWidget::ExportFields VCardExportSelectionWidget::exportType() const
0113 {
0114     ExportFields type = None;
0115     if (mPrivateBox->isChecked()) {
0116         type |= Private;
0117     }
0118     if (mBusinessBox->isChecked()) {
0119         type |= Business;
0120     }
0121     if (mOtherBox->isChecked()) {
0122         type |= Other;
0123     }
0124     if (mEncryptionKeys->isChecked()) {
0125         type |= Encryption;
0126     }
0127     if (mPictureBox->isChecked()) {
0128         type |= Picture;
0129     }
0130     if (mDisplayNameBox->isChecked()) {
0131         type |= DiplayName;
0132     }
0133     return type;
0134 }
0135 
0136 #include "moc_vcardexportselectionwidget.cpp"