2019-01-16 20:00:10 +00:00
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#include "AppConfig.h"
|
|
|
|
#include "CoverUtils.h"
|
|
|
|
#include "PathUtils.h"
|
|
|
|
#include "QStringUtils.h"
|
|
|
|
|
|
|
|
std::map<std::string, QPixmap> CoverUtils::cache;
|
2019-01-19 23:03:22 +00:00
|
|
|
std::mutex CoverUtils::m_lock;
|
2019-01-16 20:00:10 +00:00
|
|
|
|
|
|
|
QPixmap CoverUtils::find(std::string key)
|
|
|
|
{
|
|
|
|
auto itr = CoverUtils::cache.find(key);
|
|
|
|
if(itr == CoverUtils::cache.end())
|
|
|
|
{
|
2019-01-20 00:21:21 +00:00
|
|
|
return QPixmap();
|
2019-01-16 20:00:10 +00:00
|
|
|
}
|
|
|
|
return itr->second;
|
|
|
|
}
|
|
|
|
|
2019-01-17 22:05:35 +00:00
|
|
|
void CoverUtils::PopulatePlaceholderCover()
|
|
|
|
{
|
|
|
|
auto itr = CoverUtils::cache.find("PH");
|
|
|
|
if(itr == CoverUtils::cache.end())
|
|
|
|
{
|
|
|
|
auto pixmap = QPixmap(QString(":/assets/boxart.png")).scaledToWidth(250 / 2, Qt::SmoothTransformation);
|
|
|
|
CoverUtils::cache.insert(std::make_pair("PH", pixmap));
|
|
|
|
}
|
|
|
|
}
|
2019-01-19 23:01:38 +00:00
|
|
|
void CoverUtils::PopulateCache(std::vector<BootablesDb::Bootable> bootables)
|
2019-01-16 20:00:10 +00:00
|
|
|
{
|
2019-01-19 23:03:22 +00:00
|
|
|
m_lock.lock();
|
2019-01-17 22:05:35 +00:00
|
|
|
PopulatePlaceholderCover();
|
|
|
|
|
2019-01-16 20:00:10 +00:00
|
|
|
auto coverpath(CAppConfig::GetBasePath() / boost::filesystem::path("covers"));
|
|
|
|
Framework::PathUtils::EnsurePathExists(coverpath);
|
|
|
|
|
2019-01-19 23:05:21 +00:00
|
|
|
auto itr = CoverUtils::cache.find("PH");
|
|
|
|
auto placeholder_size = itr->second.size();
|
2019-01-16 20:00:10 +00:00
|
|
|
for(auto bootable : bootables)
|
|
|
|
{
|
|
|
|
if(bootable.discId.empty())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
auto path = coverpath / (bootable.discId + ".jpg");
|
2019-01-17 12:26:47 +00:00
|
|
|
if(boost::filesystem::exists(path))
|
2019-01-16 20:00:10 +00:00
|
|
|
{
|
|
|
|
auto itr = CoverUtils::cache.find(bootable.discId.c_str());
|
|
|
|
if(itr == CoverUtils::cache.end())
|
|
|
|
{
|
|
|
|
auto pixmap = QPixmap(PathToQString(path));
|
2019-01-19 23:05:21 +00:00
|
|
|
pixmap = pixmap.scaled(placeholder_size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
2019-01-16 20:00:10 +00:00
|
|
|
CoverUtils::cache.insert(std::make_pair(bootable.discId.c_str(), pixmap));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-01-19 23:03:22 +00:00
|
|
|
m_lock.unlock();
|
2019-01-16 20:00:10 +00:00
|
|
|
}
|