From 2a238a7da27b9e7c0a5ae990f79424755f6c7446 Mon Sep 17 00:00:00 2001 From: Christian Heimlich Date: Thu, 27 Jul 2023 02:48:56 -0400 Subject: [PATCH] LB: Use FP playlist icons --- CMakeLists.txt | 2 +- app/src/frontend/fe-install.cpp | 1 + app/src/frontend/fe-install.h | 1 + app/src/frontend/launchbox/lb-install.cpp | 3 ++ app/src/frontend/launchbox/lb-install.h | 3 ++ app/src/import-worker.cpp | 46 ++++++++++++++++++++++- app/src/import-worker.h | 4 +- 7 files changed, 55 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2c24274..e798b6d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/app/src/frontend/fe-install.cpp b/app/src/frontend/fe-install.cpp index bc1d2bc..d1f3622 100644 --- a/app/src/frontend/fe-install.cpp +++ b/app/src/frontend/fe-install.cpp @@ -182,5 +182,6 @@ Fe::DocHandlingError Install::commitPlaylistDoc(std::unique_ptr doc QString Install::platformCategoryIconPath() const { return QString(); } // Unsupported in default implementation std::optional Install::platformIconsDirectory() const { return std::nullopt; }; // Unsupported in default implementation +std::optional Install::playlistIconsDirectory() const { return std::nullopt; }; // Unsupported in default implementation } diff --git a/app/src/frontend/fe-install.h b/app/src/frontend/fe-install.h index afb4190..4889289 100644 --- a/app/src/frontend/fe-install.h +++ b/app/src/frontend/fe-install.h @@ -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 platformIconsDirectory() const; // Unsupported in default implementation + virtual std::optional playlistIconsDirectory() const; // Unsupported in default implementation }; } diff --git a/app/src/frontend/launchbox/lb-install.cpp b/app/src/frontend/launchbox/lb-install.cpp index 9da0e7f..cee1d41 100644 --- a/app/src/frontend/launchbox/lb-install.cpp +++ b/app/src/frontend/launchbox/lb-install.cpp @@ -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); @@ -58,6 +59,7 @@ void Install::nullify() mPlaylistsDirectory = QDir(); mPlatformImagesDirectory = QDir(); mPlatformIconsDirectory = QDir(); + mPlaylistIconsDirectory = QDir(); mPlatformCategoryIconsDirectory = QDir(); } @@ -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 Install::platformIconsDirectory() const { return mPlatformIconsDirectory; }; +std::optional Install::playlistIconsDirectory() const { return mPlaylistIconsDirectory; }; } diff --git a/app/src/frontend/launchbox/lb-install.h b/app/src/frontend/launchbox/lb-install.h index 0ebdf14..9e9aaad 100644 --- a/app/src/frontend/launchbox/lb-install.h +++ b/app/src/frontend/launchbox/lb-install.h @@ -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; @@ -60,6 +61,7 @@ class Install : public Fe::Install QDir mPlatformImagesDirectory; QDir mPlatformIconsDirectory; QDir mPlatformCategoryIconsDirectory; + QDir mPlaylistIconsDirectory; QDir mCoreDirectory; // Image transfers for import worker @@ -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 platformIconsDirectory() const override; + std::optional playlistIconsDirectory() const override; }; REGISTER_FRONTEND(Install::NAME, Install, &Install::ICON_PATH, &Install::HELP_URL); diff --git a/app/src/import-worker.cpp b/app/src/import-worker.cpp index 1236c85..ee9bf11 100644 --- a/app/src/import-worker.cpp +++ b/app/src/import-worker.cpp @@ -4,8 +4,12 @@ // Standard Library Includes #include +// Qt +#include + // Qx Includes #include +#include // Project Includes #include "clifp.h" @@ -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& playlists) { QList jobs; QString mainDest = mFrontendInstall->platformCategoryIconPath(); std::optional platformDestDir = mFrontendInstall->platformIconsDirectory(); + std::optional playlistDestDir = mFrontendInstall->playlistIconsDirectory(); // Main Job if(!mainDest.isEmpty()) @@ -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; @@ -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) { @@ -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 diff --git a/app/src/import-worker.h b/app/src/import-worker.h index 4db3f31..7f0a9a9 100644 --- a/app/src/import-worker.h +++ b/app/src/import-worker.h @@ -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: @@ -167,7 +167,7 @@ class ImportWorker : public QObject ImportResult processGames(Qx::Error& errorReport, QList& primary, QList& playlistSpecific); ImportResult processPlaylists(Qx::Error& errorReport, const QList& playlists); ImportResult processImages(Qx::Error& errorReport); - ImportResult processIcons(const QStringList& platforms); + ImportResult processIcons(Qx::Error& errorReport, const QStringList& platforms, const QList& playlists); public: ImportResult doImport(Qx::Error& errorReport);