mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/RRJClient.git
synced 2026-03-28 05:25:39 +03:00
fead: load without animation
This commit is contained in:
@@ -7,95 +7,40 @@
|
||||
TCPClient::TCPClient(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
//socket = NULL;
|
||||
socket = new QTcpSocket();
|
||||
socket->setParent(this);
|
||||
socket->moveToThread(this->thread());
|
||||
}
|
||||
|
||||
void TCPClient::initialize(RecognizeSystem *recognize,ExternalExecuter *externalExecuter)
|
||||
void TCPClient::initialize(RecognizeSystem *recognize,ExternalExecuter *externalExecuter,SendSystem *sendSystem)
|
||||
{
|
||||
this->recognizeSystem = recognize;
|
||||
this->externalExecuter = externalExecuter;
|
||||
|
||||
this->sendSystem = sendSystem;
|
||||
|
||||
emit sigSendDebugLog(Tools::getTime() + " Client started");
|
||||
}
|
||||
|
||||
void TCPClient::setConnect(ServerSettings *serverSettings)
|
||||
void TCPClient::setConnect(ServerSettings *serverSettings,QThread *th)
|
||||
{
|
||||
socket = new QTcpSocket();
|
||||
qDebug() << "TCPCLient thread: " << thread();
|
||||
if (socket != NULL && socket->state() == QTcpSocket::ConnectedState)
|
||||
{
|
||||
emit sigSendDebugLog("already connected");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
socket->connectToHost(serverSettings->Address,serverSettings->Port.toShort());
|
||||
connect(socket,&QTcpSocket::readyRead,this,&TCPClient::slotReadyRead,Qt::DirectConnection);
|
||||
connect(socket,&QTcpSocket::disconnected,this,&TCPClient::setDisconnect);
|
||||
connect(socket,&QTcpSocket::connected,this,&TCPClient::slotConnectNotify);
|
||||
connect(this,&TCPClient::sigRecognize,recognizeSystem,&RecognizeSystem::recognize,Qt::DirectConnection);
|
||||
|
||||
socket->connectToHost(serverSettings->Address,serverSettings->Port.toShort());
|
||||
connect(this,&TCPClient::sigRecognize,recognizeSystem,&RecognizeSystem::recognize,Qt::DirectConnection);
|
||||
connect(this,&TCPClient::sigSetSocket,sendSystem,&SendSystem::setSocket);
|
||||
|
||||
emit sigSetSocket(socket);
|
||||
emit sigSendDebugLog("Try connect...");
|
||||
}
|
||||
|
||||
void TCPClient::sendClientAutorization()
|
||||
{
|
||||
QDataStream stream(socket);
|
||||
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
|
||||
|
||||
if(socket->state() != QTcpSocket::ConnectedState){
|
||||
emit sigConnectionState(false);
|
||||
return;
|
||||
}
|
||||
|
||||
QFile file(tempName);
|
||||
file.open(QIODevice::ReadOnly);
|
||||
|
||||
QByteArray array = file.readAll();
|
||||
stream << PacketType::TYPE_XMLANSWER;
|
||||
stream << array;
|
||||
socket->waitForBytesWritten();
|
||||
}
|
||||
|
||||
void TCPClient::sendFile()
|
||||
{
|
||||
QDataStream stream(socket);
|
||||
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
|
||||
quint64 fileSize = 0;
|
||||
int countSend = 0;
|
||||
|
||||
QFile file(hashFilename); //Открываем файл для чтения
|
||||
|
||||
stream << PacketType::TYPE_FILE; //Отправляем тип блока
|
||||
QFileInfo fileInfo(file);
|
||||
|
||||
fileSize = fileInfo.size();
|
||||
stream << fileSize;
|
||||
|
||||
if(file.open(QFile::ReadOnly | QFile::Text)){
|
||||
while(!file.atEnd()){
|
||||
QByteArray data = file.readAll();//file.read(1025*250);
|
||||
stream << data;
|
||||
countSend++;
|
||||
}
|
||||
|
||||
qDebug() << Tools::getTime() << "count end Final: " << countSend;
|
||||
}
|
||||
|
||||
file.close();
|
||||
|
||||
qDebug() << "Transaction after send file: " << socket->isTransactionStarted();
|
||||
countSend = 0;
|
||||
}
|
||||
|
||||
|
||||
void TCPClient::sendQTConnect()
|
||||
{
|
||||
QString value = QString::number(PacketType::TYPE_QT);
|
||||
socket->write(value.toUtf8());
|
||||
socket->waitForBytesWritten();
|
||||
}
|
||||
|
||||
void TCPClient::setDisconnect()
|
||||
{
|
||||
@@ -104,20 +49,8 @@ void TCPClient::setDisconnect()
|
||||
emit sigSendDebugLog("Server disabled");
|
||||
}
|
||||
|
||||
void TCPClient::sendDisable()
|
||||
{
|
||||
QDataStream stream(socket);
|
||||
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
|
||||
|
||||
QByteArray data;
|
||||
data = emit sigGetXmlAnswer("DISABLE");
|
||||
|
||||
stream << PacketType::TYPE_XMLANSWER;
|
||||
stream << data;
|
||||
socket->waitForBytesWritten();
|
||||
}
|
||||
|
||||
void TCPClient::waitRead(int time)
|
||||
void TCPClient:: waitRead(int time)
|
||||
{
|
||||
socket->waitForReadyRead(time);
|
||||
}
|
||||
@@ -127,32 +60,32 @@ QTcpSocket *TCPClient::getSocket()
|
||||
return socket;
|
||||
}
|
||||
|
||||
void TCPClient::slotMessageEntered(QString message)
|
||||
void TCPClient::slotSendCommand(QString command)
|
||||
{
|
||||
QDataStream stream(socket);
|
||||
QByteArray data;
|
||||
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
|
||||
|
||||
if(!message.isEmpty() && socket->state() == QTcpSocket::ConnectedState){
|
||||
if(!command.isEmpty() && socket->state() == QTcpSocket::ConnectedState){
|
||||
|
||||
if(message == "check")
|
||||
if(command == "check")
|
||||
{
|
||||
stream << PacketType::TYPE_COMMAND;
|
||||
stream << message;
|
||||
stream << command;
|
||||
socket->waitForBytesWritten();
|
||||
|
||||
sendFile();
|
||||
sendSystem->sendFileBlock("/" + hashFilename);
|
||||
emit sigSendDebugLog(Tools::getTime() + " Local checkFile sended");
|
||||
|
||||
socket->waitForReadyRead(1000);
|
||||
}
|
||||
else if(message == "update"){
|
||||
else if(command == "update"){
|
||||
emit sigSendDebugLog("Update started");
|
||||
stream << PacketType::TYPE_COMMAND;
|
||||
stream << message;
|
||||
stream << command;
|
||||
socket->waitForBytesWritten();
|
||||
}
|
||||
else if(message == "run"){
|
||||
else if(command == "run"){
|
||||
externalExecuter->callApp();
|
||||
}
|
||||
}else{
|
||||
@@ -172,7 +105,7 @@ void TCPClient::slotConnectNotify()
|
||||
{
|
||||
emit sigSendDebugLog("Connect complete");
|
||||
emit sigConnectionState(true);
|
||||
sendQTConnect();
|
||||
sendSystem->sendQTConnect();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,10 +116,6 @@ void TCPClient::slotReadyRead()
|
||||
return;
|
||||
}
|
||||
|
||||
// qDebug() << "Transaction before recognize: " << socket->isTransactionStarted();
|
||||
|
||||
// if(socket->isTransactionStarted()) return;
|
||||
|
||||
emit sigRecognize(socket);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user