diff --git a/src/akonadi-contacts/job/contactgroupsearchjob.cpp b/src/akonadi-contacts/job/contactgroupsearchjob.cpp index 3cb31fc5..f59376a0 100644 --- a/src/akonadi-contacts/job/contactgroupsearchjob.cpp +++ b/src/akonadi-contacts/job/contactgroupsearchjob.cpp @@ -1,103 +1,103 @@ /* This file is part of Akonadi Contact. Copyright (c) 2009 Tobias Koenig This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "contactgroupsearchjob.h" #include #include #include using namespace Akonadi; class Q_DECL_HIDDEN ContactGroupSearchJob::Private { public: - int mLimit; + int mLimit = -1; }; ContactGroupSearchJob::ContactGroupSearchJob(QObject *parent) : ItemSearchJob(parent) , d(new Private) { fetchScope().fetchFullPayload(); d->mLimit = -1; setMimeTypes(QStringList() << KContacts::ContactGroup::mimeType()); // by default search for all contact groups Akonadi::SearchQuery query; query.addTerm(ContactSearchTerm(ContactSearchTerm::All, QVariant(), SearchTerm::CondEqual)); ItemSearchJob::setQuery(query); } ContactGroupSearchJob::~ContactGroupSearchJob() { delete d; } void ContactGroupSearchJob::setQuery(Criterion criterion, const QString &value) { // Exact match was the default in 4.4, so we have to keep it and ContactSearchJob has something // else as default setQuery(criterion, value, ExactMatch); } static Akonadi::SearchTerm::Condition matchType(ContactGroupSearchJob::Match match) { switch (match) { case ContactGroupSearchJob::ExactMatch: return Akonadi::SearchTerm::CondEqual; case ContactGroupSearchJob::StartsWithMatch: case ContactGroupSearchJob::ContainsMatch: return Akonadi::SearchTerm::CondContains; } return Akonadi::SearchTerm::CondEqual; } void ContactGroupSearchJob::setQuery(Criterion criterion, const QString &value, Match match) { Akonadi::SearchQuery query; if (criterion == Name) { query.addTerm(ContactSearchTerm(ContactSearchTerm::Name, value, matchType(match))); } query.setLimit(d->mLimit); ItemSearchJob::setQuery(query); } void ContactGroupSearchJob::setLimit(int limit) { d->mLimit = limit; } KContacts::ContactGroup::List ContactGroupSearchJob::contactGroups() const { KContacts::ContactGroup::List contactGroups; const Akonadi::Item::List lstItems = items(); for (const Item &item : lstItems) { if (item.hasPayload()) { contactGroups.append(item.payload()); } } return contactGroups; } diff --git a/src/akonadi-contacts/job/contactsearchjob.cpp b/src/akonadi-contacts/job/contactsearchjob.cpp index 9e711517..0ca3db78 100644 --- a/src/akonadi-contacts/job/contactsearchjob.cpp +++ b/src/akonadi-contacts/job/contactsearchjob.cpp @@ -1,107 +1,107 @@ /* This file is part of Akonadi Contact. Copyright (c) 2009 Tobias Koenig This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "contactsearchjob.h" #include #include using namespace Akonadi; class Q_DECL_HIDDEN ContactSearchJob::Private { public: - int mLimit; + int mLimit = -1; }; ContactSearchJob::ContactSearchJob(QObject *parent) : ItemSearchJob(parent) , d(new Private()) { fetchScope().fetchFullPayload(); d->mLimit = -1; setMimeTypes(QStringList() << KContacts::Addressee::mimeType()); // by default search for all contacts Akonadi::SearchQuery query; query.addTerm(ContactSearchTerm(ContactSearchTerm::All, QVariant(), SearchTerm::CondEqual)); ItemSearchJob::setQuery(query); } ContactSearchJob::~ContactSearchJob() { delete d; } static Akonadi::SearchTerm::Condition matchType(ContactSearchJob::Match match) { switch (match) { case ContactSearchJob::ExactMatch: return Akonadi::SearchTerm::CondEqual; case ContactSearchJob::StartsWithMatch: case ContactSearchJob::ContainsWordBoundaryMatch: case ContactSearchJob::ContainsMatch: return Akonadi::SearchTerm::CondContains; } return Akonadi::SearchTerm::CondEqual; } void ContactSearchJob::setQuery(Criterion criterion, const QString &value, Match match) { Akonadi::SearchQuery query(SearchTerm::RelOr); if (criterion == Name) { query.addTerm(ContactSearchTerm(ContactSearchTerm::Name, value, matchType(match))); } else if (criterion == Email) { query.addTerm(ContactSearchTerm(ContactSearchTerm::Email, value, matchType(match))); } else if (criterion == NickName) { query.addTerm(ContactSearchTerm(ContactSearchTerm::Nickname, value, matchType(match))); } else if (criterion == NameOrEmail) { query.addTerm(ContactSearchTerm(ContactSearchTerm::Name, value, matchType(match))); query.addTerm(ContactSearchTerm(ContactSearchTerm::Email, value, matchType(match))); } else if (criterion == ContactUid) { query.addTerm(ContactSearchTerm(ContactSearchTerm::Uid, value, matchType(match))); } query.setLimit(d->mLimit); ItemSearchJob::setQuery(query); } void ContactSearchJob::setLimit(int limit) { d->mLimit = limit; } KContacts::Addressee::List ContactSearchJob::contacts() const { KContacts::Addressee::List contacts; const Akonadi::Item::List lstItems = items(); for (const Item &item : lstItems) { if (item.hasPayload()) { contacts.append(item.payload()); } } return contacts; }