summaryrefslogtreecommitdiff
path: root/client/netcom.cc
diff options
context:
space:
mode:
authordeva <deva>2009-11-03 13:49:15 +0000
committerdeva <deva>2009-11-03 13:49:15 +0000
commit1782d12938ba89b67a52677d162d4c865f00cbe0 (patch)
treec4fe0ccd65af6485433310e54e8e8fef43f251da /client/netcom.cc
parentc91d9e62801aca5a12ca37429c39a71e6351d6d5 (diff)
First working, but not in any way optimal implementation of a http transport layer.
Diffstat (limited to 'client/netcom.cc')
-rw-r--r--client/netcom.cc58
1 files changed, 23 insertions, 35 deletions
diff --git a/client/netcom.cc b/client/netcom.cc
index 3b3abb7..6150227 100644
--- a/client/netcom.cc
+++ b/client/netcom.cc
@@ -29,28 +29,27 @@
#include <QApplication>
#include <QByteArray>
+#include <QHttp>
+
#include "widgets/widget.h"
NetCom::NetCom(QString host, quint16 port, QString user, QString cpr)
{
this->user = user;
this->cpr = cpr;
- socket.connectToHost(host, port);
- connect(&socket, SIGNAL(readyRead()), this, SLOT(readyRead()));
- socket.waitForConnected();
- transmitting = false;
+
+ connect(&http, SIGNAL(done(bool)), this, SLOT(done(bool)));
+ http.setHost(host, port);
+
+ transfering = false;
}
NetCom::~NetCom()
{
- socket.disconnectFromHost();
}
QDomDocument NetCom::send(QString templ, QString macro, bool lockgui)
{
- printf("Socket state: %d\n", socket.state());
- if(socket.state() != 3) printf("Socket state not connected: %s\n", socket.errorString().toStdString().c_str());
-
if(lockgui && qApp->activeWindow()) qApp->activeWindow()->setEnabled(false);
if(lockgui) QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
@@ -72,14 +71,15 @@ QDomDocument NetCom::send(QString templ, QString macro, bool lockgui)
printf("\nSending request:\n%s", doc.toString().toStdString().c_str());
- socket.write(doc.toByteArray());
- // socket.waitForReadyRead();
+ http.post("/", doc.toByteArray());
+ QDomDocument res_doc;
+ transfering = true;
+ buffer = "";
do {
qApp->processEvents(QEventLoop::WaitForMoreEvents);
- } while(!res_doc.setContent(buffer));
-
- buffer = "";
+ } while(transfering);
+ res_doc.setContent(buffer);
QDomElement elem = res_doc.documentElement();
@@ -91,18 +91,8 @@ QDomDocument NetCom::send(QString templ, QString macro, bool lockgui)
return res_doc;
}
-void NetCom::readyRead()
-{
- buffer.append(socket.readAll());
-}
-
void NetCom::send(QVector< Widget* > widgets, QString templ, QString macro, QString version)
{
- printf("Socket state: %d\n", socket.state());
- if(socket.state() != 3) printf("Socket state not connected: %s\n", socket.errorString().toStdString().c_str());
-
- // if(qApp->activeWindow()) qApp->activeWindow()->setEnabled(false); // Moved down!
-
QDomDocument doc;
QDomProcessingInstruction header = doc.createProcessingInstruction("xml", "version='1.0' encoding='UTF-8'");
@@ -139,22 +129,20 @@ void NetCom::send(QVector< Widget* > widgets, QString templ, QString macro, QStr
printf("\nSending commit:\n%s", doc.toString().toStdString().c_str());
- socket.write(doc.toByteArray());
- // socket.waitForReadyRead();
+ http.post("/", doc.toByteArray());
- //
- // Wait for the (hopefully) empty answer.
- //
+ transfering = true;
+ buffer = "";
do {
qApp->processEvents(QEventLoop::WaitForMoreEvents);
- } while(!res_doc.setContent(buffer));
-
- buffer = "";
-
- //QDomElement elem = res_doc.documentElement();
-
- printf("\nRecieved commit:\n%s", res_doc.toString().toStdString().c_str());
+ } while(transfering);
QApplication::restoreOverrideCursor();
if(qApp->activeWindow()) qApp->activeWindow()->setEnabled(true);
}
+
+void NetCom::done(bool)
+{
+ buffer = http.readAll();
+ transfering = false;
+}