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

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

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

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

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

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

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

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

88
    mDisplayNameBox = new QCheckBox( i18nc( "@option:check", "Display name as full name" ), this );
Laurent Montel's avatar
Laurent Montel committed
89
90
91
92
93
94
95
96
97
    mDisplayNameBox->setToolTip(
                i18nc( "@info:tooltip", "Export display name as full name" ) );
    mDisplayNameBox->setWhatsThis(
                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 );

98
99
100
101
102
103
104
105
106
107
    readSettings();
}

VCardExportSelectionWidget::~VCardExportSelectionWidget()
{
    writeSettings();
}

void VCardExportSelectionWidget::readSettings()
{
Laurent Montel's avatar
Laurent Montel committed
108
109
110
111
112
113
114
115
116
117
118
    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 ) );
}

119
void VCardExportSelectionWidget::writeSettings()
Laurent Montel's avatar
Laurent Montel committed
120
121
122
123
124
125
126
127
128
129
130
131
{
    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() );
}

132
VCardExportSelectionWidget::ExportFields VCardExportSelectionWidget::exportType() const
Laurent Montel's avatar
Laurent Montel committed
133
{
134
    ExportFields type = None;
Laurent Montel's avatar
Laurent Montel committed
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
    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;
}