Messagelib

iconnamecache.h
1/* SPDX-FileCopyrightText: 2009 Thomas McGuire <mcguire@kde.org>
2
3 SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
4*/
5#pragma once
6
7#include "messageviewer_export.h"
8#include <QMap>
9#include <QString>
10
11namespace MessageViewer
12{
13/**
14 * This class is a replacement for KIconLoader::iconPath(), because the iconPath()
15 * function can be slow for non-existing icons or icons that fall back to a generic icon.
16 * Reason is that KIconLoader does slow system calls for finding the icons.
17 *
18 * The IconNameCache caches the result of iconPath() in a map and solves the slowness.
19 */
20class MESSAGEVIEWER_EXPORT IconNameCache
21{
22public:
23 static IconNameCache *instance();
24 [[nodiscard]] QString iconPath(const QString &name, int size) const;
25 [[nodiscard]] QString iconPathFromLocal(const QString &name) const;
26
27private:
28 [[nodiscard]] QString picsPath() const;
29
30 class Entry
31 {
32 public:
33 QString fileName;
34 int size;
35
36 [[nodiscard]] bool operator<(const Entry &other) const;
37 };
38
39 mutable QMap<Entry, QString> mCachedEntries;
40 mutable QString mPicsPath;
41};
42}
This class is a replacement for KIconLoader::iconPath(), because the iconPath() function can be slow ...
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sun Feb 25 2024 18:37:31 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.