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-2024 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 QObject;
27class KJob;
28class KConfig;
29namespace Akonadi
30{
31class Item;
32}
33
34namespace KContacts
35{
36class Addressee;
37class ContactGroup;
38}
39namespace KLDAPCore
40{
41class LdapClientSearch;
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;
133Q_SIGNALS:
134 void textCompleted();
135 void addAddress(const QString &address);
136 void iconClicked();
137
138public Q_SLOTS:
139 /**
140 * Moves the cursor at the end of the line edit.
141 */
142 void cursorAtEnd();
143
144 /**
145 * Sets whether autocompletion shall be enabled.
146 */
147 void enableCompletion(bool enable);
148
149 /**
150 * Reimplemented for stripping whitespace after completion
151 * Danger: This is _not_ virtual in the base class!
152 */
153 void setText(const QString &text) override;
154
155 void expandGroups();
156 void slotEditingFinished();
157 void slotGroupSearchResult(KJob *job);
158
159protected:
160 /**
161 * Reimplemented for smart insertion of email addresses.
162 * Features:
163 * - Automatically adds ',' if necessary to separate email addresses
164 * - Correctly decodes mailto URLs
165 * - Recognizes email addresses which are protected against address
166 * harvesters, i.e. "name at kde dot org" and "name(at)kde.org"
167 */
168 virtual void insert(const QString &);
169
170 /**
171 * Reimplemented for smart insertion of pasted email addresses.
172 */
173 virtual void paste();
174
175 /**
176 * Reimplemented for smart insertion with middle mouse button.
177 */
178 void mouseReleaseEvent(QMouseEvent *) override;
179
180 /**
181 * Reimplemented for smart insertion of dragged email addresses.
182 */
183 void dropEvent(QDropEvent *) override;
184
185 /**
186 * Reimplemented for internal reasons.
187 */
188 void keyPressEvent(QKeyEvent *) override;
189
190 /**
191 * Reimplemented for subclass access to menu
192 */
193 virtual QMenu *createStandardContextMenu();
194
195 /**
196 * Reimplemented for internal reasons. API not affected.
197 *
198 * See QLineEdit::contextMenuEvent().
199 */
200 void contextMenuEvent(QContextMenuEvent *) override;
201
202 void insertEmails(const QStringList &emails);
203 void loadContacts();
204
205private:
206 PIMCOMMONAKONADI_NO_EXPORT void addContact(const QStringList &emails, const KContacts::Addressee &addr, int weight, int source, QString append = QString());
207 PIMCOMMONAKONADI_NO_EXPORT void groupExpandResult(KJob *job);
208 bool eventFilter(QObject *, QEvent *) override;
209
210 AddresseeLineEditPrivate *const d;
211};
212}
KIOWIDGETS_EXPORT PasteJob * paste(const QMimeData *mimeData, const QUrl &destDir, JobFlags flags=DefaultFlags)
KGuiItem insert()
folderdialogacltab.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:39:22 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.