summaryrefslogtreecommitdiff
path: root/client/netcom.cc
diff options
context:
space:
mode:
Diffstat (limited to 'client/netcom.cc')
-rw-r--r--client/netcom.cc43
1 files changed, 31 insertions, 12 deletions
diff --git a/client/netcom.cc b/client/netcom.cc
index 8ff62b3..755357e 100644
--- a/client/netcom.cc
+++ b/client/netcom.cc
@@ -27,6 +27,7 @@
#include "netcom.h"
#include <QApplication>
+#include <QByteArray>
#include "widgets/widget.h"
@@ -36,6 +37,7 @@ NetCom::NetCom(QString host, quint16 port, QString user, QString cpr)
this->cpr = cpr;
socket.connectToHost(host, port);
connect(&socket, SIGNAL(readyRead()), this, SLOT(readyRead()));
+ transmitting = false;
}
NetCom::~NetCom()
@@ -45,8 +47,14 @@ NetCom::~NetCom()
QDomDocument NetCom::send(QString course, QString macro)
{
+ if(qApp->activeWindow()) qApp->activeWindow()->setEnabled(false);
+ QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
+
QDomDocument doc;
+ QDomProcessingInstruction header = doc.createProcessingInstruction("xml", "version='1.0' encoding='UTF-8'");
+ doc.appendChild(header);
+
QDomElement pracro_elem = doc.createElement("pracro");
pracro_elem.setAttribute("version", "1.0");
pracro_elem.setAttribute("cpr", cpr);
@@ -58,10 +66,10 @@ QDomDocument NetCom::send(QString course, QString macro)
if(macro != "") request_elem.setAttribute("macro", macro);
pracro_elem.appendChild(request_elem);
- printf(doc.toString().toStdString().c_str());
+ printf("\nSending:\n%s", doc.toString().toStdString().c_str());
socket.write(doc.toByteArray());
- socket.waitForBytesWritten(10000);
+ socket.waitForReadyRead();
do {
qApp->processEvents();
@@ -71,7 +79,10 @@ QDomDocument NetCom::send(QString course, QString macro)
QDomElement elem = res_doc.documentElement();
- printf(res_doc.toString().toStdString().c_str());
+ printf("\nRecieved:\n%s", res_doc.toString().toStdString().c_str());
+
+ QApplication::restoreOverrideCursor();
+ if(qApp->activeWindow()) qApp->activeWindow()->setEnabled(true);
return res_doc;
}
@@ -81,10 +92,16 @@ void NetCom::readyRead()
buffer.append(socket.readAll());
}
-void NetCom::send(QVector< Widget* > widgets, QString course, QString macro, QString version)
+void NetCom::send(QVector< Widget* > widgets, QString macro, QString version)
{
+ qApp->activeWindow()->setEnabled(false);
+ if(qApp->activeWindow()) qApp->activeWindow()->setEnabled(false);
+
QDomDocument doc;
+ QDomProcessingInstruction header = doc.createProcessingInstruction("xml", "version='1.0' encoding='UTF-8'");
+ doc.appendChild(header);
+
QDomElement pracro_elem = doc.createElement("pracro");
pracro_elem.setAttribute("version", "1.0");
pracro_elem.setAttribute("cpr", cpr);
@@ -96,11 +113,6 @@ void NetCom::send(QVector< Widget* > widgets, QString course, QString macro, QSt
commit_elem.setAttribute("version", version);
pracro_elem.appendChild(commit_elem);
- QDomElement request_elem = doc.createElement("request");
- request_elem.setAttribute("course", course);
- //if(macro != "") request_elem.setAttribute("macro", macro);
- pracro_elem.appendChild(request_elem);
-
// Iterate the different entries, and append their results to the commit string
QVector< Widget* >::iterator i = widgets.begin();
while (i != widgets.end()) {
@@ -114,11 +126,14 @@ void NetCom::send(QVector< Widget* > widgets, QString course, QString macro, QSt
i++;
}
- printf(doc.toString().toStdString().c_str());
-
+ printf("\nSending:\n%s", doc.toString().toStdString().c_str());
+
socket.write(doc.toByteArray());
- socket.waitForBytesWritten(10000);
+ socket.waitForReadyRead();
+ //
+ // Wait for the (hopefully) empty answer.
+ //
do {
qApp->processEvents();
} while(!res_doc.setContent(buffer));
@@ -127,4 +142,8 @@ void NetCom::send(QVector< Widget* > widgets, QString course, QString macro, QSt
QDomElement elem = res_doc.documentElement();
+ printf("\nRecieved:\n%s", res_doc.toString().toStdString().c_str());
+
+ QApplication::restoreOverrideCursor();
+ if(qApp->activeWindow()) qApp->activeWindow()->setEnabled(true);
}