summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <montel@kde.org>2016-10-10 08:13:47 (GMT)
committerMontel Laurent <montel@kde.org>2016-10-10 08:13:47 (GMT)
commitad0fb9468967e89dd8c72ea6b7711593dac5b2c7 (patch)
tree9fac55a82998158d1d0fee3815eedbbb3c673ffb
parent4702ce496c712db778777185f6af080723a9c7a4 (diff)
Port ldap plugin
-rw-r--r--kaddressbook/importexportplugins/ldap/ldapimportexportplugininterface.cpp1
-rw-r--r--kaddressbook/importexportplugins/ldif/CMakeLists.txt1
-rw-r--r--kaddressbook/importexportplugins/ldif/ldifimportexportplugininterface.cpp54
-rw-r--r--kaddressbook/importexportplugins/ldif/ldifimportexportplugininterface.h5
4 files changed, 58 insertions, 3 deletions
diff --git a/kaddressbook/importexportplugins/ldap/ldapimportexportplugininterface.cpp b/kaddressbook/importexportplugins/ldap/ldapimportexportplugininterface.cpp
index ab57a9a..91b91d0 100644
--- a/kaddressbook/importexportplugins/ldap/ldapimportexportplugininterface.cpp
+++ b/kaddressbook/importexportplugins/ldap/ldapimportexportplugininterface.cpp
@@ -57,7 +57,6 @@ void LDapImportExportPluginInterface::exec()
case Export:
break;
}
- //TODO
}
void LDapImportExportPluginInterface::slotImportLdap()
diff --git a/kaddressbook/importexportplugins/ldif/CMakeLists.txt b/kaddressbook/importexportplugins/ldif/CMakeLists.txt
index 9b5a2d4..dc116d4 100644
--- a/kaddressbook/importexportplugins/ldif/CMakeLists.txt
+++ b/kaddressbook/importexportplugins/ldif/CMakeLists.txt
@@ -12,4 +12,5 @@ target_link_libraries(kaddressbook_importexportldifplugin KF5::KaddressbookImpor
KF5::I18n
KF5::XmlGui
KF5::Contacts
+ kaddressbookimportexportlibprivate
)
diff --git a/kaddressbook/importexportplugins/ldif/ldifimportexportplugininterface.cpp b/kaddressbook/importexportplugins/ldif/ldifimportexportplugininterface.cpp
index b7e8350..ffc8c5a 100644
--- a/kaddressbook/importexportplugins/ldif/ldifimportexportplugininterface.cpp
+++ b/kaddressbook/importexportplugins/ldif/ldifimportexportplugininterface.cpp
@@ -18,12 +18,20 @@
*/
#include "ldifimportexportplugininterface.h"
+#include "../shared/importexportengine.h"
#include <KLocalizedString>
#include <KActionCollection>
#include <QAction>
+#include <QFileDialog>
+#include <QFile>
+#include <QTextStream>
+#include <KMessageBox>
+#include <KContacts/LDIFConverter>
+#include <KAddressBookImportExport/KAddressBookImportExportContactList>
LDifImportExportPluginInterface::LDifImportExportPluginInterface(QObject *parent)
- : KAddressBookImportExport::KAddressBookImportExportPluginInterface(parent)
+ : KAddressBookImportExport::KAddressBookImportExportPluginInterface(parent),
+ mEngine(Q_NULLPTR)
{
}
@@ -53,6 +61,7 @@ void LDifImportExportPluginInterface::exec()
{
switch(mImportExportAction) {
case Import:
+ import();
break;
case Export:
break;
@@ -71,3 +80,46 @@ void LDifImportExportPluginInterface::slotExportLdif()
mImportExportAction = Export;
Q_EMIT emitPluginActivated(this);
}
+
+
+void LDifImportExportPluginInterface::import()
+{
+ KAddressBookImportExport::KAddressBookImportExportContactList contactList;
+ const QString fileName = QFileDialog::getOpenFileName(parentWidget(), QString(), QDir::homePath(), i18n("LDif Files (*.ldif)"));
+ if (fileName.isEmpty()) {
+ return;
+ }
+
+ QFile file(fileName);
+ if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
+ const QString msg = i18n("<qt>Unable to open <b>%1</b> for reading.</qt>", fileName);
+ KMessageBox::error(parentWidget(), msg);
+ return;
+ }
+
+ QTextStream stream(&file);
+ stream.setCodec("ISO 8859-1");
+
+ const QString wholeFile = stream.readAll();
+ const QDateTime dtDefault = QFileInfo(file).lastModified();
+ file.close();
+ KContacts::ContactGroup::List lstGroup;
+ KContacts::Addressee::List lstAddresses;
+ KContacts::LDIFConverter::LDIFToAddressee(wholeFile, lstAddresses, lstGroup, dtDefault);
+ contactList.setAddressList(lstAddresses);
+ contactList.setContactGroupList(lstGroup);
+
+ if (!mEngine) {
+ mEngine = new ImportExportEngine(this);
+ }
+ mEngine->setContactList(contactList);
+ mEngine->setDefaultAddressBook(defaultCollection());
+ connect(mEngine, &ImportExportEngine::finished, this, &LDifImportExportPluginInterface::slotFinished);
+ mEngine->importContacts();
+}
+
+void LDifImportExportPluginInterface::slotFinished()
+{
+ mEngine->deleteLater();
+ mEngine = Q_NULLPTR;
+}
diff --git a/kaddressbook/importexportplugins/ldif/ldifimportexportplugininterface.h b/kaddressbook/importexportplugins/ldif/ldifimportexportplugininterface.h
index 7daacfa..10593ee 100644
--- a/kaddressbook/importexportplugins/ldif/ldifimportexportplugininterface.h
+++ b/kaddressbook/importexportplugins/ldif/ldifimportexportplugininterface.h
@@ -21,7 +21,7 @@
#define LDIFIMPORTEXPORTPLUGININTERFACE_H
#include <KAddressBookImportExport/KAddressBookImportExportPluginInterface>
-
+class ImportExportEngine;
class LDifImportExportPluginInterface : public KAddressBookImportExport::KAddressBookImportExportPluginInterface
{
Q_OBJECT
@@ -34,6 +34,9 @@ public:
private:
void slotImportLdif();
void slotExportLdif();
+ void import();
+ void slotFinished();
+ ImportExportEngine *mEngine;
};
#endif // LDIFIMPORTEXPORTPLUGININTERFACE_H