18 #ifndef HEADER_NEWS_MANAGER_HPP
19 #define HEADER_NEWS_MANAGER_HPP
28 #include <irrString.h>
31 #include "utils/can_be_deleted.hpp"
32 #include "utils/synchronised.hpp"
43 enum NewsType : uint8_t
71 NewsMessage(
const core::stringw &m,
int id,
const std::string &date=
"",
72 const std::string &link=
"",
bool important=
false)
79 m_important = important;
82 const core::stringw&
getNews()
const {
return m_news; }
84 const std::string&
getDate()
const {
return m_date; }
86 const std::string&
getLink()
const {
return m_link; }
113 int m_current_news_ptr[NTYPE_COUNT];
115 int m_news_prioritize_after_id[NTYPE_COUNT];
128 std::thread m_download_thread;
130 void checkRedirect(
const XMLNode *xml);
131 void updateNews(
const XMLNode *xml,
132 const std::string &filename);
133 bool conditionFulfilled(
const std::string &cond);
144 return m_news_manager;
147 static bool isRunning() {
return m_news_manager != NULL; }
153 delete m_news_manager;
154 m_news_manager = NULL;
161 const int getNextNewsID(NewsType type);
163 getCurrentNewsMessage(NewsType type);
165 getCurrentNewsDate(NewsType type);
167 getCurrentNewsLink(NewsType type);
168 const bool isCurrentNewsImportant(NewsType type);
169 const int getNewsCount(NewsType type);
172 void prioritizeNewsAfterID(NewsType type,
int id);
174 void init(
bool force_refresh);
175 void addNewsMessage(NewsType type,
const core::stringw &s);
192 void joinDownloadThreadIfExit()
194 if (CanBeDeleted::canBeDeletedNow() && m_download_thread.joinable())
195 m_download_thread.join();
A simple class that a adds a function to wait with a timeout for a class to be ready to be deleted.
Definition: can_be_deleted.hpp:38
Definition: news_manager.hpp:56
const std::string & getLink() const
Returns the link of the news.
Definition: news_manager.hpp:86
bool operator<(NewsMessage other) const
For sorting the news.
Definition: news_manager.hpp:98
int getDisplayCount() const
Returns the display count.
Definition: news_manager.hpp:92
bool m_important
True if this is an important (i.e.
Definition: news_manager.hpp:68
core::stringw m_news
The actual news message.
Definition: news_manager.hpp:58
std::string m_date
Additional data.
Definition: news_manager.hpp:60
int m_message_id
A message id used to store some information in the user config file.
Definition: news_manager.hpp:64
bool isImportant() const
Returns if this is an important message.
Definition: news_manager.hpp:96
int getMessageId() const
Returns the news id.
Definition: news_manager.hpp:90
void setDisplayCount(int n)
Sets the display count for this message.
Definition: news_manager.hpp:94
const core::stringw & getNews() const
Returns the news message.
Definition: news_manager.hpp:82
int m_display_count
Counts how often a message has been displayed.
Definition: news_manager.hpp:66
const std::string & getDate() const
Returns the date of the news.
Definition: news_manager.hpp:84
void increaseDisplayCount()
Increases how often this message was being displayed.
Definition: news_manager.hpp:88
Definition: news_manager.hpp:40
static std::string m_news_filename
The name of the news file on the remote server.
Definition: news_manager.hpp:107
bool isNewsFetching(NewsType type)
Check if this type of news is on the way of fetching.
Definition: news_manager.hpp:181
void setErrorMessage(const core::stringw &s)
Sets an error message that is displayed instead of any news message.
Definition: news_manager.hpp:184
Synchronised< core::stringw > m_error_message
A high priority error message that is shown instead of any news message (usually indicating connectio...
Definition: news_manager.hpp:123
std::vector< int > m_saved_display_count
Stores the news message display count from the user config file.
Definition: news_manager.hpp:119
static NewsManager * get()
Singleton: if necessary create and get the news managers.
Definition: news_manager.hpp:140
void resetNewsPtr(NewsType type)
Goes back to the place before first message when called.
Definition: news_manager.hpp:179
void clearErrorMessage()
Clears the error message.
Definition: news_manager.hpp:190
bool m_force_refresh
True when all .xml files should be re-downloaded.
Definition: news_manager.hpp:126
A variable that is automatically synchronised using pthreads mutex.
Definition: synchronised.hpp:28
void setAtomic(const TYPE &v)
Sets the value of this variable using a mutex.
Definition: synchronised.hpp:59
utility class used to parse XML files
Definition: xml_node.hpp:48
void deallocate()
To be called after cleanup().
Definition: engine.cpp:1077