summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main.cpp8
-rw-r--r--src/slxbrowser.cpp50
-rw-r--r--src/slxbrowser.h4
3 files changed, 46 insertions, 16 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 2bf94f8..1504cba 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -8,15 +8,21 @@
class KeyHandler : public QObject
{
public:
+ KeyHandler(SlxBrowser *win) : QObject(), _win(win) {}
bool eventFilter(QObject *obj, QEvent *event)
{
if (event->type() == QEvent::KeyPress) {
QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
if ( keyEvent->key() == Qt::Key_Q && (keyEvent->modifiers() & Qt::ControlModifier))
exit(0);
+ _win->activity();
+ } else if (event->type() == QEvent::MouseMove) {
+ _win->activity();
}
return QObject::eventFilter(obj, event);
}
+private:
+ SlxBrowser *_win;
};
QStringList loadUrlList(const QString &file);
@@ -63,7 +69,7 @@ int main(int argc, char** argv)
settings.isWhitelist = parser.isSet(whitelist);
SlxBrowser main(settings);
main.show();
- app.installEventFilter(new KeyHandler());
+ app.installEventFilter(new KeyHandler(&main));
app.exec();
return 0;
}
diff --git a/src/slxbrowser.cpp b/src/slxbrowser.cpp
index 1fe179f..13ed326 100644
--- a/src/slxbrowser.cpp
+++ b/src/slxbrowser.cpp
@@ -15,7 +15,10 @@ SlxBrowser::SlxBrowser(BrowserSettings settings)
_settings(settings),
_unsupportedUri(false),
_blockedSite(false),
- _lastPageLoad(0)
+ _lastPageLoad(0),
+ _activity(false),
+ _lastActivity(0),
+ _pageValid(false)
{
_settings.reloadInterval *= 1000;
if (_settings.fullscreen) {
@@ -69,9 +72,10 @@ SlxBrowser::~SlxBrowser()
void SlxBrowser::loadStarted()
{
+ _pageValid = false;
_reset.stop();
if (_settings.reloadInterval > 0) {
- _reset.start(_settings.reloadInterval + 10000);
+ _reset.start(_settings.reloadInterval + 5000);
}
_normalError.clear();
_sslErrors.clear();
@@ -83,8 +87,8 @@ void SlxBrowser::loadFinished(bool ok)
{
_progress->hide();
qint64 now = QDateTime::currentMSecsSinceEpoch();
- if (!_browser->wasAbortedDownload() && !ok) {
-
+ bool abortedDl = _browser->wasAbortedDownload();
+ if (!abortedDl && !ok) {
if (_unsupportedUri) {
QMessageBox::warning(this, QString::fromUtf8("Denied"),
QString::fromUtf8("This URL type is not supported.\n\n"
@@ -101,13 +105,6 @@ void SlxBrowser::loadFinished(bool ok)
QString::fromUtf8("Target URL not allowed.\n\n"
"Dieser Link führt auf eine nicht erlaubte Seite."));
});
- /*
- _browser->page()->mainFrame()->setHtml("<html><body style='background:white;color:black'><br><br>"
- "<center><h1>Zugriff verweigert</h1>"
- "<p>Diese URL wurde gefiltert.<br>"
- "<a href='javascript:window.history.back()'>Zurück</a></p></center>"
- "</body></html>");
- */
} else {
_browser->page()->mainFrame()->setHtml("<html><body style='background:blue;color:white'><br><br>"
"<center><h1>Page Load Error</h1><pre id='content'></pre></center>"
@@ -128,12 +125,20 @@ void SlxBrowser::loadFinished(bool ok)
}
str.append("\n\n\n\n" + QDateTime::currentDateTime().toString());
el.setPlainText(str);
+ _pageValid = false;
+ if (_settings.reloadInterval > 0) {
+ _reset.start(qMin(30000, _settings.reloadInterval));
+ } else {
+ _reset.start(30000);
+ }
}
_sslErrors.clear();
_normalError.clear();
- _reset.start(qMin(30000, _settings.reloadInterval > 0 ? _settings.reloadInterval : 30000));
- } else if (_settings.reloadInterval > 0) {
- _reset.start(_settings.reloadInterval);
+ } else {
+ _pageValid = true;
+ if (_settings.reloadInterval > 0) {
+ _reset.start(qMax(_settings.reloadInterval / 20, 1000));
+ }
}
_unsupportedUri = false;
@@ -169,7 +174,22 @@ void SlxBrowser::requestFinished(QNetworkReply *reply)
void SlxBrowser::reloadInitial()
{
- _browser->page()->mainFrame()->load(_settings.url);
+ if (_pageValid) {
+ if (_activity) {
+ _lastActivity = QDateTime::currentMSecsSinceEpoch();
+ _activity = false;
+ _reset.start(qMax(_settings.reloadInterval / 20, 1000));
+ return;
+ }
+ qint64 now = QDateTime::currentMSecsSinceEpoch();
+ if (now - qMax(_lastActivity, _lastPageLoad) > _settings.reloadInterval) {
+ _browser->page()->mainFrame()->load(_settings.url);
+ } else {
+ _reset.start(qMax(_settings.reloadInterval / 20, 1000));
+ }
+ } else {
+ _browser->page()->mainFrame()->load(_settings.url);
+ }
}
static QRegularExpression urlListToRegExp(const QStringList &list)
diff --git a/src/slxbrowser.h b/src/slxbrowser.h
index 2c14465..16c5da2 100644
--- a/src/slxbrowser.h
+++ b/src/slxbrowser.h
@@ -27,6 +27,7 @@ class SlxBrowser : public QMainWindow
public:
SlxBrowser(BrowserSettings settings);
virtual ~SlxBrowser();
+ void activity() { _activity = true; }
private slots:
void loadStarted();
@@ -46,6 +47,9 @@ private:
QList<QSslError> _sslErrors;
QString _normalError;
qint64 _lastPageLoad;
+ bool _activity;
+ qint64 _lastActivity;
+ bool _pageValid;
};
#endif /* SLXBROWSER_H_ */