diff --git a/src/gamelauncher.cpp b/src/gamelauncher.cpp index b269fac..a653f81 100644 --- a/src/gamelauncher.cpp +++ b/src/gamelauncher.cpp @@ -22,8 +22,11 @@ GameLauncher::~GameLauncher() process->disconnect(); process->terminate(); process->waitForFinished(3000); - delete process; + process->deleteLater(); } + + m_runningGames.clear(); + m_processToGame.clear(); } bool GameLauncher::hasRunningGames() const diff --git a/src/gamemodel.cpp b/src/gamemodel.cpp index dc21d64..f063cef 100644 --- a/src/gamemodel.cpp +++ b/src/gamemodel.cpp @@ -202,7 +202,10 @@ void GameModel::addGame(Game *game) // Check for duplicates for (Game *existing : m_games) { if (existing->id() == game->id()) { - delete game; + if (!game->parent()) { + game->setParent(this); + } + game->deleteLater(); return; } } @@ -289,7 +292,10 @@ void GameModel::removeGame(const QString &id) endRemoveRows(); } - delete m_games.takeAt(i); + Game *game = m_games.takeAt(i); + if (game) { + game->deleteLater(); + } Q_EMIT countChanged(); return; } @@ -317,7 +323,11 @@ Game *GameModel::gameById(const QString &id) const void GameModel::clear() { beginResetModel(); - qDeleteAll(m_games); + for (Game *game : m_games) { + if (game) { + game->deleteLater(); + } + } m_games.clear(); m_filteredGames.clear(); endResetModel(); @@ -341,6 +351,76 @@ QList GameModel::allGames() const return m_games; } +bool GameModel::hasPlatformPrefix(const QString &platformPrefix) const +{ + if (platformPrefix.isEmpty()) { + return false; + } + + for (Game *game : m_games) { + if (!game) { + continue; + } + if (game->platform().startsWith(platformPrefix)) { + return true; + } + } + + return false; +} + +int GameModel::removeByPlatformPrefix(const QString &platformPrefix) +{ + if (platformPrefix.isEmpty()) { + return 0; + } + + bool hasMatch = false; + for (Game *game : m_games) { + if (!game) { + continue; + } + if (game->platform().startsWith(platformPrefix)) { + hasMatch = true; + break; + } + } + + if (!hasMatch) { + return 0; + } + + beginResetModel(); + + int removed = 0; + for (int i = m_games.count() - 1; i >= 0; --i) { + Game *game = m_games.at(i); + if (!game) { + continue; + } + if (game->platform().startsWith(platformPrefix)) { + m_games.takeAt(i)->deleteLater(); + removed++; + } + } + + m_filteredGames.clear(); + for (Game *game : m_games) { + if (matchesFilter(game)) { + m_filteredGames.append(game); + } + } + applySort(); + + endResetModel(); + + if (removed > 0) { + Q_EMIT countChanged(); + } + + return removed; +} + bool GameModel::matchesFilter(Game *game) const { if (!m_showHidden && game->hidden()) { diff --git a/src/gamemodel.h b/src/gamemodel.h index 6493350..f20fbc8 100644 --- a/src/gamemodel.h +++ b/src/gamemodel.h @@ -83,6 +83,8 @@ public: Q_INVOKABLE Game *gameById(const QString &id) const; Q_INVOKABLE void clear(); Q_INVOKABLE QStringList platforms() const; + Q_INVOKABLE bool hasPlatformPrefix(const QString &platformPrefix) const; + Q_INVOKABLE int removeByPlatformPrefix(const QString &platformPrefix); QList allGames() const;