File indexing completed on 2025-03-09 04:54:38

0001 /* SPDX-FileCopyrightText: 2009 Thomas McGuire <mcguire@kde.org>
0002 
0003    SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0004 */
0005 #pragma once
0006 
0007 #include "messageviewer_export.h"
0008 #include <QMap>
0009 #include <QString>
0010 
0011 namespace MessageViewer
0012 {
0013 /**
0014  * This class is a replacement for KIconLoader::iconPath(), because the iconPath()
0015  * function can be slow for non-existing icons or icons that fall back to a generic icon.
0016  * Reason is that KIconLoader does slow system calls for finding the icons.
0017  *
0018  * The IconNameCache caches the result of iconPath() in a map and solves the slowness.
0019  */
0020 class MESSAGEVIEWER_EXPORT IconNameCache
0021 {
0022 public:
0023     static IconNameCache *instance();
0024     [[nodiscard]] QString iconPath(const QString &name, int size) const;
0025     [[nodiscard]] QString iconPathFromLocal(const QString &name) const;
0026 
0027 private:
0028     QString picsPath() const;
0029 
0030     class Entry
0031     {
0032     public:
0033         QString fileName;
0034         int size;
0035 
0036         [[nodiscard]] bool operator<(const Entry &other) const;
0037     };
0038 
0039     mutable QMap<Entry, QString> mCachedEntries;
0040     mutable QString mPicsPath;
0041 };
0042 }