Verified Commit cf096a35 authored by Daniel Vrátil's avatar Daniel Vrátil 🤖

Move libkf5kaddressbookimportexport to KAddressBook repo

parent 11e39942
Pipeline #33993 passed with stage
in 17 minutes and 49 seconds
......@@ -67,7 +67,6 @@ set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_subdirectory(kaddressbookgrantlee)
add_subdirectory(kaddressbookimportexport)
feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES)
ecm_qt_install_logging_categories(
......
ecm_setup_version(PROJECT VARIABLE_PREFIX KADDRESSBOOKIMPORTEXPORT
VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/kaddressbookimportexport_version.h"
PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/KF5KaddressbookImportExportConfigVersion.cmake"
SOVERSION 5
)
########### CMake Config Files ###########
set(CMAKECONFIG_INSTALL_DIR "${KDE_INSTALL_CMAKEPACKAGEDIR}/KF5KaddressbookImportExport")
configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/KF5KaddressbookImportExportConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/KF5KaddressbookImportExportConfig.cmake"
INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR}
)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/KF5KaddressbookImportExportConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/KF5KaddressbookImportExportConfigVersion.cmake"
DESTINATION "${CMAKECONFIG_INSTALL_DIR}"
COMPONENT Devel
)
install(EXPORT KF5KaddressbookImportExportTargets DESTINATION "${CMAKECONFIG_INSTALL_DIR}" FILE KF5KaddressbookImportExportTargets.cmake NAMESPACE KF5::)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/kaddressbookimportexport_version.h
DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5} COMPONENT Devel
)
add_subdirectory(src)
if (BUILD_TESTING)
add_subdirectory(autotests)
endif()
@PACKAGE_INIT@
include("${CMAKE_CURRENT_LIST_DIR}/KF5KaddressbookImportExportTargets.cmake")
add_executable( contactfieldstest contactfieldstest.cpp)
add_test(NAME contactfieldstest COMMAND contactfieldstest )
ecm_mark_as_test(kaddrebook-contactfieldstest)
target_link_libraries(contactfieldstest KF5::Contacts Qt5::Test Qt5::Gui KF5::I18n KF5::KaddressbookImportExport)
add_definitions(-DTRANSLATION_DOMAIN=\"libkaddressbookimportexport\")
set(kaddressbook_importexport_LIB_SRCS
kaddressbookimportexportplugin.cpp
kaddressbookimportexportplugininterface.cpp
kaddressbookimportexportpluginmanager.cpp
kaddressbookimportexportcontactlist.cpp
kaddressbookcontactselectionwidget.cpp
kaddressbookcontactselectiondialog.cpp
kaddressbookexportselectionwidget.cpp
kaddressbookimportexportcontactfields.cpp
)
ecm_qt_declare_logging_category(kaddressbook_importexport_LIB_SRCS HEADER libkaddressbookexportimport_debug.h IDENTIFIER LIBKADDRESSBOOKIMPORTEXPORT_LOG CATEGORY_NAME org.kde.pim.kaddressbookimportexport
DESCRIPTION "kdepim-apps-lib (kaddressbookimportexport)"
EXPORT KDEPIMAPPSLIB
)
add_library(KF5KaddressbookImportExport ${kaddressbook_importexport_LIB_SRCS})
generate_export_header(KF5KaddressbookImportExport BASE_NAME kaddressbook_importexport)
add_library(KF5::KaddressbookImportExport ALIAS KF5KaddressbookImportExport)
target_include_directories(KF5KaddressbookImportExport INTERFACE "$<INSTALL_INTERFACE:${KDE_INSTALL_INCLUDEDIR_KF5}/KAddressBookImportExport/;${KDE_INSTALL_INCLUDEDIR_KF5}/kaddressbookimportexport>")
target_include_directories(KF5KaddressbookImportExport PUBLIC "$<BUILD_INTERFACE:${Grantlee_INCLUDE_DIRS}>")
target_link_libraries(KF5KaddressbookImportExport
PRIVATE
KF5::Contacts
KF5::PimCommon
KF5::I18n
KF5::AkonadiWidgets
)
set_target_properties(KF5KaddressbookImportExport PROPERTIES
VERSION ${KADDRESSBOOKIMPORTEXPORT_VERSION_STRING}
SOVERSION ${KADDRESSBOOKIMPORTEXPORT_SOVERSION}
EXPORT_NAME KaddressbookImportExport
)
install(TARGETS
KF5KaddressbookImportExport
EXPORT KF5KaddressbookImportExportTargets ${KF5_INSTALL_TARGETS_DEFAULT_ARGS}
)
ecm_generate_headers(KaddressbookImportExport_CamelCase_HEADERS
HEADER_NAMES
KAddressBookImportExportPluginInterface
KAddressBookImportExportPlugin
KAddressBookImportExportPluginManager
KAddressBookImportExportContactList
KAddressBookContactSelectionDialog
KAddressBookExportSelectionWidget
KAddressBookContactSelectionWidget
REQUIRED_HEADERS KaddressbookImportExport_HEADERS
PREFIX KAddressBookImportExport
)
ecm_generate_pri_file(BASE_NAME KaddressbookImportExport
LIB_NAME KF5KaddressbookImportExport
DEPS "" FILENAME_VAR PRI_FILENAME INCLUDE_INSTALL_DIR ${KDE_INSTALL_INCLUDEDIR_KF5}/KaddressbookImportExport
)
install(FILES
${KaddressbookImportExport_CamelCase_HEADERS}
DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/KAddressBookImportExport
COMPONENT Devel
)
install(FILES
${KaddressbookImportExport_HEADERS}
${CMAKE_CURRENT_BINARY_DIR}/kaddressbook_importexport_export.h
kaddressbookimportexportcontactfields.h
DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/kaddressbookimportexport
COMPONENT Devel
)
install(FILES
${PRI_FILENAME}
DESTINATION ${ECM_MKSPECS_INSTALL_DIR})
#! /bin/sh
$XGETTEXT `find . -name '*.h' -o -name '*.cpp' | grep -v '/autotests/'` -o $podir/libkaddressbookimportexport.pot
/*
SPDX-FileCopyrightText: 2009 Tobias Koenig <tokoe@kde.org>
SPDX-FileCopyrightText: 2015-2020 Laurent Montel <montel@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "kaddressbookcontactselectiondialog.h"
#include "kaddressbookcontactselectionwidget.h"
#include <QVBoxLayout>
#include <KLocalizedString>
#include <QDialogButtonBox>
#include <QPushButton>
using namespace KAddressBookImportExport;
KAddressBookContactSelectionDialog::KAddressBookContactSelectionDialog(QItemSelectionModel *selectionModel, bool allowToSelectTypeToExport, QWidget *parent)
: QDialog(parent)
{
setWindowTitle(i18nc("@title:window", "Select Contacts"));
QVBoxLayout *mainLayout = new QVBoxLayout(this);
mSelectionWidget = new KAddressBookContactSelectionWidget(selectionModel, this);
if (allowToSelectTypeToExport) {
mainLayout->addWidget(mSelectionWidget);
mVCardExport = new KAddressBookExportSelectionWidget(this);
mainLayout->addWidget(mVCardExport);
} else {
mainLayout->addWidget(mSelectionWidget);
}
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
okButton->setDefault(true);
okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
connect(buttonBox, &QDialogButtonBox::accepted, this, &KAddressBookContactSelectionDialog::accept);
connect(buttonBox, &QDialogButtonBox::rejected, this, &KAddressBookContactSelectionDialog::reject);
mainLayout->addWidget(buttonBox);
}
void KAddressBookContactSelectionDialog::setMessageText(const QString &message)
{
mSelectionWidget->setMessageText(message);
}
void KAddressBookContactSelectionDialog::setDefaultAddressBook(const Akonadi::Collection &addressBook)
{
mSelectionWidget->setDefaultAddressBook(addressBook);
}
Akonadi::Item::List KAddressBookContactSelectionDialog::selectedItems() const
{
return mSelectionWidget->selectedItems();
}
KAddressBookImportExport::KAddressBookImportExportContactList KAddressBookContactSelectionDialog::selectedContacts() const
{
return mSelectionWidget->selectedContacts();
}
KAddressBookExportSelectionWidget::ExportFields KAddressBookContactSelectionDialog::exportType() const
{
if (mVCardExport) {
return mVCardExport->exportType();
} else {
return KAddressBookExportSelectionWidget::None;
}
}
void KAddressBookContactSelectionDialog::setAddGroupContact(bool addGroupContact)
{
mSelectionWidget->setAddGroupContact(addGroupContact);
}
/*
SPDX-FileCopyrightText: 2009 Tobias Koenig <tokoe@kde.org>
SPDX-FileCopyrightText: 2015-2020 Laurent Montel <montel@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#ifndef IMPORTEXPORT_KADDRESSBOOKCONTACTSELECTIONDIALOG_H
#define IMPORTEXPORT_KADDRESSBOOKCONTACTSELECTIONDIALOG_H
#include "kaddressbook_importexport_export.h"
#include <KContacts/Addressee>
#include <QDialog>
#include <KAddressBookImportExport/KAddressBookImportExportContactList>
#include <KAddressBookImportExport/KAddressBookExportSelectionWidget>
#include <AkonadiCore/Item>
class QItemSelectionModel;
class KAddressBookContactSelectionWidget;
namespace Akonadi {
class Collection;
}
namespace KAddressBookImportExport {
class KAddressBookExportSelectionWidget;
class KAddressBookContactSelectionWidget;
/**
* @short A dialog to select a group of contacts.
*
* @author Tobias Koenig <tokoe@kde.org>
*/
class KADDRESSBOOK_IMPORTEXPORT_EXPORT KAddressBookContactSelectionDialog : public QDialog
{
Q_OBJECT
public:
/**
* Creates a new contact selection dialog.
*
* @param selectionModel The model that contains the currently selected contacts.
* @param parent The parent widget.
*/
explicit KAddressBookContactSelectionDialog(QItemSelectionModel *selectionModel, bool allowToSelectTypeToExport, QWidget *parent = nullptr);
/**
* Sets the @p message text.
*/
void setMessageText(const QString &message);
/**
* Sets the default addressbook.
*/
void setDefaultAddressBook(const Akonadi::Collection &addressBook);
/**
* Returns the list of selected contacts.
*/
Q_REQUIRED_RESULT KAddressBookImportExport::KAddressBookImportExportContactList selectedContacts() const;
Q_REQUIRED_RESULT KAddressBookExportSelectionWidget::ExportFields exportType() const;
void setAddGroupContact(bool addGroupContact);
Q_REQUIRED_RESULT Akonadi::Item::List selectedItems() const;
private:
KAddressBookContactSelectionWidget *mSelectionWidget = nullptr;
KAddressBookExportSelectionWidget *mVCardExport = nullptr;
};
}
#endif
/*
SPDX-FileCopyrightText: 2009 Tobias Koenig <tokoe@kde.org>
SPDX-FileCopyrightText: 2016-2020 Laurent Montel <montel@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "kaddressbookcontactselectionwidget.h"
#include <QDebug>
#include <AkonadiWidgets/CollectionComboBox>
#include <AkonadiCore/EntityTreeModel>
#include <AkonadiCore/ItemFetchJob>
#include <AkonadiCore/ItemFetchScope>
#include <AkonadiCore/RecursiveItemFetchJob>
#include <KLocalizedString>
#include <QButtonGroup>
#include <QCheckBox>
#include <QGridLayout>
#include <QGroupBox>
#include <QItemSelectionModel>
#include <QLabel>
#include <QProgressDialog>
#include <QRadioButton>
#include <QVBoxLayout>
#include <QApplication>
using namespace KAddressBookImportExport;
KAddressBookContactSelectionWidget::KAddressBookContactSelectionWidget(QItemSelectionModel *selectionModel, QWidget *parent)
: QWidget(parent)
, mSelectionModel(selectionModel)
{
initGui();
mSelectedContactsButton->setEnabled(mSelectionModel->hasSelection());
mAddressBookSelection->setEnabled(false);
mAddressBookSelectionRecursive->setEnabled(false);
connect(mAddressBookContactsButton, &QRadioButton::toggled, mAddressBookSelection, &Akonadi::CollectionComboBox::setEnabled);
connect(mAddressBookContactsButton, &QRadioButton::toggled, mAddressBookSelectionRecursive, &QCheckBox::setEnabled);
// apply default configuration
if (mSelectionModel->hasSelection()) {
mSelectedContactsButton->setChecked(true);
} else {
mAllContactsButton->setChecked(true);
}
}
void KAddressBookContactSelectionWidget::setMessageText(const QString &message)
{
if (!message.isEmpty()) {
mMessageLabel->setText(message);
mMessageLabel->show();
}
}
void KAddressBookContactSelectionWidget::setDefaultAddressBook(const Akonadi::Collection &addressBook)
{
mAddressBookSelection->setDefaultCollection(addressBook);
}
Akonadi::Item::List KAddressBookContactSelectionWidget::selectedItems() const
{
if (mAllContactsButton->isChecked()) {
return collectAllItems();
} else if (mSelectedContactsButton->isChecked()) {
return collectSelectedItems();
} else if (mAddressBookContactsButton->isChecked()) {
return collectAddressBookItems();
} else {
qWarning() << " It's a bug here.";
}
return Akonadi::Item::List();
}
KAddressBookImportExport::KAddressBookImportExportContactList KAddressBookContactSelectionWidget::selectedContacts() const
{
if (mAllContactsButton->isChecked()) {
return collectAllContacts();
} else if (mSelectedContactsButton->isChecked()) {
return collectSelectedContacts();
} else if (mAddressBookContactsButton->isChecked()) {
return collectAddressBookContacts();
}
return KAddressBookImportExport::KAddressBookImportExportContactList();
}
void KAddressBookContactSelectionWidget::setAddGroupContact(bool addGroupContact)
{
mAddContactGroup = addGroupContact;
}
void KAddressBookContactSelectionWidget::initGui()
{
QVBoxLayout *layout = new QVBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
mMessageLabel = new QLabel;
layout->addWidget(mMessageLabel);
mMessageLabel->hide();
QButtonGroup *group = new QButtonGroup(this);
QGroupBox *groupBox = new QGroupBox;
QGridLayout *boxLayout = new QGridLayout;
groupBox->setLayout(boxLayout);
mAllContactsButton = new QRadioButton(i18nc("@option:radio", "All contacts"));
mAllContactsButton->setToolTip(
i18nc("@info:tooltip", "All contacts from all your address books"));
mAllContactsButton->setWhatsThis(
i18nc("@info:whatsthis",
"Choose this option you want to select all your contacts from "
"all your address books."));
mSelectedContactsButton = new QRadioButton(i18nc("@option:radio", "Selected contacts"));
mSelectedContactsButton->setToolTip(
i18nc("@info:tooltip", "Only the contacts currently selected"));
mSelectedContactsButton->setWhatsThis(
i18nc("@info:whatsthis",
"Choose this option if you want only the contacts you have already "
"selected in the graphical interface."));
mAddressBookContactsButton = new QRadioButton(i18nc("@option:radio", "All contacts from:"));
mAddressBookContactsButton->setToolTip(
i18nc("@info:tooltip", "All contacts from a chosen address book"));
mAddressBookContactsButton->setWhatsThis(
i18nc("@info:whatsthis",
"Choose this option if you want to select all the contacts from only one "
"of your address books. Once this option is clicked you will be provided "
"a drop down box listing all those address books and permitted to select "
"the one you want."));
mAddressBookSelection = new Akonadi::CollectionComboBox;
mAddressBookSelection->setMimeTypeFilter(QStringList() << KContacts::Addressee::mimeType());
mAddressBookSelection->setAccessRightsFilter(Akonadi::Collection::ReadOnly);
mAddressBookSelection->setExcludeVirtualCollections(true);
mAddressBookSelectionRecursive = new QCheckBox(i18nc("@option:check", "Include Subfolders"));
mAddressBookSelectionRecursive->setToolTip(
i18nc("@info:tooltip", "Select all subfolders including the top-level folder"));
mAddressBookSelectionRecursive->setWhatsThis(
i18nc("@info:whatsthis",
"Check this box if you want to select all contacts from this folder, "
"including all subfolders. If you only want the contacts from the "
"top-level folder then leave this box unchecked."));
group->addButton(mAllContactsButton);
group->addButton(mSelectedContactsButton);
group->addButton(mAddressBookContactsButton);
boxLayout->addWidget(mAllContactsButton, 0, 0, 1, 2);
boxLayout->addWidget(mSelectedContactsButton, 1, 0, 1, 2);
boxLayout->addWidget(mAddressBookContactsButton, 2, 0, Qt::AlignTop);
QVBoxLayout *addressBookLayout = new QVBoxLayout;
addressBookLayout->setContentsMargins(0, 0, 0, 0);
addressBookLayout->addWidget(mAddressBookSelection);
addressBookLayout->addWidget(mAddressBookSelectionRecursive);
boxLayout->addLayout(addressBookLayout, 2, 1);
layout->addWidget(groupBox);
layout->addStretch(1);
}
Akonadi::Item::List KAddressBookContactSelectionWidget::collectAllItems() const
{
Akonadi::RecursiveItemFetchJob *job
= new Akonadi::RecursiveItemFetchJob(Akonadi::Collection::root(),
QStringList() << KContacts::Addressee::mimeType());
job->fetchScope().fetchFullPayload();
QProgressDialog progressDialog(nullptr);
progressDialog.setWindowTitle(i18nc("@title:window", "Collect Contacts"));
progressDialog.setAutoClose(true);
progressDialog.setMinimumDuration(1000);
progressDialog.setLabelText(i18n("Fetch Contacts"));
progressDialog.show();
qApp->processEvents();
if (!job->exec()) {
return Akonadi::Item::List();
}
return job->items();
}
KAddressBookImportExport::KAddressBookImportExportContactList KAddressBookContactSelectionWidget::collectAllContacts() const
{
KAddressBookImportExport::KAddressBookImportExportContactList contacts;
Akonadi::RecursiveItemFetchJob *job
= new Akonadi::RecursiveItemFetchJob(Akonadi::Collection::root(),
QStringList() << KContacts::Addressee::mimeType());
job->fetchScope().fetchFullPayload();
if (!job->exec()) {
return contacts;
}
const Akonadi::Item::List lstItems = job->items();
for (const Akonadi::Item &item : lstItems) {
if (item.isValid()) {
if (item.hasPayload<KContacts::Addressee>()) {
contacts.append(item.payload<KContacts::Addressee>());
}
}
}
return contacts;
}
Akonadi::Item::List KAddressBookContactSelectionWidget::collectSelectedItems() const
{
Akonadi::Item::List items;
const QModelIndexList indexes = mSelectionModel->selectedRows(0);
for (int i = 0, total = indexes.count(); i < total; ++i) {
const QModelIndex index = indexes.at(i);
if (index.isValid()) {
const Akonadi::Item item
= index.data(Akonadi::EntityTreeModel::ItemRole).value<Akonadi::Item>();
if (item.isValid()) {
items.append(item);
}
}
}
return items;
}
KAddressBookImportExport::KAddressBookImportExportContactList KAddressBookContactSelectionWidget::collectSelectedContacts() const
{
KAddressBookImportExport::KAddressBookImportExportContactList contacts;
const QModelIndexList indexes = mSelectionModel->selectedRows(0);
for (int i = 0, total = indexes.count(); i < total; ++i) {
const QModelIndex index = indexes.at(i);
if (index.isValid()) {
const Akonadi::Item item
= index.data(Akonadi::EntityTreeModel::ItemRole).value<Akonadi::Item>();
if (item.isValid()) {
if (item.hasPayload<KContacts::Addressee>()) {
contacts.append(item.payload<KContacts::Addressee>());
}
}
}
}
return contacts;
}
Akonadi::Item::List KAddressBookContactSelectionWidget::collectAddressBookItems() const
{
Akonadi::Item::List items;
const Akonadi::Collection collection = mAddressBookSelection->currentCollection();
if (!collection.isValid()) {
return items;
}
if (mAddressBookSelectionRecursive->isChecked()) {
Akonadi::RecursiveItemFetchJob *job
= new Akonadi::RecursiveItemFetchJob(collection,
QStringList() << KContacts::Addressee::mimeType());
job->fetchScope().fetchFullPayload();
if (!job->exec()) {
return items;
}
items = job->items();
} else {
Akonadi::ItemFetchJob *job = new Akonadi::ItemFetchJob(collection);
job->fetchScope().fetchFullPayload();
if (!job->exec()) {
return items;
}
items = job->items();
}
return items;
}
KAddressBookImportExport::KAddressBookImportExportContactList KAddressBookContactSelectionWidget::collectAddressBookContacts() const
{
KAddressBookImportExport::KAddressBookImportExportContactList contacts;
const Akonadi::Collection collection = mAddressBookSelection->currentCollection();
if (!collection.isValid()) {
return contacts;
}
if (mAddressBookSelectionRecursive->isChecked()) {
Akonadi::RecursiveItemFetchJob *job
= new Akonadi::RecursiveItemFetchJob(collection,
QStringList() << KContacts::Addressee::mimeType());
job->fetchScope().fetchFullPayload();
if (!job->exec()) {
return contacts;
}
const Akonadi::Item::List lstItems = job->items();
for (const Akonadi::Item &item : lstItems) {
if (item.hasPayload<KContacts::Addressee>()) {
contacts.append(item.payload<KContacts::Addressee>());