summaryrefslogtreecommitdiff
path: root/client/builder.cc
diff options
context:
space:
mode:
Diffstat (limited to 'client/builder.cc')
-rw-r--r--client/builder.cc173
1 files changed, 99 insertions, 74 deletions
diff --git a/client/builder.cc b/client/builder.cc
index d868f12..48739a2 100644
--- a/client/builder.cc
+++ b/client/builder.cc
@@ -1,23 +1,25 @@
#include "builder.h"
+#include "sendrecieve.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/listbox.h"
#include "widgets/frame.h"
+#include "widgets/groupbox.h"
+#include "widgets/radiobuttons.h"
#include "widgets/radiobutton.h"
#include "widgets/checkbox.h"
#include "widgets/window.h"
-//#include <QApplication>
#include <QVBoxLayout>
#include <QDomDocument>
#include <QDomElement>
#include <QDomNode>
+#include <QByteArray>
#include <vector>
-std::vector< Widget* > widgets;
-
Builder::Builder(QDomDocument *xml_doc)
: QObject()
{
@@ -27,66 +29,6 @@ Builder::Builder(QDomDocument *xml_doc)
// 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()
@@ -97,17 +39,23 @@ void Builder::recurser(QDomNode xml_node, QWidget *parent)
{
QWidget *widget = NULL;
QDomElement xml_elem = xml_node.toElement();
- if(xml_elem.tagName() == "window") {
+ if(xml_elem.tagName() == "macro") {
+ // Assign the macro name and version to QStrings for use when comitting
+ if(xml_elem.hasAttribute("name")) macro = xml_elem.attribute("name");
+ if(xml_elem.hasAttribute("version")) version = xml_elem.attribute("version");
+ } else 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;
+ if(xml_elem.hasAttribute("caption")) {
+ GroupBox *frame = new GroupBox(xml_elem);
+ widget = frame;
+ } else {
+ Frame *frame = new Frame(xml_elem);
+ 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);
@@ -115,7 +63,9 @@ void Builder::recurser(QDomNode xml_node, QWidget *parent)
widget = lineedit;
} else if(xml_elem.tagName() == "button") {
PushButton *pushbutton = new PushButton(xml_elem);
- widgets.push_back(pushbutton);
+ connect(pushbutton, SIGNAL(act_commit()), this, SLOT(commit()));
+ connect(pushbutton, SIGNAL(act_reset()), this, SLOT(reset()));
+ connect(pushbutton, SIGNAL(act_cancel()), this, SLOT(cancel()));
widget = pushbutton;
} else if(xml_elem.tagName() == "textedit") {
TextEdit *textedit = new TextEdit(xml_elem);
@@ -125,10 +75,21 @@ void Builder::recurser(QDomNode xml_node, QWidget *parent)
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;
+ } else if(xml_elem.tagName() == "radiobuttons") {
+ RadioButtons *radiobuttons = new RadioButtons(xml_elem);
+ widgets.push_back(radiobuttons);
+ widget = radiobuttons;
+ //return; // Don't iterate children
+ } else if(xml_elem.tagName() == "combobox") {
+ ComboBox *combobox = new ComboBox(xml_elem);
+ widgets.push_back(combobox);
+ widget = combobox;
+ //return; // Don't iterate children
+ } else if(xml_elem.tagName() == "listbox") {
+ ListBox *listbox = new ListBox(xml_elem);
+ widgets.push_back(listbox);
+ widget = listbox;
+ //return; // Don't iterate children
}
QDomNodeList children = xml_node.childNodes();
@@ -140,3 +101,67 @@ void Builder::recurser(QDomNode xml_node, QWidget *parent)
if(parent != NULL && widget != NULL) parent->layout()->addWidget(widget);
if(widget != NULL) widget->show();
}
+
+void Builder::commit()
+{
+ // Check for errors on all entries before comitting
+ int faulty = 0;
+ QVector< Widget* >::iterator i=widgets.begin();
+ while (i != widgets.end()) {
+ Widget* w = *i;
+ if(!w->isValid()) faulty++;
+
+ // All selectable entries return "none" if nothing is selected
+ if(w->getValue() == "none") faulty++;
+ i++;
+ }
+ // If all entries passed validation, continue commit
+ if(faulty == 0) {
+ printf("Builder -> committing...\n");
+
+ QString xml_string;
+ xml_string.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
+ xml_string.append("<pracro version=\"1.0\" cpr=\"1505050505\" user=\"tux\">\n");
+ xml_string.append(" <commit macro=\"" + macro + "\" version=\"" +
+ version + "\">\n");
+
+ // Iterate the different entries, and append their results to the commit string
+ QVector< Widget* >::iterator i=widgets.begin();
+ while (i != widgets.end()) {
+ Widget* w = *i;
+
+ xml_string.append(" <field name=\"" + w->getName()
+ + "\" value=\"" + w->getValue() + "\"/>\n");
+ i++;
+ }
+
+ xml_string.append(" </commit>\n");
+ xml_string.append("</pracro>\n");
+
+ //char *test = xml_array.data();
+ printf("%s\n", xml_string.toStdString().c_str());
+
+ QByteArray xml_array = xml_string.toUtf8();
+ QDomDocument xml_result;
+ //QDomDocument xml_req;
+ if (!xml_result.setContent(xml_array)) {
+ printf("Parse error: Invalid XML\n");
+ }
+
+ SendRecieve xml_acquire;
+ xml_acquire.makeConnection(&xml_result);
+ QByteArray ba = xml_acquire.getResult();
+ } else {
+ printf("ERROR!!! Some entries contain errors, aborting commit...\n");
+ }
+}
+
+void Builder::reset()
+{
+ printf("Builder -> resetting...\n");
+}
+
+void Builder::cancel()
+{
+ printf("Builder -> cancelling...\n");
+}