1 /*
2 SPDX-FileCopyrightText: 2015-2021 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7 #include "vcardexportselectionwidget.h"
8
9 #include <KLocalizedString>
10
11 #include <KConfig>
12 #include <KConfigGroup>
13 #include <QCheckBox>
14 #include <QGridLayout>
15 #include <QGroupBox>
16
VCardExportSelectionWidget(QWidget * parent)17 VCardExportSelectionWidget::VCardExportSelectionWidget(QWidget *parent)
18 : QWidget(parent)
19 {
20 auto mainLayout = new QVBoxLayout(this);
21 mainLayout->setContentsMargins({});
22 auto gbox = new QGroupBox(i18nc("@title:group", "Fields to be exported"), this);
23 mainLayout->addWidget(gbox);
24 auto layout = new QGridLayout;
25 gbox->setLayout(layout);
26 gbox->setFlat(true);
27 layout->addWidget(gbox, 0, 0, 1, 2);
28
29 mPrivateBox = new QCheckBox(i18nc("@option:check", "Private fields"), this);
30 mPrivateBox->setToolTip(i18nc("@info:tooltip", "Export private fields"));
31 mPrivateBox->setWhatsThis(i18nc("@info:whatsthis",
32 "Check this box if you want to export the contact's "
33 "private fields to the vCard output file."));
34 layout->addWidget(mPrivateBox, 1, 0);
35
36 mBusinessBox = new QCheckBox(i18nc("@option:check", "Business fields"), this);
37 mBusinessBox->setToolTip(i18nc("@info:tooltip", "Export business fields"));
38 mBusinessBox->setWhatsThis(i18nc("@info:whatsthis",
39 "Check this box if you want to export the contact's "
40 "business fields to the vCard output file."));
41 layout->addWidget(mBusinessBox, 2, 0);
42
43 mOtherBox = new QCheckBox(i18nc("@option:check", "Other fields"), this);
44 mOtherBox->setToolTip(i18nc("@info:tooltip", "Export other fields"));
45 mOtherBox->setWhatsThis(i18nc("@info:whatsthis",
46 "Check this box if you want to export the contact's "
47 "other fields to the vCard output file."));
48 layout->addWidget(mOtherBox, 3, 0);
49
50 mEncryptionKeys = new QCheckBox(i18nc("@option:check", "Encryption keys"), this);
51 mEncryptionKeys->setToolTip(i18nc("@info:tooltip", "Export encryption keys"));
52 mEncryptionKeys->setWhatsThis(i18nc("@info:whatsthis",
53 "Check this box if you want to export the contact's "
54 "encryption keys to the vCard output file."));
55 layout->addWidget(mEncryptionKeys, 1, 1);
56
57 mPictureBox = new QCheckBox(i18nc("@option:check", "Pictures"), this);
58 mPictureBox->setToolTip(i18nc("@info:tooltip", "Export pictures"));
59 mPictureBox->setWhatsThis(i18nc("@info:whatsthis",
60 "Check this box if you want to export the contact's "
61 "picture to the vCard output file."));
62 layout->addWidget(mPictureBox, 2, 1);
63
64 gbox = new QGroupBox(i18nc("@title:group", "Export options"), this);
65 gbox->setFlat(true);
66 mainLayout->addWidget(gbox);
67 auto gbLayout = new QHBoxLayout;
68 gbox->setLayout(gbLayout);
69
70 mDisplayNameBox = new QCheckBox(i18nc("@option:check", "Display name as full name"), this);
71 mDisplayNameBox->setToolTip(i18nc("@info:tooltip", "Export display name as full name"));
72 mDisplayNameBox->setWhatsThis(i18nc("@info:whatsthis",
73 "Check this box if you want to export the contact's display name "
74 "in the vCard's full name field. This may be required to get the "
75 "name shown correctly in GMail or Android."));
76 gbLayout->addWidget(mDisplayNameBox);
77
78 readSettings();
79 }
80
~VCardExportSelectionWidget()81 VCardExportSelectionWidget::~VCardExportSelectionWidget()
82 {
83 writeSettings();
84 }
85
readSettings()86 void VCardExportSelectionWidget::readSettings()
87 {
88 KConfig config(QStringLiteral("kaddressbookrc"));
89 const KConfigGroup group(&config, "XXPortVCard");
90
91 mPrivateBox->setChecked(group.readEntry("ExportPrivateFields", true));
92 mBusinessBox->setChecked(group.readEntry("ExportBusinessFields", true));
93 mOtherBox->setChecked(group.readEntry("ExportOtherFields", true));
94 mEncryptionKeys->setChecked(group.readEntry("ExportEncryptionKeys", true));
95 mPictureBox->setChecked(group.readEntry("ExportPictureFields", true));
96 mDisplayNameBox->setChecked(group.readEntry("ExportDisplayName", false));
97 }
98
writeSettings()99 void VCardExportSelectionWidget::writeSettings()
100 {
101 KConfig config(QStringLiteral("kaddressbookrc"));
102 KConfigGroup group(&config, "XXPortVCard");
103
104 group.writeEntry("ExportPrivateFields", mPrivateBox->isChecked());
105 group.writeEntry("ExportBusinessFields", mBusinessBox->isChecked());
106 group.writeEntry("ExportOtherFields", mOtherBox->isChecked());
107 group.writeEntry("ExportEncryptionKeys", mEncryptionKeys->isChecked());
108 group.writeEntry("ExportPictureFields", mPictureBox->isChecked());
109 group.writeEntry("ExportDisplayName", mDisplayNameBox->isChecked());
110 }
111
exportType() const112 VCardExportSelectionWidget::ExportFields VCardExportSelectionWidget::exportType() const
113 {
114 ExportFields type = None;
115 if (mPrivateBox->isChecked()) {
116 type |= Private;
117 }
118 if (mBusinessBox->isChecked()) {
119 type |= Business;
120 }
121 if (mOtherBox->isChecked()) {
122 type |= Other;
123 }
124 if (mEncryptionKeys->isChecked()) {
125 type |= Encryption;
126 }
127 if (mPictureBox->isChecked()) {
128 type |= Picture;
129 }
130 if (mDisplayNameBox->isChecked()) {
131 type |= DiplayName;
132 }
133 return type;
134 }
135