Skip to content

Commit

Permalink
LB: Use FP playlist icons
Browse files Browse the repository at this point in the history
  • Loading branch information
oblivioncth committed Jul 27, 2023
1 parent 0405cd5 commit 2a238a7
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ ob_fetch_qx(

# Fetch libfp (build and import from source)
include(OB/Fetchlibfp)
ob_fetch_libfp("v0.4.1")
ob_fetch_libfp("0bbb9be67ccf0048100ba1eb01939900177d5068")

# Fetch CLIFp (build and import from source)
include(OB/FetchCLIFp)
Expand Down
1 change: 1 addition & 0 deletions app/src/frontend/fe-install.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,5 +182,6 @@ Fe::DocHandlingError Install::commitPlaylistDoc(std::unique_ptr<PlaylistDoc> doc

QString Install::platformCategoryIconPath() const { return QString(); } // Unsupported in default implementation
std::optional<QDir> Install::platformIconsDirectory() const { return std::nullopt; }; // Unsupported in default implementation
std::optional<QDir> Install::playlistIconsDirectory() const { return std::nullopt; }; // Unsupported in default implementation

}
1 change: 1 addition & 0 deletions app/src/frontend/fe-install.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class Install : public InstallFoundation
// but currently none do this so this works.
virtual QString platformCategoryIconPath() const; // Unsupported in default implementation, needs to return path with .png extension
virtual std::optional<QDir> platformIconsDirectory() const; // Unsupported in default implementation
virtual std::optional<QDir> playlistIconsDirectory() const; // Unsupported in default implementation
};

}
Expand Down
3 changes: 3 additions & 0 deletions app/src/frontend/launchbox/lb-install.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Install::Install(const QString& installPath) :
// Initialize files and directories;
mPlatformImagesDirectory = QDir(installPath + '/' + PLATFORM_IMAGES_PATH);
mPlatformIconsDirectory = QDir(installPath + '/' + PLATFORM_ICONS_PATH);
mPlaylistIconsDirectory = QDir(installPath + '/' + PLAYLIST_ICONS_PATH);
mPlatformCategoryIconsDirectory = QDir(installPath + '/' + PLATFORM_CATEGORY_ICONS_PATH);
mDataDirectory = QDir(installPath + '/' + DATA_PATH);
mCoreDirectory = QDir(installPath + '/' + CORE_PATH);
Expand Down Expand Up @@ -58,6 +59,7 @@ void Install::nullify()
mPlaylistsDirectory = QDir();
mPlatformImagesDirectory = QDir();
mPlatformIconsDirectory = QDir();
mPlaylistIconsDirectory = QDir();
mPlatformCategoryIconsDirectory = QDir();
}

Expand Down Expand Up @@ -442,5 +444,6 @@ void Install::processDirectGameImages(const Fe::Game* game, const Fe::ImageSourc

QString Install::platformCategoryIconPath() const { return mPlatformCategoryIconsDirectory.absoluteFilePath(u"Flashpoint.png"_s); }
std::optional<QDir> Install::platformIconsDirectory() const { return mPlatformIconsDirectory; };
std::optional<QDir> Install::playlistIconsDirectory() const { return mPlaylistIconsDirectory; };

}
3 changes: 3 additions & 0 deletions app/src/frontend/launchbox/lb-install.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class Install : public Fe::Install
static inline const QString MAIN_EXE_PATH = u"Core/LaunchBox.exe"_s;
static inline const QString PLATFORM_IMAGES_PATH = u"Images"_s;
static inline const QString PLATFORM_ICONS_PATH = u"Images/Platform Icons/Platforms"_s;
static inline const QString PLAYLIST_ICONS_PATH = u"Images/Platform Icons/Playlists"_s;
static inline const QString PLATFORM_CATEGORY_ICONS_PATH = u"Images/Platform Icons/Platform Categories"_s;
static inline const QString LOGO_PATH = u"Box - Front"_s;
static inline const QString SCREENSHOT_PATH = u"Screenshot - Gameplay"_s;
Expand All @@ -60,6 +61,7 @@ class Install : public Fe::Install
QDir mPlatformImagesDirectory;
QDir mPlatformIconsDirectory;
QDir mPlatformCategoryIconsDirectory;
QDir mPlaylistIconsDirectory;
QDir mCoreDirectory;

// Image transfers for import worker
Expand Down Expand Up @@ -125,6 +127,7 @@ class Install : public Fe::Install
void processDirectGameImages(const Fe::Game* game, const Fe::ImageSources& imageSources) override;
QString platformCategoryIconPath() const override;
std::optional<QDir> platformIconsDirectory() const override;
std::optional<QDir> playlistIconsDirectory() const override;

};
REGISTER_FRONTEND(Install::NAME, Install, &Install::ICON_PATH, &Install::HELP_URL);
Expand Down
46 changes: 44 additions & 2 deletions app/src/import-worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
// Standard Library Includes
#include <filesystem>

// Qt
#include <QImageWriter>

// Qx Includes
#include <qx/core/qx-regularexpression.h>
#include <qx/core/qx-genericerror.h>

// Project Includes
#include "clifp.h"
Expand Down Expand Up @@ -595,11 +599,12 @@ ImportWorker::ImportResult ImportWorker::processImages(Qx::Error& errorReport)
return Successful;
}

ImportWorker::ImportResult ImportWorker::processIcons(const QStringList& platforms)
ImportWorker::ImportResult ImportWorker::processIcons(Qx::Error& errorReport, const QStringList& platforms, const QList<Fp::Playlist>& playlists)
{
QList<Fe::Install::ImageMap> jobs;
QString mainDest = mFrontendInstall->platformCategoryIconPath();
std::optional<QDir> platformDestDir = mFrontendInstall->platformIconsDirectory();
std::optional<QDir> playlistDestDir = mFrontendInstall->playlistIconsDirectory();

// Main Job
if(!mainDest.isEmpty())
Expand All @@ -618,11 +623,46 @@ ImportWorker::ImportResult ImportWorker::processIcons(const QStringList& platfor
}
}

// Playlist jobs
if(playlistDestDir)
{
// Create temp dir
QTemporaryDir iconInflateDir;
if(!iconInflateDir.isValid())
{
errorReport = Qx::GenericError(Qx::Critical, 13501, u"Failed to create directory for playlist icons inflation."_s, iconInflateDir.errorString());
return Failed;
}

// Setup playlist image jobs
QImageWriter iw;
QDir pdd = playlistDestDir.value();
for(const Fp::Playlist& p : playlists)
{
const QImage& icon = p.icon();
QString filename = p.title() + ".png";
QString source = iconInflateDir.filePath(filename);
QString dest = pdd.absoluteFilePath(filename);

iw.setFileName(source);
if(!iw.write(icon))
{
errorReport = Qx::GenericError(Qx::Critical, 13502, u"Failed to inflate playlist icon"_s, iw.errorString());
return Failed;
}

jobs.emplace_back(Fe::Install::ImageMap{.sourcePath = source, .destPath = dest});
}
}

// Perform
if(!jobs.isEmpty())
{
if(!performImageJobs(jobs, false, mProgressManager.group(Pg::IconTransfer))) // Always copy
{
errorReport = Qx::Error();
return Canceled;
}
}

return Successful;
Expand Down Expand Up @@ -749,6 +789,8 @@ ImportWorker::ImportResult ImportWorker::doImport(Qx::Error& errorReport)
iconCount++;
if(mFrontendInstall->platformIconsDirectory())
iconCount += involvedPlatforms.size();
if(mFrontendInstall->playlistIconsDirectory())
iconCount += targetPlaylists.size();

if(iconCount > 0)
{
Expand Down Expand Up @@ -808,7 +850,7 @@ ImportWorker::ImportResult ImportWorker::doImport(Qx::Error& errorReport)
return importStepStatus;

// Process Icons
if((importStepStatus = processIcons(involvedPlatforms)) != Successful)
if((importStepStatus = processIcons(errorReport, involvedPlatforms, targetPlaylists)) != Successful)
return importStepStatus;

// Process playlists
Expand Down
4 changes: 2 additions & 2 deletions app/src/import-worker.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// Project Includes
#include "frontend/fe-install.h"

class QX_ERROR_TYPE(ImageTransferError, "ImageTransferError", 1350)
class QX_ERROR_TYPE(ImageTransferError, "ImageTransferError", 1351)
{
//-Class Enums-------------------------------------------------------------
public:
Expand Down Expand Up @@ -167,7 +167,7 @@ class ImportWorker : public QObject
ImportResult processGames(Qx::Error& errorReport, QList<Fp::Db::QueryBuffer>& primary, QList<Fp::Db::QueryBuffer>& playlistSpecific);
ImportResult processPlaylists(Qx::Error& errorReport, const QList<Fp::Playlist>& playlists);
ImportResult processImages(Qx::Error& errorReport);
ImportResult processIcons(const QStringList& platforms);
ImportResult processIcons(Qx::Error& errorReport, const QStringList& platforms, const QList<Fp::Playlist>& playlists);

public:
ImportResult doImport(Qx::Error& errorReport);
Expand Down

0 comments on commit 2a238a7

Please sign in to comment.