mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/RRJServer.git
synced 2026-03-28 19:55:48 +03:00
128 lines
3.3 KiB
C++
128 lines
3.3 KiB
C++
#include "clientanswerparser.h"
|
||
|
||
ClientAnswerParser::ClientAnswerParser(QObject *parent) : QObject(parent)
|
||
{
|
||
|
||
}
|
||
|
||
void ClientAnswerParser::initialize(DataParser *dataParser)
|
||
{
|
||
this->dataParser = dataParser;
|
||
}
|
||
|
||
QByteArray ClientAnswerParser::authorization(bool result, QString instructorName,QString clientName, QString accessType, QString login, int id)
|
||
{
|
||
|
||
QList<SXmlAnswerTag> listTag;
|
||
|
||
SAttribute attribute1 = {"Result", result? "true" : "false"};
|
||
SAttribute attribute2 = {"InstructorName", instructorName};
|
||
SAttribute attribute3 = {"ClientName", clientName};
|
||
SAttribute attribute4 = {"AccessType", accessType};
|
||
SAttribute attribute5 = {"Login", login};
|
||
SAttribute attribute6 = {"id_client", QString::number(id)};
|
||
QList<SAttribute> listAttr = {attribute1, attribute2, attribute3, attribute4, attribute5, attribute6};
|
||
SXmlAnswerTag tag = {"ServerAuthorization", listAttr};
|
||
|
||
listTag.append(tag);
|
||
|
||
return dataParser->xmlAnswer(listTag);
|
||
}
|
||
|
||
QByteArray ClientAnswerParser::deAuthorization(bool result, QString login)
|
||
{
|
||
QList<SXmlAnswerTag> listTag;
|
||
|
||
SAttribute attribute1 = {"Result", result? "true" : "false"};
|
||
SAttribute attribute2 = {"Login", login};
|
||
QList<SAttribute> listAttr = {attribute1, attribute2};
|
||
SXmlAnswerTag tag = {"ServerDeAuthorization", listAttr};
|
||
|
||
listTag.append(tag);
|
||
|
||
return dataParser->xmlAnswer(listTag);
|
||
}
|
||
|
||
QByteArray ClientAnswerParser::message(QString text, QString login)
|
||
{
|
||
QList<SXmlAnswerTag> listTag;
|
||
SAttribute attribute2;
|
||
|
||
SAttribute attribute1 = {"Text", text};
|
||
QList<SAttribute> listAttr = {attribute1};
|
||
if(login != "")
|
||
{
|
||
attribute2 = {"Login", login};
|
||
listAttr.append(attribute2);
|
||
}
|
||
SXmlAnswerTag tag = {"ServerMessage", listAttr};
|
||
|
||
listTag.append(tag);
|
||
|
||
return dataParser->xmlAnswer(listTag);
|
||
}
|
||
|
||
QByteArray ClientAnswerParser::task(QString text)
|
||
{
|
||
QList<SXmlAnswerTag> listTag;
|
||
|
||
SAttribute attribute1 = {"Text", text};
|
||
QList<SAttribute> listAttr = {attribute1};
|
||
SXmlAnswerTag tag = {"ServerTask", listAttr};
|
||
|
||
listTag.append(tag);
|
||
|
||
return dataParser->xmlAnswer(listTag);
|
||
}
|
||
|
||
QByteArray ClientAnswerParser::notify(QString code)
|
||
{
|
||
QList<SXmlAnswerTag> listTag;
|
||
|
||
SAttribute attribute1 = {"Code", code};
|
||
QList<SAttribute> listAttr = {attribute1};
|
||
SXmlAnswerTag tag = {"ServerNotify", listAttr};
|
||
|
||
listTag.append(tag);
|
||
|
||
return dataParser->xmlAnswer(listTag);
|
||
}
|
||
|
||
QByteArray ClientAnswerParser::tasks(QStringList listTasks)
|
||
{
|
||
QList<SXmlAnswerTag> listTag;
|
||
|
||
foreach(QString task, listTasks)
|
||
{
|
||
QList<SAttribute> listAttr;
|
||
|
||
SAttribute attribute1 = {"Head", task};
|
||
SAttribute attribute2 = {"IsComplete", "false"};
|
||
listAttr.append(attribute1);
|
||
listAttr.append(attribute2);
|
||
|
||
SXmlAnswerTag tag = {"ServerTask", listAttr};
|
||
listTag.append(tag);
|
||
}
|
||
|
||
return dataParser->xmlAnswer(listTag, "TaskArray", "Tasks");
|
||
}
|
||
|
||
QByteArray ClientAnswerParser::currentVersion()
|
||
{
|
||
QByteArray array;
|
||
QFile fileR(version);
|
||
if (!fileR.open(QFile::ReadOnly | QFile::Text))
|
||
{
|
||
QString str = "Не удалось открыть файл";
|
||
qDebug() << "xmlAnswer: " << str;
|
||
}
|
||
else
|
||
{
|
||
array = fileR.readAll();
|
||
fileR.close(); // Закрываем файл
|
||
}
|
||
|
||
return array;
|
||
}
|