summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authordeva <deva>2008-09-23 09:37:51 +0000
committerdeva <deva>2008-09-23 09:37:51 +0000
commit78f095bd8649f8c67aeed3ceee8f693cb1c4d656 (patch)
tree855eddb464183d0daf7986bf3eec95abb9f436c1 /client
parentefb0b27f5bc659a49e330fb7970a9b1b6ae0f398 (diff)
Cleaned up the network code a bit. Now the window is locked while communication s going on to prevent network clutching.
Diffstat (limited to 'client')
-rw-r--r--client/macrowindow.cc12
-rw-r--r--client/netcom.cc43
-rw-r--r--client/netcom.h3
3 files changed, 37 insertions, 21 deletions
diff --git a/client/macrowindow.cc b/client/macrowindow.cc
index 360488e..37129aa 100644
--- a/client/macrowindow.cc
+++ b/client/macrowindow.cc
@@ -26,6 +26,7 @@
*/
#include "macrowindow.h"
+//#include <QApplication>
#include <QVBoxLayout>
#include <QMessageBox>
#include <QDomDocument>
@@ -65,12 +66,6 @@ MacroWindow::~MacroWindow()
void MacroWindow::update(QDomNode &node)
{
- // if(mainwidget) delete mainwidget;
- // if(resumewidget) delete resumewidget;
-
- // mainwidget = new QLabel("Expanded");
- // resumewidget = new QLabel("Collapsed");
-
mainwidget = NULL;
widgets.clear();
@@ -151,7 +146,7 @@ bool MacroWindow::doCommit()
// If all entries passed validation, continue commit
if(faulty == 0) {
- netcom.send(widgets, course, macro, version);
+ netcom.send(widgets, macro, version);
emit updateOnCommit();
setCollapsed(true);
return true;
@@ -279,10 +274,11 @@ void MacroWindow::addAuxWidgets(QVector< Widget* > ws)
void MacroWindow::toggleMacro()
{
-
if(isCollapsed()) {
widgets.clear();
auxwidgets.clear();
+ luaprograms.clear();
+
QDomDocument xml_doc = netcom.send(course, macro);
//
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);
}
diff --git a/client/netcom.h b/client/netcom.h
index 8f8b007..81fb147 100644
--- a/client/netcom.h
+++ b/client/netcom.h
@@ -42,12 +42,13 @@ public:
~NetCom();
QDomDocument send(QString course, QString macro = "");
- void send(QVector< Widget* > widgets, QString course, QString macro, QString version);
+ void send(QVector< Widget* > widgets, QString macro, QString version);
public slots:
void readyRead();
private:
+ volatile bool transmitting;
QTcpSocket socket;
QByteArray buffer;