mirror of
https://github.com/tnodir/fort
synced 2024-11-15 07:25:18 +00:00
UI: IconCache: Check "./icons/" existence once on startup
This commit is contained in:
parent
bd6b1165d7
commit
306cfe78d6
@ -1,5 +1,6 @@
|
||||
#include "iconcache.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QIcon>
|
||||
#include <QLoggingCategory>
|
||||
#include <QPixmapCache>
|
||||
@ -24,6 +25,34 @@ void checkThread()
|
||||
#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)
|
||||
@ -53,18 +82,7 @@ QPixmap IconCache::file(const QString &filePath)
|
||||
|
||||
QPixmap pixmap;
|
||||
if (!find(filePath, &pixmap)) {
|
||||
QString adjustedFilePath = filePath;
|
||||
|
||||
// Try to use "./icons/" folder from current working dir.
|
||||
if (filePath.startsWith(':')) {
|
||||
adjustedFilePath[0] = '.';
|
||||
|
||||
if (!FileUtil::fileExists(adjustedFilePath)) {
|
||||
adjustedFilePath = filePath;
|
||||
}
|
||||
}
|
||||
|
||||
pixmap.load(adjustedFilePath);
|
||||
pixmap.load(adjustFilePath(filePath));
|
||||
|
||||
insert(filePath, pixmap);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user