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

  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
    QGridLayout *layout = new QGridLayout(this);
Laurent Montel's avatar
Laurent Montel committed
32
33

    QGroupBox *gbox = new QGroupBox(
Laurent Montel's avatar
Laurent Montel committed
34
35
36
        i18nc("@title:group", "Fields to be exported"), this);
    gbox->setFlat(true);
    layout->addWidget(gbox, 0, 0, 1, 2);
Laurent Montel's avatar
Laurent Montel committed
37

Laurent Montel's avatar
Laurent Montel committed
38
    mPrivateBox = new QCheckBox(i18nc("@option:check", "Private fields"), this);
Laurent Montel's avatar
Laurent Montel committed
39
    mPrivateBox->setToolTip(
Laurent Montel's avatar
Laurent Montel committed
40
        i18nc("@info:tooltip", "Export private fields"));
Laurent Montel's avatar
Laurent Montel committed
41
    mPrivateBox->setWhatsThis(
Laurent Montel's avatar
Laurent Montel committed
42
43
44
45
        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
46

Laurent Montel's avatar
Laurent Montel committed
47
    mBusinessBox = new QCheckBox(i18nc("@option:check", "Business fields"), this);
Laurent Montel's avatar
Laurent Montel committed
48
    mBusinessBox->setToolTip(
Laurent Montel's avatar
Laurent Montel committed
49
        i18nc("@info:tooltip", "Export business fields"));
Laurent Montel's avatar
Laurent Montel committed
50
    mBusinessBox->setWhatsThis(
Laurent Montel's avatar
Laurent Montel committed
51
52
53
54
        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
55

Laurent Montel's avatar
Laurent Montel committed
56
    mOtherBox = new QCheckBox(i18nc("@option:check", "Other fields"), this);
Laurent Montel's avatar
Laurent Montel committed
57
    mOtherBox->setToolTip(
Laurent Montel's avatar
Laurent Montel committed
58
        i18nc("@info:tooltip", "Export other fields"));
Laurent Montel's avatar
Laurent Montel committed
59
    mOtherBox->setWhatsThis(
Laurent Montel's avatar
Laurent Montel committed
60
61
62
63
        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
64

Laurent Montel's avatar
Laurent Montel committed
65
    mEncryptionKeys = new QCheckBox(i18nc("@option:check", "Encryption keys"), this);
Laurent Montel's avatar
Laurent Montel committed
66
    mEncryptionKeys->setToolTip(
Laurent Montel's avatar
Laurent Montel committed
67
        i18nc("@info:tooltip", "Export encryption keys"));
Laurent Montel's avatar
Laurent Montel committed
68
    mEncryptionKeys->setWhatsThis(
Laurent Montel's avatar
Laurent Montel committed
69
70
71
72
        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
73

Laurent Montel's avatar
Laurent Montel committed
74
    mPictureBox = new QCheckBox(i18nc("@option:check", "Pictures"), this);
Laurent Montel's avatar
Laurent Montel committed
75
    mPictureBox->setToolTip(
Laurent Montel's avatar
Laurent Montel committed
76
        i18nc("@info:tooltip", "Export pictures"));
Laurent Montel's avatar
Laurent Montel committed
77
    mPictureBox->setWhatsThis(
Laurent Montel's avatar
Laurent Montel committed
78
79
80
81
        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
82
83

    gbox = new QGroupBox(
Laurent Montel's avatar
Laurent Montel committed
84
85
86
        i18nc("@title:group", "Export options"), this);
    gbox->setFlat(true);
    layout->addWidget(gbox, 4, 0, 1, 2);
Laurent Montel's avatar
Laurent Montel committed
87

Laurent Montel's avatar
Laurent Montel committed
88
    mDisplayNameBox = new QCheckBox(i18nc("@option:check", "Display name as full name"), this);
Laurent Montel's avatar
Laurent Montel committed
89
    mDisplayNameBox->setToolTip(
Laurent Montel's avatar
Laurent Montel committed
90
        i18nc("@info:tooltip", "Export display name as full name"));
Laurent Montel's avatar
Laurent Montel committed
91
    mDisplayNameBox->setWhatsThis(
Laurent Montel's avatar
Laurent Montel committed
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
        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."));
    layout->addWidget(mDisplayNameBox, 5, 0, 1, 2);

    KConfig config(QLatin1String("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));
107

Laurent Montel's avatar
Laurent Montel committed
108
109
}

110
VCardExportSelectionWidget::~VCardExportSelectionWidget()
Laurent Montel's avatar
Laurent Montel committed
111
{
Laurent Montel's avatar
Laurent Montel committed
112
113
114
115
116
117
118
119
120
    KConfig config(QLatin1String("kaddressbookrc"));
    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
121
122
}

123
VCardExportSelectionWidget::ExportFields VCardExportSelectionWidget::exportType() const
Laurent Montel's avatar
Laurent Montel committed
124
{
125
    ExportFields type = None;
Laurent Montel's avatar
Laurent Montel committed
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
    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;
}