diff options
author | Michal Klocek <michal.klocek@qt.io> | 2023-03-20 08:46:13 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2023-03-22 12:48:47 +0000 |
commit | b71403faeedf2955e3af541f9e140305af9ba0a8 (patch) | |
tree | 5c3537c500c5c65dc473c9fd3e2d45b327fdcd95 /tests/manual/examples/quick/customdialogs/server.cpp | |
parent | 7d9805df3a471e7172bf72ff1bc08c63ccfd67fa (diff) | |
download | qtwebengine-b71403faeedf2955e3af541f9e140305af9ba0a8.tar.gz |
Move custom dialogs example to manual tests
This example shows how to use dialogs, however documentation
already provides snippets for that added in 3cbe59e29a.
The only missing one was tooltip, therefore add missing snippet
and move example to manual tests.
Task-number: QTBUG-108751
Change-Id: I84eda805455fb0276046ed1089389d605a8af672
Reviewed-by: Michal Klocek <michal.klocek@qt.io>
(cherry picked from commit 6bf30525ee49d270dae6a6440bc607513f21237c)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests/manual/examples/quick/customdialogs/server.cpp')
-rw-r--r-- | tests/manual/examples/quick/customdialogs/server.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/manual/examples/quick/customdialogs/server.cpp b/tests/manual/examples/quick/customdialogs/server.cpp new file mode 100644 index 000000000..efb870618 --- /dev/null +++ b/tests/manual/examples/quick/customdialogs/server.cpp @@ -0,0 +1,47 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +#include "server.h" +#include <QDataStream> +#include <QTcpSocket> + +Server::Server(QObject *parent) : QObject(parent) +{ + connect(&m_server, &QTcpServer::newConnection, this, &Server::handleNewConnection); +} + +void Server::run() +{ + if (!m_server.listen(QHostAddress::LocalHost, 5555)) + qWarning() << "Could not start the server -> http/proxy authentication dialog" + " will not work. Error:" << m_server.errorString(); +} + +void Server::handleNewConnection() +{ + QTcpSocket *socket = m_server.nextPendingConnection(); + connect(socket, &QAbstractSocket::disconnected, socket, &QObject::deleteLater); + connect(socket, &QAbstractSocket::readyRead, this, &Server::handleReadReady); +} + +void Server::handleReadReady() +{ + QTcpSocket *socket = qobject_cast<QTcpSocket*>(sender()); + Q_ASSERT(socket); + m_data.append(socket->readAll()); + + // simply wait for whole request + if (!m_data.endsWith("\r\n\r\n")) + return; + if (m_data.contains(QByteArrayLiteral("OPEN_AUTH"))) { + socket->write("HTTP/1.1 401 Unauthorized\nWWW-Authenticate: " + "Basic realm=\"Very Restricted Area\"\r\n\r\n"); + m_data.clear(); + return; + } + + socket->write("HTTP/1.1 407 Proxy Auth Required\nProxy-Authenticate: " + "Basic realm=\"Proxy requires authentication\"\r\n" + "content-length: 0\r\n\r\n"); + m_data.clear(); +} |