UI: IconCache: Check "./icons/" existence once on startup

This commit is contained in:
Nodir Temirkhodjaev 2023-12-25 08:21:27 +03:00
parent bd6b1165d7
commit 306cfe78d6

View File

@ -1,5 +1,6 @@
#include "iconcache.h" #include "iconcache.h"
#include <QDir>
#include <QIcon> #include <QIcon>
#include <QLoggingCategory> #include <QLoggingCategory>
#include <QPixmapCache> #include <QPixmapCache>
@ -24,6 +25,34 @@ void checkThread()
#endif #endif
} }
QString adjustFilePath(const QString &filePath)
{
static struct
{
bool checked : 1 = false;
bool exists : 1 = false;
} g_iconsDir;
if (!g_iconsDir.checked) {
g_iconsDir.checked = true;
g_iconsDir.exists = QDir().exists("icons");
}
if (!g_iconsDir.exists)
return filePath;
// Try to use "./icons/" folder from current working dir.
if (filePath.startsWith(':')) {
QString adjustedFilePath = filePath;
adjustedFilePath[0] = '.';
if (FileUtil::fileExists(adjustedFilePath))
return adjustedFilePath;
}
return filePath;
}
} }
bool IconCache::find(const QString &key, QPixmap *pixmap) bool IconCache::find(const QString &key, QPixmap *pixmap)
@ -53,18 +82,7 @@ QPixmap IconCache::file(const QString &filePath)
QPixmap pixmap; QPixmap pixmap;
if (!find(filePath, &pixmap)) { if (!find(filePath, &pixmap)) {
QString adjustedFilePath = filePath; pixmap.load(adjustFilePath(filePath));
// Try to use "./icons/" folder from current working dir.
if (filePath.startsWith(':')) {
adjustedFilePath[0] = '.';
if (!FileUtil::fileExists(adjustedFilePath)) {
adjustedFilePath = filePath;
}
}
pixmap.load(adjustedFilePath);
insert(filePath, pixmap); insert(filePath, pixmap);
} }