Pimcommon

addresseelineedit.h
1/*
2 This file is part of libkdepim.
3
4 SPDX-FileCopyrightText: 2002 Helge Deller <deller@gmx.de>
5 SPDX-FileCopyrightText: 2002 Lubos Lunak <llunak@suse.cz>
6 SPDX-FileCopyrightText: 2001, 2003 Carsten Pfeiffer <pfeiffer@kde.org>
7 SPDX-FileCopyrightText: 2001 Waldo Bastian <bastian@kde.org>
8 SPDX-FileCopyrightText: 2004 Daniel Molkentin <danimo@klaralvdalens-datakonsult.se>
9 SPDX-FileCopyrightText: 2004 Karl-Heinz Zimmer <khz@klaralvdalens-datakonsult.se>
10 SPDX-FileCopyrightText: 2017-2025 Laurent Montel <montel@kde.org>
11
12 SPDX-License-Identifier: LGPL-2.0-or-later
13*/
14
15#pragma once
16
17#include "pimcommonakonadi_export.h"
18
19#include <KLineEdit>
20
21class QDropEvent;
22class QEvent;
23class QKeyEvent;
24class QMenu;
25class QMouseEvent;
26class KJob;
27class KConfig;
28namespace Akonadi
29{
30class Item;
31}
32
33namespace KContacts
34{
35class Addressee;
36class ContactGroup;
37}
38namespace KLDAPCore
39{
40class LdapClientSearch;
41class LdapActivitiesAbstract;
42}
43
44namespace PimCommon
45{
46class AddresseeLineEditPrivate;
47class PIMCOMMONAKONADI_EXPORT AddresseeLineEdit : public KLineEdit
48{
49 Q_OBJECT
50
51public:
52 /**
53 * Creates a new addressee line edit.
54 *
55 * @param parent The parent object.
56 * @param enableCompletion Whether autocompletion shall be enabled.
57 */
58 explicit AddresseeLineEdit(QWidget *parent = nullptr, bool enableCompletion = true);
59
60 /**
61 * Destroys the addressee line edit.
62 */
63 ~AddresseeLineEdit() override;
64
65 /**
66 * Sets whether semicolons are allowed as separators.
67 */
68 void allowSemicolonAsSeparator(bool allow);
69
70 /**
71 * Reimplemented for setting the @p font for line edit and completion box.
72 */
73 void setFont(const QFont &font);
74
75 void setEnableBalooSearch(bool enable);
76 [[nodiscard]] bool enableBalooSearch() const;
77
78 void setEnableAkonadiSearch(bool enable);
79 [[nodiscard]] bool enableAkonadiSearch() const;
80
81 void setExpandIntern(bool);
82 [[nodiscard]] bool expandIntern() const;
83
84 [[nodiscard]] bool isCompletionEnabled() const;
85
86 /**
87 * Adds a new @p contact to the completion with a given
88 * @p weight
89 * @p source index
90 * @p append is added to completion string, but removed, when mail is selected.
91 */
92 void addContact(const KContacts::Addressee &contact, int weight, int source = -1, const QString &append = QString());
93
94 /**
95 * Same as the above, but this time with contact groups.
96 */
97 void addContactGroup(const KContacts::ContactGroup &group, int weight, int source = -1);
98
99 void addItem(const Akonadi::Item &item, int weight, int source = -1);
100
101 /**
102 * Adds the @p name of a completion source and its @p weight
103 * to the internal list of completion sources and returns its index,
104 * which can be used for insertion of items associated with that source.
105 *
106 * If the source already exists, the weight will be updated.
107 */
108 [[nodiscard]] int addCompletionSource(const QString &name, int weight);
109
110 void removeCompletionSource(const QString &source);
111 void emitTextCompleted();
112
113 void callUserCancelled(const QString &str);
114 void callSetCompletedText(const QString & /*text*/, bool /*marked*/);
115 void callSetCompletedText(const QString &text);
116 void callSetUserSelection(bool);
117
118 void updateBalooBlackList();
119 void updateCompletionOrder();
120 [[nodiscard]] KLDAPCore::LdapClientSearch *ldapSearch() const;
121
122 void setShowRecentAddresses(bool b);
123 [[nodiscard]] bool showRecentAddresses() const;
124
125 void setRecentAddressConfig(KConfig *config);
126 [[nodiscard]] KConfig *recentAddressConfig() const;
127
128 void configureCompletion();
129
130 void setIcon(const QIcon &icon, const QString &tooltip = QString());
131
132 [[nodiscard]] bool canDeleteLineEdit() const;
133 void setLdapActivitiesAbstract(KLDAPCore::LdapActivitiesAbstract *ldapActivities);
134Q_SIGNALS:
135 void textCompleted();
136 void addAddress(const QString &address);
137 void iconClicked();
138
139public Q_SLOTS:
140 /**
141 * Moves the cursor at the end of the line edit.
142 */
143 void cursorAtEnd();
144
145 /**
146 * Sets whether autocompletion shall be enabled.
147 */
148 void enableCompletion(bool enable);
149
150 /**
151 * Reimplemented for stripping whitespace after completion
152 * Danger: This is _not_ virtual in the base class!
153 */
154 void setText(const QString &text) override;
155
156 void expandGroups();
157 void slotEditingFinished();
158 void slotGroupSearchResult(KJob *job);
159
160protected:
161 /**
162 * Reimplemented for smart insertion of email addresses.
163 * Features:
164 * - Automatically adds ',' if necessary to separate email addresses
165 * - Correctly decodes mailto URLs
166 * - Recognizes email addresses which are protected against address
167 * harvesters, i.e. "name at kde dot org" and "name(at)kde.org"
168 */
169 virtual void insert(const QString &);
170
171 /**
172 * Reimplemented for smart insertion of pasted email addresses.
173 */
174 virtual void paste();
175
176 /**
177 * Reimplemented for smart insertion with middle mouse button.
178 */
179 void mouseReleaseEvent(QMouseEvent *) override;
180
181 /**
182 * Reimplemented for smart insertion of dragged email addresses.
183 */
184 void dropEvent(QDropEvent *) override;
185
186 /**
187 * Reimplemented for internal reasons.
188 */
189 void keyPressEvent(QKeyEvent *) override;
190
191 /**
192 * Reimplemented for subclass access to menu
193 */
194 virtual QMenu *createStandardContextMenu();
195
196 /**
197 * Reimplemented for internal reasons. API not affected.
198 *
199 * See QLineEdit::contextMenuEvent().
200 */
201 void contextMenuEvent(QContextMenuEvent *) override;
202
203 void insertEmails(const QStringList &emails);
204 void loadContacts();
205
206private:
207 PIMCOMMONAKONADI_NO_EXPORT void addContact(const QStringList &emails, const KContacts::Addressee &addr, int weight, int source, QString append = QString());
208 PIMCOMMONAKONADI_NO_EXPORT void groupExpandResult(KJob *job);
209 bool eventFilter(QObject *, QEvent *) override;
210
211 AddresseeLineEditPrivate *const d;
212};
213}
bool insert(Part *part, qint64 *insertId=nullptr)
QAction * paste(const QObject *recvr, const char *slot, QObject *parent)
folderdialogacltab.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Jan 3 2025 11:57:39 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.