From 9bca81b853bf66e58a8357a094c93808b2e38445 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 15 Jan 2018 12:07:41 +0100 Subject: Add --reload-interval option to periodically reload the passed URL --- src/main.cpp | 4 +++- src/slxbrowser.cpp | 10 ++++++++-- src/slxbrowser.h | 3 ++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 9ac7748..b828d60 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -29,8 +29,10 @@ int main(int argc, char** argv) parser.addPositionalArgument("url", "URL to load"); QCommandLineOption ignoreSsl("insecure", "Ignore SSL errors"); QCommandLineOption fullscreen("fullscreen", "Run browser in full screen"); + QCommandLineOption reloadInterval("reload-interval", "Reload displayed page every X seconds", "seconds"); parser.addOption(ignoreSsl); parser.addOption(fullscreen); + parser.addOption(reloadInterval); parser.process(app); QStringList list(parser.positionalArguments()); if (list.empty()) { @@ -38,7 +40,7 @@ int main(int argc, char** argv) return 1; } QString url(list[0]); - SLXbrowser main(url, parser.isSet(fullscreen), parser.isSet(ignoreSsl)); + SLXbrowser main(url, parser.isSet(fullscreen), parser.isSet(ignoreSsl), parser.value(reloadInterval).toInt()); main.show(); app.installEventFilter(new KeyHandler()); app.exec(); diff --git a/src/slxbrowser.cpp b/src/slxbrowser.cpp index 45c235a..a8fc1d8 100644 --- a/src/slxbrowser.cpp +++ b/src/slxbrowser.cpp @@ -6,10 +6,11 @@ #include #include -SLXbrowser::SLXbrowser(QString url, bool fullscreen, bool ignoreSslErrors) +SLXbrowser::SLXbrowser(QString url, bool fullscreen, bool ignoreSslErrors, int reloadIntervalSeconds) : QMainWindow(NULL), _url(url), - _ignoreSslErrors(ignoreSslErrors) + _ignoreSslErrors(ignoreSslErrors), + _reloadIntervalMs(reloadIntervalSeconds * 1000) { if (fullscreen) { this->showFullScreen(); @@ -55,6 +56,9 @@ SLXbrowser::~SLXbrowser() void SLXbrowser::loadStarted() { _reset.stop(); + if (_reloadIntervalMs > 0) { + _reset.start(_reloadIntervalMs + 10000); + } _normalError.clear(); _sslErrors.clear(); _progress->setValue(0); @@ -85,6 +89,8 @@ void SLXbrowser::loadFinished(bool ok) _sslErrors.clear(); _normalError.clear(); _reset.start(30000); + } else if (_reloadIntervalMs > 0) { + _reset.start(_reloadIntervalMs); } } diff --git a/src/slxbrowser.h b/src/slxbrowser.h index dc357dd..acbb7d8 100644 --- a/src/slxbrowser.h +++ b/src/slxbrowser.h @@ -15,7 +15,7 @@ class SLXbrowser : public QMainWindow { Q_OBJECT public: - SLXbrowser(QString url, bool fullscreen, bool ignoreSslErrors); + SLXbrowser(QString url, bool fullscreen, bool ignoreSslErrors, int reloadInterval); virtual ~SLXbrowser(); private slots: @@ -34,6 +34,7 @@ private: QTimer _reset; QList _sslErrors; QString _normalError; + int _reloadIntervalMs; }; #endif /* SLXBROWSER_H_ */ -- cgit v1.2.3-55-g7522