SuperTuxKart
Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
NewsManager Class Reference
Inheritance diagram for NewsManager:
Inheritance graph
[legend]

Classes

class  NewsMessage
 

Public Member Functions

const core::stringw getNextNewsMessage ()
 Returns the next loaded news message.
 
const core::stringw getImportantMessage ()
 Returns the important message with the smallest id that has not been shown, or NULL if no important (not shown before) message exists atm.
 
void init (bool force_refresh)
 This function initialises the data for the news manager.
 
void addNewsMessage (const core::stringw &s)
 Add a news message.
 
void setErrorMessage (const core::stringw &s)
 Sets an error message that is displayed instead of any news message.
 
void clearErrorMessage ()
 Clears the error message.
 
void joinDownloadThreadIfExit ()
 
- Public Member Functions inherited from CanBeDeleted
 CanBeDeleted ()
 Set this instance to be not ready to be deleted.
 
void setCanBeDeleted ()
 Sets this instance to be ready to be deleted.
 
void resetCanBeDeleted ()
 
bool canBeDeletedNow ()
 
bool waitForReadyToDeleted (float waiting_time)
 Waits at most t seconds for this class to be ready to be deleted.
 

Static Public Member Functions

static NewsManagerget ()
 Singleton: if necessary create and get the news managers.
 
static bool isRunning ()
 
static void deallocate ()
 

Private Member Functions

void checkRedirect (const XMLNode *xml)
 Checks if a redirect is received, causing a new server to be used for downloading addons.
 
void updateNews (const XMLNode *xml, const std::string &filename)
 Updates the 'news' string to be displayed in the main menu.
 
bool conditionFulfilled (const std::string &cond)
 Checks if the given condition list are all fulfilled.
 
void downloadNews ()
 This function submits request which will download the m_news_filename file if necessary.
 

Private Attributes

Synchronised< std::vector< NewsMessage > > m_news
 
int m_current_news_message
 Index of the current news message that is being displayed.
 
core::stringw m_all_news_messages
 A single string that concatenats all news messages, separated by " +++ ".
 
std::vector< int > m_saved_display_count
 Stores the news message display count from the user config file.
 
Synchronised< core::stringw > m_error_message
 A high priority error message that is shown instead of any news message (usually indicating connection problems).
 
bool m_force_refresh
 True when all .xml files should be re-downloaded.
 
std::thread m_download_thread
 

Static Private Attributes

static NewsManagerm_news_manager = nullptr
 
static std::string m_news_filename = "online_news.xml"
 The name of the news file on the remote server.
 

Member Function Documentation

◆ addNewsMessage()

void NewsManager::addNewsMessage ( const core::stringw &  s)

Add a news message.

This is used to add error messages, e.g. for problems when downloading addons.

Parameters
sThe news message to add.

◆ checkRedirect()

void NewsManager::checkRedirect ( const XMLNode xml)
private

Checks if a redirect is received, causing a new server to be used for downloading addons.

Parameters
xmlXML data structure containing the redirect information.

◆ conditionFulfilled()

bool NewsManager::conditionFulfilled ( const std::string &  cond)
private

Checks if the given condition list are all fulfilled.

The conditions must be separated by ";", and each condition must be of the form "type comp version". Type must be 'stkversion' comp must be one of "<", "=", ">" version must be a valid STK version string

Parameters
condThe list of conditions
Returns
True if all conditions are true.

◆ downloadNews()

void NewsManager::downloadNews ( )
private

This function submits request which will download the m_news_filename file if necessary.

It is running in its own thread, so we can use blocking download calls without blocking the GUI.

◆ getImportantMessage()

const core::stringw NewsManager::getImportantMessage ( )

Returns the important message with the smallest id that has not been shown, or NULL if no important (not shown before) message exists atm.

The user config is updated to store the last important message id shown.

◆ getNextNewsMessage()

const core::stringw NewsManager::getNextNewsMessage ( )

Returns the next loaded news message.

It will 'wrap around', i.e. if there is only one message it will be returned over and over again. To be used by the the main menu to get the next news message after one message was scrolled off screen.

◆ init()

void NewsManager::init ( bool  force_refresh)

This function initialises the data for the news manager.

It starts a separate thread to execute downloadNews() - which (if necessary) downloads the m_news_filename file and updates the list of news messages. It also initialises the addons manager (which can trigger another download of m_news_filename).

Parameters
force_refreshRe-download m_news_filename, even if

◆ updateNews()

void NewsManager::updateNews ( const XMLNode xml,
const std::string &  filename 
)
private

Updates the 'news' string to be displayed in the main menu.

Parameters
xmlThe XML data from the news file.
filenameThe filename of the news xml file. Only needed in case of an error (e.g. the file might be corrupted)
  • the file will be deleted so that on next start of stk it will be updated again.

Member Data Documentation

◆ m_all_news_messages

core::stringw NewsManager::m_all_news_messages
private

A single string that concatenats all news messages, separated by " +++ ".

Using this to display the news message avoids the delay between messages.


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