Messagelib

iconnamecache.h
1 /* SPDX-FileCopyrightText: 2009 Thomas McGuire <[email protected]>
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 
11 namespace 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  */
20 class MESSAGEVIEWER_EXPORT IconNameCache
21 {
22 public:
23  static IconNameCache *instance();
24  Q_REQUIRED_RESULT QString iconPath(const QString &name, int size) const;
25  Q_REQUIRED_RESULT QString iconPathFromLocal(const QString &name) const;
26 
27 private:
28  QString picsPath() const;
29 
30  class Entry
31  {
32  public:
33  QString fileName;
34  int size;
35 
36  Q_REQUIRED_RESULT 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 ...
Definition: iconnamecache.h:20
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Fri Mar 24 2023 04:08:31 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.