![]() |
Eclipse SUMO - Simulation of Urban MObility
|
Periodically fetches an RSS feed with news about upcoming releases. More...
#include <GUINewsFeed.h>
Data Structures | |
| struct | Item |
| a single entry of the feed More... | |
Public Types | |
| enum | { ID_FETCHED = 1 , ID_SHOW , ID_LAST } |
| message ids More... | |
Public Member Functions | |
| time_t | getLastAccess () const |
| time of the last successful access (0 if never) | |
| GUINewsFeed (FXApp *app, FXWindow *owner, FXStatusBar *statusBar, const std::string &url=DEFAULT_URL) | |
| constructor | |
| long | onCmdShow (FXObject *, FXSelector, void *) |
| called when the news button was clicked, shows the latest items | |
| long | onFetched (FXObject *, FXSelector, void *) |
| called in the GUI thread when the download has finished | |
| void | showLatest () |
| shows the latest items, downloading them first if necessary | |
| bool | startCheck (const bool force=false) |
| starts a download if enabled, curl is available and the last access is long enough ago | |
| ~GUINewsFeed () | |
| destructor, aborts a running download | |
Static Public Member Functions | |
| static std::vector< Item > | parseRSS (const std::string &xml) |
| extracts the items of an RSS document | |
Static Public Attributes | |
| static const std::string | DEFAULT_URL = "https://eclipse.dev/sumo/feed/news.xml" |
| default feed location | |
| static const time_t | MIN_INTERVAL = 30 * 24 * 60 * 60 |
| minimum time between two accesses (seconds) | |
Private Member Functions | |
| void | fetch () |
| the download, executed in myThread | |
| GUINewsFeed (const GUINewsFeed &)=delete | |
| invalidated copy constructor | |
| GUINewsFeed & | operator= (const GUINewsFeed &)=delete |
| invalidated assignment operator | |
Private Attributes | |
| std::atomic< bool > | myAbort |
| tells the worker thread to give up | |
| FXApp * | myApp = nullptr |
| the application (registry access) | |
| FXButton * | myButton = nullptr |
| the button in the status bar (null while there is nothing new) | |
| std::string | myDocument |
| the downloaded document | |
| std::vector< Item > | myItems |
| the latest items (empty until a download succeeded) | |
| std::mutex | myMutex |
| protects myDocument and myOK | |
| bool | myOK = false |
| whether the download succeeded | |
| FXWindow * | myOwner = nullptr |
| parent of the news dialog | |
| time_t | myPreviousAccess = 0 |
| the last access time before this download started | |
| bool | myShowAfterFetch = false |
| whether the dialog should open as soon as the running download finishes | |
| FXStatusBar * | myStatusBar = nullptr |
| the status bar holding the news button | |
| std::thread | myThread |
| the worker thread | |
| FXEX::MFXThreadEvent | myThreadEvent |
| wakes the GUI thread | |
| std::string | myURL |
| the feed address | |
Periodically fetches an RSS feed with news about upcoming releases.
The download runs in a separate thread, the GUI thread is notified via an MFXThreadEvent. The time of the last successful access is stored in the FOX registry (section "NEWS", key "lastaccess", seconds since the epoch). The automatic check can be disabled by setting "lastaccess" to a time far in the future. Explicit requests via showLatest() always work and do not modify "lastaccess".
Definition at line 47 of file GUINewsFeed.h.
| anonymous enum |
| GUINewsFeed::GUINewsFeed | ( | FXApp * | app, |
| FXWindow * | owner, | ||
| FXStatusBar * | statusBar, | ||
| const std::string & | url = DEFAULT_URL |
||
| ) |
constructor
| [in] | app | the application whose registry is used |
| [in] | owner | the window used as parent of the news dialog |
| [in] | statusBar | the status bar receiving the news button (if null the dialog is shown directly) |
| [in] | url | the feed address |
Definition at line 151 of file GUINewsFeed.cpp.
| GUINewsFeed::~GUINewsFeed | ( | ) |
destructor, aborts a running download
Definition at line 161 of file GUINewsFeed.cpp.
|
privatedelete |
invalidated copy constructor
|
private |
the download, executed in myThread
Definition at line 214 of file GUINewsFeed.cpp.
References L, myAbort, myDocument, myMutex, myOK, myThreadEvent, myURL, and FXEX::MFXThreadEvent::signal().
Referenced by startCheck().
| time_t GUINewsFeed::getLastAccess | ( | ) | const |
time of the last successful access (0 if never)
Definition at line 170 of file GUINewsFeed.cpp.
References myApp, NEWS_REG_SECTION, and StringUtils::toLong().
Referenced by onCmdShow(), and startCheck().
| long GUINewsFeed::onCmdShow | ( | FXObject * | , |
| FXSelector | , | ||
| void * | |||
| ) |
called when the news button was clicked, shows the latest items
Definition at line 351 of file GUINewsFeed.cpp.
References ACCEPT, addRichLine(), GUIDesigns::buildFXButton(), GUIIconSubSys::getIcon(), getLastAccess(), GUIDesignAuxiliarHorizontalFrame, GUIDesignButtonDialog, GUIDesignDialogBox, GUIDesignHorizontalFrame, GUIDesignHorizontalSeparator, GUIDesignScrollWindowFixed, myApp, myButton, myItems, myOwner, myStatusBar, NEWS_DISABLED, NEWS_REG_SECTION, NEWS_WRAP_COLUMNS, SUMO_MINI, TL, toString(), StringUtils::trim(), and wrapLine().
Referenced by FXDEFMAP(), onFetched(), and showLatest().
| long GUINewsFeed::onFetched | ( | FXObject * | , |
| FXSelector | , | ||
| void * | |||
| ) |
called in the GUI thread when the download has finished
Definition at line 259 of file GUINewsFeed.cpp.
References GUIDesigns::buildFXButton(), GUIIconSubSys::getIcon(), ID_SHOW, myApp, myButton, myDocument, myItems, myMutex, myOK, myOwner, myPreviousAccess, myShowAfterFetch, myStatusBar, myThread, NEWS, NEWS_MAX_SHOWN, NEWS_REG_SECTION, onCmdShow(), parseRSS(), TL, and toString().
Referenced by FXDEFMAP().
|
privatedelete |
invalidated assignment operator
|
static |
extracts the items of an RSS document
Definition at line 420 of file GUINewsFeed.cpp.
References GUINewsFeed::Item::description, getElement(), GUINewsFeed::Item::link, parseDate(), GUINewsFeed::Item::published, and GUINewsFeed::Item::title.
Referenced by onFetched().
| void GUINewsFeed::showLatest | ( | ) |
shows the latest items, downloading them first if necessary
Definition at line 181 of file GUINewsFeed.cpp.
References myItems, myOwner, myShowAfterFetch, myThread, onCmdShow(), startCheck(), and TL.
Referenced by GUIMainWindow::onCmdNews().
| bool GUINewsFeed::startCheck | ( | const bool | force = false | ) |
starts a download if enabled, curl is available and the last access is long enough ago
Definition at line 193 of file GUINewsFeed.cpp.
References fetch(), getLastAccess(), MIN_INTERVAL, myPreviousAccess, myShowAfterFetch, and myThread.
Referenced by GUIMainWindow::checkNews(), and showLatest().
|
static |
default feed location
Definition at line 68 of file GUINewsFeed.h.
|
static |
minimum time between two accesses (seconds)
Definition at line 71 of file GUINewsFeed.h.
Referenced by startCheck().
|
private |
tells the worker thread to give up
Definition at line 136 of file GUINewsFeed.h.
Referenced by fetch(), and ~GUINewsFeed().
|
private |
the application (registry access)
Definition at line 112 of file GUINewsFeed.h.
Referenced by getLastAccess(), onCmdShow(), and onFetched().
|
private |
the button in the status bar (null while there is nothing new)
Definition at line 121 of file GUINewsFeed.h.
Referenced by onCmdShow(), and onFetched().
|
private |
the downloaded document
Definition at line 145 of file GUINewsFeed.h.
Referenced by fetch(), and onFetched().
|
private |
the latest items (empty until a download succeeded)
Definition at line 124 of file GUINewsFeed.h.
Referenced by onCmdShow(), onFetched(), and showLatest().
|
private |
protects myDocument and myOK
Definition at line 142 of file GUINewsFeed.h.
Referenced by fetch(), and onFetched().
|
private |
whether the download succeeded
Definition at line 148 of file GUINewsFeed.h.
Referenced by fetch(), and onFetched().
|
private |
parent of the news dialog
Definition at line 115 of file GUINewsFeed.h.
Referenced by onCmdShow(), onFetched(), and showLatest().
|
private |
the last access time before this download started
Definition at line 151 of file GUINewsFeed.h.
Referenced by onFetched(), and startCheck().
|
private |
whether the dialog should open as soon as the running download finishes
Definition at line 127 of file GUINewsFeed.h.
Referenced by onFetched(), showLatest(), and startCheck().
|
private |
the status bar holding the news button
Definition at line 118 of file GUINewsFeed.h.
Referenced by onCmdShow(), and onFetched().
|
private |
the worker thread
Definition at line 133 of file GUINewsFeed.h.
Referenced by onFetched(), showLatest(), startCheck(), and ~GUINewsFeed().
|
private |
|
private |