summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <montel@kde.org>2016-10-12 11:29:36 (GMT)
committerMontel Laurent <montel@kde.org>2016-10-12 11:48:05 (GMT)
commit6d8c74093ef00ae5da7084ae279741bb79756218 (patch)
tree5e6a8c5bcc508a6100450d283e57db3045b0f1af
parent62014908f670f479eabd599df93c2655eae994a2 (diff)
Fix import/export
-rw-r--r--kaddressbook/importexportplugins/gmx/CMakeLists.txt2
-rw-r--r--kaddressbook/importexportplugins/gmx/gmximportexportplugininterface.cpp7
-rw-r--r--kaddressbook/importexportplugins/ldif/ldifimportexportplugininterface.cpp15
-rw-r--r--kaddressbook/importexportplugins/ldif/ldifimportexportplugininterface.h2
-rw-r--r--kaddressbook/importexportplugins/vcards/vcardimportexportplugininterface.cpp45
5 files changed, 63 insertions, 8 deletions
diff --git a/kaddressbook/importexportplugins/gmx/CMakeLists.txt b/kaddressbook/importexportplugins/gmx/CMakeLists.txt
index c9c61dc..57e6e00 100644
--- a/kaddressbook/importexportplugins/gmx/CMakeLists.txt
+++ b/kaddressbook/importexportplugins/gmx/CMakeLists.txt
@@ -3,6 +3,8 @@ set(kaddressbook_importexport_gmx_SRCS
gmximportexportplugininterface.cpp
)
+ecm_qt_declare_logging_category(kaddressbook_importexport_gmx_SRCS HEADER kaddressbook_importexport_gmx_debug.h IDENTIFIER KADDRESSBOOK_IMPORTEXPORT_GMX_LOG CATEGORY_NAME org.kde.pim.kaddressbook_importexportgmx)
+
kcoreaddons_add_plugin(kaddressbook_importexportgmxplugin JSON kaddressbook_importexportgmxplugin.json SOURCES
${kaddressbook_importexport_gmx_SRCS} INSTALL_NAMESPACE kaddressbook)
diff --git a/kaddressbook/importexportplugins/gmx/gmximportexportplugininterface.cpp b/kaddressbook/importexportplugins/gmx/gmximportexportplugininterface.cpp
index cb0ac9c..3cde0b4 100644
--- a/kaddressbook/importexportplugins/gmx/gmximportexportplugininterface.cpp
+++ b/kaddressbook/importexportplugins/gmx/gmximportexportplugininterface.cpp
@@ -18,6 +18,7 @@
*/
#include "gmximportexportplugininterface.h"
+#include "kaddressbook_importexport_gmx_debug.h"
#include <KLocalizedString>
#include <KActionCollection>
#include <QAction>
@@ -519,7 +520,7 @@ void GMXImportExportPluginInterface::importGMX()
// now read the address records
line = gmxStream.readLine();
if (!line.startsWith(QStringLiteral("AB_ADDRESS_RECORDS:"))) {
- //qCWarning(KADDRESSBOOK_LOG) << "Could not find address records!";
+ qCWarning(KADDRESSBOOK_IMPORTEXPORT_GMX_LOG) << "Could not find address records!";
return;
}
// Address_id,Record_id,Street,Country,Zipcode,City,Phone,Fax,Mobile,
@@ -609,7 +610,7 @@ void GMXImportExportPluginInterface::importGMX()
// itemList[20]=Status (should always be "1")
addressee->insertAddress(address);
} else {
- //qCWarning(KADDRESSBOOK_LOG) << "unresolved line:" << line;
+ qCWarning(KADDRESSBOOK_IMPORTEXPORT_GMX_LOG) << "unresolved line:" << line;
}
line = gmxStream.readLine();
}
@@ -620,7 +621,7 @@ void GMXImportExportPluginInterface::importGMX()
line2 = gmxStream.readLine();
if (!line.startsWith(QStringLiteral("AB_CATEGORIES:")) ||
!line2.startsWith(QStringLiteral("Category_id"))) {
- //qCWarning(KADDRESSBOOK_LOG) << "Could not find category records!";
+ qCWarning(KADDRESSBOOK_IMPORTEXPORT_GMX_LOG) << "Could not find category records!";
} else {
while (!line.startsWith(QStringLiteral("####")) &&
!gmxStream.atEnd()) {
diff --git a/kaddressbook/importexportplugins/ldif/ldifimportexportplugininterface.cpp b/kaddressbook/importexportplugins/ldif/ldifimportexportplugininterface.cpp
index edac74e..94c6533 100644
--- a/kaddressbook/importexportplugins/ldif/ldifimportexportplugininterface.cpp
+++ b/kaddressbook/importexportplugins/ldif/ldifimportexportplugininterface.cpp
@@ -85,10 +85,8 @@ void LDifImportExportPluginInterface::slotExportLdif()
Q_EMIT emitPluginActivated(this);
}
-void LDifImportExportPluginInterface::importLdif()
+void LDifImportExportPluginInterface::importLdifFile(const QString &fileName)
{
- KAddressBookImportExport::KAddressBookImportExportContactList contactList;
- const QString fileName = QFileDialog::getOpenFileName(parentWidget(), QString(), QDir::homePath(), i18n("LDif Files (*.ldif)"));
if (fileName.isEmpty()) {
return;
}
@@ -109,6 +107,7 @@ void LDifImportExportPluginInterface::importLdif()
KContacts::ContactGroup::List lstGroup;
KContacts::Addressee::List lstAddresses;
KContacts::LDIFConverter::LDIFToAddressee(wholeFile, lstAddresses, lstGroup, dtDefault);
+ KAddressBookImportExport::KAddressBookImportExportContactList contactList;
contactList.setAddressList(lstAddresses);
contactList.setContactGroupList(lstGroup);
@@ -118,6 +117,12 @@ void LDifImportExportPluginInterface::importLdif()
engine->importContacts();
}
+void LDifImportExportPluginInterface::importLdif()
+{
+ const QString fileName = QFileDialog::getOpenFileName(parentWidget(), QString(), QDir::homePath(), i18n("LDif Files (*.ldif)"));
+ importLdifFile(fileName);
+}
+
void doExport(QFile *file, const KAddressBookImportExport::KAddressBookImportExportContactList &list)
{
QString data;
@@ -211,5 +216,7 @@ bool LDifImportExportPluginInterface::canImportFileType(const QUrl &url)
void LDifImportExportPluginInterface::importFile(const QUrl &url)
{
- //TODO
+ if (url.isLocalFile()) {
+ importLdifFile(url.path());
+ }
}
diff --git a/kaddressbook/importexportplugins/ldif/ldifimportexportplugininterface.h b/kaddressbook/importexportplugins/ldif/ldifimportexportplugininterface.h
index ad63417..27c0f81 100644
--- a/kaddressbook/importexportplugins/ldif/ldifimportexportplugininterface.h
+++ b/kaddressbook/importexportplugins/ldif/ldifimportexportplugininterface.h
@@ -37,7 +37,7 @@ private:
void slotExportLdif();
void importLdif();
void exportLdif();
-
+ void importLdifFile(const QString &fileName);
};
#endif // LDIFIMPORTEXPORTPLUGININTERFACE_H
diff --git a/kaddressbook/importexportplugins/vcards/vcardimportexportplugininterface.cpp b/kaddressbook/importexportplugins/vcards/vcardimportexportplugininterface.cpp
index 9859885..b0747d2 100644
--- a/kaddressbook/importexportplugins/vcards/vcardimportexportplugininterface.cpp
+++ b/kaddressbook/importexportplugins/vcards/vcardimportexportplugininterface.cpp
@@ -29,10 +29,12 @@
#include <KContacts/VCardConverter>
#include <PimCommon/RenameFileDialog>
#include <KIOCore/kio/filecopyjob.h>
+#include <KIOCore/kio/storedtransferjob.h>
#include <KJobWidgets>
#ifdef QGPGME_FOUND
#include <QTemporaryFile>
+#include <importexportengine.h>
#include <gpgme++/context.h>
#include <gpgme++/data.h>
#include <gpgme++/key.h>
@@ -122,6 +124,49 @@ void VCardImportExportPluginInterface::slotImportVCard()
void VCardImportExportPluginInterface::importVCard()
{
+ KContacts::Addressee::List addrList;
+ QList<QUrl> urls;
+
+ 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;
+ }
+
+ 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;
+ }
+ }
+ KAddressBookImportExport::KAddressBookImportExportContactList contactList;
+ contactList.setAddressList(addrList);
+ ImportExportEngine *engine = new ImportExportEngine(this);
+ engine->setContactList(contactList);
+ engine->setDefaultAddressBook(defaultCollection());
+ engine->importContacts();
#if 0
KAddressBookImportExport::KAddressBookImportExportContactList contactList;
KContacts::Addressee::List addrList;