#include "connectortoserver.h" #include ConnectorToServer::ConnectorToServer(QObject *parent) : QObject(parent), connectionThread(nullptr), client(nullptr), dataParser(nullptr), sendSystem(nullptr), recognizeSystem(nullptr) { initialize(); } bool ConnectorToServer::authorizationInstructorLocal(QString login, QString password) { if (!client->getIsConnected()) { return false; } ClientAutorization *autorization = new ClientAutorization; autorization->Login = login; autorization->Password = password; autorization->TypeClient = TypeClientAutorization::TYPE_GUI; dataParser->createAuthMessage(autorization); emit sigSendAutorization(); return true; } bool ConnectorToServer::deAuthorizationInstructorLocal(QString login) { if (!client->getIsConnected()) { return false; } ClientDeAutorization *deAutorization = new ClientDeAutorization; deAutorization->Login = login; dataParser->createDeAuthMessage(deAutorization); emit sigSendDeAutorization(); return true; } bool ConnectorToServer::sendQueryToDB(TypeQueryToDB typeQuery, int id, void* data) { if (!client->getIsConnected()) { return false; } ClientQueryToDB *queryToDB = new ClientQueryToDB; queryToDB->typeQuery = typeQuery; dataParser->createQueryToDBMessage(queryToDB, id, data); emit sigSendQueryToDB(); return true; } void ConnectorToServer::SetConnectToServer() { emit sigSetConnect(dataParser->getServerSettings(),connectionThread); } QList ConnectorToServer::getListInstructors() { return listInstructors; } QList ConnectorToServer::getListTrainees() { return listTrainees; } QList ConnectorToServer::getListGroups() { return listGroups; } QList ConnectorToServer::getListComputers() { return listComputers; } QList ConnectorToServer::getListClassrooms() { return listClassrooms; } QList ConnectorToServer::getListTasks() { return listTasks; } bool ConnectorToServer::isArchivedInstructor(int id) { for(Instructor instructor : listInstructors) { if(instructor.getID() == id) { if(instructor.getArchived()) return true; else return false; } } return false; } bool ConnectorToServer::isAdminInstructor(int id) { for(Instructor instructor : listInstructors) { if(instructor.getID() == id) { if(instructor.getIsAdmin()) return true; else return false; } } return false; } bool ConnectorToServer::isLoggedInInstructor(int id) { for(Instructor instructor : listInstructors) { if(instructor.getID() == id) { if(instructor.getLoggedIn()) return true; else return false; } } return false; } Instructor ConnectorToServer::getInstructor(int id) { for(Instructor instructor : listInstructors) { if(instructor.getID() == id) return instructor; } return Instructor(); } QList ConnectorToServer::getListTraineesInGroup(int id) { QList list; for(Trainee trainee : listTrainees) { if(trainee.getGroup().getID() == id) list.append(trainee); } return list; } bool ConnectorToServer::isArchivedTrainee(int id) { for(Trainee trainee : listTrainees) { if(trainee.getID() == id) { if(trainee.getArchived()) return true; else return false; } } return false; } bool ConnectorToServer::isLoggedInTrainee(int id) { for(Trainee trainee : listTrainees) { if(trainee.getID() == id) { if(trainee.getLoggedIn()) return true; else return false; } } return false; } Trainee ConnectorToServer::getTrainee(int id) { for(Trainee trainee : listTrainees) { if(trainee.getID() == id) return trainee; } return Trainee(); } Group ConnectorToServer::getGroup(int id) { for(Group group : listGroups) { if(group.getID() == id) return group; } return Group(); } /* void ConnectorToServer::slot_AnswerQueryToDB(QList* listInstructors, QList* listTrainees, QList* listGroups) { this->listInstructors = *listInstructors; this->listTrainees = *listTrainees; this->listGroups = *listGroups; emit signal_UpdateDB(true, true); }*/ void ConnectorToServer::slot_AnswerQueryToDB_ListInstructors(QList listInstructors) { this->listInstructors = listInstructors; emit signal_UpdateDB(true, false); } void ConnectorToServer::slot_AnswerQueryToDB_ListGroups(QList listGroups) { this->listGroups = listGroups; emit signal_UpdateDB(false, true); } void ConnectorToServer::slot_AnswerQueryToDB_ListTrainees(QList listTrainees) { this->listTrainees = listTrainees; emit signal_UpdateDB(false, true); } void ConnectorToServer::slot_AnswerQueryToDB_ListComputers(QList listComputers) { this->listComputers = listComputers; //emit signal_UpdateDB(false, true); } void ConnectorToServer::slot_AnswerQueryToDB_ListClassrooms(QList listClassrooms) { this->listClassrooms = listClassrooms; //emit signal_UpdateDB(false, true); } void ConnectorToServer::slot_AnswerQueryToDB_ListTasks(QList listTasks) { this->listTasks = listTasks; //emit signal_UpdateDB(false, true); } void ConnectorToServer::initialize() { createObjects(); bindConnection(); emit sigInitializeClient(recognizeSystem,sendSystem,connectionThread); emit sigSetConnect(dataParser->getServerSettings(),connectionThread); } void ConnectorToServer::bindConnection() { connect(this,&ConnectorToServer::sigInitializeClient,client,&TCPClient::initialize,Qt::AutoConnection); connect(this,&ConnectorToServer::sigSetConnect,client,&TCPClient::setConnect,Qt::AutoConnection); connect(this,&ConnectorToServer::sigSendAutorization,sendSystem,&SendSystem::sendClientAutorization); connect(this,&ConnectorToServer::sigSendDeAutorization,sendSystem,&SendSystem::sendClientAutorization); connect(this,&ConnectorToServer::sigSendQueryToDB,sendSystem,&SendSystem::sendClientQueryToDB); connect(recognizeSystem,&RecognizeSystem::sigAuth,this,&ConnectorToServer::sigLoginResult); connect(recognizeSystem,&RecognizeSystem::sigDeAuth,this,&ConnectorToServer::sigDeLoginResult); //connect(recognizeSystem,&RecognizeSystem::sigAnswerQueryToDB,this,&ConnectorToServer::slot_AnswerQueryToDB); connect(recognizeSystem,&RecognizeSystem::sigAnswerQueryToDB_ListInstructors,this,&ConnectorToServer::slot_AnswerQueryToDB_ListInstructors); connect(recognizeSystem,&RecognizeSystem::sigAnswerQueryToDB_ListGroups,this,&ConnectorToServer::slot_AnswerQueryToDB_ListGroups); connect(recognizeSystem,&RecognizeSystem::sigAnswerQueryToDB_ListTrainees,this,&ConnectorToServer::slot_AnswerQueryToDB_ListTrainees); connect(recognizeSystem,&RecognizeSystem::sigAnswerQueryToDB_ListComputers,this,&ConnectorToServer::slot_AnswerQueryToDB_ListComputers); connect(recognizeSystem,&RecognizeSystem::sigAnswerQueryToDB_ListClassrooms,this,&ConnectorToServer::slot_AnswerQueryToDB_ListClassrooms); connect(recognizeSystem,&RecognizeSystem::sigAnswerQueryToDB_ListTasks,this,&ConnectorToServer::slot_AnswerQueryToDB_ListTasks); connect(client,&TCPClient::signal_ConnectedToServer,this,&ConnectorToServer::signal_ConnectedToServer); } void ConnectorToServer::createObjects() { connectionThread = new QThread; client = new TCPClient; client->moveToThread(connectionThread); dataParser = new DataParser; sendSystem = new SendSystem; sendSystem->moveToThread(connectionThread); recognizeSystem = new RecognizeSystem; recognizeSystem->moveToThread(connectionThread); connectionThread->start(); connectionThread->setPriority(QThread::HighestPriority); }