diff options
author | Simon Rettberg | 2021-10-25 13:19:30 +0200 |
---|---|---|
committer | Simon Rettberg | 2021-10-25 13:59:34 +0200 |
commit | 5b7bbddc91117f13e0a77e0cfe8681496032dbb7 (patch) | |
tree | 1a0b97e3867d87354d850c317ce0bffa7ec2050a | |
parent | Make guest hint more generic (diff) | |
download | slxgreeter-5b7bbddc91117f13e0a77e0cfe8681496032dbb7.tar.gz slxgreeter-5b7bbddc91117f13e0a77e0cfe8681496032dbb7.tar.xz slxgreeter-5b7bbddc91117f13e0a77e0cfe8681496032dbb7.zip |
Add "Mobile" to User-Agent header for embedded browser
As the browser window is rather small, try to get a mobile optimized
version of whatever login page we're supposed to display.
-rw-r--r-- | src/webview.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/webview.cpp b/src/webview.cpp index 0ca7328..17a5261 100644 --- a/src/webview.cpp +++ b/src/webview.cpp @@ -9,6 +9,21 @@ #include <QWebHistory> #include <QNetworkCookieJar> #include <QWebElement> +#include <QRegularExpression> +#include <QWebPage> + +// Override user-agent to make it appear mobile +class UaWebPage : public QWebPage +{ +public: + static QRegularExpression re; + + QString userAgentForUrl(const QUrl &url) const override { + return QWebPage::userAgentForUrl(url).replace(re, "Mobile \\1"); + } +}; + +QRegularExpression UaWebPage::re("(\\S+)$"); WebView::WebView(QWidget* parent) : QWebView(parent), @@ -16,6 +31,7 @@ WebView::WebView(QWidget* parent) _abortedDownload(false), _timerReset(new QTimer(this)) { + this->setPage(new UaWebPage); _timerAbortMessage->setSingleShot(true); _timerReset->setSingleShot(true); connect(page(), SIGNAL(windowCloseRequested()), this, SLOT(windowCloseRequested())); |