Pimcommon

addresseelineeditmanager.cpp
1/*
2 SPDX-FileCopyrightText: 2015-2025 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "addresseelineeditmanager.h"
8#include "addresseelineeditakonadi.h"
9#include "addresseelineeditakonadisearch.h"
10#include "addresseelineeditldap.h"
11#include "kmailcompletion.h"
12
13#include "pimcommonakonadi_debug.h"
14#include <KColorScheme>
15#include <KConfigGroup>
16#include <KLDAPCore/LdapClient>
17#include <KSharedConfig>
18#include <QCoreApplication>
19#include <QNetworkInformation>
20#include <QTimer>
21
22using namespace PimCommon;
23
24Q_GLOBAL_STATIC(AddresseeLineEditManager, sInstance)
25
26AddresseeLineEditManager::AddresseeLineEditManager()
27 : mCompletion(new KMailCompletion)
28 , mAddresseeLineEditAkonadi(new AddresseeLineEditAkonadi)
29 , mAddressessLineEditLdap(new AddresseeLineEditLdap(this))
30 , mAddressessLineEditBaloo(new AddresseeLineEditAkonadiSearch)
31{
32 KConfigGroup group(KSharedConfig::openConfig(), QStringLiteral("AddressLineEdit"));
33 mShowOU = group.readEntry("ShowOU", false);
34 mAutoGroupExpand = group.readEntry("AutoGroupExpand", false);
35}
36
37AddresseeLineEditManager::~AddresseeLineEditManager()
38{
39 delete mCompletion;
40
41 delete mAddresseeLineEditAkonadi;
42 delete mAddressessLineEditLdap;
43 delete mAddressessLineEditBaloo;
44}
45
46AddresseeLineEditManager *AddresseeLineEditManager::self()
47{
48 return sInstance;
49}
50
51void AddresseeLineEditManager::updateCompletionOrder()
52{
53 updateLDAPWeights();
54 updateCollectionWeights();
55}
56
57void AddresseeLineEditManager::setLdapActivitiesAbstract(KLDAPCore::LdapActivitiesAbstract *ldapActivities)
58{
59 mAddressessLineEditLdap->setLdapActivitiesAbstract(ldapActivities);
60}
61
62void AddresseeLineEditManager::updateCollectionWeights()
63{
64 akonadiCollectionToCompletionSourceMap.clear();
65}
66
67void AddresseeLineEditManager::updateLDAPWeights()
68{
69 mAddressessLineEditLdap->updateLDAPWeights();
70}
71
72int AddresseeLineEditManager::addCompletionSource(const QString &source, int weight)
73{
74 QMap<QString, int>::iterator it = completionSourceWeights.find(source);
75 if (it == completionSourceWeights.end()) {
76 completionSourceWeights.insert(source, weight);
77 } else {
78 completionSourceWeights[source] = weight;
79 }
80
81 const int sourceIndex = completionSources.indexOf(source);
82 if (sourceIndex == -1) {
83 completionSources.append(source);
84 return completionSources.size() - 1;
85 } else {
86 return sourceIndex;
87 }
88}
89
90void AddresseeLineEditManager::removeCompletionSource(const QString &source)
91{
92 QMap<QString, int>::iterator it = completionSourceWeights.find(source);
93 if (it != completionSourceWeights.end()) {
94 completionSourceWeights.remove(source);
95 mCompletion->clear();
96 }
97}
98
99Akonadi::Session *AddresseeLineEditManager::akonadiSession() const
100{
101 return mAddresseeLineEditAkonadi->akonadiSession();
102}
103
104KMailCompletion *AddresseeLineEditManager::completion() const
105{
106 return mCompletion;
107}
108
109AddresseeLineEdit *AddresseeLineEditManager::addressLineEdit() const
110{
111 return mAddressessLineEditLdap->addressLineEdit();
112}
113
114void AddresseeLineEditManager::setAddressLineEdit(AddresseeLineEdit *addressLineEdit)
115{
116 mAddressessLineEditLdap->setAddressLineEdit(addressLineEdit);
117}
118
119bool AddresseeLineEditManager::isOnline() const
120{
121 if (QNetworkInformation::loadBackendByFeatures(QNetworkInformation::Feature::Reachability)) {
122 return QNetworkInformation::instance()->reachability() == QNetworkInformation::Reachability::Online
124 } else {
125 qCWarning(PIMCOMMONAKONADI_LOG) << "Couldn't find a working backend for QNetworkInformation";
126 return false;
127 }
128}
129
130KLDAPCore::LdapClientSearch *AddresseeLineEditManager::ldapSearch() const
131{
132 return mAddressessLineEditLdap->ldapSearch();
133}
134
135QTimer *AddresseeLineEditManager::ldapTimer() const
136{
137 return mAddressessLineEditLdap->ldapTimer();
138}
139
140int AddresseeLineEditManager::ldapClientToCompletionSourceValue(int value) const
141{
142 return mAddressessLineEditLdap->ldapClientToCompletionSourceValue(value);
143}
144
145bool AddresseeLineEditManager::isLdapClientToCompletionSourceMapContains(int value) const
146{
147 return mAddressessLineEditLdap->isLdapClientToCompletionSourceMapContains(value);
148}
149
150int AddresseeLineEditManager::balooCompletionSource() const
151{
152 return mAddressessLineEditBaloo->akonadiSearchCompletionSource();
153}
154
155void AddresseeLineEditManager::setBalooCompletionSource(int value)
156{
157 mAddressessLineEditBaloo->setAkonadiSearchCompletionSource(value);
158}
159
160void AddresseeLineEditManager::initializeLdap()
161{
162 mAddressessLineEditLdap->init();
163}
164
165QString AddresseeLineEditManager::ldapText() const
166{
167 return mAddressessLineEditLdap->ldapText();
168}
169
170void AddresseeLineEditManager::setLdapText(const QString &ldapText)
171{
172 mAddressessLineEditLdap->setLdapText(ldapText);
173}
174
175void AddresseeLineEditManager::stopLDAPLookup()
176{
177 mAddressessLineEditLdap->stopLDAPLookup();
178}
179
180void AddresseeLineEditManager::startLoadingLDAPEntries()
181{
182 mAddressessLineEditLdap->startLoadingLDAPEntries();
183}
184
185void AddresseeLineEditManager::restartLdap(const QString &searchString, AddresseeLineEdit *addressLine)
186{
187 mAddressessLineEditLdap->restartLdap(searchString, addressLine);
188}
189
190void AddresseeLineEditManager::loadBalooBlackList()
191{
192 mAddressessLineEditBaloo->loadAkonadiSearchBlackList();
193}
194
195QStringList AddresseeLineEditManager::cleanupRecentAddressEmailList(const QStringList &inputList)
196{
197 if (inputList != mRecentAddressEmailList) {
198 mRecentCleanupAddressEmailList = mAddressessLineEditBaloo->cleanupEmailList(inputList);
199 mRecentAddressEmailList = inputList;
200 }
201 return mRecentCleanupAddressEmailList;
202}
203
204QStringList AddresseeLineEditManager::cleanupEmailList(const QStringList &inputList)
205{
206 return mAddressessLineEditBaloo->cleanupEmailList(inputList);
207}
208
209QStringList AddresseeLineEditManager::balooBlackList() const
210{
211 return mAddressessLineEditBaloo->akonadiSearchBlackList();
212}
213
214bool AddresseeLineEditManager::showOU() const
215{
216 return mShowOU;
217}
218
219void AddresseeLineEditManager::setShowOU(bool checked)
220{
221 if (checked != mShowOU) {
222 KConfigGroup group(KSharedConfig::openConfig(), QStringLiteral("AddressLineEdit"));
223 group.writeEntry("ShowOU", checked);
224 mShowOU = checked;
225 }
226}
227
228bool AddresseeLineEditManager::autoGroupExpand() const
229{
230 return mAutoGroupExpand;
231}
232
233void AddresseeLineEditManager::setAutoGroupExpand(bool checked)
234{
235 if (mAutoGroupExpand != checked) {
236 mAutoGroupExpand = checked;
237 KConfigGroup group(KSharedConfig::openConfig(), QStringLiteral("AddressLineEdit"));
238 group.writeEntry("AutoGroupExpand", mAutoGroupExpand);
239 }
240}
241
242QColor AddresseeLineEditManager::alternateColor() const
243{
244 if (!mAlternateColor.isValid()) {
246 mAlternateColor = colorScheme.background(KColorScheme::AlternateBackground).color();
247 }
248 return mAlternateColor;
249}
static KSharedConfig::Ptr openConfig(const QString &fileName=QString(), OpenFlags mode=FullConfig, QStandardPaths::StandardLocation type=QStandardPaths::GenericConfigLocation)
The AddresseeLineEditAkonadi class.
KMailCompletion allows lookup of email addresses by keyword.
void clear() override
clears internal keyword map and calls KCompletion::clear.
folderdialogacltab.h
bool isValid() const const
void append(QList< T > &&value)
qsizetype size() const const
void clear()
iterator end()
iterator find(const Key &key)
iterator insert(const Key &key, const T &value)
size_type remove(const Key &key)
QNetworkInformation * instance()
bool loadBackendByFeatures(Features features)
qsizetype indexOf(const QRegularExpression &re, qsizetype from) const const
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.