vcardexportselectionwidget.cpp 5.83 KB
Newer Older
Laurent Montel's avatar
Laurent Montel committed
1
/*
Laurent Montel's avatar
Laurent Montel committed
2
  Copyright (c) 2015-2016 Montel Laurent <montel@kde.org>
Laurent Montel's avatar
Laurent Montel committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

  This program is free software; you can redistribute it and/or modify it
  under the terms of the GNU General Public License, version 2, as
  published by the Free Software Foundation.

  This program is distributed in the hope that it will be useful, but
  WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  General Public License for more details.

  You should have received a copy of the GNU General Public License along
  with this program; if not, write to the Free Software Foundation, Inc.,
  51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/

18
#include "vcardexportselectionwidget.h"
Laurent Montel's avatar
Laurent Montel committed
19
20

#include <KLocalizedString>
21

Laurent Montel's avatar
Laurent Montel committed
22
23
#include <kconfig.h>
#include <KConfigGroup>
24
25
26
#include <qcheckbox.h>
#include <qgridlayout.h>
#include <qgroupbox.h>
Laurent Montel's avatar
Laurent Montel committed
27

28
29
VCardExportSelectionWidget::VCardExportSelectionWidget(QWidget *parent)
    : QWidget(parent)
Laurent Montel's avatar
Laurent Montel committed
30
{
Laurent Montel's avatar
Laurent Montel committed
31
    QVBoxLayout *mainLayout = new QVBoxLayout(this);
Laurent Montel's avatar
Laurent Montel committed
32
    mainLayout->setMargin(0);
Laurent Montel's avatar
Laurent Montel committed
33
    QGroupBox *gbox = new QGroupBox(
Laurent Montel's avatar
Laurent Montel committed
34
        i18nc("@title:group", "Fields to be exported"), this);
Laurent Montel's avatar
Laurent Montel committed
35
36
37
    mainLayout->addWidget(gbox);
    QGridLayout *layout = new QGridLayout;
    gbox->setLayout(layout);
Laurent Montel's avatar
Laurent Montel committed
38
39
    gbox->setFlat(true);
    layout->addWidget(gbox, 0, 0, 1, 2);
Laurent Montel's avatar
Laurent Montel committed
40

Laurent Montel's avatar
Laurent Montel committed
41
    mPrivateBox = new QCheckBox(i18nc("@option:check", "Private fields"), this);
Laurent Montel's avatar
Laurent Montel committed
42
    mPrivateBox->setToolTip(
Laurent Montel's avatar
Laurent Montel committed
43
        i18nc("@info:tooltip", "Export private fields"));
Laurent Montel's avatar
Laurent Montel committed
44
    mPrivateBox->setWhatsThis(
Laurent Montel's avatar
Laurent Montel committed
45
46
47
48
        i18nc("@info:whatsthis",
              "Check this box if you want to export the contact's "
              "private fields to the vCard output file."));
    layout->addWidget(mPrivateBox, 1, 0);
Laurent Montel's avatar
Laurent Montel committed
49

Laurent Montel's avatar
Laurent Montel committed
50
    mBusinessBox = new QCheckBox(i18nc("@option:check", "Business fields"), this);
Laurent Montel's avatar
Laurent Montel committed
51
    mBusinessBox->setToolTip(
Laurent Montel's avatar
Laurent Montel committed
52
        i18nc("@info:tooltip", "Export business fields"));
Laurent Montel's avatar
Laurent Montel committed
53
    mBusinessBox->setWhatsThis(
Laurent Montel's avatar
Laurent Montel committed
54
55
56
57
        i18nc("@info:whatsthis",
              "Check this box if you want to export the contact's "
              "business fields to the vCard output file."));
    layout->addWidget(mBusinessBox, 2, 0);
Laurent Montel's avatar
Laurent Montel committed
58

Laurent Montel's avatar
Laurent Montel committed
59
    mOtherBox = new QCheckBox(i18nc("@option:check", "Other fields"), this);
Laurent Montel's avatar
Laurent Montel committed
60
    mOtherBox->setToolTip(
Laurent Montel's avatar
Laurent Montel committed
61
        i18nc("@info:tooltip", "Export other fields"));
Laurent Montel's avatar
Laurent Montel committed
62
    mOtherBox->setWhatsThis(
Laurent Montel's avatar
Laurent Montel committed
63
64
65
66
        i18nc("@info:whatsthis",
              "Check this box if you want to export the contact's "
              "other fields to the vCard output file."));
    layout->addWidget(mOtherBox, 3, 0);
Laurent Montel's avatar
Laurent Montel committed
67

Laurent Montel's avatar
Laurent Montel committed
68
    mEncryptionKeys = new QCheckBox(i18nc("@option:check", "Encryption keys"), this);
Laurent Montel's avatar
Laurent Montel committed
69
    mEncryptionKeys->setToolTip(
Laurent Montel's avatar
Laurent Montel committed
70
        i18nc("@info:tooltip", "Export encryption keys"));
Laurent Montel's avatar
Laurent Montel committed
71
    mEncryptionKeys->setWhatsThis(
Laurent Montel's avatar
Laurent Montel committed
72
73
74
75
        i18nc("@info:whatsthis",
              "Check this box if you want to export the contact's "
              "encryption keys to the vCard output file."));
    layout->addWidget(mEncryptionKeys, 1, 1);
Laurent Montel's avatar
Laurent Montel committed
76

Laurent Montel's avatar
Laurent Montel committed
77
    mPictureBox = new QCheckBox(i18nc("@option:check", "Pictures"), this);
Laurent Montel's avatar
Laurent Montel committed
78
    mPictureBox->setToolTip(
Laurent Montel's avatar
Laurent Montel committed
79
        i18nc("@info:tooltip", "Export pictures"));
Laurent Montel's avatar
Laurent Montel committed
80
    mPictureBox->setWhatsThis(
Laurent Montel's avatar
Laurent Montel committed
81
82
83
84
        i18nc("@info:whatsthis",
              "Check this box if you want to export the contact's "
              "picture to the vCard output file."));
    layout->addWidget(mPictureBox, 2, 1);
Laurent Montel's avatar
Laurent Montel committed
85
86

    gbox = new QGroupBox(
Laurent Montel's avatar
Laurent Montel committed
87
88
        i18nc("@title:group", "Export options"), this);
    gbox->setFlat(true);
Laurent Montel's avatar
Laurent Montel committed
89
90
91
    mainLayout->addWidget(gbox);
    QHBoxLayout *gbLayout = new QHBoxLayout;
    gbox->setLayout(gbLayout);
Laurent Montel's avatar
Laurent Montel committed
92

Laurent Montel's avatar
Laurent Montel committed
93
    mDisplayNameBox = new QCheckBox(i18nc("@option:check", "Display name as full name"), this);
Laurent Montel's avatar
Laurent Montel committed
94
    mDisplayNameBox->setToolTip(
Laurent Montel's avatar
Laurent Montel committed
95
        i18nc("@info:tooltip", "Export display name as full name"));
Laurent Montel's avatar
Laurent Montel committed
96
    mDisplayNameBox->setWhatsThis(
Laurent Montel's avatar
Laurent Montel committed
97
98
99
100
        i18nc("@info:whatsthis",
              "Check this box if you want to export the contact's display name "
              "in the vCard's full name field.  This may be required to get the "
              "name shown correctly in GMail or Android."));
Laurent Montel's avatar
Laurent Montel committed
101
    gbLayout->addWidget(mDisplayNameBox);
Laurent Montel's avatar
Laurent Montel committed
102

103
104
    readSettings();
}
Laurent Montel's avatar
Laurent Montel committed
105

106
107
108
109
VCardExportSelectionWidget::~VCardExportSelectionWidget()
{
    writeSettings();
}
110

111
112
void VCardExportSelectionWidget::readSettings()
{
Laurent Montel's avatar
Laurent Montel committed
113
114
115
116
117
118
119
120
121
    KConfig config(QStringLiteral("kaddressbookrc"));
    const KConfigGroup group(&config, "XXPortVCard");

    mPrivateBox->setChecked(group.readEntry("ExportPrivateFields", true));
    mBusinessBox->setChecked(group.readEntry("ExportBusinessFields", true));
    mOtherBox->setChecked(group.readEntry("ExportOtherFields", true));
    mEncryptionKeys->setChecked(group.readEntry("ExportEncryptionKeys", true));
    mPictureBox->setChecked(group.readEntry("ExportPictureFields", true));
    mDisplayNameBox->setChecked(group.readEntry("ExportDisplayName", false));
Laurent Montel's avatar
Laurent Montel committed
122
123
}

124
void VCardExportSelectionWidget::writeSettings()
Laurent Montel's avatar
Laurent Montel committed
125
{
Laurent Montel's avatar
Laurent Montel committed
126
    KConfig config(QStringLiteral("kaddressbookrc"));
Laurent Montel's avatar
Laurent Montel committed
127
128
129
130
131
132
133
134
    KConfigGroup group(&config, "XXPortVCard");

    group.writeEntry("ExportPrivateFields", mPrivateBox->isChecked());
    group.writeEntry("ExportBusinessFields", mBusinessBox->isChecked());
    group.writeEntry("ExportOtherFields", mOtherBox->isChecked());
    group.writeEntry("ExportEncryptionKeys", mEncryptionKeys->isChecked());
    group.writeEntry("ExportPictureFields", mPictureBox->isChecked());
    group.writeEntry("ExportDisplayName", mDisplayNameBox->isChecked());
Laurent Montel's avatar
Laurent Montel committed
135
136
}

137
VCardExportSelectionWidget::ExportFields VCardExportSelectionWidget::exportType() const
Laurent Montel's avatar
Laurent Montel committed
138
{
139
    ExportFields type = None;
Laurent Montel's avatar
Laurent Montel committed
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
    if (mPrivateBox->isChecked()) {
        type |= Private;
    }
    if (mBusinessBox->isChecked()) {
        type |= Business;
    }
    if (mOtherBox->isChecked()) {
        type |= Other;
    }
    if (mEncryptionKeys->isChecked()) {
        type |= Encryption;
    }
    if (mPictureBox->isChecked()) {
        type |= Picture;
    }
    if (mDisplayNameBox->isChecked()) {
        type |= DiplayName;
    }
    return type;
}