summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <montel@kde.org>2016-10-07 11:52:13 (GMT)
committerMontel Laurent <montel@kde.org>2016-10-07 11:52:13 (GMT)
commit9fb78251a8fba0d67aa670ecb6f777ee13b670c0 (patch)
treeea79b631920b0eb17a595f9c3b342c3765b73f15
parent01fb3e4b6616f134f0277b99aded472628ebfdd1 (diff)
We need all code here now
-rw-r--r--kaddressbook/importexportplugins/vcards/engine/vcard_xxport.cpp436
-rw-r--r--kaddressbook/importexportplugins/vcards/engine/vcard_xxport.h42
-rw-r--r--kaddressbook/importexportplugins/vcards/engine/vcardexportselectionwidget.cpp161
-rw-r--r--kaddressbook/importexportplugins/vcards/engine/vcardexportselectionwidget.h56
-rw-r--r--kaddressbook/importexportplugins/vcards/engine/vcardviewerdialog.cpp152
-rw-r--r--kaddressbook/importexportplugins/vcards/engine/vcardviewerdialog.h58
6 files changed, 905 insertions, 0 deletions
diff --git a/kaddressbook/importexportplugins/vcards/engine/vcard_xxport.cpp b/kaddressbook/importexportplugins/vcards/engine/vcard_xxport.cpp
new file mode 100644
index 0000000..0034354
--- /dev/null
+++ b/kaddressbook/importexportplugins/vcards/engine/vcard_xxport.cpp
@@ -0,0 +1,436 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2009 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ 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.
+*/
+
+#include "vcard_xxport.h"
+
+#include "vcardviewerdialog.h"
+#include "vcardexportselectionwidget.h"
+
+#include "PimCommon/RenameFileDialog"
+
+#include <KaddressbookGrantlee/GrantleeContactViewer>
+
+#ifdef QGPGME_FOUND
+#include <gpgme++/context.h>
+#include <gpgme++/data.h>
+#include <gpgme++/key.h>
+#include <qgpgme/dataprovider.h>
+#endif // QGPGME_FOUND
+
+#include <KContacts/VCardConverter>
+
+#include "kaddressbook_debug.h"
+#include <QDialog>
+#include <QFileDialog>
+#include <KLocalizedString>
+#include <KMessageBox>
+#include <QTemporaryFile>
+#include <QUrl>
+#include <KStandardGuiItem>
+#include <KSharedConfig>
+
+#include <KJobWidgets>
+#include <KIO/StatJob>
+#include <KIO/FileCopyJob>
+#include <KIO/StoredTransferJob>
+
+#include <QFile>
+#include <QPointer>
+
+VCardXXPort::VCardXXPort(QWidget *parent)
+ : XXPort(parent)
+{
+}
+
+bool VCardXXPort::exportContacts(const ContactList &contacts, VCardExportSelectionWidget::ExportFields exportFields) const
+{
+ KContacts::VCardConverter converter;
+ QUrl url;
+
+ const KContacts::Addressee::List list = filterContacts(contacts.addressList(), exportFields);
+ if (list.isEmpty()) { // no contact selected
+ return true;
+ }
+
+ bool ok = true;
+ if (list.count() == 1) {
+ url = QFileDialog::getSaveFileUrl(parentWidget(), QString(), QUrl::fromLocalFile(
+ QString(list[ 0 ].givenName() +
+ QLatin1Char(QLatin1Char('_')) +
+ list[ 0 ].familyName() +
+ QLatin1String(".vcf"))));
+ if (url.isEmpty()) { // user canceled export
+ return true;
+ }
+
+ if (option(QStringLiteral("version")) == QLatin1String("v21")) {
+ ok = doExport(url, converter.exportVCards(list, KContacts::VCardConverter::v2_1));
+ } else if (option(QStringLiteral("version")) == QLatin1String("v30")) {
+ ok = doExport(url, converter.exportVCards(list, KContacts::VCardConverter::v3_0));
+ } else {
+ ok = doExport(url, converter.exportVCards(list, KContacts::VCardConverter::v4_0));
+ }
+ } else {
+ const int answer =
+ KMessageBox::questionYesNoCancel(
+ parentWidget(),
+ i18nc("@info",
+ "You have selected a list of contacts, "
+ "shall they be exported to several files?"),
+ QString(),
+ KGuiItem(i18nc("@action:button", "Export to One File")),
+ KGuiItem(i18nc("@action:button", "Export to Several Files")));
+
+ switch (answer) {
+ case KMessageBox::No: {
+ const QUrl baseUrl = QFileDialog::getExistingDirectoryUrl();
+ if (baseUrl.isEmpty()) {
+ return true; // user canceled export
+ }
+
+ for (int i = 0; i < list.count(); ++i) {
+ const KContacts::Addressee contact = list.at(i);
+
+ url = QUrl::fromLocalFile(baseUrl.path() + QLatin1Char('/') + contactFileName(contact) + QLatin1String(".vcf"));
+
+ bool tmpOk = false;
+
+ if (option(QStringLiteral("version")) == QLatin1String("v21")) {
+ tmpOk = doExport(url, converter.exportVCard(contact, KContacts::VCardConverter::v2_1));
+ } else if (option(QStringLiteral("version")) == QLatin1String("v30")) {
+ tmpOk = doExport(url, converter.exportVCard(contact, KContacts::VCardConverter::v3_0));
+ } else {
+ tmpOk = doExport(url, converter.exportVCard(contact, KContacts::VCardConverter::v4_0));
+ }
+
+ ok = ok && tmpOk;
+ }
+ break;
+ }
+ case KMessageBox::Yes: {
+ url = QFileDialog::getSaveFileUrl(parentWidget(), QString(), QUrl::fromLocalFile(QStringLiteral("addressbook.vcf")));
+ if (url.isEmpty()) {
+ return true; // user canceled export
+ }
+
+ if (option(QStringLiteral("version")) == QLatin1String("v21")) {
+ ok = doExport(url, converter.exportVCards(list, KContacts::VCardConverter::v2_1));
+ } else if (option(QStringLiteral("version")) == QLatin1String("v30")) {
+ ok = doExport(url, converter.exportVCards(list, KContacts::VCardConverter::v3_0));
+ } else {
+ ok = doExport(url, converter.exportVCards(list, KContacts::VCardConverter::v4_0));
+ }
+ break;
+ }
+ case KMessageBox::Cancel:
+ default:
+ return true; // user canceled export
+ }
+ }
+
+ return ok;
+}
+
+ContactList VCardXXPort::importContacts() const
+{
+ ContactList contactList;
+ KContacts::Addressee::List addrList;
+ QList<QUrl> urls;
+
+ if (!option(QStringLiteral("importData")).isEmpty()) {
+ addrList = parseVCard(option(QStringLiteral("importData")).toUtf8());
+ } else {
+ if (!option(QStringLiteral("importUrl")).isEmpty()) {
+ urls.append(QUrl::fromLocalFile(option(QStringLiteral("importUrl"))));
+ } else {
+ const QString filter = i18n("*.vcf|vCard (*.vcf)\n*|all files (*)");
+ urls =
+ QFileDialog::getOpenFileUrls(parentWidget(), i18nc("@title:window", "Select vCard to Import"),
+ QUrl(),
+ filter);
+ }
+
+ if (urls.isEmpty()) {
+ return contactList;
+ }
+
+ const QString caption(i18nc("@title:window", "vCard Import Failed"));
+ bool anyFailures = false;
+
+ const int numberOfUrl(urls.count());
+ for (int i = 0; i < numberOfUrl; ++i) {
+ const QUrl url = urls.at(i);
+
+ auto job = KIO::storedGet(url);
+ KJobWidgets::setWindow(job, parentWidget());
+ if (job->exec()) {
+
+ const QByteArray data = job->data();
+ if (!data.isEmpty()) {
+ addrList += parseVCard(data);
+ }
+ } else {
+ const QString msg = xi18nc(
+ "@info",
+ "<para>Unable to access vCard:</para><para>%1</para>",
+ job->errorString());
+ KMessageBox::error(parentWidget(), msg, caption);
+ anyFailures = true;
+ }
+ }
+
+ if (!option(QStringLiteral("importUrl")).isEmpty()) { // a vcard was passed via cmd
+ if (addrList.isEmpty()) {
+ if (anyFailures && urls.count() > 1) {
+ KMessageBox::information(
+ parentWidget(),
+ i18nc("@info", "No contacts were imported, due to errors with the vCards."));
+ } else if (!anyFailures) {
+ KMessageBox::information(
+ parentWidget(),
+ i18nc("@info", "The vCard does not contain any contacts."));
+ }
+ } else {
+ QPointer<VCardViewerDialog> dlg = new VCardViewerDialog(addrList, parentWidget());
+ if (dlg->exec() && dlg) {
+ addrList = dlg->contacts();
+ } else {
+ addrList.clear();
+ }
+ delete dlg;
+ }
+ }
+ }
+ contactList.setAddressList(addrList);
+ return contactList;
+}
+
+KContacts::Addressee::List VCardXXPort::parseVCard(const QByteArray &data) const
+{
+ KContacts::VCardConverter converter;
+
+ return converter.parseVCards(data);
+}
+
+bool VCardXXPort::doExport(const QUrl &url, const QByteArray &data) const
+{
+ QUrl newUrl(url);
+ if (newUrl.isLocalFile() && QFileInfo(newUrl.toLocalFile()).exists()) {
+ PimCommon::RenameFileDialog *dialog = new PimCommon::RenameFileDialog(newUrl, false, parentWidget());
+ PimCommon::RenameFileDialog::RenameFileDialogResult result = static_cast<PimCommon::RenameFileDialog::RenameFileDialogResult>(dialog->exec());
+ if (result == PimCommon::RenameFileDialog::RENAMEFILE_RENAME) {
+ newUrl = dialog->newName();
+ } else if (result == PimCommon::RenameFileDialog::RENAMEFILE_IGNORE) {
+ delete dialog;
+ return true;
+ }
+ delete dialog;
+ }
+
+ QTemporaryFile tmpFile;
+ tmpFile.open();
+
+ tmpFile.write(data);
+ tmpFile.flush();
+ auto job = KIO::file_copy(QUrl::fromLocalFile(tmpFile.fileName()), newUrl, -1, KIO::Overwrite);
+ KJobWidgets::setWindow(job, parentWidget());
+ return job->exec();
+}
+
+KContacts::Addressee::List VCardXXPort::filterContacts(const KContacts::Addressee::List &addrList, VCardExportSelectionWidget::ExportFields exportFieldType) const
+{
+ KContacts::Addressee::List list;
+
+ if (addrList.isEmpty()) {
+ return addrList;
+ }
+
+ KContacts::Addressee::List::ConstIterator it;
+ KContacts::Addressee::List::ConstIterator end(addrList.end());
+ for (it = addrList.begin(); it != end; ++it) {
+ KContacts::Addressee addr;
+
+ addr.setUid((*it).uid());
+ addr.setFormattedName((*it).formattedName());
+
+ bool addrDone = false;
+ if (exportFieldType & VCardExportSelectionWidget::DiplayName) { // output display name as N field
+ QString fmtName = (*it).formattedName();
+ QStringList splitNames = fmtName.split(QLatin1Char(' '), QString::SkipEmptyParts);
+ if (splitNames.count() >= 2) {
+ addr.setPrefix(QString());
+ addr.setGivenName(splitNames.takeFirst());
+ addr.setFamilyName(splitNames.takeLast());
+ addr.setAdditionalName(splitNames.join(QLatin1Char(' ')));
+ addr.setSuffix(QString());
+ addrDone = true;
+ }
+ }
+
+ if (!addrDone) { // not wanted, or could not be split
+ addr.setPrefix((*it).prefix());
+ addr.setGivenName((*it).givenName());
+ addr.setAdditionalName((*it).additionalName());
+ addr.setFamilyName((*it).familyName());
+ addr.setSuffix((*it).suffix());
+ }
+
+ addr.setExtraNickNameList((*it).extraNickNameList());
+ addr.setMailer((*it).mailer());
+ addr.setTimeZone((*it).timeZone());
+ addr.setGeo((*it).geo());
+ addr.setProductId((*it).productId());
+ addr.setSortString((*it).sortString());
+ addr.setUrl((*it).url());
+ addr.setExtraUrlList((*it).extraUrlList());
+ addr.setSecrecy((*it).secrecy());
+ addr.setSound((*it).sound());
+ addr.setEmailList((*it).emailList());
+ addr.setCategories((*it).categories());
+ addr.setExtraSoundList((*it).extraSoundList());
+ addr.setGender((*it).gender());
+ addr.setLangs((*it).langs());
+ addr.setKind((*it).kind());
+ addr.setMembers((*it).members());
+ addr.setRelationShips((*it).relationShips());
+ addr.setSourcesUrlList((*it).sourcesUrlList());
+ addr.setImppList((*it).imppList());
+ addr.setFieldGroupList((*it).fieldGroupList());
+
+ if (exportFieldType & VCardExportSelectionWidget::Private) {
+ addr.setBirthday((*it).birthday(), (*it).birthdayHasTime());
+ addr.setNote((*it).note());
+ }
+
+ if (exportFieldType & VCardExportSelectionWidget::Picture) {
+ if (exportFieldType & VCardExportSelectionWidget::Private) {
+ addr.setPhoto((*it).photo());
+ addr.setExtraPhotoList((*it).extraPhotoList());
+ }
+
+ if (exportFieldType & VCardExportSelectionWidget::Business) {
+ addr.setLogo((*it).logo());
+ addr.setExtraLogoList((*it).extraLogoList());
+ }
+ }
+
+ if (exportFieldType & VCardExportSelectionWidget::Business) {
+ addr.setExtraTitleList((*it).extraTitleList());
+ addr.setExtraRoleList((*it).extraRoleList());
+ addr.setExtraOrganizationList((*it).extraOrganizationList());
+ addr.setDepartment((*it).department());
+
+ KContacts::PhoneNumber::List phones = (*it).phoneNumbers(KContacts::PhoneNumber::Work);
+ KContacts::PhoneNumber::List::Iterator phoneIt;
+ KContacts::PhoneNumber::List::Iterator phoneEnd(phones.end());
+ for (phoneIt = phones.begin(); phoneIt != phoneEnd; ++phoneIt) {
+ addr.insertPhoneNumber(*phoneIt);
+ }
+
+ KContacts::Address::List addresses = (*it).addresses(KContacts::Address::Work);
+ KContacts::Address::List::Iterator addrIt;
+ KContacts::Address::List::Iterator addrEnd(addresses.end());
+ for (addrIt = addresses.begin(); addrIt != addrEnd; ++addrIt) {
+ addr.insertAddress(*addrIt);
+ }
+ }
+
+ KContacts::PhoneNumber::List phones = (*it).phoneNumbers();
+ KContacts::PhoneNumber::List::Iterator phoneIt;
+ KContacts::PhoneNumber::List::Iterator phoneEnd(phones.end());
+ for (phoneIt = phones.begin(); phoneIt != phoneEnd; ++phoneIt) {
+ int phoneType = (*phoneIt).type();
+
+ if ((phoneType & KContacts::PhoneNumber::Home) && (exportFieldType & VCardExportSelectionWidget::Private)) {
+ addr.insertPhoneNumber(*phoneIt);
+ } else if ((phoneType & KContacts::PhoneNumber::Work) && (exportFieldType & VCardExportSelectionWidget::Business)) {
+ addr.insertPhoneNumber(*phoneIt);
+ } else if ((exportFieldType & VCardExportSelectionWidget::Other)) {
+ addr.insertPhoneNumber(*phoneIt);
+ }
+ }
+
+ KContacts::Address::List addresses = (*it).addresses();
+ KContacts::Address::List::Iterator addrIt;
+ KContacts::Address::List::Iterator addrEnd(addresses.end());
+ for (addrIt = addresses.begin(); addrIt != addrEnd; ++addrIt) {
+ int addressType = (*addrIt).type();
+
+ if ((addressType & KContacts::Address::Home) && exportFieldType & VCardExportSelectionWidget::Private) {
+ addr.insertAddress(*addrIt);
+ } else if ((addressType & KContacts::Address::Work) && (exportFieldType & VCardExportSelectionWidget::Business)) {
+ addr.insertAddress(*addrIt);
+ } else if (exportFieldType & VCardExportSelectionWidget::Other) {
+ addr.insertAddress(*addrIt);
+ }
+ }
+
+ if (exportFieldType & VCardExportSelectionWidget::Other) {
+ addr.setCustoms((*it).customs());
+ }
+
+ if (exportFieldType & VCardExportSelectionWidget::Encryption) {
+ addKey(addr, KContacts::Key::PGP);
+ addKey(addr, KContacts::Key::X509);
+ }
+
+ list.append(addr);
+ }
+
+ return list;
+}
+
+void VCardXXPort::addKey(KContacts::Addressee &addr, KContacts::Key::Type type) const
+{
+#ifdef QGPGME_FOUND
+ const QString fingerprint = addr.custom(QStringLiteral("KADDRESSBOOK"),
+ (type == KContacts::Key::PGP ? QStringLiteral("OPENPGPFP") : QStringLiteral("SMIMEFP")));
+ if (fingerprint.isEmpty()) {
+ return;
+ }
+
+ GpgME::Context *context = GpgME::Context::createForProtocol(GpgME::OpenPGP);
+ if (!context) {
+ qCritical() << "No context available";
+ return;
+ }
+
+ context->setArmor(false);
+ context->setTextMode(false);
+
+ QGpgME::QByteArrayDataProvider dataProvider;
+ GpgME::Data dataObj(&dataProvider);
+ GpgME::Error error = context->exportPublicKeys(fingerprint.toLatin1(), dataObj);
+ delete context;
+
+ if (error) {
+ qCritical() << error.asString();
+ return;
+ }
+
+ KContacts::Key key;
+ key.setType(type);
+ key.setBinaryData(dataProvider.data());
+
+ addr.insertKey(key);
+#else
+ return;
+#endif
+}
+
diff --git a/kaddressbook/importexportplugins/vcards/engine/vcard_xxport.h b/kaddressbook/importexportplugins/vcards/engine/vcard_xxport.h
new file mode 100644
index 0000000..514867c
--- /dev/null
+++ b/kaddressbook/importexportplugins/vcards/engine/vcard_xxport.h
@@ -0,0 +1,42 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2009 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ 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.
+*/
+
+#ifndef VCARD_XXPORT_H
+#define VCARD_XXPORT_H
+
+#include "xxport.h"
+
+class VCardXXPort : public XXPort
+{
+public:
+ explicit VCardXXPort(QWidget *parent = Q_NULLPTR);
+
+ bool exportContacts(const ContactList &contacts, VCardExportSelectionWidget::ExportFields exportFieldType) const Q_DECL_OVERRIDE;
+ ContactList importContacts() const Q_DECL_OVERRIDE;
+
+private:
+ KContacts::Addressee::List parseVCard(const QByteArray &data) const;
+ bool doExport(const QUrl &url, const QByteArray &data) const;
+
+ void addKey(KContacts::Addressee &addr, KContacts::Key::Type type) const;
+
+ KContacts::Addressee::List filterContacts(const KContacts::Addressee::List &, VCardExportSelectionWidget::ExportFields exportFieldType) const;
+};
+
+#endif
diff --git a/kaddressbook/importexportplugins/vcards/engine/vcardexportselectionwidget.cpp b/kaddressbook/importexportplugins/vcards/engine/vcardexportselectionwidget.cpp
new file mode 100644
index 0000000..59fab46
--- /dev/null
+++ b/kaddressbook/importexportplugins/vcards/engine/vcardexportselectionwidget.cpp
@@ -0,0 +1,161 @@
+/*
+ Copyright (C) 2015-2016 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 as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ 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; see the file COPYING. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "vcardexportselectionwidget.h"
+
+#include <KLocalizedString>
+
+#include <kconfig.h>
+#include <KConfigGroup>
+#include <qcheckbox.h>
+#include <qgridlayout.h>
+#include <qgroupbox.h>
+
+VCardExportSelectionWidget::VCardExportSelectionWidget(QWidget *parent)
+ : QWidget(parent)
+{
+ QVBoxLayout *mainLayout = new QVBoxLayout(this);
+ mainLayout->setMargin(0);
+ QGroupBox *gbox = new QGroupBox(
+ i18nc("@title:group", "Fields to be exported"), this);
+ mainLayout->addWidget(gbox);
+ QGridLayout *layout = new QGridLayout;
+ gbox->setLayout(layout);
+ gbox->setFlat(true);
+ layout->addWidget(gbox, 0, 0, 1, 2);
+
+ mPrivateBox = new QCheckBox(i18nc("@option:check", "Private fields"), this);
+ 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);
+
+ mBusinessBox = new QCheckBox(i18nc("@option:check", "Business fields"), this);
+ 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);
+
+ mOtherBox = new QCheckBox(i18nc("@option:check", "Other fields"), this);
+ 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);
+
+ mEncryptionKeys = new QCheckBox(i18nc("@option:check", "Encryption keys"), this);
+ 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);
+
+ mPictureBox = new QCheckBox(i18nc("@option:check", "Pictures"), this);
+ 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(
+ i18nc("@title:group", "Export options"), this);
+ gbox->setFlat(true);
+ mainLayout->addWidget(gbox);
+ QHBoxLayout *gbLayout = new QHBoxLayout;
+ gbox->setLayout(gbLayout);
+
+ mDisplayNameBox = new QCheckBox(i18nc("@option:check", "Display name as full name"), this);
+ 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."));
+ gbLayout->addWidget(mDisplayNameBox);
+
+ readSettings();
+}
+
+VCardExportSelectionWidget::~VCardExportSelectionWidget()
+{
+ writeSettings();
+}
+
+void VCardExportSelectionWidget::readSettings()
+{
+ 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));
+}
+
+void VCardExportSelectionWidget::writeSettings()
+{
+ KConfig config(QStringLiteral("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());
+}
+
+VCardExportSelectionWidget::ExportFields VCardExportSelectionWidget::exportType() const
+{
+ ExportFields type = None;
+ 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;
+}
diff --git a/kaddressbook/importexportplugins/vcards/engine/vcardexportselectionwidget.h b/kaddressbook/importexportplugins/vcards/engine/vcardexportselectionwidget.h
new file mode 100644
index 0000000..7d7bbaa
--- /dev/null
+++ b/kaddressbook/importexportplugins/vcards/engine/vcardexportselectionwidget.h
@@ -0,0 +1,56 @@
+/*
+ Copyright (C) 2015-2016 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 as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ 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; see the file COPYING. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef VCARDEXPORTSELECTIONWIDGET_H
+#define VCARDEXPORTSELECTIONWIDGET_H
+
+#include <QWidget>
+
+class QCheckBox;
+class VCardExportSelectionWidget : public QWidget
+{
+ Q_OBJECT
+public:
+ explicit VCardExportSelectionWidget(QWidget *parent = Q_NULLPTR);
+ ~VCardExportSelectionWidget();
+ enum ExportField {
+ None = 0,
+ Private = 1,
+ Business = 2,
+ Other = 4,
+ Encryption = 8,
+ Picture = 16,
+ DiplayName = 32
+ };
+ Q_ENUMS(ExportField)
+ Q_DECLARE_FLAGS(ExportFields, ExportField)
+
+ ExportFields exportType() const;
+private:
+ void readSettings();
+ void writeSettings();
+ QCheckBox *mPrivateBox;
+ QCheckBox *mBusinessBox;
+ QCheckBox *mOtherBox;
+ QCheckBox *mEncryptionKeys;
+ QCheckBox *mPictureBox;
+ QCheckBox *mDisplayNameBox;
+};
+
+#endif // VCARDEXPORTSELECTIONWIDGET_H
diff --git a/kaddressbook/importexportplugins/vcards/engine/vcardviewerdialog.cpp b/kaddressbook/importexportplugins/vcards/engine/vcardviewerdialog.cpp
new file mode 100644
index 0000000..be0180f
--- /dev/null
+++ b/kaddressbook/importexportplugins/vcards/engine/vcardviewerdialog.cpp
@@ -0,0 +1,152 @@
+/*
+ Copyright (C) 2015-2016 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 as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ 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; see the file COPYING. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "vcardviewerdialog.h"
+#include <KLocalizedString>
+#include <KStandardGuiItem>
+#include <KSharedConfig>
+#include <KConfigGroup>
+#include <QLabel>
+#include <QVBoxLayout>
+#include <KaddressbookGrantlee/GrantleeContactViewer>
+#include <QPushButton>
+#include <QDialogButtonBox>
+
+VCardViewerDialog::VCardViewerDialog(const KContacts::Addressee::List &list, QWidget *parent)
+ : QDialog(parent),
+ mContacts(list)
+{
+ setWindowTitle(i18nc("@title:window", "Import vCard"));
+ QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Cancel | QDialogButtonBox::Apply);
+ QVBoxLayout *mainLayout = new QVBoxLayout;
+ setLayout(mainLayout);
+ QPushButton *user1Button = new QPushButton;
+ buttonBox->addButton(user1Button, QDialogButtonBox::ActionRole);
+ QPushButton *user2Button = new QPushButton;
+ buttonBox->addButton(user2Button, QDialogButtonBox::ActionRole);
+ connect(buttonBox, &QDialogButtonBox::accepted, this, &VCardViewerDialog::accept);
+ connect(buttonBox, &QDialogButtonBox::rejected, this, &VCardViewerDialog::reject);
+ KGuiItem::assign(user1Button, KStandardGuiItem::no());
+ KGuiItem::assign(user2Button, KStandardGuiItem::yes());
+ mApplyButton = buttonBox->button(QDialogButtonBox::Apply);
+ user1Button->setDefault(true);
+ setModal(true);
+
+ QFrame *page = new QFrame(this);
+ mainLayout->addWidget(page);
+ mainLayout->addWidget(buttonBox);
+
+ QVBoxLayout *layout = new QVBoxLayout(page);
+
+ QLabel *label =
+ new QLabel(
+ i18nc("@info", "Do you want to import this contact into your address book?"), page);
+ QFont font = label->font();
+ font.setBold(true);
+ label->setFont(font);
+ layout->addWidget(label);
+
+ mView = new KAddressBookGrantlee::GrantleeContactViewer(page);
+
+ layout->addWidget(mView);
+
+ buttonBox->button(QDialogButtonBox::Apply)->setText(i18nc("@action:button", "Import All..."));
+
+ mIt = mContacts.begin();
+
+ connect(user2Button, &QPushButton::clicked, this, &VCardViewerDialog::slotYes);
+ connect(user1Button, &QPushButton::clicked, this, &VCardViewerDialog::slotNo);
+ connect(buttonBox->button(QDialogButtonBox::Apply), &QPushButton::clicked, this, &VCardViewerDialog::slotApply);
+ connect(buttonBox->button(QDialogButtonBox::Cancel), &QPushButton::clicked, this, &VCardViewerDialog::slotCancel);
+
+ updateView();
+ readConfig();
+}
+
+VCardViewerDialog::~VCardViewerDialog()
+{
+ writeConfig();
+}
+
+void VCardViewerDialog::readConfig()
+{
+ KConfigGroup group(KSharedConfig::openConfig(), "VCardViewerDialog");
+ const QSize size = group.readEntry("Size", QSize(600, 400));
+ if (size.isValid()) {
+ resize(size);
+ }
+}
+
+void VCardViewerDialog::writeConfig()
+{
+ KConfigGroup group(KSharedConfig::openConfig(), "VCardViewerDialog");
+ group.writeEntry("Size", size());
+ group.sync();
+}
+
+KContacts::Addressee::List VCardViewerDialog::contacts() const
+{
+ return mContacts;
+}
+
+void VCardViewerDialog::updateView()
+{
+ mView->setRawContact(*mIt);
+
+ KContacts::Addressee::List::Iterator it = mIt;
+ mApplyButton->setEnabled(++it != mContacts.end());
+}
+
+void VCardViewerDialog::slotYes()
+{
+ mIt++;
+
+ if (mIt == mContacts.end()) {
+ slotApply();
+ return;
+ }
+
+ updateView();
+}
+
+void VCardViewerDialog::slotNo()
+{
+ if (mIt == mContacts.end()) {
+ accept();
+ return;
+ }
+ // remove the current contact from the result set
+ mIt = mContacts.erase(mIt);
+ if (mIt == mContacts.end()) {
+ return;
+ }
+
+ updateView();
+}
+
+void VCardViewerDialog::slotApply()
+{
+ QDialog::accept();
+}
+
+void VCardViewerDialog::slotCancel()
+{
+ mContacts.clear();
+ reject();
+}
diff --git a/kaddressbook/importexportplugins/vcards/engine/vcardviewerdialog.h b/kaddressbook/importexportplugins/vcards/engine/vcardviewerdialog.h
new file mode 100644
index 0000000..9c08dac
--- /dev/null
+++ b/kaddressbook/importexportplugins/vcards/engine/vcardviewerdialog.h
@@ -0,0 +1,58 @@
+/*
+ Copyright (C) 2015-2016 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 as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ 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; see the file COPYING. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+#ifndef VCARDVIEWERDIALOG_H
+#define VCARDVIEWERDIALOG_H
+
+#include <QDialog>
+#include <KContacts/Addressee>
+
+namespace KAddressBookGrantlee
+{
+class GrantleeContactViewer;
+}
+class QPushButton;
+class VCardViewerDialog : public QDialog
+{
+ Q_OBJECT
+public:
+ VCardViewerDialog(const KContacts::Addressee::List &list,
+ QWidget *parent);
+ ~VCardViewerDialog();
+
+ KContacts::Addressee::List contacts() const;
+
+protected Q_SLOTS:
+ void slotYes();
+ void slotNo();
+ void slotApply();
+ void slotCancel();
+
+private:
+ void readConfig();
+ void writeConfig();
+ void updateView();
+
+ KAddressBookGrantlee::GrantleeContactViewer *mView;
+
+ KContacts::Addressee::List mContacts;
+ KContacts::Addressee::List::Iterator mIt;
+ QPushButton *mApplyButton;
+};
+
+#endif // VCARDVIEWERDIALOG_H