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;
|
|
|
|
|
|
|
|
QPixmap CoverUtils::find(std::string key)
|
|
|
|
{
|
|
|
|
auto itr = CoverUtils::cache.find(key);
|
|
|
|
if(itr == CoverUtils::cache.end())
|
|
|
|
{
|
|
|
|
itr = CoverUtils::cache.find("PH");
|
|
|
|
}
|
|
|
|
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-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);
|
|
|
|
|
|
|
|
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));
|
|
|
|
pixmap = pixmap.scaledToWidth(250 / 2, Qt::SmoothTransformation);
|
|
|
|
CoverUtils::cache.insert(std::make_pair(bootable.discId.c_str(), pixmap));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|