diff --git a/src/libkdepimakonadi/CMakeLists.txt b/src/libkdepimakonadi/CMakeLists.txt index b760fd5..efda1b9 100644 --- a/src/libkdepimakonadi/CMakeLists.txt +++ b/src/libkdepimakonadi/CMakeLists.txt @@ -1,243 +1,234 @@ ecm_setup_version(PROJECT VARIABLE_PREFIX LIBKDEPIM VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/libkdepimakonadi_version.h" PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/KF5LibkdepimAkonadiConfigVersion.cmake" SOVERSION 5 ) if(BUILD_TESTING) add_subdirectory(tests) if (NOT FORCE_DISABLE_AKONADI_SEARCH) add_subdirectory(addressline/blacklistbaloocompletion/autotests) endif() add_subdirectory(addressline/autotests/) endif() add_subdirectory(designer) set(kdepim_addressline_LIB_SRCS addressline/completionorder/completionordereditor.cpp addressline/completionorder/completionorderwidget.cpp addressline/addresslineedit/addresseelineedit.cpp addressline/addresslineedit/addresseelineedit_p.cpp addressline/addresslineedit/addresseelineeditmanager.cpp addressline/addresslineedit/addresseelineeditldap.cpp addressline/addresslineedit/addresseelineeditakonadi.cpp addressline/addresslineedit/addresseelineeditbaloo.cpp addressline/addresslineedit/kmailcompletion.cpp addressline/addresslineedit/baloocompletionemail.cpp addressline/completionconfiguredialog/completionconfiguredialog.cpp ) if (NOT FORCE_DISABLE_AKONADI_SEARCH) set(kdepim_addressline_blacklist_baloo_LIB_SRCS addressline/blacklistbaloocompletion/blacklistbalooemaillist.cpp addressline/blacklistbaloocompletion/blacklistbalooemailutil.cpp addressline/blacklistbaloocompletion/blacklistbalooemailcompletionwidget.cpp addressline/blacklistbaloocompletion/blacklistbalooemailwarning.cpp addressline/blacklistbaloocompletion/blacklistbalooemailsearchjob.cpp ) endif() set(kdepim_addressline_plugin_LIB_SRCS addressline/plugins/addressesslineeditabstractplugin.cpp addressline/plugins/addressesslineeditpluginmanager.cpp ) ############ next target ############### set(kdepimakonadi_progresswidget_LIB_SRCS progresswidget/progressmanagerakonadi.cpp progresswidget/agentprogressmonitor.cpp ) set(kdepim_job_LIB_SRCS job/addemailaddressjob.cpp job/addcontactjob.cpp job/openemailaddressjob.cpp job/addemaildisplayjob.cpp ) -if (NOT FORCE_DISABLE_AKONADI_SEARCH) - list(APPEND kdepim_job_LIB_SRCS - job/collectionsearchjob.cpp - job/personsearchjob.cpp - ) -endif() set(kdepimakonadi_widgets_LIB_SRCS widgets/tagwidgets.cpp widgets/tagselectioncombo.cpp ) set(kdepimakonadi_LIB_SRCS ${kdepim_job_LIB_SRCS} ${kdepimakonadi_widgets_LIB_SRCS} ${kdepim_addressline_LIB_SRCS} ${kdepim_addressline_blacklist_baloo_LIB_SRCS} ${kdepimakonadi_progresswidget_LIB_SRCS} ${kdepim_addressline_plugin_LIB_SRCS} ) ecm_qt_declare_logging_category(kdepimakonadi_LIB_SRCS HEADER libkdepimakonadi_debug.h IDENTIFIER LIBKDEPIMAKONADI_LOG CATEGORY_NAME org.kde.pim.libkdepimakonadi) add_library(KF5LibkdepimAkonadi ${kdepimakonadi_LIB_SRCS}) generate_export_header(KF5LibkdepimAkonadi BASE_NAME kdepimakonadi) add_library(KF5::LibkdepimAkonadi ALIAS KF5LibkdepimAkonadi) target_include_directories(KF5LibkdepimAkonadi INTERFACE "$") target_include_directories(KF5LibkdepimAkonadi PUBLIC "$") target_link_libraries(KF5LibkdepimAkonadi PUBLIC KF5::AkonadiCore KF5::AkonadiContact KF5::Libkdepim KF5::Completion PRIVATE KF5::AkonadiWidgets KF5::Ldap KF5::Contacts KF5::Codecs KF5::I18n KF5::ItemViews KF5::KIOCore KF5::KIOWidgets Qt5::DBus Qt5::Network KF5::ConfigWidgets ) if(MINGW) target_link_libraries(KF5LibkdepimAkonadi PRIVATE oleaut32) endif() if (NOT FORCE_DISABLE_AKONADI_SEARCH) target_link_libraries(KF5LibkdepimAkonadi PRIVATE KF5::AkonadiSearchPIM) endif() set_target_properties(KF5LibkdepimAkonadi PROPERTIES VERSION ${LIBKDEPIM_VERSION_STRING} SOVERSION ${LIBKDEPIM_SOVERSION} EXPORT_NAME LibkdepimAkonadi ) install(TARGETS KF5LibkdepimAkonadi EXPORT KF5LibkdepimAkonadiTargets ${KF5_INSTALL_TARGETS_DEFAULT_ARGS} ${LIBRARY_NAMELINK} ) ecm_generate_headers(libkdepimakonadi_Camelcasewidgets_HEADERS HEADER_NAMES TagSelectionCombo TagWidgets REQUIRED_HEADERS libkdepimakonadi_widgets_HEADERS PREFIX LibkdepimAkonadi RELATIVE widgets ) ecm_generate_headers(libkdepimakonadi_Camelcaseprogresswidget_HEADERS HEADER_NAMES ProgressManagerAkonadi REQUIRED_HEADERS libkdepimakonadi_progresswidget_HEADERS PREFIX LibkdepimAkonadi RELATIVE progresswidget ) ecm_generate_headers(libkdepim_Camelcasejob_HEADERS HEADER_NAMES AddContactJob AddEmailAddressJob AddEmailDisplayJob - CollectionSearchJob OpenEmailAddressJob - PersonSearchJob - Person REQUIRED_HEADERS libkdepim_job_HEADERS PREFIX LibkdepimAkonadi RELATIVE job ) ecm_generate_headers(libkdepim_Camelcaseaddressline_HEADERS HEADER_NAMES AddresseeLineEdit REQUIRED_HEADERS libkdepim_addressline_HEADERS PREFIX LibkdepimAkonadi RELATIVE addressline/addresslineedit/ ) ecm_generate_headers(libkdepim_Camelcasecompletionorder_HEADERS HEADER_NAMES CompletionOrderEditor REQUIRED_HEADERS libkdepim_completionorder_HEADERS PREFIX LibkdepimAkonadi RELATIVE addressline/completionorder ) ecm_generate_headers(libkdepim_Camelcasecompletionconfiguredialog_HEADERS HEADER_NAMES CompletionConfigureDialog REQUIRED_HEADERS libkdepim_completionconfiguredialog_HEADERS PREFIX LibkdepimAkonadi RELATIVE addressline/completionconfiguredialog/ ) ecm_generate_pri_file(BASE_NAME LibkdepimAkonadi LIB_NAME KF5LibkdepimAkonadi DEPS "AkonadiCore AkonadiContact Libkdepim" FILENAME_VAR PRI_FILENAME INCLUDE_INSTALL_DIR ${KDE_INSTALL_INCLUDEDIR_KF5}/LibkdepimAkonadi ) install(FILES ${libkdepim_Camelcasecompletionconfiguredialog_HEADERS} ${libkdepim_Camelcasecompletionorder_HEADERS} ${libkdepimakonadi_Camelcaseprogresswidget_HEADERS} ${libkdepimakonadi_Camelcasewidgets_HEADERS} ${libkdepim_Camelcasejob_HEADERS} ${libkdepim_Camelcaseaddressline_HEADERS} DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/LibkdepimAkonadi COMPONENT Devel ) install(FILES ${libkdepim_completionconfiguredialog_HEADERS} ${libkdepim_completionorder_HEADERS} ${CMAKE_CURRENT_BINARY_DIR}/kdepimakonadi_export.h ${libkdepimakonadi_progresswidget_HEADERS} ${libkdepimakonadi_widgets_HEADERS} ${libkdepim_job_HEADERS} ${libkdepim_addressline_HEADERS} DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/libkdepimakonadi COMPONENT Devel ) install(FILES ${PRI_FILENAME} DESTINATION ${ECM_MKSPECS_INSTALL_DIR}) set(CMAKECONFIG_INSTALL_DIR "${KDE_INSTALL_CMAKEPACKAGEDIR}/KF5LibkdepimAkonadi") install(EXPORT KF5LibkdepimAkonadiTargets DESTINATION "${CMAKECONFIG_INSTALL_DIR}" FILE KF5LibkdepimAkonadiTargets.cmake NAMESPACE KF5::) configure_package_config_file( "${CMAKE_CURRENT_SOURCE_DIR}/KF5LibkdepimAkonadiConfig.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/KF5LibkdepimAkonadiConfig.cmake" INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR} ) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/KF5LibkdepimAkonadiConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/KF5LibkdepimAkonadiConfigVersion.cmake" DESTINATION "${CMAKECONFIG_INSTALL_DIR}" COMPONENT Devel ) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libkdepimakonadi_version.h DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5} COMPONENT Devel ) diff --git a/src/libkdepimakonadi/job/collectionsearchjob.cpp b/src/libkdepimakonadi/job/collectionsearchjob.cpp deleted file mode 100644 index 8030c67..0000000 --- a/src/libkdepimakonadi/job/collectionsearchjob.cpp +++ /dev/null @@ -1,157 +0,0 @@ -/* -Copyright (C) 2014 Christian Mollekopf - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License along -with this program; if not, write to the Free Software Foundation, Inc., -51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -As a special exception, permission is given to link this program -with any edition of Qt, and distribute the resulting executable, -without including the source code for Qt in the source distribution. -*/ -#include "collectionsearchjob.h" -#include "libkdepimakonadi_debug.h" - -#include -#include -#include - -using namespace KPIM; -class KPIM::CollectionSearchJobPrivate -{ -public: - CollectionSearchJobPrivate(const QString &searchString, const QStringList &mimetypeFilter) - : mSearchString(searchString) - , mMimeTypeFilter(mimetypeFilter) - { - } - - QString mSearchString; - QStringList mMimeTypeFilter; - Akonadi::Collection::List mMatchingCollections; - Akonadi::Collection::List mAncestors; -}; - -CollectionSearchJob::CollectionSearchJob(const QString &searchString, const QStringList &mimetypeFilter, QObject *parent) - : KJob(parent) - , d(new KPIM::CollectionSearchJobPrivate(searchString, mimetypeFilter)) -{ -} - -CollectionSearchJob::~CollectionSearchJob() -{ - delete d; -} - -void CollectionSearchJob::start() -{ - Akonadi::Search::PIM::CollectionQuery query; - if (d->mSearchString == QLatin1String("*")) { - query.setNamespace(QStringList() << QStringLiteral("")); - } else { - //We exclude the other users namespace - query.setNamespace(QStringList() << QStringLiteral("shared") << QStringLiteral("")); - query.pathMatches(d->mSearchString); - } - query.setMimetype(d->mMimeTypeFilter); - query.setLimit(200); - Akonadi::Search::PIM::ResultIterator it = query.exec(); - Akonadi::Collection::List collections; - while (it.next()) { - collections << Akonadi::Collection(it.id()); - } - qCDebug(LIBKDEPIMAKONADI_LOG) << "Found collections " << collections.size(); - - if (collections.isEmpty()) { - //We didn't find anything - emitResult(); - return; - } - - Akonadi::CollectionFetchJob *fetchJob = new Akonadi::CollectionFetchJob(collections, Akonadi::CollectionFetchJob::Base, this); - fetchJob->fetchScope().setAncestorRetrieval(Akonadi::CollectionFetchScope::All); - fetchJob->fetchScope().setListFilter(Akonadi::CollectionFetchScope::NoFilter); - fetchJob->fetchScope().setIgnoreRetrievalErrors(true); - connect(fetchJob, &Akonadi::CollectionFetchJob::collectionsReceived, this, &CollectionSearchJob::onCollectionsReceived); - connect(fetchJob, &Akonadi::CollectionFetchJob::result, this, &CollectionSearchJob::onCollectionsFetched); -} - -void CollectionSearchJob::onCollectionsReceived(const Akonadi::Collection::List &list) -{ - for (const Akonadi::Collection &col : list) { - d->mMatchingCollections << col; - Akonadi::Collection ancestor = col.parentCollection(); - while (ancestor.isValid() && (ancestor != Akonadi::Collection::root())) { - if (!d->mAncestors.contains(ancestor)) { - d->mAncestors << ancestor; - } - ancestor = ancestor.parentCollection(); - } - } -} - -void CollectionSearchJob::onCollectionsFetched(KJob *job) -{ - if (job->error()) { - qCWarning(LIBKDEPIMAKONADI_LOG) << job->errorString(); - emitResult(); - return; - } - if (!d->mAncestors.isEmpty()) { - Akonadi::CollectionFetchJob *fetchJob = new Akonadi::CollectionFetchJob(d->mAncestors, Akonadi::CollectionFetchJob::Base, this); - fetchJob->fetchScope().setListFilter(Akonadi::CollectionFetchScope::NoFilter); - connect(fetchJob, &Akonadi::CollectionFetchJob::result, this, &CollectionSearchJob::onAncestorsFetched); - } else { - //We didn't find anything - emitResult(); - } -} - -static Akonadi::Collection replaceParent(Akonadi::Collection col, const Akonadi::Collection::List &ancestors) -{ - if (!col.isValid()) { - return col; - } - const Akonadi::Collection parent = replaceParent(col.parentCollection(), ancestors); - for (const Akonadi::Collection &c : ancestors) { - if (col == c) { - col = c; - break; - } - } - col.setParentCollection(parent); - return col; -} - -void CollectionSearchJob::onAncestorsFetched(KJob *job) -{ - if (job->error()) { - qCWarning(LIBKDEPIMAKONADI_LOG) << job->errorString(); - emitResult(); - return; - } - Akonadi::CollectionFetchJob *fetchJob = static_cast(job); - Akonadi::Collection::List matchingCollections; - matchingCollections.reserve(d->mMatchingCollections.count()); - for (const Akonadi::Collection &c : qAsConst(d->mMatchingCollections)) { - //We need to replace the parents with the version that contains the name, so we can display it accordingly - matchingCollections << replaceParent(c, fetchJob->collections()); - } - d->mMatchingCollections = matchingCollections; - emitResult(); -} - -Akonadi::Collection::List CollectionSearchJob::matchingCollections() const -{ - return d->mMatchingCollections; -} diff --git a/src/libkdepimakonadi/job/collectionsearchjob.h b/src/libkdepimakonadi/job/collectionsearchjob.h deleted file mode 100644 index 1df9a4e..0000000 --- a/src/libkdepimakonadi/job/collectionsearchjob.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - Copyright (C) 2014 Christian Mollekopf - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - As a special exception, permission is given to link this program - with any edition of Qt, and distribute the resulting executable, - without including the source code for Qt in the source distribution. -*/ - -#ifndef KDEPIM_COLLECTIONSEARCHJOB_H -#define KDEPIM_COLLECTIONSEARCHJOB_H - -#include "kdepimakonadi_export.h" - -#include -#include -#include - -namespace KPIM { -class CollectionSearchJobPrivate; -class KDEPIMAKONADI_EXPORT CollectionSearchJob : public KJob -{ - Q_OBJECT -public: - explicit CollectionSearchJob(const QString &searchString, const QStringList &mimetypeFilter, QObject *parent = nullptr); - ~CollectionSearchJob() override; - void start() override; - - Akonadi::Collection::List matchingCollections() const; - -private: - void onCollectionsReceived(const Akonadi::Collection::List &); - void onCollectionsFetched(KJob *); - void onAncestorsFetched(KJob *); - CollectionSearchJobPrivate *const d; -}; -} - -#endif diff --git a/src/libkdepimakonadi/job/person.h b/src/libkdepimakonadi/job/person.h deleted file mode 100644 index ee14593..0000000 --- a/src/libkdepimakonadi/job/person.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - Copyright (C) 2014 Christian Mollekopf - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - As a special exception, permission is given to link this program - with any edition of Qt, and distribute the resulting executable, - without including the source code for Qt in the source distribution. -*/ - -#ifndef KDEPIM_PERSON_H -#define KDEPIM_PERSON_H - -#include "kdepimakonadi_export.h" - -#include -#include - -namespace KPIM { -struct KDEPIMAKONADI_EXPORT Person { - Person() - : rootCollection(-1) - , updateDisplayName(false) - { - } - - QString name; - QString uid; - QString ou; - QString mail; - - //FIXME not sure we actually require those two - QStringList folderPaths; - QList collections; - - Akonadi::Collection::Id rootCollection; - bool updateDisplayName; -}; -} - -Q_DECLARE_METATYPE(KPIM::Person) -Q_DECLARE_TYPEINFO(KPIM::Person, Q_MOVABLE_TYPE); - -#endif diff --git a/src/libkdepimakonadi/job/personsearchjob.cpp b/src/libkdepimakonadi/job/personsearchjob.cpp deleted file mode 100644 index 31a9757..0000000 --- a/src/libkdepimakonadi/job/personsearchjob.cpp +++ /dev/null @@ -1,275 +0,0 @@ -/* - Copyright (C) 2014 Christian Mollekopf - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - As a special exception, permission is given to link this program - with any edition of Qt, and distribute the resulting executable, - without including the source code for Qt in the source distribution. -*/ -#include "personsearchjob.h" -#include "libkdepimakonadi_debug.h" - -#include -#include -#include -#include -#include -#include - -using namespace KPIM; - -class KPIM::PersonSearchJobPrivate -{ -public: - PersonSearchJobPrivate(const QString &searchString) - : mSearchString(searchString) - , mCollectionSearchDone(false) - , mLdapSearchDone(false) - { - } - - ~PersonSearchJobPrivate() - { - mLdapSearch.cancelSearch(); - } - - QString mSearchString; - QHash mMatches; - KLDAP::LdapClientSearch mLdapSearch; - bool mCollectionSearchDone; - bool mLdapSearchDone; -}; - -PersonSearchJob::PersonSearchJob(const QString &searchString, QObject *parent) - : KJob(parent) - , d(new KPIM::PersonSearchJobPrivate(searchString)) -{ - connect(&d->mLdapSearch, QOverload::of(&KLDAP::LdapClientSearch::searchData), this, &PersonSearchJob::onLDAPSearchData); - - connect(&d->mLdapSearch, &KLDAP::LdapClientSearch::searchDone, this, &PersonSearchJob::onLDAPSearchDone); -} - -PersonSearchJob::~PersonSearchJob() -{ - delete d; -} - -bool PersonSearchJob::kill(KJob::KillVerbosity verbosity) -{ - d->mLdapSearch.cancelSearch(); - return KJob::kill(verbosity); -} - -void PersonSearchJob::start() -{ - Akonadi::Search::PIM::CollectionQuery query; - query.setNamespace(QStringList() << QStringLiteral("usertoplevel")); - query.nameMatches(d->mSearchString); - query.setLimit(200); - Akonadi::Search::PIM::ResultIterator it = query.exec(); - Akonadi::Collection::List collections; - while (it.next()) { - collections << Akonadi::Collection(it.id()); - } - qCDebug(LIBKDEPIMAKONADI_LOG) << "Found persons " << collections.size(); - - d->mCollectionSearchDone = false; - d->mLdapSearchDone = false; - if (collections.isEmpty()) { - //We didn't find anything - d->mCollectionSearchDone = true; - } - - d->mLdapSearch.startSearch(QStringLiteral("*") + d->mSearchString); - - if (!collections.isEmpty()) { - Akonadi::CollectionFetchJob *fetchJob = new Akonadi::CollectionFetchJob(collections, Akonadi::CollectionFetchJob::Base, this); - fetchJob->fetchScope().setAncestorRetrieval(Akonadi::CollectionFetchScope::All); - fetchJob->fetchScope().setListFilter(Akonadi::CollectionFetchScope::NoFilter); - connect(fetchJob, &Akonadi::CollectionFetchJob::collectionsReceived, this, &PersonSearchJob::onCollectionsReceived); - connect(fetchJob, &Akonadi::CollectionFetchJob::result, this, &PersonSearchJob::onCollectionsFetched); - } - - //The IMAP resource should add a "Person" attribute to the collections in the person namespace, - //the ldap query can then be used to update the name (entitydisplayattribute) for the person. -} - -void PersonSearchJob::onLDAPSearchData(const KLDAP::LdapResultObject::List &list) -{ - QVector persons; - for (const KLDAP::LdapResultObject &item : list) { - Person person; - person.name = QString::fromUtf8(item.object.value(QStringLiteral("cn"))); - person.mail = QString::fromUtf8(item.object.value(QStringLiteral("mail"))); - - const int depth = item.object.dn().depth(); - for (int i = 0; i < depth; ++i) { - const QString rdnStr = item.object.dn().rdnString(i); - if (rdnStr.startsWith(QLatin1String("ou="), Qt::CaseInsensitive)) { - person.ou = rdnStr.mid(3); - break; - } - } - const QStringList &parts = person.mail.split(QLatin1Char('@')); - if (parts.count() == 2) { - const QString &uid = parts.at(0); - person.uid = uid; - if (d->mMatches.contains(uid)) { - const Person &p = d->mMatches.value(uid); - if (p.mail != person.mail) { - if (p.rootCollection > -1) { - person.rootCollection = p.rootCollection; - person.updateDisplayName = p.updateDisplayName; - updatePersonCollection(person); - d->mMatches.insert(uid, person); - } else { - qCWarning(LIBKDEPIMAKONADI_LOG) << "That should not happen: we found two times persons with the same uid (" << uid << "), but differnet name:" << p.name << "vs" << person.name; - } - } - } else { //New person found - d->mMatches.insert(uid, person); - persons << person; - } - } else { - qCWarning(LIBKDEPIMAKONADI_LOG) << item.object.dn().toString() << ": invalid email address" << person.mail; - } - } - if (!persons.isEmpty()) { - Q_EMIT personsFound(persons); - } -} - -void PersonSearchJob::onLDAPSearchDone() -{ - d->mLdapSearchDone = true; - if (d->mCollectionSearchDone) { - emitResult(); - } -} - -void PersonSearchJob::onCollectionsReceived(const Akonadi::Collection::List &list) -{ - QVector persons; - for (const Akonadi::Collection &col : list) { - Person person; - const QString &uid = col.name(); - const Akonadi::CollectionIdentificationAttribute *const attr = col.attribute(); - const Akonadi::EntityDisplayAttribute *const displayname = col.attribute(); - person.rootCollection = col.id(); - person.uid = uid; - if (attr) { - person.ou = QString::fromUtf8(attr->ou()); - person.mail = QString::fromUtf8(attr->mail()); - person.name = QString::fromUtf8(attr->identifier()); - if (!displayname || displayname->displayName().isEmpty() || displayname->displayName() == person.name) { - person.updateDisplayName = true; - } - } else { - person.name = col.displayName(); - if (!displayname || displayname->displayName().isEmpty()) { - person.updateDisplayName = true; - } - } - if (d->mMatches.contains(uid)) { - Person p = d->mMatches.value(uid); - if (p.rootCollection > -1) { - //two collection with the same uid ?! - qCWarning(LIBKDEPIMAKONADI_LOG) << "Two collections match to same person" << p.rootCollection << person.rootCollection; - } else if (p.mail != person.mail) { - p.rootCollection = person.rootCollection; - p.updateDisplayName = person.updateDisplayName; - updatePersonCollection(p); - } else { - d->mMatches.insert(uid, person); - Q_EMIT personUpdate(person); - } - } else { - d->mMatches.insert(uid, person); - persons << person; - } - } - - if (!persons.isEmpty()) { - Q_EMIT personsFound(persons); - } -} - -void PersonSearchJob::updatePersonCollection(const Person &person) -{ - Akonadi::Collection c(person.rootCollection); - Akonadi::CollectionIdentificationAttribute *identification = c.attribute(Akonadi::Collection::AddIfMissing); - - if (person.updateDisplayName) { - Akonadi::EntityDisplayAttribute *displayname = c.attribute(Akonadi::Collection::AddIfMissing); - displayname->setDisplayName(person.name); - } - - //identification->setIdentifier("Other Users/" + person.uid); - identification->setIdentifier(person.name.toUtf8()); - identification->setName(person.name.toUtf8()); - identification->setCollectionNamespace("usertoplevel"); - identification->setMail(person.mail.toUtf8()); - identification->setOu(person.ou.toUtf8()); - - Akonadi::CollectionModifyJob *job = new Akonadi::CollectionModifyJob(c, this); - connect(job, &Akonadi::CollectionModifyJob::result, this, &PersonSearchJob::modifyResult); -} - -void PersonSearchJob::onCollectionsFetched(KJob *job) -{ - if (job->error()) { - qCWarning(LIBKDEPIMAKONADI_LOG) << job->errorString(); - } - d->mCollectionSearchDone = true; - if (d->mLdapSearchDone) { - emitResult(); - } -} - -QList PersonSearchJob::matches() const -{ - return d->mMatches.values(); -} - -void PersonSearchJob::modifyResult(KJob *job) -{ - if (job->error()) { - qCWarning(LIBKDEPIMAKONADI_LOG) << job->errorString(); - return; - } - - const Akonadi::CollectionModifyJob *modifyJob = static_cast(job); - const Akonadi::Collection &col = modifyJob->collection(); - - const Akonadi::CollectionIdentificationAttribute *const attr = col.attribute(); - const Akonadi::EntityDisplayAttribute *const displayname = col.attribute(); - const QString &uid = col.name(); - Person &person = d->mMatches[col.name()]; - person.rootCollection = col.id(); - person.uid = uid; - if (attr) { - person.ou = QString::fromUtf8(attr->ou()); - person.mail = QString::fromUtf8(attr->mail()); - person.name = QString::fromUtf8(attr->identifier()); - if (!displayname || displayname->displayName().isEmpty() || displayname->displayName() == person.name) { - person.updateDisplayName = true; - } - } - qCDebug(LIBKDEPIMAKONADI_LOG) << "modified person to" << person.uid << person.name << person.rootCollection; - - d->mMatches.insert(person.uid, person); - Q_EMIT personUpdate(person); -} diff --git a/src/libkdepimakonadi/job/personsearchjob.h b/src/libkdepimakonadi/job/personsearchjob.h deleted file mode 100644 index bbe3dbc..0000000 --- a/src/libkdepimakonadi/job/personsearchjob.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - Copyright (C) 2014 Christian Mollekopf - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - As a special exception, permission is given to link this program - with any edition of Qt, and distribute the resulting executable, - without including the source code for Qt in the source distribution. -*/ - -#ifndef KDEPIM_PERSONSEARCHJOB_H -#define KDEPIM_PERSONSEARCHJOB_H - -#include "kdepimakonadi_export.h" - -#include -#include -#include -#include "person.h" - -namespace KPIM { -class PersonSearchJobPrivate; -class KDEPIMAKONADI_EXPORT PersonSearchJob : public KJob -{ - Q_OBJECT -public: - explicit PersonSearchJob(const QString &searchString, QObject *parent = nullptr); - ~PersonSearchJob() override; - - void start() override; - - QList matches() const; - -Q_SIGNALS: - void personsFound(const QVector &persons); - void personUpdate(const Person &person); - -public Q_SLOTS: - bool kill(KillVerbosity verbosity = Quietly); - -private Q_SLOTS: - void onCollectionsReceived(const Akonadi::Collection::List &); - void onCollectionsFetched(KJob *); - void onLDAPSearchData(const KLDAP::LdapResultObject::List &); - void onLDAPSearchDone(); - void updatePersonCollection(const Person &person); - void modifyResult(KJob *job); - -private: - PersonSearchJobPrivate *const d; -}; -} - -#endif