File indexing completed on 2025-01-05 04:58:18
0001 /* 0002 This file is part of libkdepim. 0003 0004 SPDX-FileCopyrightText: 2002 Helge Deller <deller@gmx.de> 0005 SPDX-FileCopyrightText: 2002 Lubos Lunak <llunak@suse.cz> 0006 SPDX-FileCopyrightText: 2001, 2003 Carsten Pfeiffer <pfeiffer@kde.org> 0007 SPDX-FileCopyrightText: 2001 Waldo Bastian <bastian@kde.org> 0008 SPDX-FileCopyrightText: 2004 Daniel Molkentin <danimo@klaralvdalens-datakonsult.se> 0009 SPDX-FileCopyrightText: 2004 Karl-Heinz Zimmer <khz@klaralvdalens-datakonsult.se> 0010 SPDX-FileCopyrightText: 2017-2024 Laurent Montel <montel@kde.org> 0011 0012 SPDX-License-Identifier: LGPL-2.0-or-later 0013 */ 0014 0015 #pragma once 0016 0017 #include "pimcommonakonadi_export.h" 0018 0019 #include <KLineEdit> 0020 0021 class QDropEvent; 0022 class QEvent; 0023 class QKeyEvent; 0024 class QMenu; 0025 class QMouseEvent; 0026 class QObject; 0027 class KJob; 0028 class KConfig; 0029 namespace Akonadi 0030 { 0031 class Item; 0032 } 0033 0034 namespace KContacts 0035 { 0036 class Addressee; 0037 class ContactGroup; 0038 } 0039 namespace KLDAPWidgets 0040 { 0041 class LdapClientSearch; 0042 } 0043 0044 namespace PimCommon 0045 { 0046 class AddresseeLineEditPrivate; 0047 class PIMCOMMONAKONADI_EXPORT AddresseeLineEdit : public KLineEdit 0048 { 0049 Q_OBJECT 0050 0051 public: 0052 /** 0053 * Creates a new addressee line edit. 0054 * 0055 * @param parent The parent object. 0056 * @param enableCompletion Whether autocompletion shall be enabled. 0057 */ 0058 explicit AddresseeLineEdit(QWidget *parent = nullptr, bool enableCompletion = true); 0059 0060 /** 0061 * Destroys the addressee line edit. 0062 */ 0063 ~AddresseeLineEdit() override; 0064 0065 /** 0066 * Sets whether semicolons are allowed as separators. 0067 */ 0068 void allowSemicolonAsSeparator(bool allow); 0069 0070 /** 0071 * Reimplemented for setting the @p font for line edit and completion box. 0072 */ 0073 void setFont(const QFont &font); 0074 0075 void setEnableBalooSearch(bool enable); 0076 [[nodiscard]] bool enableBalooSearch() const; 0077 0078 void setEnableAkonadiSearch(bool enable); 0079 [[nodiscard]] bool enableAkonadiSearch() const; 0080 0081 void setExpandIntern(bool); 0082 [[nodiscard]] bool expandIntern() const; 0083 0084 [[nodiscard]] bool isCompletionEnabled() const; 0085 0086 /** 0087 * Adds a new @p contact to the completion with a given 0088 * @p weight 0089 * @p source index 0090 * @p append is added to completion string, but removed, when mail is selected. 0091 */ 0092 void addContact(const KContacts::Addressee &contact, int weight, int source = -1, const QString &append = QString()); 0093 0094 /** 0095 * Same as the above, but this time with contact groups. 0096 */ 0097 void addContactGroup(const KContacts::ContactGroup &group, int weight, int source = -1); 0098 0099 void addItem(const Akonadi::Item &item, int weight, int source = -1); 0100 0101 /** 0102 * Adds the @p name of a completion source and its @p weight 0103 * to the internal list of completion sources and returns its index, 0104 * which can be used for insertion of items associated with that source. 0105 * 0106 * If the source already exists, the weight will be updated. 0107 */ 0108 [[nodiscard]] int addCompletionSource(const QString &name, int weight); 0109 0110 void removeCompletionSource(const QString &source); 0111 void emitTextCompleted(); 0112 0113 void callUserCancelled(const QString &str); 0114 void callSetCompletedText(const QString & /*text*/, bool /*marked*/); 0115 void callSetCompletedText(const QString &text); 0116 void callSetUserSelection(bool); 0117 0118 void updateBalooBlackList(); 0119 void updateCompletionOrder(); 0120 [[nodiscard]] KLDAPWidgets::LdapClientSearch *ldapSearch() const; 0121 0122 void setShowRecentAddresses(bool b); 0123 [[nodiscard]] bool showRecentAddresses() const; 0124 0125 void setRecentAddressConfig(KConfig *config); 0126 [[nodiscard]] KConfig *recentAddressConfig() const; 0127 0128 void configureCompletion(); 0129 0130 void setIcon(const QIcon &icon, const QString &tooltip = QString()); 0131 0132 [[nodiscard]] bool canDeleteLineEdit() const; 0133 Q_SIGNALS: 0134 void textCompleted(); 0135 void addAddress(const QString &address); 0136 void iconClicked(); 0137 0138 public Q_SLOTS: 0139 /** 0140 * Moves the cursor at the end of the line edit. 0141 */ 0142 void cursorAtEnd(); 0143 0144 /** 0145 * Sets whether autocompletion shall be enabled. 0146 */ 0147 void enableCompletion(bool enable); 0148 0149 /** 0150 * Reimplemented for stripping whitespace after completion 0151 * Danger: This is _not_ virtual in the base class! 0152 */ 0153 void setText(const QString &text) override; 0154 0155 void expandGroups(); 0156 void slotEditingFinished(); 0157 void slotGroupSearchResult(KJob *job); 0158 0159 protected: 0160 /** 0161 * Reimplemented for smart insertion of email addresses. 0162 * Features: 0163 * - Automatically adds ',' if necessary to separate email addresses 0164 * - Correctly decodes mailto URLs 0165 * - Recognizes email addresses which are protected against address 0166 * harvesters, i.e. "name at kde dot org" and "name(at)kde.org" 0167 */ 0168 virtual void insert(const QString &); 0169 0170 /** 0171 * Reimplemented for smart insertion of pasted email addresses. 0172 */ 0173 virtual void paste(); 0174 0175 /** 0176 * Reimplemented for smart insertion with middle mouse button. 0177 */ 0178 void mouseReleaseEvent(QMouseEvent *) override; 0179 0180 #ifndef QT_NO_DRAGANDDROP 0181 /** 0182 * Reimplemented for smart insertion of dragged email addresses. 0183 */ 0184 void dropEvent(QDropEvent *) override; 0185 #endif 0186 0187 /** 0188 * Reimplemented for internal reasons. 0189 */ 0190 void keyPressEvent(QKeyEvent *) override; 0191 0192 #ifndef QT_NO_CONTEXTMENU 0193 /** 0194 * Reimplemented for subclass access to menu 0195 */ 0196 virtual QMenu *createStandardContextMenu(); 0197 0198 /** 0199 * Reimplemented for internal reasons. API not affected. 0200 * 0201 * See QLineEdit::contextMenuEvent(). 0202 */ 0203 void contextMenuEvent(QContextMenuEvent *) override; 0204 #endif 0205 0206 void insertEmails(const QStringList &emails); 0207 void loadContacts(); 0208 0209 private: 0210 PIMCOMMONAKONADI_NO_EXPORT void addContact(const QStringList &emails, const KContacts::Addressee &addr, int weight, int source, QString append = QString()); 0211 PIMCOMMONAKONADI_NO_EXPORT void groupExpandResult(KJob *job); 0212 bool eventFilter(QObject *, QEvent *) override; 0213 0214 AddresseeLineEditPrivate *const d; 0215 }; 0216 }