Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GUINewsFeed.h
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2026-2026 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
18// Fetches the SUMO release news RSS feed in the background (sumo-gui, netedit)
19/****************************************************************************/
20#pragma once
21#include <config.h>
22
23#include <atomic>
24#include <ctime>
25#include <mutex>
26#include <string>
27#include <thread>
28#include <vector>
29
32
33
34// ===========================================================================
35// class definitions
36// ===========================================================================
47class GUINewsFeed : public FXObject {
48 FXDECLARE(GUINewsFeed)
49
50public:
52 struct Item {
53 std::string title;
54 std::string link;
55 std::string description;
57 time_t published = 0;
58 };
59
61 enum {
65 };
66
68 static const std::string DEFAULT_URL;
69
71 static const time_t MIN_INTERVAL;
72
79 GUINewsFeed(FXApp* app, FXWindow* owner, FXStatusBar* statusBar, const std::string& url = DEFAULT_URL);
80
83
87 bool startCheck(const bool force = false);
88
90 void showLatest();
91
93 time_t getLastAccess() const;
94
96 static std::vector<Item> parseRSS(const std::string& xml);
97
99 long onFetched(FXObject*, FXSelector, void*);
100
102 long onCmdShow(FXObject*, FXSelector, void*);
103
104protected:
105 FOX_CONSTRUCTOR(GUINewsFeed)
106
107private:
109 void fetch();
110
112 FXApp* myApp = nullptr;
113
115 FXWindow* myOwner = nullptr;
116
118 FXStatusBar* myStatusBar = nullptr;
119
121 FXButton* myButton = nullptr;
122
124 std::vector<Item> myItems;
125
127 bool myShowAfterFetch = false;
128
130 std::string myURL;
131
133 std::thread myThread;
134
136 std::atomic<bool> myAbort;
137
140
142 std::mutex myMutex;
143
145 std::string myDocument;
146
148 bool myOK = false;
149
152
154 GUINewsFeed(const GUINewsFeed&) = delete;
155
158};
Periodically fetches an RSS feed with news about upcoming releases.
Definition GUINewsFeed.h:47
FXButton * myButton
the button in the status bar (null while there is nothing new)
FXStatusBar * myStatusBar
the status bar holding the news button
time_t getLastAccess() const
time of the last successful access (0 if never)
static const std::string DEFAULT_URL
default feed location
Definition GUINewsFeed.h:68
std::atomic< bool > myAbort
tells the worker thread to give up
std::mutex myMutex
protects myDocument and myOK
time_t myPreviousAccess
the last access time before this download started
void fetch()
the download, executed in myThread
bool myShowAfterFetch
whether the dialog should open as soon as the running download finishes
GUINewsFeed & operator=(const GUINewsFeed &)=delete
invalidated assignment operator
void showLatest()
shows the latest items, downloading them first if necessary
static std::vector< Item > parseRSS(const std::string &xml)
extracts the items of an RSS document
std::string myURL
the feed address
long onCmdShow(FXObject *, FXSelector, void *)
called when the news button was clicked, shows the latest items
std::string myDocument
the downloaded document
FXEX::MFXThreadEvent myThreadEvent
wakes the GUI thread
FXApp * myApp
the application (registry access)
FXWindow * myOwner
parent of the news dialog
~GUINewsFeed()
destructor, aborts a running download
GUINewsFeed(const GUINewsFeed &)=delete
invalidated copy constructor
static const time_t MIN_INTERVAL
minimum time between two accesses (seconds)
Definition GUINewsFeed.h:71
std::vector< Item > myItems
the latest items (empty until a download succeeded)
bool myOK
whether the download succeeded
bool startCheck(const bool force=false)
starts a download if enabled, curl is available and the last access is long enough ago
std::thread myThread
the worker thread
long onFetched(FXObject *, FXSelector, void *)
called in the GUI thread when the download has finished
a single entry of the feed
Definition GUINewsFeed.h:52
std::string description
Definition GUINewsFeed.h:55
std::string title
Definition GUINewsFeed.h:53
std::string link
Definition GUINewsFeed.h:54
time_t published
publication time (seconds since epoch), 0 if unknown
Definition GUINewsFeed.h:57