Baloo

usergroupcache.h
1/*
2 SPDX-FileCopyrightText: 1999 Carsten Pfeiffer <pfeiffer@kde.org>
3 SPDX-FileCopyrightText: 1999-2001 David Faure <faure@kde.org>
4 SPDX-FileCopyrightText: 2005 Till Adam <adam@kde.org>
5 SPDX-FileCopyrightText: 2014 Alex Richardson <arichardson@kde.org>
6 SPDX-FileCopyrightText: 2018 Friedrich W. H. Kossebau <kossebau@kde.org>
7 SPDX-FileCopyrightText: 2020 Stefan BrĂ¼ns <bruns@kde.org>
8
9 SPDX-License-Identifier: LGPL-2.0-or-later
10*/
11
12#ifndef BALOO_KIO_COMMON_USERGROUPCACHE_H_
13#define BALOO_KIO_COMMON_USERGROUPCACHE_H_
14
15#include <KUser>
16
17#include <QHash>
18#include <QString>
19
20namespace Baloo {
21
22class UserGroupCache
23{
24public:
25 QString getUserName(const KUserId &uid) const;
26 QString getGroupName(const KGroupId &gid) const;
27
28private:
29 mutable QHash<KUserId, QString> mUsercache;
30 mutable QHash<KGroupId, QString> mGroupcache;
31};
32
33inline QString
34UserGroupCache::getUserName(const KUserId &uid) const
35{
36 if (Q_UNLIKELY(!uid.isValid())) {
37 return QString();
38 }
39 if (!mUsercache.contains(uid)) {
40 KUser user(uid);
41 QString name = user.loginName();
42 if (name.isEmpty()) {
43 name = uid.toString();
44 }
45 mUsercache.insert(uid, name);
46 return name;
47 }
48 return mUsercache[uid];
49}
50
51inline QString
52UserGroupCache::getGroupName(const KGroupId &gid) const
53{
54 if (Q_UNLIKELY(!gid.isValid())) {
55 return QString();
56 }
57 if (!mGroupcache.contains(gid)) {
58 KUserGroup group(gid);
59 QString name = group.name();
60 if (name.isEmpty()) {
61 name = gid.toString();
62 }
63 mGroupcache.insert(gid, name);
64 return name;
65 }
66 return mGroupcache[gid];
67}
68
69}
70#endif
Implements storage for docIds without any associated data Instantiated for:
Definition coding.cpp:11
QString name(StandardAction id)
bool contains(const Key &key) const const
iterator insert(const Key &key, const T &value)
bool isEmpty() const const
bool isValid() const
QString toString() const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:56:58 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.