summaryrefslogtreecommitdiff
path: root/client/builder.cc
diff options
context:
space:
mode:
Diffstat (limited to 'client/builder.cc')
-rw-r--r--client/builder.cc50
1 files changed, 35 insertions, 15 deletions
diff --git a/client/builder.cc b/client/builder.cc
index b30f225..29f58d0 100644
--- a/client/builder.cc
+++ b/client/builder.cc
@@ -13,6 +13,7 @@
#include "widgets/radiobutton.h"
#include "widgets/checkbox.h"
#include "widgets/window.h"
+#include "macro.h"
#include <QVBoxLayout>
#include <QMessageBox>
#include <QDomDocument>
@@ -20,6 +21,9 @@
#include <QDomNode>
#include <QByteArray>
+extern QString cpr;
+extern QString user;
+
Builder::Builder(QDomDocument *xml_doc)
: QObject()
{
@@ -48,6 +52,7 @@ void Builder::recurser(QDomNode xml_node, QWidget *parent)
} else if(xml_elem.tagName() == "window") {
Window *window = new Window(xml_elem);
widget = window;
+ mainwidget = window;
} else if(xml_elem.tagName() == "frame") {
if(xml_elem.hasAttribute("caption")) {
@@ -73,7 +78,7 @@ void Builder::recurser(QDomNode xml_node, QWidget *parent)
connect(pushbutton, SIGNAL(act_commit()), this, SLOT(commit()));
connect(pushbutton, SIGNAL(act_reset()), this, SLOT(reset()));
connect(pushbutton, SIGNAL(act_cancel()), this, SLOT(cancel()));
- //connect(pushbutton, SIGNAL(act_continue()), this, SLOT(cont("fisk")));
+ connect(pushbutton, SIGNAL(act_continue(QString)), this, SLOT(cont(QString)));
widget = pushbutton;
} else if(xml_elem.tagName() == "textedit") {
@@ -116,7 +121,7 @@ void Builder::recurser(QDomNode xml_node, QWidget *parent)
if(widget != NULL) widget->show();
}
-void Builder::commit()
+bool Builder::doCommit()
{
// Check for, and count, errors on all entries before comitting
int faulty = 0; // 0 initial errors
@@ -127,7 +132,7 @@ void Builder::commit()
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++; // Faulty+1 if error detected
+ //if(w->getValue() == "none") faulty++; // Faulty+1 if error detected
i++;
}
@@ -138,7 +143,7 @@ void Builder::commit()
// 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");
+ xml_string.append("<pracro version=\"1.0\" cpr=\"" + cpr + "\" user=\"" + user + "\">\n");
xml_string.append(" <commit macro=\"" + macro + "\" version=\"" +
version + "\">\n");
@@ -174,9 +179,18 @@ void Builder::commit()
//QByteArray ba = macro_commit.getResult();
QString ba = macro_commit.getResult();
printf("Server returned result: %s", ba.toStdString().c_str());
- exit(1); // Probably bad exit. Implemented for test version.
+ return true;
+ } else {
+ return false;
+ }
+}
+
+void Builder::commit()
+{
+ if(doCommit()) {
+ mainwidget->close();
} else {
- QMessageBox::critical(NULL, "Fejl",
+ QMessageBox::critical(NULL, "Fejl",
"Makroen er ikke udfyldt korrekt, prøv igen.\n"
, QMessageBox::Ok);
}
@@ -184,7 +198,7 @@ void Builder::commit()
void Builder::reset()
{
-int ret = QMessageBox::warning(NULL, "Reset",
+ int ret = QMessageBox::warning(NULL, tr("Reset"),
tr("Du har valgt at nulstille de indtastede data.\n"
"Er du sikker?"),
QMessageBox::Yes | QMessageBox::Cancel);
@@ -194,21 +208,27 @@ int ret = QMessageBox::warning(NULL, "Reset",
void Builder::cancel()
{
printf("Builder -> cancelling...\n");
- exit(1); // Probably bad exit. Implemented for test version.
+ mainwidget->close();
}
void Builder::cont(QString name)
{
- /*
+ QString macro;
QVector< Widget* >::iterator i=widgets.begin();
while (i != widgets.end()) {
Widget* w = *i;
-
- if(w->getName()
- xml_string.append(" <field name=\"" + w->getName()
- + "\" value=\"" + w->getValue() + "\"/>\n");
+ if(w->getName() == name) {
+ macro = w->getValue();
+ }
i++;
}
- */
- printf("%s : Builder -> continuing...\n", name.toStdString().c_str());
+ if(doCommit()) {
+ new_macro(macro);
+ mainwidget->close();
+ } else {
+ QMessageBox::critical(NULL, "Fejl",
+ "Makroen er ikke udfyldt korrekt, prøv igen.\n"
+ , QMessageBox::Ok);
+ }
+ printf("%s : Builder -> continuing...\n", macro.toStdString().c_str());
}