game_launcher 1.1.0
Modern Linux game launcher with Steam / Proton / Wine integration
Loading...
Searching...
No Matches
core::GameLibraryController Class Reference

#include <game_library_controller.h>

Classes

class  Impl

Public Types

using OnFilteredListChanged = std::function<void(const std::vector<const Game*>&)>
using OnGameAdded = std::function<void(const GameAddedEvent&)>
using OnGameRemoved = std::function<void(const GameRemovedEvent&)>
using OnGameUpdated = std::function<void(const GameUpdatedEvent&)>
using OnLibraryLoaded = std::function<void(const LibraryLoadedEvent&)>

Public Member Functions

 GameLibraryController ()
 GameLibraryController (const GameLibraryController &)=delete
 GameLibraryController (GameLibraryController &&) noexcept
 ~GameLibraryController ()
bool addCollection (const std::string &name)
 Add a new collection.
std::string addGame (const Game &game)
 Add a new game to the library Returns the assigned game ID, or empty string on failure.
bool addGameToCollection (const std::string &gameId, const std::string &collection)
 Add a game to a collection.
bool discoverImagesForGame (const std::string &gameId)
 Discover images for a specific game (by Steam App ID) Returns true if images were found and updated.
int discoverMissingImages ()
 Discover and update image paths for games that are missing cover art This should be called in a background thread Returns number of games updated.
std::string duplicateGame (const std::string &sourceGameId, const std::string &newName)
 Duplicate a game with a new name Returns the new game's ID, or empty string on failure.
void executeWithGame (const std::string &gameId, const std::function< void(Game &)> &updater)
 Execute an update function on a game while holding the library's internal lock.
std::vector< Game * > getAllGames ()
 Get all games (non-const for process tracking).
std::vector< std::string > getCollections () const
 Get all collection names.
FilterOptions getFilter () const
 Get current filter options (returns copy for thread safety).
std::vector< const Game * > getFilteredGames () const
 Get the currently filtered and sorted game list (returns copy for thread safety).
const Game * getGame (const std::string &gameId) const
 Get a game by ID (returns nullptr if not found).
size_t getGameCount () const
 Get total game count.
Game * getGameForEdit (const std::string &gameId)
 Get mutable game for editing (returns nullptr if not found).
std::vector< const Game * > getGamesByPlatform (GamePlatform platform) const
 Get games by platform.
std::vector< const Game * > getGamesByRunner (GameRunner runner) const
 Get games by runner.
std::vector< const Game * > getRecentlyPlayed (int count=10) const
 Get recently played games.
std::vector< PlaySession > getRecentSessions (const std::string &gameId, int limit=20) const
 Get recent play sessions for a game from the database.
SortOptions getSort () const
 Get current sort options (returns copy for thread safety).
bool isFavorite (const std::string &gameId) const
 Check if a game is favorited.
void loadLibrary ()
 Load library from disk.
GameLibraryController & operator= (const GameLibraryController &)=delete
GameLibraryController & operator= (GameLibraryController &&) noexcept
void refreshFilteredList ()
 Force refresh of filtered list (e.g., after external game state change).
int refreshStaleImages ()
 Refresh images for games with stale/missing image files Checks if stored paths still exist and re-discovers if not This should be called in a background thread Returns number of games refreshed.
bool removeCollection (const std::string &name)
 Remove a collection.
bool removeGame (const std::string &gameId)
 Remove a game from the library Returns true on success.
bool removeGameFromCollection (const std::string &gameId, const std::string &collection)
 Remove a game from a collection.
bool renameCollection (const std::string &oldName, const std::string &newName)
 Rename a collection.
void saveLibrary ()
 Save library to disk.
std::vector< const Game * > searchGames (const std::string &query) const
 Search games by name (substring match).
void setFilter (const FilterOptions &options)
 Set filter options and refresh filtered list.
void setOnFilteredListChanged (OnFilteredListChanged callback)
void setOnGameAdded (OnGameAdded callback)
void setOnGameRemoved (OnGameRemoved callback)
void setOnGameUpdated (OnGameUpdated callback)
void setOnLibraryLoaded (OnLibraryLoaded callback)
void setSort (const SortOptions &options)
 Set sort options and refresh filtered list.
void toggleFavorite (const std::string &gameId)
 Toggle favorite status.
bool updateGame (const std::string &gameId, const Game &updatedGame)
 Update an existing game Returns true on success.

Detailed Description

Definition at line 101 of file game_library_controller.h.

Member Typedef Documentation

◆ OnFilteredListChanged

using core::GameLibraryController::OnFilteredListChanged = std::function<void(const std::vector<const Game*>&)>

Definition at line 109 of file game_library_controller.h.

◆ OnGameAdded

using core::GameLibraryController::OnGameAdded = std::function<void(const GameAddedEvent&)>

Definition at line 105 of file game_library_controller.h.

◆ OnGameRemoved

using core::GameLibraryController::OnGameRemoved = std::function<void(const GameRemovedEvent&)>

Definition at line 106 of file game_library_controller.h.

◆ OnGameUpdated

using core::GameLibraryController::OnGameUpdated = std::function<void(const GameUpdatedEvent&)>

Definition at line 107 of file game_library_controller.h.

◆ OnLibraryLoaded

Definition at line 108 of file game_library_controller.h.

Constructor & Destructor Documentation

◆ GameLibraryController() [1/3]

core::GameLibraryController::GameLibraryController ( )

◆ ~GameLibraryController()

core::GameLibraryController::~GameLibraryController ( )
default

◆ GameLibraryController() [2/3]

core::GameLibraryController::GameLibraryController ( const GameLibraryController & )
delete

◆ GameLibraryController() [3/3]

core::GameLibraryController::GameLibraryController ( GameLibraryController && )
defaultnoexcept

Member Function Documentation

◆ addCollection()

bool core::GameLibraryController::addCollection ( const std::string & name)

Add a new collection.

Definition at line 460 of file game_library_controller.cpp.

Referenced by operator=().

◆ addGame()

std::string core::GameLibraryController::addGame ( const Game & game)

Add a new game to the library Returns the assigned game ID, or empty string on failure.

Definition at line 294 of file game_library_controller.cpp.

References core::GameAddedEvent::gameId, and Game::name.

Referenced by duplicateGame(), and operator=().

◆ addGameToCollection()

bool core::GameLibraryController::addGameToCollection ( const std::string & gameId,
const std::string & collection )

Add a game to a collection.

Definition at line 482 of file game_library_controller.cpp.

References Game::collections, and core::GameUpdatedEvent::gameId.

Referenced by operator=().

◆ discoverImagesForGame()

bool core::GameLibraryController::discoverImagesForGame ( const std::string & gameId)

Discover images for a specific game (by Steam App ID) Returns true if images were found and updated.

Definition at line 691 of file game_library_controller.cpp.

Referenced by operator=().

◆ discoverMissingImages()

int core::GameLibraryController::discoverMissingImages ( )

Discover and update image paths for games that are missing cover art This should be called in a background thread Returns number of games updated.

Definition at line 683 of file game_library_controller.cpp.

Referenced by operator=().

◆ duplicateGame()

std::string core::GameLibraryController::duplicateGame ( const std::string & sourceGameId,
const std::string & newName )

Duplicate a game with a new name Returns the new game's ID, or empty string on failure.

Definition at line 386 of file game_library_controller.cpp.

References addGame(), Game::id, Game::name, and Game::statistics.

Referenced by operator=().

◆ executeWithGame()

void core::GameLibraryController::executeWithGame ( const std::string & gameId,
const std::function< void(Game &)> & updater )

Execute an update function on a game while holding the library's internal lock.

Safe to call from any thread. The updater receives a mutable Game& valid only for its duration.

Definition at line 281 of file game_library_controller.cpp.

Referenced by operator=().

◆ getAllGames()

std::vector< Game * > core::GameLibraryController::getAllGames ( )

Get all games (non-const for process tracking).

Definition at line 613 of file game_library_controller.cpp.

Referenced by operator=().

◆ getCollections()

std::vector< std::string > core::GameLibraryController::getCollections ( ) const

Get all collection names.

Definition at line 454 of file game_library_controller.cpp.

Referenced by operator=().

◆ getFilter()

FilterOptions core::GameLibraryController::getFilter ( ) const

Get current filter options (returns copy for thread safety).

Definition at line 418 of file game_library_controller.cpp.

Referenced by operator=().

◆ getFilteredGames()

std::vector< const Game * > core::GameLibraryController::getFilteredGames ( ) const

Get the currently filtered and sorted game list (returns copy for thread safety).

Definition at line 439 of file game_library_controller.cpp.

Referenced by operator=().

◆ getGame()

const Game * core::GameLibraryController::getGame ( const std::string & gameId) const

Get a game by ID (returns nullptr if not found).

Definition at line 261 of file game_library_controller.cpp.

Referenced by operator=().

◆ getGameCount()

size_t core::GameLibraryController::getGameCount ( ) const

Get total game count.

Definition at line 255 of file game_library_controller.cpp.

Referenced by operator=().

◆ getGameForEdit()

Game * core::GameLibraryController::getGameForEdit ( const std::string & gameId)

Get mutable game for editing (returns nullptr if not found).

WARNING: the returned pointer is only safe to use immediately on the same thread as the call and must not be stored across event-loop yields. Prefer executeWithGame() for cross-thread or long-lived access.

Definition at line 273 of file game_library_controller.cpp.

Referenced by operator=().

◆ getGamesByPlatform()

std::vector< const Game * > core::GameLibraryController::getGamesByPlatform ( GamePlatform platform) const

Get games by platform.

Definition at line 639 of file game_library_controller.cpp.

Referenced by operator=().

◆ getGamesByRunner()

std::vector< const Game * > core::GameLibraryController::getGamesByRunner ( GameRunner runner) const

Get games by runner.

Definition at line 652 of file game_library_controller.cpp.

Referenced by operator=().

◆ getRecentlyPlayed()

std::vector< const Game * > core::GameLibraryController::getRecentlyPlayed ( int count = 10) const

Get recently played games.

Definition at line 619 of file game_library_controller.cpp.

Referenced by operator=().

◆ getRecentSessions()

std::vector< PlaySession > core::GameLibraryController::getRecentSessions ( const std::string & gameId,
int limit = 20 ) const

Get recent play sessions for a game from the database.

Definition at line 632 of file game_library_controller.cpp.

Referenced by operator=().

◆ getSort()

SortOptions core::GameLibraryController::getSort ( ) const

Get current sort options (returns copy for thread safety).

Definition at line 433 of file game_library_controller.cpp.

Referenced by operator=().

◆ isFavorite()

bool core::GameLibraryController::isFavorite ( const std::string & gameId) const

Check if a game is favorited.

Definition at line 598 of file game_library_controller.cpp.

Referenced by operator=().

◆ loadLibrary()

void core::GameLibraryController::loadLibrary ( )

Load library from disk.

Definition at line 226 of file game_library_controller.cpp.

References GameLibraryController(), and loadLibrary().

Referenced by loadLibrary(), and operator=().

◆ operator=() [1/2]

GameLibraryController & core::GameLibraryController::operator= ( const GameLibraryController & )
delete

◆ operator=() [2/2]

◆ refreshFilteredList()

void core::GameLibraryController::refreshFilteredList ( )

Force refresh of filtered list (e.g., after external game state change).

Definition at line 445 of file game_library_controller.cpp.

Referenced by operator=().

◆ refreshStaleImages()

int core::GameLibraryController::refreshStaleImages ( )

Refresh images for games with stale/missing image files Checks if stored paths still exist and re-discovers if not This should be called in a background thread Returns number of games refreshed.

Definition at line 696 of file game_library_controller.cpp.

Referenced by operator=().

◆ removeCollection()

bool core::GameLibraryController::removeCollection ( const std::string & name)

Remove a collection.

Definition at line 467 of file game_library_controller.cpp.

Referenced by operator=().

◆ removeGame()

bool core::GameLibraryController::removeGame ( const std::string & gameId)

Remove a game from the library Returns true on success.

Definition at line 350 of file game_library_controller.cpp.

References core::GameRemovedEvent::gameId.

Referenced by operator=().

◆ removeGameFromCollection()

bool core::GameLibraryController::removeGameFromCollection ( const std::string & gameId,
const std::string & collection )

Remove a game from a collection.

Definition at line 521 of file game_library_controller.cpp.

References Game::collections, and core::GameUpdatedEvent::gameId.

Referenced by operator=().

◆ renameCollection()

bool core::GameLibraryController::renameCollection ( const std::string & oldName,
const std::string & newName )

Rename a collection.

Definition at line 474 of file game_library_controller.cpp.

Referenced by operator=().

◆ saveLibrary()

void core::GameLibraryController::saveLibrary ( )

Save library to disk.

Definition at line 249 of file game_library_controller.cpp.

Referenced by operator=().

◆ searchGames()

std::vector< const Game * > core::GameLibraryController::searchGames ( const std::string & query) const

Search games by name (substring match).

Definition at line 666 of file game_library_controller.cpp.

Referenced by operator=().

◆ setFilter()

void core::GameLibraryController::setFilter ( const FilterOptions & options)

Set filter options and refresh filtered list.

Definition at line 409 of file game_library_controller.cpp.

Referenced by operator=().

◆ setOnFilteredListChanged()

void core::GameLibraryController::setOnFilteredListChanged ( OnFilteredListChanged callback)

Definition at line 729 of file game_library_controller.cpp.

Referenced by operator=().

◆ setOnGameAdded()

void core::GameLibraryController::setOnGameAdded ( OnGameAdded callback)

Definition at line 705 of file game_library_controller.cpp.

Referenced by operator=().

◆ setOnGameRemoved()

void core::GameLibraryController::setOnGameRemoved ( OnGameRemoved callback)

Definition at line 711 of file game_library_controller.cpp.

Referenced by operator=().

◆ setOnGameUpdated()

void core::GameLibraryController::setOnGameUpdated ( OnGameUpdated callback)

Definition at line 717 of file game_library_controller.cpp.

Referenced by operator=().

◆ setOnLibraryLoaded()

void core::GameLibraryController::setOnLibraryLoaded ( OnLibraryLoaded callback)

Definition at line 723 of file game_library_controller.cpp.

Referenced by operator=().

◆ setSort()

void core::GameLibraryController::setSort ( const SortOptions & options)

Set sort options and refresh filtered list.

Definition at line 424 of file game_library_controller.cpp.

Referenced by operator=().

◆ toggleFavorite()

void core::GameLibraryController::toggleFavorite ( const std::string & gameId)

Toggle favorite status.

Definition at line 565 of file game_library_controller.cpp.

References core::GameUpdatedEvent::gameId, Game::id, and Game::isFavorite.

Referenced by operator=().

◆ updateGame()

bool core::GameLibraryController::updateGame ( const std::string & gameId,
const Game & updatedGame )

Update an existing game Returns true on success.

Definition at line 322 of file game_library_controller.cpp.

References core::GameUpdatedEvent::gameId.

Referenced by operator=().


The documentation for this class was generated from the following files: