summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSimon Rettberg2021-10-25 13:19:30 +0200
committerSimon Rettberg2021-10-25 13:59:34 +0200
commit5b7bbddc91117f13e0a77e0cfe8681496032dbb7 (patch)
tree1a0b97e3867d87354d850c317ce0bffa7ec2050a /src
parentMake guest hint more generic (diff)
downloadslxgreeter-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.
Diffstat (limited to 'src')
-rw-r--r--src/webview.cpp16
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()));