Import: Avoid re-importing sources

Skip sources that already have imported games and avoid importing
platforms that are disabled in settings.

Remove imported games when a source is disabled so the library stays in
sync with user preferences.
This commit is contained in:
Marco Allegretti 2026-01-24 13:53:12 +01:00
parent 9c3c0e1dfd
commit 3357e48cc7

View file

@ -30,6 +30,116 @@ App::App(QObject *parent)
, m_config(new Config(this)) , m_config(new Config(this))
{ {
loadLibrary(); loadLibrary();
if (!m_config->importSteam()) {
if (m_gameModel->removeByPlatformPrefix(QStringLiteral("Steam")) > 0) {
saveLibrary();
}
}
if (!m_config->importLutris()) {
if (m_gameModel->removeByPlatformPrefix(QStringLiteral("Lutris")) > 0) {
saveLibrary();
}
}
if (!m_config->importHeroic()) {
if (m_gameModel->removeByPlatformPrefix(QStringLiteral("Heroic")) > 0) {
saveLibrary();
}
}
if (!m_config->importDesktop()) {
if (m_gameModel->removeByPlatformPrefix(QStringLiteral("Desktop")) > 0) {
saveLibrary();
}
}
if (!m_config->importBottles()) {
if (m_gameModel->removeByPlatformPrefix(QStringLiteral("Bottles")) > 0) {
saveLibrary();
}
}
if (!m_config->importFlatpak()) {
if (m_gameModel->removeByPlatformPrefix(QStringLiteral("Flatpak")) > 0) {
saveLibrary();
}
}
if (!m_config->importItch()) {
if (m_gameModel->removeByPlatformPrefix(QStringLiteral("itch.io")) > 0) {
saveLibrary();
}
}
if (!m_config->importLegendary()) {
if (m_gameModel->removeByPlatformPrefix(QStringLiteral("Legendary")) > 0) {
saveLibrary();
}
}
if (!m_config->importRetroArch()) {
if (m_gameModel->removeByPlatformPrefix(QStringLiteral("RetroArch")) > 0) {
saveLibrary();
}
}
connect(m_config, &Config::importSteamChanged, this, [this]() {
if (!m_config->importSteam()) {
if (m_gameModel->removeByPlatformPrefix(QStringLiteral("Steam")) > 0) {
saveLibrary();
}
}
});
connect(m_config, &Config::importLutrisChanged, this, [this]() {
if (!m_config->importLutris()) {
if (m_gameModel->removeByPlatformPrefix(QStringLiteral("Lutris")) > 0) {
saveLibrary();
}
}
});
connect(m_config, &Config::importHeroicChanged, this, [this]() {
if (!m_config->importHeroic()) {
if (m_gameModel->removeByPlatformPrefix(QStringLiteral("Heroic")) > 0) {
saveLibrary();
}
}
});
connect(m_config, &Config::importDesktopChanged, this, [this]() {
if (!m_config->importDesktop()) {
if (m_gameModel->removeByPlatformPrefix(QStringLiteral("Desktop")) > 0) {
saveLibrary();
}
}
});
connect(m_config, &Config::importBottlesChanged, this, [this]() {
if (!m_config->importBottles()) {
if (m_gameModel->removeByPlatformPrefix(QStringLiteral("Bottles")) > 0) {
saveLibrary();
}
}
});
connect(m_config, &Config::importFlatpakChanged, this, [this]() {
if (!m_config->importFlatpak()) {
if (m_gameModel->removeByPlatformPrefix(QStringLiteral("Flatpak")) > 0) {
saveLibrary();
}
}
});
connect(m_config, &Config::importItchChanged, this, [this]() {
if (!m_config->importItch()) {
if (m_gameModel->removeByPlatformPrefix(QStringLiteral("itch.io")) > 0) {
saveLibrary();
}
}
});
connect(m_config, &Config::importLegendaryChanged, this, [this]() {
if (!m_config->importLegendary()) {
if (m_gameModel->removeByPlatformPrefix(QStringLiteral("Legendary")) > 0) {
saveLibrary();
}
}
});
connect(m_config, &Config::importRetroArchChanged, this, [this]() {
if (!m_config->importRetroArch()) {
if (m_gameModel->removeByPlatformPrefix(QStringLiteral("RetroArch")) > 0) {
saveLibrary();
}
}
});
} }
App *App::instance() App *App::instance()
@ -98,13 +208,39 @@ void App::importAllGames()
if (m_importing) if (m_importing)
return; 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() && !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"));
if (!anyEnabled) {
setImportStatus(tr("No import sources enabled"));
Q_EMIT importCompleted(0);
return;
}
if (!(doSteam || doLutris || doHeroic || doDesktop || doBottles || doFlatpak || doItch || doLegendary || doRetroArch)) {
setImportStatus(tr("All enabled sources already imported"));
Q_EMIT importCompleted(0);
return;
}
setImporting(true); setImporting(true);
setImportStatus(tr("Importing games...")); setImportStatus(tr("Importing games..."));
QtConcurrent::run([this]() { [[maybe_unused]] auto future = QtConcurrent::run([this, doSteam, doLutris, doHeroic, doDesktop, doBottles, doFlatpak, doItch, doLegendary, doRetroArch]() {
int totalCount = 0; int totalCount = 0;
// Import from Steam // Import from Steam
if (doSteam) {
QMetaObject::invokeMethod( QMetaObject::invokeMethod(
this, this,
[this]() { [this]() {
@ -122,14 +258,24 @@ void App::importAllGames()
QMetaObject::invokeMethod( QMetaObject::invokeMethod(
this, this,
[this, steamGames]() { [this, steamGames]() {
if (!m_config->importSteam()) {
for (Game *game : steamGames) {
if (game) {
game->deleteLater();
}
}
return;
}
for (Game *game : steamGames) { for (Game *game : steamGames) {
m_gameModel->addGame(game); m_gameModel->addGame(game);
} }
}, },
Qt::QueuedConnection); Qt::QueuedConnection);
totalCount += steamGames.count(); totalCount += steamGames.count();
}
// Import from Lutris // Import from Lutris
if (doLutris) {
QMetaObject::invokeMethod( QMetaObject::invokeMethod(
this, this,
[this]() { [this]() {
@ -147,14 +293,24 @@ void App::importAllGames()
QMetaObject::invokeMethod( QMetaObject::invokeMethod(
this, this,
[this, lutrisGames]() { [this, lutrisGames]() {
if (!m_config->importLutris()) {
for (Game *game : lutrisGames) {
if (game) {
game->deleteLater();
}
}
return;
}
for (Game *game : lutrisGames) { for (Game *game : lutrisGames) {
m_gameModel->addGame(game); m_gameModel->addGame(game);
} }
}, },
Qt::QueuedConnection); Qt::QueuedConnection);
totalCount += lutrisGames.count(); totalCount += lutrisGames.count();
}
// Import from Heroic // Import from Heroic
if (doHeroic) {
QMetaObject::invokeMethod( QMetaObject::invokeMethod(
this, this,
[this]() { [this]() {
@ -172,14 +328,24 @@ void App::importAllGames()
QMetaObject::invokeMethod( QMetaObject::invokeMethod(
this, this,
[this, heroicGames]() { [this, heroicGames]() {
if (!m_config->importHeroic()) {
for (Game *game : heroicGames) {
if (game) {
game->deleteLater();
}
}
return;
}
for (Game *game : heroicGames) { for (Game *game : heroicGames) {
m_gameModel->addGame(game); m_gameModel->addGame(game);
} }
}, },
Qt::QueuedConnection); Qt::QueuedConnection);
totalCount += heroicGames.count(); totalCount += heroicGames.count();
}
// Import from Desktop entries // Import from Desktop entries
if (doDesktop) {
QMetaObject::invokeMethod( QMetaObject::invokeMethod(
this, this,
[this]() { [this]() {
@ -197,14 +363,24 @@ void App::importAllGames()
QMetaObject::invokeMethod( QMetaObject::invokeMethod(
this, this,
[this, desktopGames]() { [this, desktopGames]() {
if (!m_config->importDesktop()) {
for (Game *game : desktopGames) {
if (game) {
game->deleteLater();
}
}
return;
}
for (Game *game : desktopGames) { for (Game *game : desktopGames) {
m_gameModel->addGame(game); m_gameModel->addGame(game);
} }
}, },
Qt::QueuedConnection); Qt::QueuedConnection);
totalCount += desktopGames.count(); totalCount += desktopGames.count();
}
// Import from Bottles // Import from Bottles
if (doBottles) {
QMetaObject::invokeMethod( QMetaObject::invokeMethod(
this, this,
[this]() { [this]() {
@ -222,14 +398,24 @@ void App::importAllGames()
QMetaObject::invokeMethod( QMetaObject::invokeMethod(
this, this,
[this, bottlesGames]() { [this, bottlesGames]() {
if (!m_config->importBottles()) {
for (Game *game : bottlesGames) {
if (game) {
game->deleteLater();
}
}
return;
}
for (Game *game : bottlesGames) { for (Game *game : bottlesGames) {
m_gameModel->addGame(game); m_gameModel->addGame(game);
} }
}, },
Qt::QueuedConnection); Qt::QueuedConnection);
totalCount += bottlesGames.count(); totalCount += bottlesGames.count();
}
// Import from Flatpak // Import from Flatpak
if (doFlatpak) {
QMetaObject::invokeMethod( QMetaObject::invokeMethod(
this, this,
[this]() { [this]() {
@ -247,14 +433,24 @@ void App::importAllGames()
QMetaObject::invokeMethod( QMetaObject::invokeMethod(
this, this,
[this, flatpakGames]() { [this, flatpakGames]() {
if (!m_config->importFlatpak()) {
for (Game *game : flatpakGames) {
if (game) {
game->deleteLater();
}
}
return;
}
for (Game *game : flatpakGames) { for (Game *game : flatpakGames) {
m_gameModel->addGame(game); m_gameModel->addGame(game);
} }
}, },
Qt::QueuedConnection); Qt::QueuedConnection);
totalCount += flatpakGames.count(); totalCount += flatpakGames.count();
}
// Import from itch.io // Import from itch.io
if (doItch) {
QMetaObject::invokeMethod( QMetaObject::invokeMethod(
this, this,
[this]() { [this]() {
@ -272,14 +468,24 @@ void App::importAllGames()
QMetaObject::invokeMethod( QMetaObject::invokeMethod(
this, this,
[this, itchGames]() { [this, itchGames]() {
if (!m_config->importItch()) {
for (Game *game : itchGames) {
if (game) {
game->deleteLater();
}
}
return;
}
for (Game *game : itchGames) { for (Game *game : itchGames) {
m_gameModel->addGame(game); m_gameModel->addGame(game);
} }
}, },
Qt::QueuedConnection); Qt::QueuedConnection);
totalCount += itchGames.count(); totalCount += itchGames.count();
}
// Import from Legendary // Import from Legendary
if (doLegendary) {
QMetaObject::invokeMethod( QMetaObject::invokeMethod(
this, this,
[this]() { [this]() {
@ -297,14 +503,24 @@ void App::importAllGames()
QMetaObject::invokeMethod( QMetaObject::invokeMethod(
this, this,
[this, legendaryGames]() { [this, legendaryGames]() {
if (!m_config->importLegendary()) {
for (Game *game : legendaryGames) {
if (game) {
game->deleteLater();
}
}
return;
}
for (Game *game : legendaryGames) { for (Game *game : legendaryGames) {
m_gameModel->addGame(game); m_gameModel->addGame(game);
} }
}, },
Qt::QueuedConnection); Qt::QueuedConnection);
totalCount += legendaryGames.count(); totalCount += legendaryGames.count();
}
// Import from RetroArch // Import from RetroArch
if (doRetroArch) {
QMetaObject::invokeMethod( QMetaObject::invokeMethod(
this, this,
[this]() { [this]() {
@ -322,12 +538,21 @@ void App::importAllGames()
QMetaObject::invokeMethod( QMetaObject::invokeMethod(
this, this,
[this, retroArchGames]() { [this, retroArchGames]() {
if (!m_config->importRetroArch()) {
for (Game *game : retroArchGames) {
if (game) {
game->deleteLater();
}
}
return;
}
for (Game *game : retroArchGames) { for (Game *game : retroArchGames) {
m_gameModel->addGame(game); m_gameModel->addGame(game);
} }
}, },
Qt::QueuedConnection); Qt::QueuedConnection);
totalCount += retroArchGames.count(); totalCount += retroArchGames.count();
}
// Complete // Complete
QMetaObject::invokeMethod( QMetaObject::invokeMethod(
@ -350,7 +575,7 @@ void App::importFromSteam()
setImporting(true); setImporting(true);
setImportStatus(tr("Scanning Steam library...")); setImportStatus(tr("Scanning Steam library..."));
QtConcurrent::run([this]() { [[maybe_unused]] auto future = QtConcurrent::run([this]() {
SteamImporter importer; SteamImporter importer;
QList<Game *> games = importer.importGames(); QList<Game *> games = importer.importGames();
@ -382,7 +607,7 @@ void App::importFromLutris()
setImporting(true); setImporting(true);
setImportStatus(tr("Scanning Lutris library...")); setImportStatus(tr("Scanning Lutris library..."));
QtConcurrent::run([this]() { [[maybe_unused]] auto future = QtConcurrent::run([this]() {
LutrisImporter importer; LutrisImporter importer;
QList<Game *> games = importer.importGames(); QList<Game *> games = importer.importGames();
@ -414,7 +639,7 @@ void App::importFromHeroic()
setImporting(true); setImporting(true);
setImportStatus(tr("Scanning Heroic library...")); setImportStatus(tr("Scanning Heroic library..."));
QtConcurrent::run([this]() { [[maybe_unused]] auto future = QtConcurrent::run([this]() {
HeroicImporter importer; HeroicImporter importer;
QList<Game *> games = importer.importGames(); QList<Game *> games = importer.importGames();
@ -446,7 +671,7 @@ void App::importFromDesktop()
setImporting(true); setImporting(true);
setImportStatus(tr("Scanning desktop entries...")); setImportStatus(tr("Scanning desktop entries..."));
QtConcurrent::run([this]() { [[maybe_unused]] auto future = QtConcurrent::run([this]() {
DesktopImporter importer; DesktopImporter importer;
QList<Game *> games = importer.importGames(); QList<Game *> games = importer.importGames();
@ -478,7 +703,7 @@ void App::importFromBottles()
setImporting(true); setImporting(true);
setImportStatus(tr("Scanning Bottles...")); setImportStatus(tr("Scanning Bottles..."));
QtConcurrent::run([this]() { [[maybe_unused]] auto future = QtConcurrent::run([this]() {
BottlesImporter importer; BottlesImporter importer;
QList<Game *> games = importer.importGames(); QList<Game *> games = importer.importGames();
@ -510,7 +735,7 @@ void App::importFromFlatpak()
setImporting(true); setImporting(true);
setImportStatus(tr("Scanning Flatpak games...")); setImportStatus(tr("Scanning Flatpak games..."));
QtConcurrent::run([this]() { [[maybe_unused]] auto future = QtConcurrent::run([this]() {
FlatpakImporter importer; FlatpakImporter importer;
QList<Game *> games = importer.importGames(); QList<Game *> games = importer.importGames();
@ -542,7 +767,7 @@ void App::importFromItch()
setImporting(true); setImporting(true);
setImportStatus(tr("Scanning itch.io library...")); setImportStatus(tr("Scanning itch.io library..."));
QtConcurrent::run([this]() { [[maybe_unused]] auto future = QtConcurrent::run([this]() {
ItchImporter importer; ItchImporter importer;
QList<Game *> games = importer.importGames(); QList<Game *> games = importer.importGames();
@ -574,7 +799,7 @@ void App::importFromLegendary()
setImporting(true); setImporting(true);
setImportStatus(tr("Scanning Legendary library...")); setImportStatus(tr("Scanning Legendary library..."));
QtConcurrent::run([this]() { [[maybe_unused]] auto future = QtConcurrent::run([this]() {
LegendaryImporter importer; LegendaryImporter importer;
QList<Game *> games = importer.importGames(); QList<Game *> games = importer.importGames();
@ -606,7 +831,7 @@ void App::importFromRetroArch()
setImporting(true); setImporting(true);
setImportStatus(tr("Scanning RetroArch playlists...")); setImportStatus(tr("Scanning RetroArch playlists..."));
QtConcurrent::run([this]() { [[maybe_unused]] auto future = QtConcurrent::run([this]() {
RetroArchImporter importer; RetroArchImporter importer;
QList<Game *> games = importer.importGames(); QList<Game *> games = importer.importGames();