diff options
Diffstat (limited to 'client')
-rw-r--r-- | client/builder.cc | 50 | ||||
-rw-r--r-- | client/builder.h | 2 | ||||
-rw-r--r-- | client/macro.cc | 25 | ||||
-rw-r--r-- | client/macro.h | 3 | ||||
-rw-r--r-- | client/main.cc | 16 | ||||
-rw-r--r-- | client/widgets/listbox.cc | 42 | ||||
-rw-r--r-- | client/widgets/listbox.h | 1 | ||||
-rw-r--r-- | client/widgets/pushbutton.cc | 2 | ||||
-rw-r--r-- | client/widgets/pushbutton.h | 2 |
9 files changed, 102 insertions, 41 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()); } diff --git a/client/builder.h b/client/builder.h index 534480f..735b58d 100644 --- a/client/builder.h +++ b/client/builder.h @@ -50,11 +50,13 @@ public slots: void cont(QString name); private: + bool doCommit(); void recurser(QDomNode xml_node, QWidget *parent); QDomDocument *xml_doc; QVector< Widget* > widgets; QString macro; QString version; + QWidget *mainwidget; }; diff --git a/client/macro.cc b/client/macro.cc index 669674b..5e3b83d 100644 --- a/client/macro.cc +++ b/client/macro.cc @@ -32,25 +32,24 @@ #define MY_EVENT_ID 65432 +extern QString cpr; +extern QString user; + class MyEvent : public QEvent { public: - MyEvent(QString macro, QString cpr, QString user) : QEvent((QEvent::Type)MY_EVENT_ID) + MyEvent(QString macro) : QEvent((QEvent::Type)MY_EVENT_ID) { this->macro = macro; - this->cpr = cpr; - this->user = user; } QString macro; - QString cpr; - QString user; }; -static QDomDocument xml_request(QString name, QString cpr, QString user); +static QDomDocument xml_request(QString name); -void create_macro(QString name, QString cpr, QString user) +void create_macro(QString name) { // Build the XML request - QDomDocument xml_req = xml_request(name, cpr, user); + QDomDocument xml_req = xml_request(name); // Fetch the XML document SendRecieve xml_acquire; @@ -76,7 +75,7 @@ bool MyEventHandler::eventFilter( QObject *o, QEvent *e ) if ( e->type() == MY_EVENT_ID ) { MyEvent *event = (MyEvent*)e; - create_macro(event->macro, event->cpr, event->user); + create_macro(event->macro); // ... DO SOMETHING WITH EVENT return TRUE; // eat event } else { @@ -85,13 +84,15 @@ bool MyEventHandler::eventFilter( QObject *o, QEvent *e ) } } -void new_macro(QString macro, QString cpr, QString user) +void new_macro(QString macro) { - MyEvent *event = new MyEvent(macro, cpr, user); + MyEvent *event = new MyEvent(macro); qApp->postEvent(qApp, event); + qApp->processEvents(); /* To prevent QT from closing when + no windows are present */ } -static QDomDocument xml_request(QString name, QString cpr, QString user) +static QDomDocument xml_request(QString name) { // Create the xml request array QByteArray xml_array; diff --git a/client/macro.h b/client/macro.h index a3fadf5..8ddd963 100644 --- a/client/macro.h +++ b/client/macro.h @@ -36,6 +36,7 @@ protected: bool eventFilter( QObject *o, QEvent *e ); }; -void new_macro(QString name, QString cpr, QString user); +//void new_macro(QString name, QString cpr, QString user); +void new_macro(QString name); #endif/*__PRACRO_MACRO_H__*/ diff --git a/client/main.cc b/client/main.cc index 0bd94d7..af3dbf5 100644 --- a/client/main.cc +++ b/client/main.cc @@ -30,6 +30,9 @@ #include <QEvent> #include "macro.h" +QString cpr; +QString user; + int main(int argc, char *argv[]) { QApplication app(argc, argv); @@ -38,8 +41,8 @@ int main(int argc, char *argv[]) app.installEventFilter( eventhandler ); char macro[100] = "example"; - char cpr[11] = "0000000000"; - char user[20] = "testuser"; + char _cpr[11] = "0000000000"; + char _user[20] = "testuser"; char config[30] = "pracro.ini"; int a; @@ -73,7 +76,7 @@ int main(int argc, char *argv[]) printf("Missing argument for cpr, exiting...\n"); exit(1); } - strcpy(cpr, argv[a+1]); + strcpy(_cpr, argv[a+1]); a++; continue; } @@ -82,7 +85,7 @@ int main(int argc, char *argv[]) printf("Missing argument for user, exiting...\n"); exit(1); } - strcpy(user, argv[a+1]); + strcpy(_user, argv[a+1]); a++; continue; } @@ -97,7 +100,10 @@ int main(int argc, char *argv[]) } } - new_macro(macro, cpr, user); + cpr = _cpr; + user = _user; + new_macro("start"); + //app.setQuitOnLastWindowClosed(false); return app.exec(); } diff --git a/client/widgets/listbox.cc b/client/widgets/listbox.cc index 9435ac1..823a4bb 100644 --- a/client/widgets/listbox.cc +++ b/client/widgets/listbox.cc @@ -25,6 +25,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ #include "listbox.h" +#include <QListWidgetItem> ListBox::ListBox(QDomNode node) : QListWidget(), Widget(node) @@ -47,21 +48,50 @@ ListBox::ListBox(QDomNode node) for (int i=0; i < children.count(); i++) { QDomNode child = children.at(i); QDomElement list_elem = child.toElement(); - - if(list_elem.hasAttribute("caption") && list_elem.hasAttribute("value")) { + + if(list_elem.hasAttribute("type")) { + if(list_elem.attribute("type") == "header") { + // create header element + QListWidgetItem *header = new + QListWidgetItem(list_elem.attribute("caption")); + //header->setBackground(Qt::HorPattern); + header->setFlags(0); + QFont headerfont; + headerfont.setBold(true); + headerfont.setItalic(true); + header->setFont(headerfont); + QBrush headerbrush(Qt::SolidPattern); + headerbrush.setColor(Qt::lightGray); + header->setBackground(headerbrush); + addItem(header); + } else if (list_elem.attribute("type") == "separator") { + // insert separator + QListWidgetItem *separator = new QListWidgetItem(" "); + //separator->setBackground(Qt::HorPattern); + separator->setFlags(0); + addItem(separator); + } + } else if(list_elem.hasAttribute("caption") && + list_elem.hasAttribute("value")) { // insert item into current listbox addItem(list_elem.attribute("caption")); - if(elem.attribute("value") == list_elem.attribute("value")) { - setCurrentRow(count() - 1); - default_found = 1; + if(default_found == 0 && elem.attribute("value") == list_elem.attribute("value")) { + //setCurrentRow(count() - 1); + //default_found = 1; } } else { - printf("XML Error!!! Listbox item is missing one or more attributes...\n"); + printf("XML Error!!! Listbox item is missing one or more " + "attributes...\n"); } } if(default_found == 0) setCurrentRow(-1); // -1 is default for none selected } +bool ListBox::isValid() +{ + return selectedItems().size() != 0; +} + QString ListBox::getValue() { QString value = "none"; diff --git a/client/widgets/listbox.h b/client/widgets/listbox.h index bf70420..30c4129 100644 --- a/client/widgets/listbox.h +++ b/client/widgets/listbox.h @@ -38,6 +38,7 @@ public: ListBox(QDomNode); public slots: + bool isValid(); QString getValue(); private: diff --git a/client/widgets/pushbutton.cc b/client/widgets/pushbutton.cc index 8d74e4e..26ae83c 100644 --- a/client/widgets/pushbutton.cc +++ b/client/widgets/pushbutton.cc @@ -92,6 +92,6 @@ void PushButton::cancel() void PushButton::cont() { - emit act_continue(); + emit act_continue(field); printf("Emit: continue\n"); } diff --git a/client/widgets/pushbutton.h b/client/widgets/pushbutton.h index 663be79..4db5952 100644 --- a/client/widgets/pushbutton.h +++ b/client/widgets/pushbutton.h @@ -52,7 +52,7 @@ signals: void act_commit(); void act_reset(); void act_cancel(); - void act_continue(); + void act_continue(QString); private: |