-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjbimagecache.cpp
More file actions
39 lines (35 loc) · 1.37 KB
/
jbimagecache.cpp
File metadata and controls
39 lines (35 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/////////////////////////////////////////////////////////////////////////////
// Name: jbimagecache.cpp
// Purpose: Local cache for covers, etc.
// Author: Jan Buchholz
// Created: 2026-05-21
/////////////////////////////////////////////////////////////////////////////
#include "jbimagecache.h"
#include "apicall.h"
#include "conversions.hpp"
JBImageCache::JBImageCache(SqlReader& reader) : m_sqlReader(reader) {}
QPixmap JBImageCache::getPixmap(const std::string& itemId, const std::string& tag) {
QPixmap pix;
const QString key = toQString(itemId + ":" + tag);
if (m_cache.contains(key)) {
return m_cache.value(key);
} else {
// ---Not in cache -> load---
if (tag == DEF_OFFLINE) {
ByteArrayResult r = m_sqlReader.loadImage(toQString(itemId));
if (r.code == MSG_OK) {
QByteArray bytes = toQByteArray(r.bytes);
pix.loadFromData(bytes);
m_cache[key] = pix;
}
return pix;
} else {
ItemImageImp img = APICall::getPrimaryImageForItem(itemId, tag);
if (img.code != 0) return QPixmap();
QByteArray bytes = QByteArray::fromBase64(img.imageData.c_str());
pix.loadFromData(bytes);
m_cache[key] = pix;
return pix;
}
}
}