Commit 505e8a84 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Add shared lib + start to define export ldif support

parent ad0fb946
......@@ -12,4 +12,5 @@ target_link_libraries(kaddressbook_importexportcsvplugin KF5::KaddressbookImport
KF5::I18n
KF5::XmlGui
KF5::Contacts
kaddressbookimportexportlibprivate
)
......@@ -12,4 +12,5 @@ target_link_libraries(kaddressbook_importexportgmxplugin KF5::KaddressbookImport
KF5::I18n
KF5::XmlGui
KF5::Contacts
kaddressbookimportexportlibprivate
)
......@@ -12,5 +12,6 @@ target_link_libraries(kaddressbook_importexportldifplugin KF5::KaddressbookImpor
KF5::I18n
KF5::XmlGui
KF5::Contacts
KF5::JobWidgets
kaddressbookimportexportlibprivate
)
......@@ -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();
......
......@@ -35,6 +35,7 @@ private:
void slotImportLdif();
void slotExportLdif();
void import();
void exportLdif();
void slotFinished();
ImportExportEngine *mEngine;
};
......
......@@ -15,4 +15,5 @@ target_link_libraries(kaddressbook_importexportvcardplugin KF5::KaddressbookImpo
KF5::XmlGui
KF5::Contacts
KF5::KaddressbookGrantlee
kaddressbookimportexportlibprivate
)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment