Commit dc473a0a authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

improve plugins

parent 84fba0ea
......@@ -72,7 +72,7 @@ set(MESSAGELIB_LIB_VERSION "5.3.64")
set(AKONADICALENDAR_LIB_VERSION "5.3.40")
set(CALENDAR_UTILS_VERSION "5.3.40")
set(KPIMTEXTEDIT_LIB_VERSION "5.3.42")
set(GPGMEPP_LIB_VERSION "5.3.40")
find_package(KF5CalendarUtils ${CALENDAR_UTILS_VERSION} CONFIG REQUIRED)
find_package(KF5WebEngineViewer ${MESSAGELIB_LIB_VERSION} CONFIG REQUIRED)
......@@ -94,6 +94,7 @@ find_package(KF5Akonadi ${AKONADI_LIB_VERSION} CONFIG REQUIRED)
find_package(KF5AkonadiCalendar ${AKONADICALENDAR_LIB_VERSION} CONFIG REQUIRED)
find_package(KF5Gravatar ${GRAVATAR_LIB_VERSION} CONFIG REQUIRED)
find_package(KF5PimTextEdit ${KPIMTEXTEDIT_LIB_VERSION} CONFIG REQUIRED)
find_package(KF5Gpgmepp ${GPGMEPP_LIB_VERSION} CONFIG REQUIRED)
find_package(KF5Tnef ${KTNEF_LIB_VERSION} CONFIG REQUIRED)
......
add_definitions(-DTRANSLATION_DOMAIN=\"kaddressbook_importexportplugins\")
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/shared)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/shared)
if(KF5Gpgmepp_FOUND)
add_definitions(-DQGPGME_FOUND)
endif()
add_subdirectory(shared)
......
......@@ -32,6 +32,7 @@
#include <QFileDialog>
#include <QTextCodec>
#include <QPointer>
#include <KAddressBookContactSelectionDialog>
#include <KIO/Job>
CSVImportExportPluginInterface::CSVImportExportPluginInterface(QObject *parent)
......@@ -162,6 +163,24 @@ void CSVImportExportPluginInterface::exportToFile(QFile *file, const KContacts::
void CSVImportExportPluginInterface::exportCSV()
{
QPointer<KAddressBookImportExport::KAddressBookContactSelectionDialog> dlg =
new KAddressBookImportExport::KAddressBookContactSelectionDialog(itemSelectionModel(), false, parentWidget());
dlg->setMessageText(i18n("Which contact do you want to export?"));
dlg->setDefaultAddressBook(defaultCollection());
if (!dlg->exec() || !dlg) {
delete dlg;
return;
}
const KContacts::AddresseeList contacts = dlg->selectedContacts().addressList();
delete dlg;
if (contacts.isEmpty()) {
KMessageBox::sorry(Q_NULLPTR, i18n("You have not selected any contacts to export."));
return;
}
KAddressBookImportExport::KAddressBookImportExportContactList contactLists;
contactLists.setAddressList(contacts);
QUrl url = QFileDialog::getSaveFileUrl(parentWidget(), QString(), QUrl::fromLocalFile(QStringLiteral("addressbook.csv")));
if (url.isEmpty()) {
return;
......@@ -189,7 +208,7 @@ void CSVImportExportPluginInterface::exportCSV()
KMessageBox::error(parentWidget(), msg);
return;
}
exportToFile(&tmpFile, addressBookImportExportList().addressList());
exportToFile(&tmpFile, contactLists.addressList());
tmpFile.flush();
auto job = KIO::file_copy(QUrl::fromLocalFile(tmpFile.fileName()), url, -1, KIO::Overwrite);
KJobWidgets::setWindow(job, parentWidget());
......@@ -202,8 +221,13 @@ void CSVImportExportPluginInterface::exportCSV()
return;
}
exportToFile(&file, addressBookImportExportList().addressList());
exportToFile(&file, contactLists.addressList());
file.close();
}
}
bool CSVImportExportPluginInterface::canImportFileType(const QUrl &url)
{
return url.path().endsWith(QStringLiteral(".csv"));
}
......@@ -32,6 +32,9 @@ public:
void createAction(KActionCollection *ac) Q_DECL_OVERRIDE;
void exec() Q_DECL_OVERRIDE;
bool canImportFileType(const QUrl &url) Q_DECL_OVERRIDE;
private:
void slotFinished();
void exportCSV();
......@@ -39,6 +42,7 @@ private:
void slotExportCVS();
void exportToFile(QFile *file, const KContacts::Addressee::List &contacts) const;
void importCSV();
};
#endif // CSVIMPORTEXPORTPLUGININTERFACE_H
......@@ -21,6 +21,7 @@
#include <KLocalizedString>
#include <KActionCollection>
#include <QAction>
#include <QUrl>
GMXImportExportPluginInterface::GMXImportExportPluginInterface(QObject *parent)
: KAddressBookImportExport::KAddressBookImportExportPluginInterface(parent)
......@@ -82,3 +83,9 @@ void GMXImportExportPluginInterface::importGMX()
{
}
bool GMXImportExportPluginInterface::canImportFileType(const QUrl &url)
{
return url.path().endsWith(QStringLiteral(".gmx"));
}
......@@ -31,6 +31,7 @@ public:
void createAction(KActionCollection *ac) Q_DECL_OVERRIDE;
void exec() Q_DECL_OVERRIDE;
bool canImportFileType(const QUrl &url) Q_DECL_OVERRIDE;
private:
void slotImportGmx();
void slotExportGmx();
......
......@@ -28,9 +28,11 @@
#include <KMessageBox>
#include <QTemporaryFile>
#include <KJobWidgets>
#include <QPointer>
#include <KIOCore/kio/filecopyjob.h>
#include <PimCommon/RenameFileDialog>
#include <KContacts/LDIFConverter>
#include <KAddressBookImportExport/KAddressBookContactSelectionDialog>
#include <KAddressBookImportExport/KAddressBookImportExportContactList>
LDifImportExportPluginInterface::LDifImportExportPluginInterface(QObject *parent)
......@@ -130,6 +132,25 @@ void doExport(QFile *file, const KAddressBookImportExport::KAddressBookImportExp
void LDifImportExportPluginInterface::exportLdif()
{
QPointer<KAddressBookImportExport::KAddressBookContactSelectionDialog> dlg =
new KAddressBookImportExport::KAddressBookContactSelectionDialog(itemSelectionModel(), false, parentWidget());
dlg->setMessageText(i18n("Which contact do you want to export?"));
dlg->setDefaultAddressBook(defaultCollection());
if (!dlg->exec() || !dlg) {
delete dlg;
return;
}
const KContacts::AddresseeList contacts = dlg->selectedContacts().addressList();
delete dlg;
if (contacts.isEmpty()) {
KMessageBox::sorry(Q_NULLPTR, i18n("You have not selected any contacts to export."));
return;
}
KAddressBookImportExport::KAddressBookImportExportContactList contactLists;
contactLists.setAddressList(contacts);
const QUrl url =
QFileDialog::getSaveFileUrl(parentWidget(), QString(), QUrl::fromLocalFile(QDir::homePath() + QLatin1String("/addressbook.ldif")), i18n("LDif Files (*.ldif)"));
if (url.isEmpty()) {
......@@ -144,7 +165,7 @@ void LDifImportExportPluginInterface::exportLdif()
return;
}
doExport(&tmpFile, addressBookImportExportList());
doExport(&tmpFile, contactLists);
tmpFile.flush();
auto job = KIO::file_copy(QUrl::fromLocalFile(tmpFile.fileName()), url, -1, KIO::Overwrite);
KJobWidgets::setWindow(job, parentWidget());
......@@ -176,7 +197,7 @@ void LDifImportExportPluginInterface::exportLdif()
return;
}
QString data;
KContacts::LDIFConverter::addresseeAndContactGroupToLDIF(addressBookImportExportList().addressList(), addressBookImportExportList().contactGroupList(), data);
KContacts::LDIFConverter::addresseeAndContactGroupToLDIF(contactLists.addressList(), contactLists.contactGroupList(), data);
QTextStream stream(&file);
stream.setCodec("UTF-8");
......@@ -184,3 +205,9 @@ void LDifImportExportPluginInterface::exportLdif()
file.close();
}
}
bool LDifImportExportPluginInterface::canImportFileType(const QUrl &url)
{
return url.path().endsWith(QStringLiteral(".ldif"));
}
......@@ -30,11 +30,12 @@ public:
void createAction(KActionCollection *ac) Q_DECL_OVERRIDE;
void exec() Q_DECL_OVERRIDE;
bool canImportFileType(const QUrl &url) Q_DECL_OVERRIDE;
private:
void slotImportLdif();
void slotExportLdif();
void import();
void exportLdif();
void exportLdif();
};
#endif // LDIFIMPORTEXPORTPLUGININTERFACE_H
......@@ -21,6 +21,10 @@
#include <KLocalizedString>
#include <KActionCollection>
#include <QAction>
#include <KAddressBookImportExport/KAddressBookContactSelectionDialog>
#include <QPointer>
#include <KMessageBox>
#include <QUrl>
VCardImportExportPluginInterface::VCardImportExportPluginInterface(QObject *parent)
: KAddressBookImportExport::KAddressBookImportExportPluginInterface(parent)
......@@ -43,11 +47,6 @@ void VCardImportExportPluginInterface::createAction(KActionCollection *ac)
QList<QAction *> exportActionList;
action = ac->addAction(QStringLiteral("file_import_vcard"));
action->setText(i18n("Import vCard..."));
action->setWhatsThis(i18n("Import contacts from a vCard file."));
exportActionList << action;
action = ac->addAction(QStringLiteral("file_export_vcard40"));
action->setWhatsThis(i18n("Export contacts to a vCard 4.0 file."));
action->setText(i18n("Export vCard 4.0..."));
......@@ -67,4 +66,114 @@ void VCardImportExportPluginInterface::createAction(KActionCollection *ac)
void VCardImportExportPluginInterface::exec()
{
switch(mImportExportAction) {
case Import:
importVCard();
break;
case Export:
exportVCard();
break;
}
}
void VCardImportExportPluginInterface::importVCard()
{
#if 0
KAddressBookImportExport::KAddressBookImportExportContactList 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);
#endif
}
void VCardImportExportPluginInterface::exportVCard()
{
QPointer<KAddressBookImportExport::KAddressBookContactSelectionDialog> dlg =
new KAddressBookImportExport::KAddressBookContactSelectionDialog(itemSelectionModel(), true, parentWidget());
dlg->setMessageText(i18n("Which contact do you want to export?"));
dlg->setDefaultAddressBook(defaultCollection());
if (!dlg->exec() || !dlg) {
delete dlg;
return;
}
const KContacts::AddresseeList contacts = dlg->selectedContacts().addressList();
const KAddressBookImportExport::KAddressBookExportSelectionWidget::ExportFields exportFields = dlg->exportType();
delete dlg;
if (contacts.isEmpty()) {
KMessageBox::sorry(Q_NULLPTR, i18n("You have not selected any contacts to export."));
return;
}
}
bool VCardImportExportPluginInterface::canImportFileType(const QUrl &url)
{
return url.path().endsWith(QStringLiteral(".vcf"));
}
......@@ -31,6 +31,11 @@ public:
void createAction(KActionCollection *ac) Q_DECL_OVERRIDE;
void exec() Q_DECL_OVERRIDE;
bool canImportFileType(const QUrl &url) Q_DECL_OVERRIDE;
private:
void exportVCard();
void importVCard();
};
#endif // VCARDIMPORTEXPORTPLUGININTERFACE_H
......@@ -11,7 +11,7 @@
"Description[sv]": "Insticksprogrammet gör det möjligt att ändra skiftläge på markerad text.",
"Description[uk]": "За допомогою цього додатка можна змінювати регістр символів позначеного фрагмента тексту.",
"Description[x-test]": "xxThis plugins allows you to change selected text case.xx",
"EnabledByDefault": "true",
"EnabledByDefault": "false",
"Id": "kmailchangecase",
"Name": "Change Case",
"Name[ca@valencia]": "Canvia la caixa",
......@@ -42,4 +42,4 @@
"Version": "1.0"
},
"X-KDE-KMailEditor-Order": "1"
}
\ No newline at end of file
}
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