qt 6.6.0 clean

This commit is contained in:
kleuter
2023-11-01 22:23:55 +01:00
parent 7b5ada15e7
commit 5d8194efa7
1449 changed files with 134276 additions and 31391 deletions

View File

@ -28,6 +28,10 @@ set_target_properties(network-chat PROPERTIES
MACOSX_BUNDLE TRUE
)
target_compile_definitions(network-chat PRIVATE
QT_USE_QSTRINGBUILDER
)
target_link_libraries(network-chat PRIVATE
Qt6::Core
Qt6::Gui

View File

@ -1,10 +1,14 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include <QtWidgets>
#include "chatdialog.h"
#include <QTimer>
#include <QScrollBar>
#include <QLineEdit>
#include <QTextTable>
#include <QMessageBox>
ChatDialog::ChatDialog(QWidget *parent)
: QDialog(parent)
{
@ -27,7 +31,7 @@ ChatDialog::ChatDialog(QWidget *parent)
myNickName = client.nickName();
newParticipant(myNickName);
tableFormat.setBorder(0);
QTimer::singleShot(10 * 1000, this, SLOT(showInformation()));
QTimer::singleShot(10 * 1000, this, &ChatDialog::showInformation);
}
void ChatDialog::appendMessage(const QString &from, const QString &message)

View File

@ -12,7 +12,7 @@ class ChatDialog : public QDialog, private Ui::ChatDialog
Q_OBJECT
public:
ChatDialog(QWidget *parent = nullptr);
explicit ChatDialog(QWidget *parent = nullptr);
public slots:
void appendMessage(const QString &from, const QString &message);

View File

@ -1,15 +1,18 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include <QtNetwork>
#include "client.h"
#include "connection.h"
#include "peermanager.h"
#include <QHostInfo>
#include <algorithm>
#include <functional>
Client::Client()
: peerManager(new PeerManager(this))
{
peerManager = new PeerManager(this);
peerManager->setServerPort(server.serverPort());
peerManager->startBroadcasting();
@ -36,14 +39,15 @@ QString Client::nickName() const
bool Client::hasConnection(const QHostAddress &senderIp, int senderPort) const
{
if (senderPort == -1)
return peers.contains(senderIp);
if (!peers.contains(senderIp))
auto [begin, end] = peers.equal_range(senderIp);
if (begin == peers.constEnd())
return false;
const QList<Connection *> connections = peers.values(senderIp);
for (const Connection *connection : connections) {
if (senderPort == -1)
return true;
for (; begin != end; ++begin) {
Connection *connection = *begin;
if (connection->peerPort() == senderPort)
return true;
}
@ -63,8 +67,7 @@ void Client::newConnection(Connection *connection)
void Client::readyForUse()
{
Connection *connection = qobject_cast<Connection *>(sender());
if (!connection || hasConnection(connection->peerAddress(),
connection->peerPort()))
if (!connection || hasConnection(connection->peerAddress(), connection->peerPort()))
return;
connect(connection, &Connection::newMessage,
@ -90,8 +93,7 @@ void Client::connectionError(QAbstractSocket::SocketError /* socketError */)
void Client::removeConnection(Connection *connection)
{
if (peers.contains(connection->peerAddress())) {
peers.remove(connection->peerAddress());
if (peers.remove(connection->peerAddress(), connection) > 0) {
QString nick = connection->name();
if (!nick.isEmpty())
emit participantLeft(nick);

View File

@ -4,12 +4,12 @@
#ifndef CLIENT_H
#define CLIENT_H
#include "server.h"
#include <QAbstractSocket>
#include <QHash>
#include <QHostAddress>
#include "server.h"
class PeerManager;
class Client : public QObject

View File

@ -4,7 +4,7 @@
#include "connection.h"
#include <QtNetwork>
#include <QTimerEvent>
static const int TransferTimeout = 30 * 1000;
static const int PongTimeout = 60 * 1000;
@ -27,12 +27,6 @@ static const int PingInterval = 5 * 1000;
Connection::Connection(QObject *parent)
: QTcpSocket(parent), writer(this)
{
greetingMessage = tr("undefined");
username = tr("unknown");
state = WaitingForGreeting;
currentDataType = Undefined;
transferTimerId = -1;
isGreetingMessageSent = false;
pingTimer.setInterval(PingInterval);
connect(this, &QTcpSocket::readyRead, this,

View File

@ -32,8 +32,8 @@ public:
Undefined
};
Connection(QObject *parent = nullptr);
Connection(qintptr socketDescriptor, QObject *parent = nullptr);
explicit Connection(QObject *parent = nullptr);
explicit Connection(qintptr socketDescriptor, QObject *parent = nullptr);
~Connection();
QString name() const;
@ -59,15 +59,15 @@ private:
QCborStreamReader reader;
QCborStreamWriter writer;
QString greetingMessage;
QString username;
QString greetingMessage = tr("undefined");
QString username = tr("unknown");
QTimer pingTimer;
QElapsedTimer pongTime;
QString buffer;
ConnectionState state;
DataType currentDataType;
int transferTimerId;
bool isGreetingMessageSent;
ConnectionState state = WaitingForGreeting;
DataType currentDataType = Undefined;
int transferTimerId = -1;
bool isGreetingMessageSent = false;
};
#endif

View File

@ -1,11 +1,9 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include <QApplication>
#include "chatdialog.h"
#include <QtCore/QSettings>
#include <QtWidgets/QApplication>
int main(int argc, char *argv[])
{

View File

@ -11,6 +11,7 @@ SOURCES = chatdialog.cpp \
server.cpp
FORMS = chatdialog.ui
QT += network widgets
DEFINES += QT_USE_QSTRINGBUILDER
requires(qtConfig(udpsocket))
requires(qtConfig(listwidget))

View File

@ -2,20 +2,18 @@
// Copyright (C) 2018 Intel Corporation.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include <QtNetwork>
#include "client.h"
#include "connection.h"
#include "peermanager.h"
#include <QNetworkInterface>
static const qint32 BroadcastInterval = 2000;
static const unsigned broadcastPort = 45000;
PeerManager::PeerManager(Client *client)
: QObject(client)
: QObject(client), client(client)
{
this->client = client;
static const char *envVariables[] = {
"USERNAME", "USER", "USERDOMAIN", "HOSTNAME", "DOMAINNAME"
};
@ -30,7 +28,6 @@ PeerManager::PeerManager(Client *client)
username = "unknown";
updateAddresses();
serverPort = 0;
broadcastSocket.bind(QHostAddress::Any, broadcastPort, QUdpSocket::ShareAddress
| QUdpSocket::ReuseAddressHint);
@ -59,11 +56,7 @@ void PeerManager::startBroadcasting()
bool PeerManager::isLocalHostAddress(const QHostAddress &address) const
{
for (const QHostAddress &localAddress : ipAddresses) {
if (address.isEqual(localAddress))
return true;
}
return false;
return ipAddresses.contains(address);
}
void PeerManager::sendBroadcastDatagram()
@ -79,8 +72,7 @@ void PeerManager::sendBroadcastDatagram()
bool validBroadcastAddresses = true;
for (const QHostAddress &address : std::as_const(broadcastAddresses)) {
if (broadcastSocket.writeDatagram(datagram, address,
broadcastPort) == -1)
if (broadcastSocket.writeDatagram(datagram, address, broadcastPort) == -1)
validBroadcastAddresses = false;
}

View File

@ -18,7 +18,7 @@ class PeerManager : public QObject
Q_OBJECT
public:
PeerManager(Client *client);
explicit PeerManager(Client *client);
void setServerPort(int port);
QString userName() const;
@ -35,13 +35,13 @@ private slots:
private:
void updateAddresses();
Client *client;
Client *client = nullptr;
QList<QHostAddress> broadcastAddresses;
QList<QHostAddress> ipAddresses;
QUdpSocket broadcastSocket;
QTimer broadcastTimer;
QString username;
int serverPort;
int serverPort = 0;
};
#endif

View File

@ -1,8 +1,6 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include <QtNetwork>
#include "connection.h"
#include "server.h"

View File

@ -13,7 +13,7 @@ class Server : public QTcpServer
Q_OBJECT
public:
Server(QObject *parent = nullptr);
explicit Server(QObject *parent = nullptr);
signals:
void newConnection(Connection *connection);