Pimcommon

addresseelineeditmanager.cpp
1/*
2 SPDX-FileCopyrightText: 2015-2024 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 "addresseelineeditbaloo.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 AddresseeLineEditBaloo)
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::updateCollectionWeights()
58{
59 akonadiCollectionToCompletionSourceMap.clear();
60}
61
62void AddresseeLineEditManager::updateLDAPWeights()
63{
64 mAddressessLineEditLdap->updateLDAPWeights();
65}
66
67int AddresseeLineEditManager::addCompletionSource(const QString &source, int weight)
68{
69 QMap<QString, int>::iterator it = completionSourceWeights.find(source);
70 if (it == completionSourceWeights.end()) {
71 completionSourceWeights.insert(source, weight);
72 } else {
73 completionSourceWeights[source] = weight;
74 }
75
76 const int sourceIndex = completionSources.indexOf(source);
77 if (sourceIndex == -1) {
78 completionSources.append(source);
79 return completionSources.size() - 1;
80 } else {
81 return sourceIndex;
82 }
83}
84
85void AddresseeLineEditManager::removeCompletionSource(const QString &source)
86{
87 QMap<QString, int>::iterator it = completionSourceWeights.find(source);
88 if (it != completionSourceWeights.end()) {
89 completionSourceWeights.remove(source);
90 mCompletion->clear();
91 }
92}
93
94Akonadi::Session *AddresseeLineEditManager::akonadiSession() const
95{
96 return mAddresseeLineEditAkonadi->akonadiSession();
97}
98
99KMailCompletion *AddresseeLineEditManager::completion() const
100{
101 return mCompletion;
102}
103
104AddresseeLineEdit *AddresseeLineEditManager::addressLineEdit() const
105{
106 return mAddressessLineEditLdap->addressLineEdit();
107}
108
109void AddresseeLineEditManager::setAddressLineEdit(AddresseeLineEdit *addressLineEdit)
110{
111 mAddressessLineEditLdap->setAddressLineEdit(addressLineEdit);
112}
113
114bool AddresseeLineEditManager::isOnline() const
115{
116 if (QNetworkInformation::loadBackendByFeatures(QNetworkInformation::Feature::Reachability)) {
117 return QNetworkInformation::instance()->reachability() == QNetworkInformation::Reachability::Online
119 } else {
120 qCWarning(PIMCOMMONAKONADI_LOG) << "Couldn't find a working backend for QNetworkInformation";
121 return false;
122 }
123}
124
125KLDAPCore::LdapClientSearch *AddresseeLineEditManager::ldapSearch() const
126{
127 return mAddressessLineEditLdap->ldapSearch();
128}
129
130QTimer *AddresseeLineEditManager::ldapTimer() const
131{
132 return mAddressessLineEditLdap->ldapTimer();
133}
134
135int AddresseeLineEditManager::ldapClientToCompletionSourceValue(int value) const
136{
137 return mAddressessLineEditLdap->ldapClientToCompletionSourceValue(value);
138}
139
140bool AddresseeLineEditManager::isLdapClientToCompletionSourceMapContains(int value) const
141{
142 return mAddressessLineEditLdap->isLdapClientToCompletionSourceMapContains(value);
143}
144
145int AddresseeLineEditManager::balooCompletionSource() const
146{
147 return mAddressessLineEditBaloo->balooCompletionSource();
148}
149
150void AddresseeLineEditManager::setBalooCompletionSource(int value)
151{
152 mAddressessLineEditBaloo->setBalooCompletionSource(value);
153}
154
155void AddresseeLineEditManager::initializeLdap()
156{
157 mAddressessLineEditLdap->init();
158}
159
160QString AddresseeLineEditManager::ldapText() const
161{
162 return mAddressessLineEditLdap->ldapText();
163}
164
165void AddresseeLineEditManager::setLdapText(const QString &ldapText)
166{
167 mAddressessLineEditLdap->setLdapText(ldapText);
168}
169
170void AddresseeLineEditManager::stopLDAPLookup()
171{
172 mAddressessLineEditLdap->stopLDAPLookup();
173}
174
175void AddresseeLineEditManager::startLoadingLDAPEntries()
176{
177 mAddressessLineEditLdap->startLoadingLDAPEntries();
178}
179
180void AddresseeLineEditManager::restartLdap(const QString &searchString, AddresseeLineEdit *addressLine)
181{
182 mAddressessLineEditLdap->restartLdap(searchString, addressLine);
183}
184
185void AddresseeLineEditManager::loadBalooBlackList()
186{
187 mAddressessLineEditBaloo->loadBalooBlackList();
188}
189
190QStringList AddresseeLineEditManager::cleanupRecentAddressEmailList(const QStringList &inputList)
191{
192 if (inputList != mRecentAddressEmailList) {
193 mRecentCleanupAddressEmailList = mAddressessLineEditBaloo->cleanupEmailList(inputList);
194 mRecentAddressEmailList = inputList;
195 }
196 return mRecentCleanupAddressEmailList;
197}
198
199QStringList AddresseeLineEditManager::cleanupEmailList(const QStringList &inputList)
200{
201 return mAddressessLineEditBaloo->cleanupEmailList(inputList);
202}
203
204QStringList AddresseeLineEditManager::balooBlackList() const
205{
206 return mAddressessLineEditBaloo->balooBlackList();
207}
208
209bool AddresseeLineEditManager::showOU() const
210{
211 return mShowOU;
212}
213
214void AddresseeLineEditManager::setShowOU(bool checked)
215{
216 if (checked != mShowOU) {
217 KConfigGroup group(KSharedConfig::openConfig(), QStringLiteral("AddressLineEdit"));
218 group.writeEntry("ShowOU", checked);
219 mShowOU = checked;
220 }
221}
222
223bool AddresseeLineEditManager::autoGroupExpand() const
224{
225 return mAutoGroupExpand;
226}
227
228void AddresseeLineEditManager::setAutoGroupExpand(bool checked)
229{
230 if (mAutoGroupExpand != checked) {
231 mAutoGroupExpand = checked;
232 KConfigGroup group(KSharedConfig::openConfig(), QStringLiteral("AddressLineEdit"));
233 group.writeEntry("AutoGroupExpand", mAutoGroupExpand);
234 }
235}
236
237QColor AddresseeLineEditManager::alternateColor() const
238{
239 if (!mAlternateColor.isValid()) {
241 mAlternateColor = colorScheme.background(KColorScheme::AlternateBackground).color();
242 }
243 return mAlternateColor;
244}
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-2024 The KDE developers.
Generated on Fri Jul 26 2024 12:00:34 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.