SuperTuxKart
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
AddonsManager Class Reference

Public Member Functions

 AddonsManager ()
 Initialises the non-online component of the addons manager (i.e. More...
 
 ~AddonsManager ()
 The destructor saves the installed addons file again. More...
 
void init (const XMLNode *xml, bool force_refresh)
 This init function is called from a separate thread (started in news_manager, since the news.xml file contains the address of the addons.xml URL). More...
 
void initAddons (const XMLNode *xml)
 This initialises the online portion of the addons manager. More...
 
void checkInstalledAddons ()
 This function checks if the information in the installed addons file is consistent with what is actually available. More...
 
AddongetAddon (const std::string &id)
 Returns an addon with a given id. More...
 
int getAddonIndex (const std::string &id) const
 Returns the index of the addon with the given id, or -1 if no such addon exist. More...
 
bool install (const Addon &addon)
 Installs or updates (i.e. More...
 
bool uninstall (const Addon &addon)
 Removes all files froma login. More...
 
void reInit ()
 Reinitialises the addon manager, which happens when the user selects 'reload' in the addon manager.
 
bool anyAddonsInstalled () const
 
bool onlineReady () const
 Returns true if the list of online addons has been downloaded. More...
 
bool wasError () const
 
bool isLoading () const
 
void setErrorState ()
 Marks addon as not being available. More...
 
void saveInstalled ()
 Saves the information about installed addons and cached icons to addons_installed.xml. More...
 
unsigned int getNumAddons () const
 Returns the list of addons (installed and uninstalled). More...
 
const AddongetAddon (unsigned int i)
 Returns the i-th addons. More...
 
bool hasDownloadedIcons () const
 

Private Types

enum  STATE_TYPE { STATE_INIT, STATE_READY, STATE_ERROR }
 Which state the addons manager is: INIT: Waiting to download the list of addons. More...
 

Private Member Functions

void loadInstalledAddons ()
 Loads the installed addons from .../addons/addons_installed.xml.
 
void downloadIcons ()
 Download all necessary icons (i.e. More...
 

Private Attributes

Synchronised< std::vector< Addon > > m_addons_list
 The list of all addons - installed or uninstalled. More...
 
std::string m_file_installed
 Full filename of the addons_installed.xml file. More...
 
std::vector< std::string > m_icon_list
 List of loaded icons. More...
 
Synchronised< STATE_TYPEm_state
 
bool m_downloaded_icons
 

Member Enumeration Documentation

◆ STATE_TYPE

Which state the addons manager is: INIT: Waiting to download the list of addons.

READY: List is downloaded, manager is ready. ERROR: Error downloading the list, no addons available.

Constructor & Destructor Documentation

◆ AddonsManager()

AddonsManager::AddonsManager ( )

Initialises the non-online component of the addons manager (i.e.

handling the list of already installed addons). The online component is initialised later from a separate thread started from the news manager (see NewsManager::init() ).

◆ ~AddonsManager()

AddonsManager::~AddonsManager ( )

The destructor saves the installed addons file again.

This is necessary so that information about downloaded icons is saved for the next run.

Member Function Documentation

◆ checkInstalledAddons()

void AddonsManager::checkInstalledAddons ( )

This function checks if the information in the installed addons file is consistent with what is actually available.

This avoids e.g. that an addon is installed, but not marked here (and therefore shows up as not installed in the addons GUI), see bug #455.

◆ downloadIcons()

void AddonsManager::downloadIcons ( )
private

Download all necessary icons (i.e.

icons that are either missing or have been updated since they were downloaded).

◆ getAddon() [1/2]

Addon * AddonsManager::getAddon ( const std::string &  id)

Returns an addon with a given id.

Raises an assertion if the id is not found!

Parameters
idThe id to search for.

◆ getAddon() [2/2]

const Addon& AddonsManager::getAddon ( unsigned int  i)
inline

Returns the i-th addons.

◆ getAddonIndex()

int AddonsManager::getAddonIndex ( const std::string &  id) const

Returns the index of the addon with the given id, or -1 if no such addon exist.

Parameters
idThe (unique) identifier of the addon.

◆ getNumAddons()

unsigned int AddonsManager::getNumAddons ( ) const
inline

Returns the list of addons (installed and uninstalled).

◆ init()

void AddonsManager::init ( const XMLNode xml,
bool  force_refresh 
)

This init function is called from a separate thread (started in news_manager, since the news.xml file contains the address of the addons.xml URL).

Parameters
xmlThe news.xml file, which inclues the data about the addons.xml file (in the 'include' node).
force_refreshDownload addons.xml, even if the usual waiting period between downloads hasn't passed yet.

◆ initAddons()

void AddonsManager::initAddons ( const XMLNode xml)

This initialises the online portion of the addons manager.

It uses the downloaded list of available addons. It is called from init(), which is called from a separate thread, so blocking download requests can be used without blocking the GUI. This function will update the state variable.

Parameters
xmlThe xml tree of addons.xml with information about all available addons.

◆ install()

bool AddonsManager::install ( const Addon addon)

Installs or updates (i.e.

remove old and then install a new) an addon. It checks for the directories and then unzips the file (which must already have been downloaded).

Parameters
addonAddon data for the addon to install.
Returns
true if installation was successful.

◆ onlineReady()

bool AddonsManager::onlineReady ( ) const
inline

Returns true if the list of online addons has been downloaded.

This is used to grey out the 'addons' entry till a network connections could be established.

◆ saveInstalled()

void AddonsManager::saveInstalled ( )

Saves the information about installed addons and cached icons to addons_installed.xml.

If this is not called, information about downloaded icons is lost (and will trigger a complete redownload when STK is started next time).

◆ setErrorState()

void AddonsManager::setErrorState ( )
inline

Marks addon as not being available.

◆ uninstall()

bool AddonsManager::uninstall ( const Addon addon)

Removes all files froma login.

Parameters
addonThe addon to be removed.
Returns
True if uninstallation was successful.

Member Data Documentation

◆ m_addons_list

Synchronised<std::vector<Addon> > AddonsManager::m_addons_list
private

The list of all addons - installed or uninstalled.

The list is combined from the addons_installed.xml file first, then information from the downloaded list of items is merged/added to that.

◆ m_file_installed

std::string AddonsManager::m_file_installed
private

Full filename of the addons_installed.xml file.

◆ m_icon_list

std::vector<std::string> AddonsManager::m_icon_list
private

List of loaded icons.


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