Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qdesigner_server.cpp
Go to the documentation of this file.
1
// Copyright (C) 2016 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
// Qt-Security score:significant reason:default
4
5
#
include
"qdesigner.h"
6
#
include
"qdesigner_server.h"
7
8
#
include
<
QtGui
/
qevent
.
h
>
9
10
#
include
<
QtNetwork
/
qhostaddress
.
h
>
11
#
include
<
QtNetwork
/
qlocalsocket
.
h
>
12
#
include
<
QtNetwork
/
qtcpserver
.
h
>
13
#
include
<
QtNetwork
/
qtcpsocket
.
h
>
14
15
#
include
<
QtCore
/
qfileinfo
.
h
>
16
#
include
<
QtCore
/
qstringlist
.
h
>
17
18
QT_BEGIN_NAMESPACE
19
20
using
namespace
Qt::StringLiterals;
21
22
// ### review
23
24
static
void
readFiles
(QIODevice *device)
25
{
26
while
(device->canReadLine()) {
27
QString file = QString::fromUtf8(device->readLine());
28
if
(!file.isNull()) {
29
file.remove(u'\n');
30
file.remove(u'\r');
31
if
(QFile::exists(file))
32
QCoreApplication::postEvent(
qDesigner
,
new
QFileOpenEvent(file));
33
}
34
}
35
}
36
37
QDesignerTcpServer
::QDesignerTcpServer(QObject *parent) : QObject(parent), m_server(
new
QTcpServer(
this
))
38
{
39
if
(m_server->listen(QHostAddress::LocalHost, 0))
40
connect(m_server, &QTcpServer::newConnection,
this
, &QDesignerTcpServer::handleNewConnection);
41
}
42
43
QDesignerTcpServer
::~
QDesignerTcpServer
() =
default
;
44
45
quint16
QDesignerTcpServer
::
serverPort
()
const
46
{
47
return
m_server ? m_server->serverPort() : 0;
48
}
49
50
void
QDesignerTcpServer
::sendOpenRequest(
int
port,
const
QStringList &files)
51
{
52
auto
*sSocket =
new
QTcpSocket();
53
sSocket->connectToHost(QHostAddress::LocalHost, port);
54
if
(sSocket->waitForConnected(3000)) {
55
for
(
const
QString &file : files) {
56
QFileInfo fi(file);
57
sSocket->write(fi.absoluteFilePath().toUtf8() +
'\n'
);
58
}
59
sSocket->waitForBytesWritten(3000);
60
sSocket->close();
61
}
62
delete
sSocket;
63
}
64
65
void
QDesignerTcpServer
::readFromClient()
66
{
67
readFiles(m_socket);
68
}
69
70
void
QDesignerTcpServer
::socketClosed()
71
{
72
m_socket =
nullptr
;
73
}
74
75
void
QDesignerTcpServer
::handleNewConnection()
76
{
77
// no need for more than one connection
78
if
(m_socket ==
nullptr
) {
79
m_socket = m_server->nextPendingConnection();
80
connect(m_socket, &QTcpSocket::readyRead,
this
, &
QDesignerTcpServer
::readFromClient);
81
connect(m_socket, &QTcpSocket::disconnected,
this
, &
QDesignerTcpServer
::socketClosed);
82
}
83
}
84
85
QDesignerLocalSocketClient
::QDesignerLocalSocketClient(
const
QString &serverName, QObject *parent)
86
: QObject(parent), m_socket(
new
QLocalSocket(
this
))
87
{
88
m_socket->connectToServer(serverName, QIODevice::ReadOnly);
89
connect(m_socket, &QLocalSocket::readyRead,
this
, &QDesignerLocalSocketClient::readFromSocket);
90
}
91
92
QDesignerLocalSocketClient
::~
QDesignerLocalSocketClient
()
93
{
94
m_socket->close();
95
m_socket->flush();
96
}
97
98
void
QDesignerLocalSocketClient
::readFromSocket()
99
{
100
readFiles(m_socket);
101
}
102
103
QDesignerTcpClient
::QDesignerTcpClient(quint16 port, QObject *parent)
104
: QObject(parent), m_socket(
new
QTcpSocket(
this
))
105
{
106
m_socket->connectToHost(QHostAddress::LocalHost, port);
107
connect(m_socket, &QTcpSocket::readyRead,
this
, &QDesignerTcpClient::readFromSocket);
108
}
109
110
QDesignerTcpClient
::~
QDesignerTcpClient
()
111
{
112
m_socket->close();
113
m_socket->flush();
114
}
115
116
void
QDesignerTcpClient
::readFromSocket()
117
{
118
readFiles(m_socket);
119
}
120
121
QT_END_NAMESPACE
QDesignerLocalSocketClient
Definition
qdesigner_server.h:39
QDesignerLocalSocketClient::~QDesignerLocalSocketClient
~QDesignerLocalSocketClient() override
Definition
qdesigner_server.cpp:92
QDesignerTcpClient
Definition
qdesigner_server.h:54
QDesignerTcpClient::~QDesignerTcpClient
~QDesignerTcpClient() override
Definition
qdesigner_server.cpp:110
QDesignerTcpServer
Definition
qdesigner_server.h:18
QDesignerTcpServer::~QDesignerTcpServer
~QDesignerTcpServer() override
QDesignerTcpServer::serverPort
quint16 serverPort() const
Definition
qdesigner_server.cpp:45
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qDesigner
#define qDesigner
Definition
qdesigner.h:19
readFiles
static void readFiles(QIODevice *device)
Definition
qdesigner_server.cpp:24
qttools
src
designer
src
designer
qdesigner_server.cpp
Generated on
for Qt by
1.18.0