File indexing completed on 2025-01-05 04:58:19
0001 /* 0002 This file is part of libkdepim. 0003 0004 SPDX-FileCopyrightText: 2006 Christian Schaarschmidt <schaarsc@gmx.de> 0005 SPDX-FileCopyrightText: 2017-2024 Laurent Montel <montel@kde.org> 0006 0007 SPDX-License-Identifier: LGPL-2.0-or-later 0008 */ 0009 0010 #pragma once 0011 0012 #include <KCompletion> 0013 0014 #include <QMap> 0015 #include <QString> 0016 #include <QStringList> 0017 0018 namespace PimCommon 0019 { 0020 /** 0021 * KMailCompletion allows lookup of email addresses by keyword. 0022 * This is used for lookup by nickname, since we don't want the nickname to appear in the final email. 0023 * E.g. you have a nickname "idiot" for your boss, you want to type "idiot" but you want the completion 0024 * to offer "Full Name <email@domain>", without the nickname being visible. 0025 */ 0026 class KMailCompletion : public KCompletion 0027 { 0028 Q_OBJECT 0029 0030 public: 0031 KMailCompletion(); 0032 0033 /** 0034 * clears internal keyword map and calls KCompletion::clear. 0035 */ 0036 void clear() override; 0037 0038 /** 0039 * uses KCompletion::makeCompletion to find email addresses which starts 0040 * with string. ignores keywords. 0041 * 0042 * @returns email address 0043 */ 0044 QString makeCompletion(const QString &string) override; 0045 0046 /** 0047 * specify keywords for email. 0048 * 0049 * Items may be added with KCompletion::addItem, those will only be 0050 * returned as match if they are in one of these formats: 0051 * \li contains localpart@domain 0052 * \li contains <email> 0053 * or if they have also been added with this function. 0054 */ 0055 void addItemWithKeys(const QString &email, int weight, const QStringList *keyWords); 0056 0057 /** 0058 * use internal map to replace all keywords in pMatches with corresponding 0059 * email addresses. 0060 */ 0061 void postProcessMatches(QStringList *pMatches) const override; 0062 0063 // We are not using allWeightedMatches() anywhere, therefore we don't need 0064 // to override the other postProcessMatches() function 0065 using KCompletion::postProcessMatches; 0066 0067 private: 0068 QMap<QString, QStringList> m_keyMap; 0069 }; 0070 }