From b71403faeedf2955e3af541f9e140305af9ba0a8 Mon Sep 17 00:00:00 2001 From: Michal Klocek Date: Mon, 20 Mar 2023 08:46:13 +0100 Subject: 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 (cherry picked from commit 6bf30525ee49d270dae6a6440bc607513f21237c) Reviewed-by: Qt Cherry-pick Bot --- .../manual/examples/quick/customdialogs/server.cpp | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 tests/manual/examples/quick/customdialogs/server.cpp (limited to 'tests/manual/examples/quick/customdialogs/server.cpp') 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 +#include + +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(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(); +} -- cgit v1.2.1