SuperTuxKart
Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Static 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. More...
 
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. More...
 
void init (bool force_refresh)
 This function initialises the data for the news manager. More...
 
void addNewsMessage (const core::stringw &s)
 Add a news message. More...
 
void setErrorMessage (const core::stringw &s)
 Sets an error message that is displayed instead of any news message. More...
 
void clearErrorMessage ()
 Clears the error message. More...
 
- Public Member Functions inherited from CanBeDeleted
 CanBeDeleted ()
 Set this instance to be not ready to be deleted. More...
 
void setCanBeDeleted ()
 Sets this instance to be ready to be deleted. More...
 
bool waitForReadyToDeleted (float waiting_time)
 Waits at most t seconds for this class to be ready to be deleted. More...
 

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. More...
 
void updateNews (const XMLNode *xml, const std::string &filename)
 Updates the 'news' string to be displayed in the main menu. More...
 
bool conditionFulfilled (const std::string &cond)
 Checks if the given condition list are all fulfilled. More...
 

Static Private Member Functions

static void * downloadNews (void *obj)
 This function submits request which will download the m_news_filename file if necessary. More...
 

Private Attributes

Synchronised< std::vector< NewsMessage > > m_news
 
int m_current_news_message
 Index of the current news message that is being displayed. More...
 
core::stringw m_all_news_messages
 A single string that concatenats all news messages, separated by " +++ ". More...
 
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). More...
 
bool m_force_refresh
 True when all .xml files should be re-downloaded. More...
 

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.

◆ clearErrorMessage()

void NewsManager::clearErrorMessage ( )
inline

Clears the error message.

◆ 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 ( void *  obj)
staticprivate

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.

Parameters
objThis is 'this' object, passed on during pthread creation.

◆ 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

◆ setErrorMessage()

void NewsManager::setErrorMessage ( const core::stringw &  s)
inline

Sets an error message that is displayed instead of any news message.

◆ 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.

◆ m_current_news_message

int NewsManager::m_current_news_message
private

Index of the current news message that is being displayed.

◆ m_error_message

Synchronised<core::stringw> NewsManager::m_error_message
private

A high priority error message that is shown instead of any news message (usually indicating connection problems).

◆ m_force_refresh

bool NewsManager::m_force_refresh
private

True when all .xml files should be re-downloaded.


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