SuperTuxKart
Classes | Public Types | 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 Types

enum  NewsType : uint8_t { NTYPE_MAINMENU , NTYPE_LIST , NTYPE_COUNT }
 

Public Member Functions

const int getNextNewsID (NewsType type)
 News are stored in an array, it would iterate to the next one when calling this function and would go back to the first one when the iteration ends. More...
 
const core::stringw getCurrentNewsMessage (NewsType type)
 Returns the message pointed by the current ptr.
 
const std::string getCurrentNewsDate (NewsType type)
 Returns the date of the news pointed by the current ptr.
 
const std::string getCurrentNewsLink (NewsType type)
 Returns the date of the news pointed by the current ptr.
 
const bool isCurrentNewsImportant (NewsType type)
 Returns the importance of the message pointed by the current ptr.
 
const int getNewsCount (NewsType type)
 
void prioritizeNewsAfterID (NewsType type, int id)
 Set id = -1 to disable it.
 
void init (bool force_refresh)
 This function initialises the data for the news manager. More...
 
void addNewsMessage (NewsType type, const core::stringw &s)
 Add a news message. More...
 
void resetNewsPtr (NewsType type)
 Goes back to the place before first message when called.
 
bool isNewsFetching (NewsType type)
 Check if this type of news is on the way of fetching.
 
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. 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...
 
void downloadNews ()
 This function submits request which will download the m_news_filename file if necessary. More...
 

Private Attributes

Synchronised< std::vector< NewsMessage > > m_news [NTYPE_COUNT]
 m_news[NewsType] means all news within this type.
 
int m_current_news_ptr [NTYPE_COUNT]
 Index of the current news message that is being displayed.
 
int m_news_prioritize_after_id [NTYPE_COUNT]
 News after this ID would be shown on the top regardless of importance.
 
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 ( NewsType  type,
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.

◆ getNextNewsID()

const int NewsManager::getNextNewsID ( NewsType  type)

News are stored in an array, it would iterate to the next one when calling this function and would go back to the first one when the iteration ends.

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.

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