mirror of
https://invent.kde.org/marcoa/a-la-karte.git
synced 2026-02-09 21:13:08 +00:00
Make imports incremental and refreshable
This commit is contained in:
parent
365c3b31cb
commit
245944fca9
3 changed files with 405 additions and 99 deletions
450
src/app.cpp
450
src/app.cpp
|
|
@ -18,7 +18,9 @@
|
|||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonParseError>
|
||||
#include <QSet>
|
||||
#include <QStandardPaths>
|
||||
#include <QTimer>
|
||||
#include <QtConcurrent>
|
||||
|
||||
App *App::s_instance = nullptr;
|
||||
|
|
@ -142,6 +144,12 @@ App::App(QObject *parent)
|
|||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (m_config->autoImportOnStartup()) {
|
||||
QTimer::singleShot(0, this, [this]() {
|
||||
importAllGames();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
App *App::instance()
|
||||
|
|
@ -215,18 +223,17 @@ void App::importAllGames()
|
|||
if (m_importing)
|
||||
return;
|
||||
|
||||
const bool anyEnabled = m_config->importSteam() || m_config->importLutris() || m_config->importHeroic() || m_config->importDesktop()
|
||||
|| m_config->importBottles() || m_config->importFlatpak() || m_config->importItch() || m_config->importLegendary() || m_config->importRetroArch();
|
||||
const bool doSteam = m_config->importSteam();
|
||||
const bool doLutris = m_config->importLutris();
|
||||
const bool doHeroic = m_config->importHeroic();
|
||||
const bool doDesktop = m_config->importDesktop();
|
||||
const bool doBottles = m_config->importBottles();
|
||||
const bool doFlatpak = m_config->importFlatpak();
|
||||
const bool doItch = m_config->importItch();
|
||||
const bool doLegendary = m_config->importLegendary();
|
||||
const bool doRetroArch = m_config->importRetroArch();
|
||||
|
||||
const bool doSteam = m_config->importSteam() && !m_gameModel->hasPlatformPrefix(QStringLiteral("Steam"));
|
||||
const bool doLutris = m_config->importLutris() && !m_gameModel->hasPlatformPrefix(QStringLiteral("Lutris"));
|
||||
const bool doHeroic = m_config->importHeroic() && !m_gameModel->hasPlatformPrefix(QStringLiteral("Heroic"));
|
||||
const bool doDesktop = m_config->importDesktop() && !m_gameModel->hasPlatformPrefix(QStringLiteral("Desktop"));
|
||||
const bool doBottles = m_config->importBottles() && !m_gameModel->hasPlatformPrefix(QStringLiteral("Bottles"));
|
||||
const bool doFlatpak = m_config->importFlatpak() && !m_gameModel->hasPlatformPrefix(QStringLiteral("Flatpak"));
|
||||
const bool doItch = m_config->importItch() && !m_gameModel->hasPlatformPrefix(QStringLiteral("itch.io"));
|
||||
const bool doLegendary = m_config->importLegendary() && !m_gameModel->hasPlatformPrefix(QStringLiteral("Legendary"));
|
||||
const bool doRetroArch = m_config->importRetroArch() && !m_gameModel->hasPlatformPrefix(QStringLiteral("RetroArch"));
|
||||
const bool anyEnabled = doSteam || doLutris || doHeroic || doDesktop || doBottles || doFlatpak || doItch || doLegendary || doRetroArch;
|
||||
|
||||
if (!anyEnabled) {
|
||||
setImportStatus(tr("No import sources enabled"));
|
||||
|
|
@ -234,17 +241,55 @@ void App::importAllGames()
|
|||
return;
|
||||
}
|
||||
|
||||
if (!(doSteam || doLutris || doHeroic || doDesktop || doBottles || doFlatpak || doItch || doLegendary || doRetroArch)) {
|
||||
setImportStatus(tr("All enabled sources already imported"));
|
||||
Q_EMIT importCompleted(0);
|
||||
return;
|
||||
}
|
||||
const QSet<QString> existingIds = [this]() {
|
||||
QSet<QString> ids;
|
||||
const QList<Game *> games = m_gameModel->allGames();
|
||||
for (Game *game : games) {
|
||||
if (game) {
|
||||
ids.insert(game->id());
|
||||
}
|
||||
}
|
||||
return ids;
|
||||
}();
|
||||
|
||||
setImporting(true);
|
||||
setImportStatus(tr("Importing games..."));
|
||||
|
||||
[[maybe_unused]] auto future = QtConcurrent::run([this, doSteam, doLutris, doHeroic, doDesktop, doBottles, doFlatpak, doItch, doLegendary, doRetroArch]() {
|
||||
[[maybe_unused]] auto future = QtConcurrent::run([this,
|
||||
doSteam,
|
||||
doLutris,
|
||||
doHeroic,
|
||||
doDesktop,
|
||||
doBottles,
|
||||
doFlatpak,
|
||||
doItch,
|
||||
doLegendary,
|
||||
doRetroArch,
|
||||
existingIds]() {
|
||||
int totalCount = 0;
|
||||
QSet<QString> seenIds = existingIds;
|
||||
|
||||
const auto keepNewGames = [&seenIds](const QList<Game *> &games) {
|
||||
QList<Game *> result;
|
||||
result.reserve(games.size());
|
||||
|
||||
for (Game *game : games) {
|
||||
if (!game) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const QString id = game->id();
|
||||
if (id.isEmpty() || seenIds.contains(id)) {
|
||||
delete game;
|
||||
continue;
|
||||
}
|
||||
|
||||
seenIds.insert(id);
|
||||
result.append(game);
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
// Import from Steam
|
||||
if (doSteam) {
|
||||
|
|
@ -256,7 +301,7 @@ void App::importAllGames()
|
|||
Qt::QueuedConnection);
|
||||
|
||||
SteamImporter steamImporter;
|
||||
QList<Game *> steamGames = steamImporter.importGames();
|
||||
QList<Game *> steamGames = keepNewGames(steamImporter.importGames());
|
||||
for (Game *game : steamGames) {
|
||||
game->moveToThread(this->thread());
|
||||
game->setParent(nullptr);
|
||||
|
|
@ -291,7 +336,7 @@ void App::importAllGames()
|
|||
Qt::QueuedConnection);
|
||||
|
||||
LutrisImporter lutrisImporter;
|
||||
QList<Game *> lutrisGames = lutrisImporter.importGames();
|
||||
QList<Game *> lutrisGames = keepNewGames(lutrisImporter.importGames());
|
||||
for (Game *game : lutrisGames) {
|
||||
game->moveToThread(this->thread());
|
||||
game->setParent(nullptr);
|
||||
|
|
@ -326,7 +371,7 @@ void App::importAllGames()
|
|||
Qt::QueuedConnection);
|
||||
|
||||
HeroicImporter heroicImporter;
|
||||
QList<Game *> heroicGames = heroicImporter.importGames();
|
||||
QList<Game *> heroicGames = keepNewGames(heroicImporter.importGames());
|
||||
for (Game *game : heroicGames) {
|
||||
game->moveToThread(this->thread());
|
||||
game->setParent(nullptr);
|
||||
|
|
@ -361,7 +406,7 @@ void App::importAllGames()
|
|||
Qt::QueuedConnection);
|
||||
|
||||
DesktopImporter desktopImporter;
|
||||
QList<Game *> desktopGames = desktopImporter.importGames();
|
||||
QList<Game *> desktopGames = keepNewGames(desktopImporter.importGames());
|
||||
for (Game *game : desktopGames) {
|
||||
game->moveToThread(this->thread());
|
||||
game->setParent(nullptr);
|
||||
|
|
@ -396,7 +441,7 @@ void App::importAllGames()
|
|||
Qt::QueuedConnection);
|
||||
|
||||
BottlesImporter bottlesImporter;
|
||||
QList<Game *> bottlesGames = bottlesImporter.importGames();
|
||||
QList<Game *> bottlesGames = keepNewGames(bottlesImporter.importGames());
|
||||
for (Game *game : bottlesGames) {
|
||||
game->moveToThread(this->thread());
|
||||
game->setParent(nullptr);
|
||||
|
|
@ -431,7 +476,7 @@ void App::importAllGames()
|
|||
Qt::QueuedConnection);
|
||||
|
||||
FlatpakImporter flatpakImporter;
|
||||
QList<Game *> flatpakGames = flatpakImporter.importGames();
|
||||
QList<Game *> flatpakGames = keepNewGames(flatpakImporter.importGames());
|
||||
for (Game *game : flatpakGames) {
|
||||
game->moveToThread(this->thread());
|
||||
game->setParent(nullptr);
|
||||
|
|
@ -466,7 +511,7 @@ void App::importAllGames()
|
|||
Qt::QueuedConnection);
|
||||
|
||||
ItchImporter itchImporter;
|
||||
QList<Game *> itchGames = itchImporter.importGames();
|
||||
QList<Game *> itchGames = keepNewGames(itchImporter.importGames());
|
||||
for (Game *game : itchGames) {
|
||||
game->moveToThread(this->thread());
|
||||
game->setParent(nullptr);
|
||||
|
|
@ -501,7 +546,7 @@ void App::importAllGames()
|
|||
Qt::QueuedConnection);
|
||||
|
||||
LegendaryImporter legendaryImporter;
|
||||
QList<Game *> legendaryGames = legendaryImporter.importGames();
|
||||
QList<Game *> legendaryGames = keepNewGames(legendaryImporter.importGames());
|
||||
for (Game *game : legendaryGames) {
|
||||
game->moveToThread(this->thread());
|
||||
game->setParent(nullptr);
|
||||
|
|
@ -536,7 +581,7 @@ void App::importAllGames()
|
|||
Qt::QueuedConnection);
|
||||
|
||||
RetroArchImporter retroArchImporter;
|
||||
QList<Game *> retroArchGames = retroArchImporter.importGames();
|
||||
QList<Game *> retroArchGames = keepNewGames(retroArchImporter.importGames());
|
||||
for (Game *game : retroArchGames) {
|
||||
game->moveToThread(this->thread());
|
||||
game->setParent(nullptr);
|
||||
|
|
@ -565,7 +610,7 @@ void App::importAllGames()
|
|||
QMetaObject::invokeMethod(
|
||||
this,
|
||||
[this, totalCount]() {
|
||||
setImportStatus(tr("Import complete: %1 games found").arg(totalCount));
|
||||
setImportStatus(tr("Import complete: %1 new games found").arg(totalCount));
|
||||
setImporting(false);
|
||||
saveLibrary();
|
||||
Q_EMIT importCompleted(totalCount);
|
||||
|
|
@ -579,28 +624,57 @@ void App::importFromSteam()
|
|||
if (m_importing)
|
||||
return;
|
||||
|
||||
const QSet<QString> existingIds = [this]() {
|
||||
QSet<QString> ids;
|
||||
const QList<Game *> games = m_gameModel->allGames();
|
||||
for (Game *game : games) {
|
||||
if (game) {
|
||||
ids.insert(game->id());
|
||||
}
|
||||
}
|
||||
return ids;
|
||||
}();
|
||||
|
||||
setImporting(true);
|
||||
setImportStatus(tr("Scanning Steam library..."));
|
||||
|
||||
[[maybe_unused]] auto future = QtConcurrent::run([this]() {
|
||||
[[maybe_unused]] auto future = QtConcurrent::run([this, existingIds]() {
|
||||
SteamImporter importer;
|
||||
QList<Game *> games = importer.importGames();
|
||||
QSet<QString> seenIds = existingIds;
|
||||
QList<Game *> newGames;
|
||||
newGames.reserve(games.size());
|
||||
|
||||
for (Game *game : games) {
|
||||
if (!game) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const QString id = game->id();
|
||||
if (id.isEmpty() || seenIds.contains(id)) {
|
||||
delete game;
|
||||
continue;
|
||||
}
|
||||
|
||||
seenIds.insert(id);
|
||||
newGames.append(game);
|
||||
}
|
||||
|
||||
for (Game *game : newGames) {
|
||||
game->moveToThread(this->thread());
|
||||
game->setParent(nullptr);
|
||||
}
|
||||
|
||||
QMetaObject::invokeMethod(
|
||||
this,
|
||||
[this, games]() {
|
||||
for (Game *game : games) {
|
||||
[this, newGames]() {
|
||||
for (Game *game : newGames) {
|
||||
m_gameModel->addGame(game);
|
||||
}
|
||||
setImportStatus(tr("Steam import complete: %1 games found").arg(games.count()));
|
||||
setImportStatus(tr("Steam import complete: %1 new games found").arg(newGames.count()));
|
||||
setImporting(false);
|
||||
saveLibrary();
|
||||
Q_EMIT importCompleted(games.count());
|
||||
Q_EMIT importCompleted(newGames.count());
|
||||
},
|
||||
Qt::QueuedConnection);
|
||||
});
|
||||
|
|
@ -611,28 +685,57 @@ void App::importFromLutris()
|
|||
if (m_importing)
|
||||
return;
|
||||
|
||||
const QSet<QString> existingIds = [this]() {
|
||||
QSet<QString> ids;
|
||||
const QList<Game *> games = m_gameModel->allGames();
|
||||
for (Game *game : games) {
|
||||
if (game) {
|
||||
ids.insert(game->id());
|
||||
}
|
||||
}
|
||||
return ids;
|
||||
}();
|
||||
|
||||
setImporting(true);
|
||||
setImportStatus(tr("Scanning Lutris library..."));
|
||||
|
||||
[[maybe_unused]] auto future = QtConcurrent::run([this]() {
|
||||
[[maybe_unused]] auto future = QtConcurrent::run([this, existingIds]() {
|
||||
LutrisImporter importer;
|
||||
QList<Game *> games = importer.importGames();
|
||||
QSet<QString> seenIds = existingIds;
|
||||
QList<Game *> newGames;
|
||||
newGames.reserve(games.size());
|
||||
|
||||
for (Game *game : games) {
|
||||
if (!game) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const QString id = game->id();
|
||||
if (id.isEmpty() || seenIds.contains(id)) {
|
||||
delete game;
|
||||
continue;
|
||||
}
|
||||
|
||||
seenIds.insert(id);
|
||||
newGames.append(game);
|
||||
}
|
||||
|
||||
for (Game *game : newGames) {
|
||||
game->moveToThread(this->thread());
|
||||
game->setParent(nullptr);
|
||||
}
|
||||
|
||||
QMetaObject::invokeMethod(
|
||||
this,
|
||||
[this, games]() {
|
||||
for (Game *game : games) {
|
||||
[this, newGames]() {
|
||||
for (Game *game : newGames) {
|
||||
m_gameModel->addGame(game);
|
||||
}
|
||||
setImportStatus(tr("Lutris import complete: %1 games found").arg(games.count()));
|
||||
setImportStatus(tr("Lutris import complete: %1 new games found").arg(newGames.count()));
|
||||
setImporting(false);
|
||||
saveLibrary();
|
||||
Q_EMIT importCompleted(games.count());
|
||||
Q_EMIT importCompleted(newGames.count());
|
||||
},
|
||||
Qt::QueuedConnection);
|
||||
});
|
||||
|
|
@ -643,28 +746,57 @@ void App::importFromHeroic()
|
|||
if (m_importing)
|
||||
return;
|
||||
|
||||
const QSet<QString> existingIds = [this]() {
|
||||
QSet<QString> ids;
|
||||
const QList<Game *> games = m_gameModel->allGames();
|
||||
for (Game *game : games) {
|
||||
if (game) {
|
||||
ids.insert(game->id());
|
||||
}
|
||||
}
|
||||
return ids;
|
||||
}();
|
||||
|
||||
setImporting(true);
|
||||
setImportStatus(tr("Scanning Heroic library..."));
|
||||
|
||||
[[maybe_unused]] auto future = QtConcurrent::run([this]() {
|
||||
[[maybe_unused]] auto future = QtConcurrent::run([this, existingIds]() {
|
||||
HeroicImporter importer;
|
||||
QList<Game *> games = importer.importGames();
|
||||
QSet<QString> seenIds = existingIds;
|
||||
QList<Game *> newGames;
|
||||
newGames.reserve(games.size());
|
||||
|
||||
for (Game *game : games) {
|
||||
if (!game) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const QString id = game->id();
|
||||
if (id.isEmpty() || seenIds.contains(id)) {
|
||||
delete game;
|
||||
continue;
|
||||
}
|
||||
|
||||
seenIds.insert(id);
|
||||
newGames.append(game);
|
||||
}
|
||||
|
||||
for (Game *game : newGames) {
|
||||
game->moveToThread(this->thread());
|
||||
game->setParent(nullptr);
|
||||
}
|
||||
|
||||
QMetaObject::invokeMethod(
|
||||
this,
|
||||
[this, games]() {
|
||||
for (Game *game : games) {
|
||||
[this, newGames]() {
|
||||
for (Game *game : newGames) {
|
||||
m_gameModel->addGame(game);
|
||||
}
|
||||
setImportStatus(tr("Heroic import complete: %1 games found").arg(games.count()));
|
||||
setImportStatus(tr("Heroic import complete: %1 new games found").arg(newGames.count()));
|
||||
setImporting(false);
|
||||
saveLibrary();
|
||||
Q_EMIT importCompleted(games.count());
|
||||
Q_EMIT importCompleted(newGames.count());
|
||||
},
|
||||
Qt::QueuedConnection);
|
||||
});
|
||||
|
|
@ -675,28 +807,57 @@ void App::importFromDesktop()
|
|||
if (m_importing)
|
||||
return;
|
||||
|
||||
const QSet<QString> existingIds = [this]() {
|
||||
QSet<QString> ids;
|
||||
const QList<Game *> games = m_gameModel->allGames();
|
||||
for (Game *game : games) {
|
||||
if (game) {
|
||||
ids.insert(game->id());
|
||||
}
|
||||
}
|
||||
return ids;
|
||||
}();
|
||||
|
||||
setImporting(true);
|
||||
setImportStatus(tr("Scanning desktop entries..."));
|
||||
|
||||
[[maybe_unused]] auto future = QtConcurrent::run([this]() {
|
||||
[[maybe_unused]] auto future = QtConcurrent::run([this, existingIds]() {
|
||||
DesktopImporter importer;
|
||||
QList<Game *> games = importer.importGames();
|
||||
QSet<QString> seenIds = existingIds;
|
||||
QList<Game *> newGames;
|
||||
newGames.reserve(games.size());
|
||||
|
||||
for (Game *game : games) {
|
||||
if (!game) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const QString id = game->id();
|
||||
if (id.isEmpty() || seenIds.contains(id)) {
|
||||
delete game;
|
||||
continue;
|
||||
}
|
||||
|
||||
seenIds.insert(id);
|
||||
newGames.append(game);
|
||||
}
|
||||
|
||||
for (Game *game : newGames) {
|
||||
game->moveToThread(this->thread());
|
||||
game->setParent(nullptr);
|
||||
}
|
||||
|
||||
QMetaObject::invokeMethod(
|
||||
this,
|
||||
[this, games]() {
|
||||
for (Game *game : games) {
|
||||
[this, newGames]() {
|
||||
for (Game *game : newGames) {
|
||||
m_gameModel->addGame(game);
|
||||
}
|
||||
setImportStatus(tr("Desktop import complete: %1 games found").arg(games.count()));
|
||||
setImportStatus(tr("Desktop import complete: %1 new games found").arg(newGames.count()));
|
||||
setImporting(false);
|
||||
saveLibrary();
|
||||
Q_EMIT importCompleted(games.count());
|
||||
Q_EMIT importCompleted(newGames.count());
|
||||
},
|
||||
Qt::QueuedConnection);
|
||||
});
|
||||
|
|
@ -707,28 +868,57 @@ void App::importFromBottles()
|
|||
if (m_importing)
|
||||
return;
|
||||
|
||||
const QSet<QString> existingIds = [this]() {
|
||||
QSet<QString> ids;
|
||||
const QList<Game *> games = m_gameModel->allGames();
|
||||
for (Game *game : games) {
|
||||
if (game) {
|
||||
ids.insert(game->id());
|
||||
}
|
||||
}
|
||||
return ids;
|
||||
}();
|
||||
|
||||
setImporting(true);
|
||||
setImportStatus(tr("Scanning Bottles..."));
|
||||
|
||||
[[maybe_unused]] auto future = QtConcurrent::run([this]() {
|
||||
[[maybe_unused]] auto future = QtConcurrent::run([this, existingIds]() {
|
||||
BottlesImporter importer;
|
||||
QList<Game *> games = importer.importGames();
|
||||
QSet<QString> seenIds = existingIds;
|
||||
QList<Game *> newGames;
|
||||
newGames.reserve(games.size());
|
||||
|
||||
for (Game *game : games) {
|
||||
if (!game) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const QString id = game->id();
|
||||
if (id.isEmpty() || seenIds.contains(id)) {
|
||||
delete game;
|
||||
continue;
|
||||
}
|
||||
|
||||
seenIds.insert(id);
|
||||
newGames.append(game);
|
||||
}
|
||||
|
||||
for (Game *game : newGames) {
|
||||
game->moveToThread(this->thread());
|
||||
game->setParent(nullptr);
|
||||
}
|
||||
|
||||
QMetaObject::invokeMethod(
|
||||
this,
|
||||
[this, games]() {
|
||||
for (Game *game : games) {
|
||||
[this, newGames]() {
|
||||
for (Game *game : newGames) {
|
||||
m_gameModel->addGame(game);
|
||||
}
|
||||
setImportStatus(tr("Bottles import complete: %1 games found").arg(games.count()));
|
||||
setImportStatus(tr("Bottles import complete: %1 new games found").arg(newGames.count()));
|
||||
setImporting(false);
|
||||
saveLibrary();
|
||||
Q_EMIT importCompleted(games.count());
|
||||
Q_EMIT importCompleted(newGames.count());
|
||||
},
|
||||
Qt::QueuedConnection);
|
||||
});
|
||||
|
|
@ -739,28 +929,57 @@ void App::importFromFlatpak()
|
|||
if (m_importing)
|
||||
return;
|
||||
|
||||
const QSet<QString> existingIds = [this]() {
|
||||
QSet<QString> ids;
|
||||
const QList<Game *> games = m_gameModel->allGames();
|
||||
for (Game *game : games) {
|
||||
if (game) {
|
||||
ids.insert(game->id());
|
||||
}
|
||||
}
|
||||
return ids;
|
||||
}();
|
||||
|
||||
setImporting(true);
|
||||
setImportStatus(tr("Scanning Flatpak games..."));
|
||||
|
||||
[[maybe_unused]] auto future = QtConcurrent::run([this]() {
|
||||
[[maybe_unused]] auto future = QtConcurrent::run([this, existingIds]() {
|
||||
FlatpakImporter importer;
|
||||
QList<Game *> games = importer.importGames();
|
||||
QSet<QString> seenIds = existingIds;
|
||||
QList<Game *> newGames;
|
||||
newGames.reserve(games.size());
|
||||
|
||||
for (Game *game : games) {
|
||||
if (!game) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const QString id = game->id();
|
||||
if (id.isEmpty() || seenIds.contains(id)) {
|
||||
delete game;
|
||||
continue;
|
||||
}
|
||||
|
||||
seenIds.insert(id);
|
||||
newGames.append(game);
|
||||
}
|
||||
|
||||
for (Game *game : newGames) {
|
||||
game->moveToThread(this->thread());
|
||||
game->setParent(nullptr);
|
||||
}
|
||||
|
||||
QMetaObject::invokeMethod(
|
||||
this,
|
||||
[this, games]() {
|
||||
for (Game *game : games) {
|
||||
[this, newGames]() {
|
||||
for (Game *game : newGames) {
|
||||
m_gameModel->addGame(game);
|
||||
}
|
||||
setImportStatus(tr("Flatpak import complete: %1 games found").arg(games.count()));
|
||||
setImportStatus(tr("Flatpak import complete: %1 new games found").arg(newGames.count()));
|
||||
setImporting(false);
|
||||
saveLibrary();
|
||||
Q_EMIT importCompleted(games.count());
|
||||
Q_EMIT importCompleted(newGames.count());
|
||||
},
|
||||
Qt::QueuedConnection);
|
||||
});
|
||||
|
|
@ -771,28 +990,57 @@ void App::importFromItch()
|
|||
if (m_importing)
|
||||
return;
|
||||
|
||||
const QSet<QString> existingIds = [this]() {
|
||||
QSet<QString> ids;
|
||||
const QList<Game *> games = m_gameModel->allGames();
|
||||
for (Game *game : games) {
|
||||
if (game) {
|
||||
ids.insert(game->id());
|
||||
}
|
||||
}
|
||||
return ids;
|
||||
}();
|
||||
|
||||
setImporting(true);
|
||||
setImportStatus(tr("Scanning itch.io library..."));
|
||||
|
||||
[[maybe_unused]] auto future = QtConcurrent::run([this]() {
|
||||
[[maybe_unused]] auto future = QtConcurrent::run([this, existingIds]() {
|
||||
ItchImporter importer;
|
||||
QList<Game *> games = importer.importGames();
|
||||
QSet<QString> seenIds = existingIds;
|
||||
QList<Game *> newGames;
|
||||
newGames.reserve(games.size());
|
||||
|
||||
for (Game *game : games) {
|
||||
if (!game) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const QString id = game->id();
|
||||
if (id.isEmpty() || seenIds.contains(id)) {
|
||||
delete game;
|
||||
continue;
|
||||
}
|
||||
|
||||
seenIds.insert(id);
|
||||
newGames.append(game);
|
||||
}
|
||||
|
||||
for (Game *game : newGames) {
|
||||
game->moveToThread(this->thread());
|
||||
game->setParent(nullptr);
|
||||
}
|
||||
|
||||
QMetaObject::invokeMethod(
|
||||
this,
|
||||
[this, games]() {
|
||||
for (Game *game : games) {
|
||||
[this, newGames]() {
|
||||
for (Game *game : newGames) {
|
||||
m_gameModel->addGame(game);
|
||||
}
|
||||
setImportStatus(tr("itch.io import complete: %1 games found").arg(games.count()));
|
||||
setImportStatus(tr("itch.io import complete: %1 new games found").arg(newGames.count()));
|
||||
setImporting(false);
|
||||
saveLibrary();
|
||||
Q_EMIT importCompleted(games.count());
|
||||
Q_EMIT importCompleted(newGames.count());
|
||||
},
|
||||
Qt::QueuedConnection);
|
||||
});
|
||||
|
|
@ -803,28 +1051,57 @@ void App::importFromLegendary()
|
|||
if (m_importing)
|
||||
return;
|
||||
|
||||
const QSet<QString> existingIds = [this]() {
|
||||
QSet<QString> ids;
|
||||
const QList<Game *> games = m_gameModel->allGames();
|
||||
for (Game *game : games) {
|
||||
if (game) {
|
||||
ids.insert(game->id());
|
||||
}
|
||||
}
|
||||
return ids;
|
||||
}();
|
||||
|
||||
setImporting(true);
|
||||
setImportStatus(tr("Scanning Legendary library..."));
|
||||
|
||||
[[maybe_unused]] auto future = QtConcurrent::run([this]() {
|
||||
[[maybe_unused]] auto future = QtConcurrent::run([this, existingIds]() {
|
||||
LegendaryImporter importer;
|
||||
QList<Game *> games = importer.importGames();
|
||||
QSet<QString> seenIds = existingIds;
|
||||
QList<Game *> newGames;
|
||||
newGames.reserve(games.size());
|
||||
|
||||
for (Game *game : games) {
|
||||
if (!game) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const QString id = game->id();
|
||||
if (id.isEmpty() || seenIds.contains(id)) {
|
||||
delete game;
|
||||
continue;
|
||||
}
|
||||
|
||||
seenIds.insert(id);
|
||||
newGames.append(game);
|
||||
}
|
||||
|
||||
for (Game *game : newGames) {
|
||||
game->moveToThread(this->thread());
|
||||
game->setParent(nullptr);
|
||||
}
|
||||
|
||||
QMetaObject::invokeMethod(
|
||||
this,
|
||||
[this, games]() {
|
||||
for (Game *game : games) {
|
||||
[this, newGames]() {
|
||||
for (Game *game : newGames) {
|
||||
m_gameModel->addGame(game);
|
||||
}
|
||||
setImportStatus(tr("Legendary import complete: %1 games found").arg(games.count()));
|
||||
setImportStatus(tr("Legendary import complete: %1 new games found").arg(newGames.count()));
|
||||
setImporting(false);
|
||||
saveLibrary();
|
||||
Q_EMIT importCompleted(games.count());
|
||||
Q_EMIT importCompleted(newGames.count());
|
||||
},
|
||||
Qt::QueuedConnection);
|
||||
});
|
||||
|
|
@ -835,28 +1112,57 @@ void App::importFromRetroArch()
|
|||
if (m_importing)
|
||||
return;
|
||||
|
||||
const QSet<QString> existingIds = [this]() {
|
||||
QSet<QString> ids;
|
||||
const QList<Game *> games = m_gameModel->allGames();
|
||||
for (Game *game : games) {
|
||||
if (game) {
|
||||
ids.insert(game->id());
|
||||
}
|
||||
}
|
||||
return ids;
|
||||
}();
|
||||
|
||||
setImporting(true);
|
||||
setImportStatus(tr("Scanning RetroArch playlists..."));
|
||||
|
||||
[[maybe_unused]] auto future = QtConcurrent::run([this]() {
|
||||
[[maybe_unused]] auto future = QtConcurrent::run([this, existingIds]() {
|
||||
RetroArchImporter importer;
|
||||
QList<Game *> games = importer.importGames();
|
||||
QSet<QString> seenIds = existingIds;
|
||||
QList<Game *> newGames;
|
||||
newGames.reserve(games.size());
|
||||
|
||||
for (Game *game : games) {
|
||||
if (!game) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const QString id = game->id();
|
||||
if (id.isEmpty() || seenIds.contains(id)) {
|
||||
delete game;
|
||||
continue;
|
||||
}
|
||||
|
||||
seenIds.insert(id);
|
||||
newGames.append(game);
|
||||
}
|
||||
|
||||
for (Game *game : newGames) {
|
||||
game->moveToThread(this->thread());
|
||||
game->setParent(nullptr);
|
||||
}
|
||||
|
||||
QMetaObject::invokeMethod(
|
||||
this,
|
||||
[this, games]() {
|
||||
for (Game *game : games) {
|
||||
[this, newGames]() {
|
||||
for (Game *game : newGames) {
|
||||
m_gameModel->addGame(game);
|
||||
}
|
||||
setImportStatus(tr("RetroArch import complete: %1 games found").arg(games.count()));
|
||||
setImportStatus(tr("RetroArch import complete: %1 new games found").arg(newGames.count()));
|
||||
setImporting(false);
|
||||
saveLibrary();
|
||||
Q_EMIT importCompleted(games.count());
|
||||
Q_EMIT importCompleted(newGames.count());
|
||||
},
|
||||
Qt::QueuedConnection);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1143,7 +1143,7 @@ Kirigami.ApplicationWindow {
|
|||
secondary: "steam"
|
||||
resourceFallback: Qt.resolvedUrl("icons/brand/steam-symbolic.svg")
|
||||
}
|
||||
enabled: !App.importing && App.config.importSteam && !App.gameModel.hasPlatformPrefix("Steam") && App.gameModel.count >= 0
|
||||
enabled: !App.importing && App.config.importSteam && App.gameModel.count >= 0
|
||||
onClicked: App.importFromSteam()
|
||||
}
|
||||
|
||||
|
|
@ -1157,7 +1157,7 @@ Kirigami.ApplicationWindow {
|
|||
primary: "lutris"
|
||||
secondary: "applications-games"
|
||||
}
|
||||
enabled: !App.importing && App.config.importLutris && !App.gameModel.hasPlatformPrefix("Lutris") && App.gameModel.count >= 0
|
||||
enabled: !App.importing && App.config.importLutris && App.gameModel.count >= 0
|
||||
onClicked: App.importFromLutris()
|
||||
}
|
||||
|
||||
|
|
@ -1171,7 +1171,7 @@ Kirigami.ApplicationWindow {
|
|||
primary: "com.heroicgameslauncher.hgl"
|
||||
secondary: "applications-games"
|
||||
}
|
||||
enabled: !App.importing && App.config.importHeroic && !App.gameModel.hasPlatformPrefix("Heroic") && App.gameModel.count >= 0
|
||||
enabled: !App.importing && App.config.importHeroic && App.gameModel.count >= 0
|
||||
onClicked: App.importFromHeroic()
|
||||
}
|
||||
|
||||
|
|
@ -1185,7 +1185,7 @@ Kirigami.ApplicationWindow {
|
|||
primary: "user-desktop"
|
||||
secondary: "computer"
|
||||
}
|
||||
enabled: !App.importing && App.config.importDesktop && !App.gameModel.hasPlatformPrefix("Desktop") && App.gameModel.count >= 0
|
||||
enabled: !App.importing && App.config.importDesktop && App.gameModel.count >= 0
|
||||
onClicked: App.importFromDesktop()
|
||||
}
|
||||
|
||||
|
|
@ -1199,7 +1199,7 @@ Kirigami.ApplicationWindow {
|
|||
primary: "com.usebottles.bottles"
|
||||
secondary: "application-x-executable"
|
||||
}
|
||||
enabled: !App.importing && App.config.importBottles && !App.gameModel.hasPlatformPrefix("Bottles") && App.gameModel.count >= 0
|
||||
enabled: !App.importing && App.config.importBottles && App.gameModel.count >= 0
|
||||
onClicked: App.importFromBottles()
|
||||
}
|
||||
|
||||
|
|
@ -1213,7 +1213,7 @@ Kirigami.ApplicationWindow {
|
|||
primary: "flatpak-discover"
|
||||
secondary: "applications-games"
|
||||
}
|
||||
enabled: !App.importing && App.config.importFlatpak && !App.gameModel.hasPlatformPrefix("Flatpak") && App.gameModel.count >= 0
|
||||
enabled: !App.importing && App.config.importFlatpak && App.gameModel.count >= 0
|
||||
onClicked: App.importFromFlatpak()
|
||||
}
|
||||
|
||||
|
|
@ -1228,7 +1228,7 @@ Kirigami.ApplicationWindow {
|
|||
secondary: "itch"
|
||||
resourceFallback: Qt.resolvedUrl("icons/brand/itchdotio-symbolic.svg")
|
||||
}
|
||||
enabled: !App.importing && App.config.importItch && !App.gameModel.hasPlatformPrefix("itch.io") && App.gameModel.count >= 0
|
||||
enabled: !App.importing && App.config.importItch && App.gameModel.count >= 0
|
||||
onClicked: App.importFromItch()
|
||||
}
|
||||
|
||||
|
|
@ -1242,7 +1242,7 @@ Kirigami.ApplicationWindow {
|
|||
primary: "legendary"
|
||||
secondary: "applications-games"
|
||||
}
|
||||
enabled: !App.importing && App.config.importLegendary && !App.gameModel.hasPlatformPrefix("Legendary") && App.gameModel.count >= 0
|
||||
enabled: !App.importing && App.config.importLegendary && App.gameModel.count >= 0
|
||||
onClicked: App.importFromLegendary()
|
||||
}
|
||||
|
||||
|
|
@ -1257,7 +1257,7 @@ Kirigami.ApplicationWindow {
|
|||
secondary: "retroarch"
|
||||
resourceFallback: Qt.resolvedUrl("icons/brand/retroarch-symbolic.svg")
|
||||
}
|
||||
enabled: !App.importing && App.config.importRetroArch && !App.gameModel.hasPlatformPrefix("RetroArch") && App.gameModel.count >= 0
|
||||
enabled: !App.importing && App.config.importRetroArch && App.gameModel.count >= 0
|
||||
onClicked: App.importFromRetroArch()
|
||||
}
|
||||
}
|
||||
|
|
@ -1269,15 +1269,15 @@ Kirigami.ApplicationWindow {
|
|||
QQC2.Button {
|
||||
text: i18n("Import All")
|
||||
icon.name: "document-import"
|
||||
enabled: !App.importing && App.gameModel.count >= 0 && ((App.config.importSteam && !App.gameModel.hasPlatformPrefix("Steam"))
|
||||
|| (App.config.importLutris && !App.gameModel.hasPlatformPrefix("Lutris"))
|
||||
|| (App.config.importHeroic && !App.gameModel.hasPlatformPrefix("Heroic"))
|
||||
|| (App.config.importDesktop && !App.gameModel.hasPlatformPrefix("Desktop"))
|
||||
|| (App.config.importBottles && !App.gameModel.hasPlatformPrefix("Bottles"))
|
||||
|| (App.config.importFlatpak && !App.gameModel.hasPlatformPrefix("Flatpak"))
|
||||
|| (App.config.importItch && !App.gameModel.hasPlatformPrefix("itch.io"))
|
||||
|| (App.config.importLegendary && !App.gameModel.hasPlatformPrefix("Legendary"))
|
||||
|| (App.config.importRetroArch && !App.gameModel.hasPlatformPrefix("RetroArch")))
|
||||
enabled: !App.importing && App.gameModel.count >= 0 && (App.config.importSteam
|
||||
|| App.config.importLutris
|
||||
|| App.config.importHeroic
|
||||
|| App.config.importDesktop
|
||||
|| App.config.importBottles
|
||||
|| App.config.importFlatpak
|
||||
|| App.config.importItch
|
||||
|| App.config.importLegendary
|
||||
|| App.config.importRetroArch)
|
||||
onClicked: App.importAllGames()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -643,15 +643,15 @@ FormCard.FormHeader {
|
|||
text: i18n("Import All Games")
|
||||
description: i18n("Scan all enabled sources")
|
||||
icon.name: "document-import"
|
||||
enabled: !App.importing && App.gameModel.count >= 0 && ((App.config.importSteam && !App.gameModel.hasPlatformPrefix("Steam"))
|
||||
|| (App.config.importLutris && !App.gameModel.hasPlatformPrefix("Lutris"))
|
||||
|| (App.config.importHeroic && !App.gameModel.hasPlatformPrefix("Heroic"))
|
||||
|| (App.config.importDesktop && !App.gameModel.hasPlatformPrefix("Desktop"))
|
||||
|| (App.config.importBottles && !App.gameModel.hasPlatformPrefix("Bottles"))
|
||||
|| (App.config.importFlatpak && !App.gameModel.hasPlatformPrefix("Flatpak"))
|
||||
|| (App.config.importItch && !App.gameModel.hasPlatformPrefix("itch.io"))
|
||||
|| (App.config.importLegendary && !App.gameModel.hasPlatformPrefix("Legendary"))
|
||||
|| (App.config.importRetroArch && !App.gameModel.hasPlatformPrefix("RetroArch")))
|
||||
enabled: !App.importing && App.gameModel.count >= 0 && (App.config.importSteam
|
||||
|| App.config.importLutris
|
||||
|| App.config.importHeroic
|
||||
|| App.config.importDesktop
|
||||
|| App.config.importBottles
|
||||
|| App.config.importFlatpak
|
||||
|| App.config.importItch
|
||||
|| App.config.importLegendary
|
||||
|| App.config.importRetroArch)
|
||||
onClicked: App.importAllGames()
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue