KIdentityManagement

utils.cpp
1/*
2 SPDX-FileCopyrightText: 2014 Sandro Knauß <knauss@kolabsys.com>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "utils.h"
8#include "identitymanager.h"
9
10#include <QObject>
11
12using namespace KIdentityManagementCore;
13
14class IdendentitiesCache : public QObject
15{
17public:
18 explicit IdendentitiesCache(QObject *parent = nullptr)
20 , mIdentityManager(/*ro=*/true)
21 {
22 connect(&mIdentityManager, &IdentityManager::identitiesWereChanged, this, &IdendentitiesCache::slotIdentitiesChanged);
23 slotIdentitiesChanged();
24 }
25
26 [[nodiscard]] const QSet<QString> &emails() const
27 {
28 return mEmails;
29 }
30
31private:
32 void slotIdentitiesChanged()
33 {
34 mEmails.clear();
35 const QStringList lst = mIdentityManager.allEmails();
36 mEmails.reserve(lst.count());
37 for (const QString &email : lst) {
38 mEmails.insert(email.toLower());
39 }
40 }
41
42 IdentityManager mIdentityManager;
43 QSet<QString> mEmails;
44};
45
46Q_GLOBAL_STATIC(IdendentitiesCache, sIdentitiesCache)
47
48bool KIdentityManagementCore::thatIsMe(const QString &email)
49{
50 return allEmails().contains(email.toLower());
51}
52
53const QSet<QString> &KIdentityManagementCore::allEmails()
54{
55 return sIdentitiesCache()->emails();
56}
57
58#include "utils.moc"
Manages the list of identities.
QStringList allEmails() const
Returns the list of all email addresses (only name@host) from all identities.
qsizetype count() const const
Q_OBJECTQ_OBJECT
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QObject * parent() const const
void clear()
bool contains(const QSet< T > &other) const const
iterator insert(const T &value)
void reserve(qsizetype size)
QString toLower() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 6 2024 12:11:25 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.