Verified Commit f9c0193f authored by Daniel Vrátil's avatar Daniel Vrátil 🤖
Browse files

Import KAddressbookImportExport library from kdepim-apps-libs

This library provides an interface to implement import/export
plugins for KAddressbook. It was agreed that it is OK for
applications to install their own plugin interface libraries,
so moving the library from kdepim-apps-libs gets us one step
closer to killing that repo.

As part of the move I renamed files and classes and removed
KAddressbookImportExport from the name, since they are already
in KAddressbookImportExport namespace (which required adjusting
existing code in KAB.

The library has been also moved from KF5 to KPim namespace, since
this library is never going to become a Framework.
parent fc6bcf4b
Pipeline #33952 passed with stage
in 11 minutes and 38 seconds
cmake_minimum_required(VERSION 3.5)
set(PIM_VERSION "5.15.40")
set(PIM_VERSION "5.15.41")
project(kaddressbook VERSION ${PIM_VERSION})
set(RELEASE_SERVICE_VERSION "20.07.90")
set(KF5_MIN_VERSION "5.71.0")
......@@ -56,6 +56,7 @@ set(AKONADI_SEARCH_VERSION "5.15.40")
# Find KF5 package
find_package(KF5DBusAddons ${KF5_MIN_VERSION} CONFIG REQUIRED)
find_package(KF5CoreAddons ${KF5_MIN_VERSION} CONFIG REQUIRED)
find_package(KF5DocTools ${KF5_MIN_VERSION} REQUIRED)
find_package(KF5KCMUtils ${KF5_MIN_VERSION} CONFIG REQUIRED)
find_package(KF5Crash ${KF5_MIN_VERSION} REQUIRED)
......@@ -67,17 +68,17 @@ find_package(KF5Akonadi ${AKONADI_VERSION} CONFIG REQUIRED)
find_package(KF5KontactInterface ${KONTACTINTERFACE_LIB_VERSION} CONFIG REQUIRED)
find_package(KF5Libkdepim ${LIBKDEPIM_LIB_VERSION} CONFIG REQUIRED)
find_package(KF5PimCommonAkonadi ${PIMCOMMON_LIB_VERSION} CONFIG REQUIRED)
find_package(KF5AkonadiSearch ${AKONADI_SEARCH_VERSION} CONFIG REQUIRED)
find_package(KF5KaddressbookGrantlee ${KDEPIM_APPS_LIB_VERSION} CONFIG REQUIRED)
find_package(KF5KaddressbookImportExport ${KDEPIM_APPS_LIB_VERSION} CONFIG REQUIRED)
find_package(KF5GrantleeTheme ${LIBGRANTLEETHEME_LIB_VERSION} CONFIG REQUIRED)
set(GPGMEPP_LIB_VERSION "1.11.1")
find_package(Gpgmepp ${GPGMEPP_LIB_VERSION} CONFIG REQUIRED)
find_package(KF5AkonadiSearch ${AKONADI_SEARCH_VERSION} CONFIG REQUIRED)
set_package_properties(KF5AkonadiSearch PROPERTIES DESCRIPTION "The Akonadi Search libraries" URL "https://www.kde.org" TYPE REQUIRED PURPOSE "Provides search capabilities in KMail and Akonadi")
set(QGPGME_LIB_VERSION "1.13.0")
find_package(QGpgme ${QGPGME_LIB_VERSION} CONFIG REQUIRED)
include_directories(${kaddressbook_SOURCE_DIR} ${kaddressbook_BINARY_DIR})
......
......@@ -15,11 +15,7 @@ add_subdirectory(icons)
add_subdirectory(printing)
add_subdirectory(kconf_update)
add_subdirectory(configuration)
if(QGpgme_FOUND)
add_definitions(-DHAVE_QGPGME)
endif()
add_subdirectory(importexport)
set(kaddressbook_qrc_SRCS)
qt5_add_resources(kaddressbook_qrc_SRCS kaddressbook.qrc)
......@@ -54,7 +50,6 @@ if (TARGET KUserFeedbackWidgets)
)
endif()
set(kaddressbook_LIB_SRCS
aboutdata.cpp
categoryfilterproxymodel.cpp
......@@ -91,6 +86,7 @@ target_link_libraries(kaddressbookprivate
PUBLIC
KF5::PimCommonAkonadi
PRIVATE
KPimAddressbookImportExport
KF5::Libkdepim
KF5::KaddressbookGrantlee
KF5::AkonadiCore
......@@ -106,7 +102,6 @@ target_link_libraries(kaddressbookprivate
Qt5::PrintSupport
KF5::AkonadiSearchDebug
KF5::I18n
KF5::KaddressbookImportExport
KF5::Prison
${kaddressbook_userfeedback_LIB}
)
......
......@@ -19,7 +19,7 @@ target_link_libraries(kaddressbook_config_plugins
KF5::PimCommon
kaddressbookprivate
KF5::XmlGui
KF5::KaddressbookImportExport
KPimAddressbookImportExport
)
kcoreaddons_desktop_to_json(kaddressbook_config_plugins kaddressbook_config_plugins.desktop SERVICE_TYPES kcmodule.desktop)
......@@ -39,8 +39,8 @@ if (TARGET KUserFeedbackWidgets)
KF5::I18n
KF5::PimCommon
kaddressbookprivate
KPimAddressbookImportExport
KF5::XmlGui
KF5::KaddressbookImportExport
KUserFeedbackWidgets
)
......
......@@ -6,8 +6,9 @@
#include "kaddressbookconfigpluginlistwidget.h"
#include "../plugininterface/kaddressbookplugininterface.h"
#include <KAddressBookImportExport/KAddressBookImportExportPluginManager>
#include <KAddressBookImportExport/KAddressBookImportExportPlugin>
#include "../importexport/pluginmanager.h"
#include "../importexport/plugin.h"
#include "kaddressbook_configure_debug.h"
#include <KLocalizedString>
#include <PimCommon/GenericPlugin>
......@@ -40,8 +41,8 @@ void KAddressBookConfigPluginListWidget::save()
KAddressBookPluginInterface::self()->configPrefixSettingKey(),
mPluginGenericItems);
PimCommon::ConfigurePluginsListWidget::savePlugins(KAddressBookImportExport::KAddressBookImportExportPluginManager::self()->configGroupName(),
KAddressBookImportExport::KAddressBookImportExportPluginManager::self()->configPrefixSettingKey(),
PimCommon::ConfigurePluginsListWidget::savePlugins(KAddressBookImportExport::PluginManager::self()->configGroupName(),
KAddressBookImportExport::PluginManager::self()->configPrefixSettingKey(),
mPluginImportExportItems);
}
......@@ -68,10 +69,10 @@ void KAddressBookConfigPluginListWidget::initialize()
mPluginGenericItems,
kaddressbookPluginToolsGroupName());
PimCommon::ConfigurePluginsListWidget::fillTopItems(KAddressBookImportExport::KAddressBookImportExportPluginManager::self()->pluginsDataList(),
PimCommon::ConfigurePluginsListWidget::fillTopItems(KAddressBookImportExport::PluginManager::self()->pluginsDataList(),
i18n("Import/Export Plugins"),
KAddressBookImportExport::KAddressBookImportExportPluginManager::self()->configGroupName(),
KAddressBookImportExport::KAddressBookImportExportPluginManager::self()->configPrefixSettingKey(),
KAddressBookImportExport::PluginManager::self()->configGroupName(),
KAddressBookImportExport::PluginManager::self()->configPrefixSettingKey(),
mPluginImportExportItems,
kaddressbookImportExportGroupName());
......@@ -85,7 +86,7 @@ void KAddressBookConfigPluginListWidget::slotConfigureClicked(const QString &con
PimCommon::GenericPlugin *plugin = KAddressBookPluginInterface::self()->pluginFromIdentifier(identifier);
plugin->showConfigureDialog(this);
} else if (configureGroupName == kaddressbookImportExportGroupName()) {
KAddressBookImportExport::KAddressBookImportExportPlugin *plugin = KAddressBookImportExport::KAddressBookImportExportPluginManager::self()->pluginFromIdentifier(identifier);
auto *plugin = KAddressBookImportExport::PluginManager::self()->pluginFromIdentifier(identifier);
plugin->showConfigureDialog(this);
} else {
qCWarning(KADDRESSBOOK_CONFIGURE_LOG) << "Unknown configureGroupName" << configureGroupName;
......
......@@ -10,10 +10,12 @@
#include <KContacts/Addressee>
using namespace KAddressBookImportExport;
class ContactSortHelper
{
public:
ContactSortHelper(KAddressBookImportExport::KAddressBookImportExportContactFields::Field field, Qt::SortOrder sortOrder)
ContactSortHelper(ContactFields::Field field, Qt::SortOrder sortOrder)
: mSortField(field)
, mSortOrder(sortOrder)
{
......@@ -23,26 +25,26 @@ public:
{
int result
= QString::localeAwareCompare(
KAddressBookImportExport::KAddressBookImportExportContactFields::value(mSortField, contact),
KAddressBookImportExport::KAddressBookImportExportContactFields::value(mSortField, otherContact));
ContactFields::value(mSortField, contact),
ContactFields::value(mSortField, otherContact));
if (result == 0) {
int givenNameResult
= QString::localeAwareCompare(
KAddressBookImportExport::KAddressBookImportExportContactFields::value(KAddressBookImportExport::KAddressBookImportExportContactFields::GivenName, contact),
KAddressBookImportExport::KAddressBookImportExportContactFields::value(KAddressBookImportExport::KAddressBookImportExportContactFields::GivenName, otherContact));
ContactFields::value(ContactFields::GivenName, contact),
ContactFields::value(ContactFields::GivenName, otherContact));
if (givenNameResult == 0) {
int familyNameResult
= QString::localeAwareCompare(
KAddressBookImportExport::KAddressBookImportExportContactFields::value(KAddressBookImportExport::KAddressBookImportExportContactFields::FamilyName, contact),
KAddressBookImportExport::KAddressBookImportExportContactFields::value(KAddressBookImportExport::KAddressBookImportExportContactFields::FamilyName, otherContact));
ContactFields::value(ContactFields::FamilyName, contact),
ContactFields::value(ContactFields::FamilyName, otherContact));
if (familyNameResult == 0) {
result
= QString::localeAwareCompare(
KAddressBookImportExport::KAddressBookImportExportContactFields::value(KAddressBookImportExport::KAddressBookImportExportContactFields::FormattedName, contact),
KAddressBookImportExport::KAddressBookImportExportContactFields::value(KAddressBookImportExport::KAddressBookImportExportContactFields::FormattedName, otherContact));
ContactFields::value(ContactFields::FormattedName, contact),
ContactFields::value(ContactFields::FormattedName, otherContact));
} else {
result = familyNameResult;
}
......@@ -61,11 +63,11 @@ public:
}
private:
const KAddressBookImportExport::KAddressBookImportExportContactFields::Field mSortField;
const ContactFields::Field mSortField;
const Qt::SortOrder mSortOrder;
};
ContactSorter::ContactSorter(KAddressBookImportExport::KAddressBookImportExportContactFields::Field field, Qt::SortOrder sortOrder)
ContactSorter::ContactSorter(ContactFields::Field field, Qt::SortOrder sortOrder)
: mSortField(field)
, mSortOrder(sortOrder)
{
......
......@@ -9,17 +9,17 @@
#ifndef CONTACTSORTER_H
#define CONTACTSORTER_H
#include "kaddressbookimportexportcontactfields.h"
#include "importexport/contactfields.h"
class ContactSorter
{
public:
explicit ContactSorter(KAddressBookImportExport::KAddressBookImportExportContactFields::Field field, Qt::SortOrder sortOrder = Qt::AscendingOrder);
explicit ContactSorter(KAddressBookImportExport::ContactFields::Field field, Qt::SortOrder sortOrder = Qt::AscendingOrder);
void sort(KContacts::Addressee::List &contacts) const;
private:
const KAddressBookImportExport::KAddressBookImportExportContactFields::Field mSortField;
const KAddressBookImportExport::ContactFields::Field mSortField;
const Qt::SortOrder mSortOrder;
};
......
ecm_setup_version(PROJECT VARIABLE_PREFIX KADDRESSBOOKIMPORTEXPORT
VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/kaddressbookimportexport_version.h"
PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/KPimAddressbookImportExportConfigVersion.cmake"
SOVERSION 5
)
set(kaddressbook_importexport_LIB_SRCS
contactfields.cpp
contactlist.cpp
contactselectiondialog.cpp
contactselectionwidget.cpp
exportselectionwidget.cpp
importexportengine.cpp
plugin.cpp
plugininterface.cpp
pluginmanager.cpp
)
ecm_qt_declare_logging_category(kaddressbook_importexport_LIB_SRCS
HEADER libkaddressbookexportimport_debug.h
IDENTIFIER LIBKADDRESSBOOKIMPORTEXPORT_LOG
CATEGORY_NAME org.kde.pim.kaddressbookimportexport
DESCRIPTION "kaddressbook (kaddressbookimportexport)"
EXPORT KADDRESSBOOK
)
add_library(KPimAddressbookImportExport ${kaddressbook_importexport_LIB_SRCS})
generate_export_header(KPimAddressbookImportExport BASE_NAME kaddressbook_importexport)
add_library(KPim::AddressbookImportExport ALIAS KPimAddressbookImportExport)
target_include_directories(KPimAddressbookImportExport
INTERFACE "$<INSTALL_INTERFACE:${KDE_INSTALL_INCLUDEDIR}/KPim;${KDE_INSTALL_INCLUDEDIR}/KPim/KAddressBookImportExport/;${KDE_INSTALL_INCLUDEDIR}/KPim/kaddressbookimportexport>"
)
target_include_directories(KPimAddressbookImportExport
PUBLIC "$<BUILD_INTERFACE:${Grantlee_INCLUDE_DIRS}>"
)
target_link_libraries(KPimAddressbookImportExport
PRIVATE
KF5::Contacts
KF5::PimCommon
KF5::I18n
KF5::AkonadiWidgets
)
set_target_properties(KPimAddressbookImportExport PROPERTIES
VERSION ${KDEPIM_LIB_VERSION}
SOVERSION ${KDEPIM_LIB_SOVERSION}
EXPORT_NAME AddressbookImportExport
)
install(TARGETS
KPimAddressbookImportExport
EXPORT KPimAddressbookImportExportTargets ${KF5_INSTALL_TARGETS_DEFAULT_ARGS}
)
ecm_generate_headers(KaddressbookImportExport_CamelCase_HEADERS
HEADER_NAMES
PluginInterface
Plugin
PluginManager
ContactList
ContactFields
ContactSelectionDialog
ContactSelectionWidget
ImportExportEngine
ExportSelectionWidget
REQUIRED_HEADERS KaddressbookImportExport_HEADERS
PREFIX KAddressBookImportExport
)
ecm_generate_pri_file(BASE_NAME KAddressbookImportExport
LIB_NAME KPimAddressbookImportExport
DEPS ""
FILENAME_VAR
PRI_FILENAME
INCLUDE_INSTALL_DIR ${KDE_INSTALL_INCLUDEDIR}/KPim/KAddressbookImportExport
)
######## CMake Config Files ##########
set(CMAKECONFIG_INSTALL_DIR "${KDE_INSTALL_CMAKEPACKAGEDIR}/KPimAddressbookImportExport")
configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/KPimAddressbookImportExportConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/KPimAddressbookImportExportConfig.cmake"
INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR}
)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/KPimAddressbookImportExportConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/KPimAddressbookImportExportConfigVersion.cmake"
DESTINATION "${CMAKECONFIG_INSTALL_DIR}"
COMPONENT Devel
)
install(EXPORT KPimAddressbookImportExportTargets
DESTINATION "${CMAKECONFIG_INSTALL_DIR}"
FILE KPimAddressbookImportExportTargets.cmake
NAMESPACE KPim::
)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/kaddressbookimportexport_version.h
DESTINATION ${KDE_INSTALL_INCLUDEDIR}/KPim COMPONENT Devel
)
install(FILES
${KaddressbookImportExport_CamelCase_HEADERS}
DESTINATION ${KDE_INSTALL_INCLUDEDIR}/KPim/KAddressBookImportExport
COMPONENT Devel
)
install(FILES
${KaddressbookImportExport_HEADERS}
${CMAKE_CURRENT_BINARY_DIR}/kaddressbook_importexport_export.h
contactfields.h
DESTINATION ${KDE_INSTALL_INCLUDEDIR}/KPim/kaddressbookimportexport
COMPONENT Devel
)
install(FILES
${PRI_FILENAME}
DESTINATION ${ECM_MKSPECS_INSTALL_DIR}
)
@PACKAGE_INIT@
include("${CMAKE_CURRENT_LIST_DIR}/KPimAddressbookImportExportTargets.cmake")
/*
This file is part of KAddressBook.
SPDX-FileCopyrightText: 2009 Tobias Koenig <tokoe@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "contactfields.h"
#include <KLocalizedString>
#include <QUrl>
using namespace KAddressBookImportExport;
QString ContactFields::label(Field field)
{
switch (field) {
case Undefined:
return i18nc("@item Undefined import field type", "Undefined");
break;
case FormattedName:
return KContacts::Addressee::formattedNameLabel();
case Prefix:
return KContacts::Addressee::prefixLabel();
case GivenName:
return KContacts::Addressee::givenNameLabel();
case AdditionalName:
return KContacts::Addressee::additionalNameLabel();
case FamilyName:
return KContacts::Addressee::familyNameLabel();
case Suffix:
return KContacts::Addressee::suffixLabel();
case NickName:
return KContacts::Addressee::nickNameLabel();
case Birthday:
return KContacts::Addressee::birthdayLabel();
case Anniversary:
return i18nc("The wedding anniversary of a contact", "Anniversary");
case HomeAddressStreet:
return KContacts::Addressee::homeAddressStreetLabel();
case HomeAddressPostOfficeBox:
return KContacts::Addressee::homeAddressPostOfficeBoxLabel();
case HomeAddressLocality:
return KContacts::Addressee::homeAddressLocalityLabel();
case HomeAddressRegion:
return KContacts::Addressee::homeAddressRegionLabel();
case HomeAddressPostalCode:
return KContacts::Addressee::homeAddressPostalCodeLabel();
case HomeAddressCountry:
return KContacts::Addressee::homeAddressCountryLabel();
case HomeAddressLabel:
return KContacts::Addressee::homeAddressLabelLabel();
case BusinessAddressStreet:
return KContacts::Addressee::businessAddressStreetLabel();
case BusinessAddressPostOfficeBox:
return KContacts::Addressee::businessAddressPostOfficeBoxLabel();
case BusinessAddressLocality:
return KContacts::Addressee::businessAddressLocalityLabel();
case BusinessAddressRegion:
return KContacts::Addressee::businessAddressRegionLabel();
case BusinessAddressPostalCode:
return KContacts::Addressee::businessAddressPostalCodeLabel();
case BusinessAddressCountry:
return KContacts::Addressee::businessAddressCountryLabel();
case BusinessAddressLabel:
return KContacts::Addressee::businessAddressLabelLabel();
case HomePhone:
return KContacts::Addressee::homePhoneLabel();
case BusinessPhone:
return KContacts::Addressee::businessPhoneLabel();
case MobilePhone:
return KContacts::Addressee::mobilePhoneLabel();
case HomeFax:
return KContacts::Addressee::homeFaxLabel();
case BusinessFax:
return KContacts::Addressee::businessFaxLabel();
case CarPhone:
return KContacts::Addressee::carPhoneLabel();
case Isdn:
return KContacts::Addressee::isdnLabel();
case Pager:
return KContacts::Addressee::pagerLabel();
case PreferredEmail:
return i18nc("Preferred email address", "EMail (preferred)");
case Email2:
return i18nc("Second email address", "EMail (2)");
case Email3:
return i18nc("Third email address", "EMail (3)");
case Email4:
return i18nc("Fourth email address", "EMail (4)");
case Mailer:
return KContacts::Addressee::mailerLabel();
case Title:
return KContacts::Addressee::titleLabel();
case Role:
return KContacts::Addressee::roleLabel();
case Organization:
return KContacts::Addressee::organizationLabel();
case Note:
return KContacts::Addressee::noteLabel();
case Homepage:
return KContacts::Addressee::urlLabel();
case BlogFeed:
return i18n("Blog Feed");
case Profession:
return i18n("Profession");
case Office:
return i18n("Office");
case Manager:
return i18n("Manager");
case Assistant:
return i18n("Assistant");
case Spouse:
return i18n("Spouse");
}
return QString();
}
ContactFields::Fields ContactFields::allFields()
{
Fields fields;
fields << Undefined
<< FormattedName
<< Prefix
<< GivenName
<< AdditionalName
<< FamilyName
<< Suffix
<< NickName
<< Birthday
<< Anniversary
<< PreferredEmail
<< Email2
<< Email3
<< Email4
<< HomeAddressStreet
<< HomeAddressPostOfficeBox
<< HomeAddressLocality
<< HomeAddressRegion
<< HomeAddressPostalCode
<< HomeAddressCountry
<< HomeAddressLabel
<< BusinessAddressStreet
<< BusinessAddressPostOfficeBox
<< BusinessAddressLocality
<< BusinessAddressRegion
<< BusinessAddressPostalCode
<< BusinessAddressCountry
<< BusinessAddressLabel
<< HomePhone
<< BusinessPhone
<< MobilePhone
<< HomeFax
<< BusinessFax
<< CarPhone
<< Isdn
<< Pager
<< Mailer
<< Title
<< Role
<< Organization
<< Note
<< Homepage
<< BlogFeed
<< Profession
<< Office
<< Manager
<< Assistant
<< Spouse;
return fields;
}
void ContactFields::setValue(Field field, const QString &value, KContacts::Addressee &contact)
{
switch (field) {
case ContactFields::Undefined:
break;
case ContactFields::FormattedName:
contact.setFormattedName(value);
break;
case ContactFields::GivenName:
contact.setGivenName(value);
break;
case ContactFields::FamilyName:
contact.setFamilyName(value);
break;
case ContactFields::AdditionalName:
contact.setAdditionalName(value);
break;
case ContactFields::Prefix:
contact.setPrefix(value);
break;
case ContactFields::Suffix:
contact.setSuffix(value);
break;
case ContactFields::NickName:
contact.setNickName(value);
break;
case ContactFields::Birthday:
contact.setBirthday(QDate::fromString(value, Qt::ISODate));
break;
case ContactFields::Anniversary:
contact.insertCustom(QStringLiteral("KADDRESSBOOK"),
QStringLiteral("X-Anniversary"), value);
break;
case ContactFields::PreferredEmail:
contact.insertEmail(value, true);
break;
case ContactFields::Email2:
contact.insertEmail(value, false);
break;
case ContactFields::Email3:
contact.insertEmail(value, false);
break;
case ContactFields::Email4:
contact.insertEmail(value, false);
break;
case ContactFields::Role:
contact.setRole(value);
break;
case ContactFields::Title:
contact.setTitle(value);
break;
case ContactFields::Mailer:
contact.setMailer(value);
break;
case ContactFields::Homepage:
{
KContacts::ResourceLocatorUrl url;
url.setUrl(QUrl(value));
contact.setUrl(url);
break;
}
case ContactFields::Organization:
contact.setOrganization(value);
break;
case ContactFields::Note:
contact.setNote(value);
break;
case ContactFields::HomePhone:
{
KContacts::PhoneNumber number = contact.phoneNumber(KContacts::PhoneNumber::Home);
number.setNumber(value);
contact.insertPhoneNumber(number);
break;