diff options
author | senator <senator> | 2007-09-11 12:28:05 +0000 |
---|---|---|
committer | senator <senator> | 2007-09-11 12:28:05 +0000 |
commit | 07ff9de80d37dc0cd33feb027628eb95c1fccd35 (patch) | |
tree | ce0dd936f12120b428ed62f0c6a8eed37a31e571 | |
parent | 20c7a5d63dc1f68fcf0e1aa053a4b725235e6f78 (diff) |
xml request and retrieval functioning; basic macro layout recursing functioning
-rw-r--r-- | client/builder.cc | 142 | ||||
-rw-r--r-- | client/builder.h | 51 | ||||
-rw-r--r-- | client/macro.cc | 74 | ||||
-rw-r--r-- | client/macro.h | 34 | ||||
-rw-r--r-- | client/main.cc | 42 | ||||
-rw-r--r-- | client/xmlacquire.cc | 136 | ||||
-rw-r--r-- | client/xmlacquire.h | 68 |
7 files changed, 547 insertions, 0 deletions
diff --git a/client/builder.cc b/client/builder.cc new file mode 100644 index 0000000..d868f12 --- /dev/null +++ b/client/builder.cc @@ -0,0 +1,142 @@ +#include "builder.h" +#include "widgets/widget.h" +#include "widgets/label.h" +#include "widgets/lineedit.h" +#include "widgets/textedit.h" +#include "widgets/pushbutton.h" +#include "widgets/combobox.h" +#include "widgets/frame.h" +#include "widgets/radiobutton.h" +#include "widgets/checkbox.h" +#include "widgets/window.h" +//#include <QApplication> +#include <QVBoxLayout> +#include <QDomDocument> +#include <QDomElement> +#include <QDomNode> +#include <vector> + +std::vector< Widget* > widgets; + +Builder::Builder(QDomDocument *xml_doc) + : QObject() +{ + // Assign root element from xml_doc + this->xml_doc = xml_doc; + QDomElement xml_elem = xml_doc->documentElement(); + + // Execute the recursive function with documentElement + recurser(xml_elem, NULL); + + /* + Window widget(window_elem); + + Frame *frame = new Frame(frame_elem); + + QVBoxLayout *layout = new QVBoxLayout(); + QVBoxLayout *window_layout = new QVBoxLayout(); + + Label *label = new Label(label_elem); + widgets.push_back(label); + LineEdit *lineedit = new LineEdit(lineedit_elem); + widgets.push_back(lineedit); + LineEdit *lineedit2 = new LineEdit(lineedit_elem); + widgets.push_back(lineedit2); + TextEdit *textedit = new TextEdit(textedit_elem); + widgets.push_back(textedit); + + ComboBox *combobox = new ComboBox(combobox_elem); + widgets.push_back(combobox); + + RadioButton *radiobutton1 = new RadioButton(radiobutton1_elem); + widgets.push_back(radiobutton1); + RadioButton *radiobutton2 = new RadioButton(radiobutton2_elem); + widgets.push_back(radiobutton2); + CheckBox *checkbox = new CheckBox(checkbox_elem); + widgets.push_back(checkbox); + PushButton *pushbutton1 = new PushButton(pushbutton1_elem); + widgets.push_back(pushbutton1); + PushButton *pushbutton2 = new PushButton(pushbutton2_elem); + widgets.push_back(pushbutton2); + PushButton *pushbutton3 = new PushButton(pushbutton3_elem); + widgets.push_back(pushbutton3); + + layout->addWidget(label); + layout->addWidget(lineedit); + layout->addWidget(lineedit2); + layout->addWidget(textedit); + //layout->addWidget(combobox); + layout->addWidget(radiobutton1); + layout->addWidget(radiobutton2); + layout->addWidget(checkbox); + layout->addWidget(pushbutton1); + layout->addWidget(pushbutton2); + layout->addWidget(pushbutton3); + + frame->setLayout(layout); + + window_layout->addWidget(frame); + + widget.setLayout(window_layout); + widget.show(); + + std::vector< Widget* >::iterator i=widgets.begin(); + while (i != widgets.end()) { + Widget* w = *i; + printf("%s = %s\n", w->getName().toStdString().c_str(), w->getValue().toStdString().c_str()); + i++; + } + */ +} + +Builder::~Builder() +{ +} + +void Builder::recurser(QDomNode xml_node, QWidget *parent) +{ + QWidget *widget = NULL; + QDomElement xml_elem = xml_node.toElement(); + if(xml_elem.tagName() == "window") { + Window *window = new Window(xml_elem); + widgets.push_back(window); + widget = window; + } else if(xml_elem.tagName() == "frame") { + Frame *frame = new Frame(xml_elem); + widgets.push_back(frame); + widget = frame; + } else if(xml_elem.tagName() == "label") { + Label *label = new Label(xml_elem); + widgets.push_back(label); + widget = label; + } else if(xml_elem.tagName() == "lineedit") { + LineEdit *lineedit = new LineEdit(xml_elem); + widgets.push_back(lineedit); + widget = lineedit; + } else if(xml_elem.tagName() == "button") { + PushButton *pushbutton = new PushButton(xml_elem); + widgets.push_back(pushbutton); + widget = pushbutton; + } else if(xml_elem.tagName() == "textedit") { + TextEdit *textedit = new TextEdit(xml_elem); + widgets.push_back(textedit); + widget = textedit; + } else if(xml_elem.tagName() == "checkbox") { + CheckBox *checkbox = new CheckBox(xml_elem); + widgets.push_back(checkbox); + widget = checkbox; + } else if(xml_elem.tagName() == "radiobutton") { + RadioButton *radiobutton = new RadioButton(xml_elem); + widgets.push_back(radiobutton); + widget = radiobutton; + } + QDomNodeList children = xml_node.childNodes(); + + for (int i=0; i<children.count();i++) { + QDomNode child = children.at(i); + recurser(child, widget); + } + + if(parent != NULL && widget != NULL) parent->layout()->addWidget(widget); + if(widget != NULL) widget->show(); +} diff --git a/client/builder.h b/client/builder.h new file mode 100644 index 0000000..6c0577d --- /dev/null +++ b/client/builder.h @@ -0,0 +1,51 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * builder.h + * + * Fri Aug 31 12:27:45 CEST 2007 + * Copyright 2007 Bent Bisballe Nyeng, Lars Bisballe Jensen and Peter Skaarup + * deva@aasimon.org, elsenator@gmail.com and piparum@piparum.dk + ****************************************************************************/ + +/* + * This file is part of Pracro. + * + * Pracro is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Pracro is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Pracro; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +#ifndef _BUILDER_H +#define _BUILDER_H + +#include <QDomDocument> +#include <QWidget> +#include <QDomNode> +#include <QObject> + +class Builder : public QObject +{ + Q_OBJECT +public: + Builder(QDomDocument *xml_doc); + ~Builder(); + + public slots: + +private: + void recurser(QDomNode xml_node, QWidget *parent); + QDomDocument *xml_doc; + +}; + +#endif diff --git a/client/macro.cc b/client/macro.cc new file mode 100644 index 0000000..853b343 --- /dev/null +++ b/client/macro.cc @@ -0,0 +1,74 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * macro.cc + * + * Fri Aug 31 13:40:17 CEST 2007 + * Copyright 2007 Bent Bisballe Nyeng, Lars Bisballe Jensen and Peter Skaarup + * deva@aasimon.org, elsenator@gmail.com and piparum@piparum.dk + ****************************************************************************/ + +/* + * This file is part of Pracro. + * + * Pracro is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Pracro is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Pracro; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#include "macro.h" +#include "builder.h" +#include "xmlacquire.h" +#include <QDomDocument> + +static QDomDocument xml_request(QString name); + +void macro(QString name) +{ + // Build the XML request + QDomDocument xml_req = xml_request(name); + + // Fetch the XML document + XmlAcquire xml_acquire; + xml_acquire.makeConnection(&xml_req); + QByteArray ba = xml_acquire.getResult(); + + char *test = ba.data(); + printf("%s\n", test); + + // Parse the XML document + QDomDocument xml_doc; + if (!xml_doc.setContent(ba)) { + printf("ERROR: Invalid XML recieved!\n"); + } + + Builder builder(&xml_doc); +} + +static QDomDocument xml_request(QString name) +{ + // Create the xml request document here + QByteArray xml_array; + xml_array.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); + xml_array.append("<pracro version=\"1.0\" cpr=\"1505050505\">\n"); + xml_array.append(" <request macro=\"example\"/>\n"); + xml_array.append("</pracro>"); + + char *test = xml_array.data(); + printf("%s\n", test); + + QDomDocument xml_req; + if (!xml_req.setContent(xml_array)) { + printf("Error: Invalid XML found in request\n"); + } + + return xml_req; +} diff --git a/client/macro.h b/client/macro.h new file mode 100644 index 0000000..36f4f4f --- /dev/null +++ b/client/macro.h @@ -0,0 +1,34 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * macro.h + * + * Fri Aug 31 13:40:17 CEST 2007 + * Copyright 2007 Bent Bisballe Nyeng, Lars Bisballe Jensen and Peter Skaarup + * deva@aasimon.org, elsenator@gmail.com and piparum@piparum.dk + ****************************************************************************/ + +/* + * This file is part of Pracro. + * + * Pracro is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Pracro is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Pracro; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#ifndef __PRACRO_MACRO_H__ +#define __PRACRO_MACRO_H__ + +#include <QString> + +void macro(QString name); + +#endif/*__PRACRO_MACRO_H__*/ diff --git a/client/main.cc b/client/main.cc new file mode 100644 index 0000000..84701c8 --- /dev/null +++ b/client/main.cc @@ -0,0 +1,42 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * main.cc + * + * Fri Jul 13 12:38:45 CEST 2007 + * Copyright 2007 Bent Bisballe Nyeng, Lars Bisballe Jensen and Peter Skaarup + * deva@aasimon.org, elsenator@gmail.com and piparum@piparum.dk + ****************************************************************************/ + +/* + * This file is part of Pracro. + * + * Pracro is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Pracro is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Pracro; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +#include "macro.h" +#include "xmlacquire.h" +#include <QApplication> +#include <QDomDocument> +#include <QXmlSimpleReader> + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + macro("example"); + + return app.exec(); +} + diff --git a/client/xmlacquire.cc b/client/xmlacquire.cc new file mode 100644 index 0000000..2938832 --- /dev/null +++ b/client/xmlacquire.cc @@ -0,0 +1,136 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * xmlacquire.cc + * + * Fri Jul 13 12:38:45 CEST 2007 + * Copyright 2007 Bent Bisballe Nyeng, Lars Bisballe Jensen and Peter Skaarup + * deva@aasimon.org, elsenator@gmail.com and piparum@piparum.dk + ****************************************************************************/ + +/* + * This file is part of Pracro. + * + * Pracro is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Pracro is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Pracro; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +#include "xmlacquire.h" + +#include <stdio.h> +#include <QApplication> +#include <QTcpSocket> +#include <QDomDocument> +#include <QByteArray> + +XmlAcquire::XmlAcquire() + : QObject() +{ + has_result = false; +} + +void XmlAcquire::tcpConnect() +{ + tcpsocket->connectToHost("localhost", atoi("12345")); + tcpConnected = TCP_CONNECTING; +} + +void XmlAcquire::tcpDisconnect() +{ + tcpsocket->disconnectFromHost(); + while(tcpConnected != TCP_DISCONNECTED) { + if(tcpConnected == TCP_ERROR) { + tcpConnected = TCP_DISCONNECTED; + return; + } + usleep(5000); + printf("PLUP!\n"); + qApp->processEvents(); + } +} + +int XmlAcquire::tcpStatus() +{ + return tcpConnected; +} + +void XmlAcquire::makeConnection(QDomDocument *xml_req) +{ + this->xml_req = xml_req; + + tcpsocket = new QTcpSocket; + connect(tcpsocket, SIGNAL(hostFound()), this, SLOT(myHostFound())); + connect(tcpsocket, SIGNAL(readyRead()), this, SLOT(myReadyReadHandler())); + connect(tcpsocket, SIGNAL(connected()), this, SLOT(myConnected())); + connect(tcpsocket, SIGNAL(disconnected()), this, SLOT(myDisconnected())); + connect(tcpsocket, SIGNAL(error(QAbstractSocket::SocketError)), + this, SLOT(myError(QAbstractSocket::SocketError))); + tcpConnect(); +} + +void XmlAcquire::myTcpWrite(char *msg, int len) +{ + if(tcpConnected == TCP_CONNECTED) + tcpsocket->write(msg, len); + else + printf("TCP socket not initialized!\n"); +} + +void XmlAcquire::myHostFound() // slot +{ + printf("Host Found!\n"); +} + +void XmlAcquire::myConnected() // slot +{ + tcpConnected = TCP_CONNECTED; + printf("TCP Connected!\n"); + + QByteArray ba = xml_req->toByteArray(); + char *request = ba.data(); + myTcpWrite(request, ba.length()); +} + +void XmlAcquire::myDisconnected() // slot +{ + tcpConnected = TCP_DISCONNECTED; + printf("TCP Disconnected!\n"); + + // Convert recieved data into an XML document + //xml_doc.setContent(ba_all); + has_result = true; + + //char *test = ba_all.data(); + //printf("%s\n", test); +} + +void XmlAcquire::myError(QAbstractSocket::SocketError) // slot +{ + tcpConnected = TCP_ERROR; +} + +void XmlAcquire::myReadyReadHandler() +{ + QByteArray ba; + + ba = tcpsocket->readAll(); + ba_all.append(ba); +} + +QByteArray XmlAcquire::getResult() +{ + while(has_result == false) { + qApp->processEvents(); + } + return ba_all; +} diff --git a/client/xmlacquire.h b/client/xmlacquire.h new file mode 100644 index 0000000..a466f50 --- /dev/null +++ b/client/xmlacquire.h @@ -0,0 +1,68 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * xmlacquire.h + * + * Fri Jul 13 12:38:45 CEST 2007 + * Copyright 2007 Bent Bisballe Nyeng, Lars Bisballe Jensen and Peter Skaarup + * deva@aasimon.org, elsenator@gmail.com and piparum@piparum.dk + ****************************************************************************/ + +/* + * This file is part of Pracro. + * + * Pracro is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Pracro is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Pracro; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +#ifndef _XMLACQUIRE_H +#define _XMLACQUIRE_H + +#include <QObject> +#include <QTcpSocket> +#include <QDomDocument> + +#define TCP_CONNECTED 1 +#define TCP_DISCONNECTED 2 +#define TCP_CONNECTING 3 +#define TCP_ERROR -1 +#define TCP_ERROR_SERVER_NOT_FOUND -2 + +class XmlAcquire : public QObject +{ + Q_OBJECT +public: + XmlAcquire(); + void makeConnection(QDomDocument *xml_req); + QByteArray getResult(); + +public slots: + void tcpConnect(); + void tcpDisconnect(); + int tcpStatus(); + void myTcpWrite(char *msg, int len); + void myHostFound(); + void myConnected(); + void myDisconnected(); + void myError(QAbstractSocket::SocketError); + void myReadyReadHandler(); + +private: + QTcpSocket *tcpsocket; + int tcpConnected; + QByteArray ba_all; + bool has_result; + QDomDocument *xml_req; +}; + +#endif |