summaryrefslogtreecommitdiff
path: root/client/builder.cc
diff options
context:
space:
mode:
Diffstat (limited to 'client/builder.cc')
-rw-r--r--client/builder.cc47
1 files changed, 36 insertions, 11 deletions
diff --git a/client/builder.cc b/client/builder.cc
index 48739a2..29c42c6 100644
--- a/client/builder.cc
+++ b/client/builder.cc
@@ -14,11 +14,11 @@
#include "widgets/checkbox.h"
#include "widgets/window.h"
#include <QVBoxLayout>
+#include <QMessageBox>
#include <QDomDocument>
#include <QDomElement>
#include <QDomNode>
#include <QByteArray>
-#include <vector>
Builder::Builder(QDomDocument *xml_doc)
: QObject()
@@ -39,13 +39,16 @@ void Builder::recurser(QDomNode xml_node, QWidget *parent)
{
QWidget *widget = NULL;
QDomElement xml_elem = xml_node.toElement();
+
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);
widget = window;
+
} else if(xml_elem.tagName() == "frame") {
if(xml_elem.hasAttribute("caption")) {
GroupBox *frame = new GroupBox(xml_elem);
@@ -54,43 +57,52 @@ void Builder::recurser(QDomNode xml_node, QWidget *parent)
Frame *frame = new Frame(xml_elem);
widget = frame;
}
+
} else if(xml_elem.tagName() == "label") {
Label *label = new Label(xml_elem);
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);
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);
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() == "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();
for (int i=0; i<children.count();i++) {
@@ -104,21 +116,24 @@ void Builder::recurser(QDomNode xml_node, QWidget *parent)
void Builder::commit()
{
- // Check for errors on all entries before comitting
- int faulty = 0;
+ // Check for, and count, errors on all entries before comitting
+ int faulty = 0; // 0 initial errors
+
QVector< Widget* >::iterator i=widgets.begin();
while (i != widgets.end()) {
Widget* w = *i;
- if(!w->isValid()) faulty++;
+ if(!w->isValid()) faulty++; // Regexp check, returns valid if entry passed
// All selectable entries return "none" if nothing is selected
- if(w->getValue() == "none") faulty++;
+ if(w->getValue() == "none") faulty++; // Faulty+1 if error detected
i++;
}
+
// If all entries passed validation, continue commit
if(faulty == 0) {
printf("Builder -> committing...\n");
+ // Build the XML commit
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");
@@ -138,26 +153,36 @@ void Builder::commit()
xml_string.append(" </commit>\n");
xml_string.append("</pracro>\n");
- //char *test = xml_array.data();
+ // Print commit to stdout for debug purposes
printf("%s\n", xml_string.toStdString().c_str());
+ // Convert the commit to Utf-8 charset
QByteArray xml_array = xml_string.toUtf8();
QDomDocument xml_result;
- //QDomDocument xml_req;
+
+ // Use setContent of QDomDocument to validate the xml commit
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();
+ // Commit the xml data to the server
+ SendRecieve macro_commit;
+ macro_commit.makeConnection(&xml_result);
+ // Recieve answer from server whether successful or not
+ QByteArray ba = macro_commit.getResult();
} else {
- printf("ERROR!!! Some entries contain errors, aborting commit...\n");
+ QMessageBox::critical(NULL, "Fejl",
+ "Makroen er ikke udfyldt korrekt, prøv igen.\n"
+ , QMessageBox::Ok);
}
}
void Builder::reset()
{
+int ret = QMessageBox::warning(NULL, "Reset",
+ tr("Du har valgt at nulstille de indtastede data.\n"
+ "Er du sikker?"),
+ QMessageBox::Yes | QMessageBox::Cancel);
printf("Builder -> resetting...\n");
}