summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <montel@kde.org>2016-10-10 08:43:43 (GMT)
committerMontel Laurent <montel@kde.org>2016-10-10 08:43:43 (GMT)
commit505e8a8423e7ae34127ca2ddbcea3f5292f3b195 (patch)
tree0b90efdd66226524e4b55fb3130300dbb7d00415
parentad0fb9468967e89dd8c72ea6b7711593dac5b2c7 (diff)
Add shared lib + start to define export ldif support
-rw-r--r--kaddressbook/importexportplugins/csv/CMakeLists.txt1
-rw-r--r--kaddressbook/importexportplugins/gmx/CMakeLists.txt1
-rw-r--r--kaddressbook/importexportplugins/ldif/CMakeLists.txt1
-rw-r--r--kaddressbook/importexportplugins/ldif/ldifimportexportplugininterface.cpp62
-rw-r--r--kaddressbook/importexportplugins/ldif/ldifimportexportplugininterface.h1
-rw-r--r--kaddressbook/importexportplugins/vcards/CMakeLists.txt1
6 files changed, 67 insertions, 0 deletions
diff --git a/kaddressbook/importexportplugins/csv/CMakeLists.txt b/kaddressbook/importexportplugins/csv/CMakeLists.txt
index c326686..0508782 100644
--- a/kaddressbook/importexportplugins/csv/CMakeLists.txt
+++ b/kaddressbook/importexportplugins/csv/CMakeLists.txt
@@ -12,4 +12,5 @@ target_link_libraries(kaddressbook_importexportcsvplugin KF5::KaddressbookImport
KF5::I18n
KF5::XmlGui
KF5::Contacts
+ kaddressbookimportexportlibprivate
)
diff --git a/kaddressbook/importexportplugins/gmx/CMakeLists.txt b/kaddressbook/importexportplugins/gmx/CMakeLists.txt
index cdad4e8..4de8fff 100644
--- a/kaddressbook/importexportplugins/gmx/CMakeLists.txt
+++ b/kaddressbook/importexportplugins/gmx/CMakeLists.txt
@@ -12,4 +12,5 @@ target_link_libraries(kaddressbook_importexportgmxplugin KF5::KaddressbookImport
KF5::I18n
KF5::XmlGui
KF5::Contacts
+ kaddressbookimportexportlibprivate
)
diff --git a/kaddressbook/importexportplugins/ldif/CMakeLists.txt b/kaddressbook/importexportplugins/ldif/CMakeLists.txt
index dc116d4..b1bf941 100644
--- a/kaddressbook/importexportplugins/ldif/CMakeLists.txt
+++ b/kaddressbook/importexportplugins/ldif/CMakeLists.txt
@@ -12,5 +12,6 @@ target_link_libraries(kaddressbook_importexportldifplugin KF5::KaddressbookImpor
KF5::I18n
KF5::XmlGui
KF5::Contacts
+ KF5::JobWidgets
kaddressbookimportexportlibprivate
)
diff --git a/kaddressbook/importexportplugins/ldif/ldifimportexportplugininterface.cpp b/kaddressbook/importexportplugins/ldif/ldifimportexportplugininterface.cpp
index ffc8c5a..5cf2385 100644
--- a/kaddressbook/importexportplugins/ldif/ldifimportexportplugininterface.cpp
+++ b/kaddressbook/importexportplugins/ldif/ldifimportexportplugininterface.cpp
@@ -26,6 +26,8 @@
#include <QFile>
#include <QTextStream>
#include <KMessageBox>
+#include <KJobWidgets>
+#include <PimCommon/RenameFileDialog>
#include <KContacts/LDIFConverter>
#include <KAddressBookImportExport/KAddressBookImportExportContactList>
@@ -64,6 +66,7 @@ void LDifImportExportPluginInterface::exec()
import();
break;
case Export:
+ exportLdif();
break;
}
//TODO
@@ -118,6 +121,65 @@ void LDifImportExportPluginInterface::import()
mEngine->importContacts();
}
+void LDifImportExportPluginInterface::exportLdif()
+{
+#if 0
+ const QUrl url =
+ QFileDialog::getSaveFileUrl(parentWidget(), QString(), QUrl::fromLocalFile(QDir::homePath() + QLatin1String("/addressbook.ldif")), i18n("LDif Files (*.ldif)"));
+ if (url.isEmpty()) {
+ return;
+ }
+
+ if (!url.isLocalFile()) {
+ QTemporaryFile tmpFile;
+ if (!tmpFile.open()) {
+ const QString msg = i18n("<qt>Unable to open file <b>%1</b></qt>", url.url());
+ KMessageBox::error(parentWidget(), msg);
+ return;
+ }
+
+ doExport(&tmpFile, list);
+ tmpFile.flush();
+ auto job = KIO::file_copy(QUrl::fromLocalFile(tmpFile.fileName()), url, -1, KIO::Overwrite);
+ KJobWidgets::setWindow(job, parentWidget());
+ job->exec();
+
+ } else {
+ QString fileName = url.toLocalFile();
+
+ if (QFileInfo(fileName).exists()) {
+ if (url.isLocalFile() && QFileInfo(url.toLocalFile()).exists()) {
+ PimCommon::RenameFileDialog::RenameFileDialogResult result = PimCommon::RenameFileDialog::RENAMEFILE_IGNORE;
+ PimCommon::RenameFileDialog *dialog = new PimCommon::RenameFileDialog(url, false, parentWidget());
+ result = static_cast<PimCommon::RenameFileDialog::RenameFileDialogResult>(dialog->exec());
+ if (result == PimCommon::RenameFileDialog::RENAMEFILE_RENAME) {
+ fileName = dialog->newName().toLocalFile();
+ } else if (result == PimCommon::RenameFileDialog::RENAMEFILE_IGNORE) {
+ delete dialog;
+ return;
+ }
+ delete dialog;
+ }
+ }
+
+ QFile file(fileName);
+
+ if (!file.open(QIODevice::WriteOnly)) {
+ QString txt = i18n("<qt>Unable to open file <b>%1</b>.</qt>", fileName);
+ KMessageBox::error(parentWidget(), txt);
+ return;
+ }
+ QString data;
+ KContacts::LDIFConverter::addresseeAndContactGroupToLDIF(list.addressList(), list.contactGroupList(), data);
+
+ QTextStream stream(file);
+ stream.setCodec("UTF-8");
+ stream << data;
+ file.close();
+ }
+#endif
+}
+
void LDifImportExportPluginInterface::slotFinished()
{
mEngine->deleteLater();
diff --git a/kaddressbook/importexportplugins/ldif/ldifimportexportplugininterface.h b/kaddressbook/importexportplugins/ldif/ldifimportexportplugininterface.h
index 10593ee..c6f644a 100644
--- a/kaddressbook/importexportplugins/ldif/ldifimportexportplugininterface.h
+++ b/kaddressbook/importexportplugins/ldif/ldifimportexportplugininterface.h
@@ -35,6 +35,7 @@ private:
void slotImportLdif();
void slotExportLdif();
void import();
+ void exportLdif();
void slotFinished();
ImportExportEngine *mEngine;
};
diff --git a/kaddressbook/importexportplugins/vcards/CMakeLists.txt b/kaddressbook/importexportplugins/vcards/CMakeLists.txt
index e6d5ee8..251713e 100644
--- a/kaddressbook/importexportplugins/vcards/CMakeLists.txt
+++ b/kaddressbook/importexportplugins/vcards/CMakeLists.txt
@@ -15,4 +15,5 @@ target_link_libraries(kaddressbook_importexportvcardplugin KF5::KaddressbookImpo
KF5::XmlGui
KF5::Contacts
KF5::KaddressbookGrantlee
+ kaddressbookimportexportlibprivate
)