Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 05e5670d authored by Laurent Montel's avatar Laurent Montel 😁

Allow to fix only on emails and name

CCBUG: 387598
parent a59264c3
......@@ -27,22 +27,25 @@
#include <kcontacts/addressee.h>
#include <kcontacts/contactgroup.h>
static bool contactMatchesFilter(const KContacts::Addressee &contact, const QString &filterString);
using namespace Akonadi;
static bool contactMatchesFilter(const KContacts::Addressee &contact, const QString &filterString, ContactsFilterProxyModel::MatchFilterContactFlag flag);
static bool contactGroupMatchesFilter(const KContacts::ContactGroup &group, const QString &filterString);
using namespace Akonadi;
class Q_DECL_HIDDEN ContactsFilterProxyModel::Private
{
public:
Private()
: flags(nullptr)
: flags(0)
, matchFilterFlag(ContactsFilterProxyModel::MatchFilterContactFlag::All)
, mExcludeVirtualCollections(false)
{
}
QString mFilter;
ContactsFilterProxyModel::FilterFlags flags;
ContactsFilterProxyModel::MatchFilterContactFlag matchFilterFlag;
bool mExcludeVirtualCollections;
};
......@@ -90,7 +93,7 @@ bool ContactsFilterProxyModel::filterAcceptsRow(int row, const QModelIndex &pare
}
}
if (!d->mFilter.isEmpty()) {
return contactMatchesFilter(contact, d->mFilter);
return contactMatchesFilter(contact, d->mFilter, d->matchFilterFlag);
}
} else {
if (!d->mFilter.isEmpty()) {
......@@ -123,6 +126,11 @@ bool ContactsFilterProxyModel::lessThan(const QModelIndex &leftIndex, const QMod
return QSortFilterProxyModel::lessThan(leftIndex, rightIndex);
}
void ContactsFilterProxyModel::setMatchFilterContactFlag(ContactsFilterProxyModel::MatchFilterContactFlag flag)
{
d->matchFilterFlag = flag;
}
void ContactsFilterProxyModel::setFilterFlags(ContactsFilterProxyModel::FilterFlags flags)
{
d->flags = flags;
......@@ -182,7 +190,7 @@ static bool addressMatchesFilter(const KContacts::Address &address, const QStrin
return false;
}
static bool contactMatchesFilter(const KContacts::Addressee &contact, const QString &filterString)
static bool contactMatchesFilter(const KContacts::Addressee &contact, const QString &filterString, ContactsFilterProxyModel::MatchFilterContactFlag flag)
{
if (contact.assembledName().contains(filterString, Qt::CaseInsensitive)) {
return true;
......@@ -196,23 +204,26 @@ static bool contactMatchesFilter(const KContacts::Addressee &contact, const QStr
return true;
}
if (contact.birthday().toString().contains(filterString, Qt::CaseInsensitive)) {
return true;
}
const KContacts::Address::List addresses = contact.addresses();
int count = addresses.count();
for (int i = 0; i < count; ++i) {
if (addressMatchesFilter(addresses.at(i), filterString)) {
int count = 0;
if (flag == ContactsFilterProxyModel::MatchFilterContactFlag::All) {
if (contact.birthday().toString().contains(filterString, Qt::CaseInsensitive)) {
return true;
}
}
const KContacts::Address::List addresses = contact.addresses();
count = addresses.count();
for (int i = 0; i < count; ++i) {
if (addressMatchesFilter(addresses.at(i), filterString)) {
return true;
}
}
const KContacts::PhoneNumber::List phoneNumbers = contact.phoneNumbers();
count = phoneNumbers.count();
for (int i = 0; i < count; ++i) {
if (phoneNumbers.at(i).number().contains(filterString, Qt::CaseInsensitive)) {
return true;
const KContacts::PhoneNumber::List phoneNumbers = contact.phoneNumbers();
count = phoneNumbers.count();
for (int i = 0; i < count; ++i) {
if (phoneNumbers.at(i).number().contains(filterString, Qt::CaseInsensitive)) {
return true;
}
}
}
......@@ -224,48 +235,50 @@ static bool contactMatchesFilter(const KContacts::Addressee &contact, const QStr
}
}
const QStringList categories = contact.categories();
count = categories.count();
for (int i = 0; i < count; ++i) {
if (categories.at(i).contains(filterString, Qt::CaseInsensitive)) {
if (flag == ContactsFilterProxyModel::MatchFilterContactFlag::All) {
const QStringList categories = contact.categories();
count = categories.count();
for (int i = 0; i < count; ++i) {
if (categories.at(i).contains(filterString, Qt::CaseInsensitive)) {
return true;
}
}
if (contact.mailer().contains(filterString, Qt::CaseInsensitive)) {
return true;
}
}
if (contact.mailer().contains(filterString, Qt::CaseInsensitive)) {
return true;
}
if (contact.title().contains(filterString, Qt::CaseInsensitive)) {
return true;
}
if (contact.role().contains(filterString, Qt::CaseInsensitive)) {
return true;
}
if (contact.title().contains(filterString, Qt::CaseInsensitive)) {
return true;
}
if (contact.organization().contains(filterString, Qt::CaseInsensitive)) {
return true;
}
if (contact.role().contains(filterString, Qt::CaseInsensitive)) {
return true;
}
if (contact.department().contains(filterString, Qt::CaseInsensitive)) {
return true;
}
if (contact.organization().contains(filterString, Qt::CaseInsensitive)) {
return true;
}
if (contact.note().contains(filterString, Qt::CaseInsensitive)) {
return true;
}
if (contact.department().contains(filterString, Qt::CaseInsensitive)) {
return true;
}
if (contact.url().url().url().contains(filterString, Qt::CaseInsensitive)) {
return true;
}
if (contact.note().contains(filterString, Qt::CaseInsensitive)) {
return true;
}
const QStringList customs = contact.customs();
count = customs.count();
for (int i = 0; i < count; ++i) {
if (customs.at(i).contains(filterString, Qt::CaseInsensitive)) {
if (contact.url().url().url().contains(filterString, Qt::CaseInsensitive)) {
return true;
}
const QStringList customs = contact.customs();
count = customs.count();
for (int i = 0; i < count; ++i) {
if (customs.at(i).contains(filterString, Qt::CaseInsensitive)) {
return true;
}
}
}
return false;
......
......@@ -61,7 +61,10 @@ class AKONADI_CONTACT_EXPORT ContactsFilterProxyModel : public QSortFilterProxyM
Q_OBJECT
public:
enum MatchFilterContactFlag {
All = 0,
OnlyNameAndEmailsAddresses = 1
};
enum FilterFlag {
HasEmail = 0x01 /// Filters out contacts without any email address set.
};
......@@ -87,6 +90,15 @@ public:
*/
void setFilterFlags(ContactsFilterProxyModel::FilterFlags flags);
/**
* @brief setMatchFilterContactFlag
* @param flag
* @since 5.8.0
*
*/
void setMatchFilterContactFlag(ContactsFilterProxyModel::MatchFilterContactFlag flag);
Qt::ItemFlags flags(const QModelIndex &index) const override;
/**
......
......@@ -138,6 +138,7 @@ void EmailAddressSelectionWidget::Private::init()
if (mShowOnlyContactWithEmail) {
filter->setFilterFlags(ContactsFilterProxyModel::HasEmail);
}
filter->setMatchFilterContactFlag(ContactsFilterProxyModel::MatchFilterContactFlag::OnlyNameAndEmailsAddresses);
filter->setExcludeVirtualCollections(true);
filter->setSourceModel(mModel);
......
Markdown is supported
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