diff options
Diffstat (limited to 'client/macrowindow.cc')
-rw-r--r-- | client/macrowindow.cc | 113 |
1 files changed, 77 insertions, 36 deletions
diff --git a/client/macrowindow.cc b/client/macrowindow.cc index 3638ea2..6a20632 100644 --- a/client/macrowindow.cc +++ b/client/macrowindow.cc @@ -38,44 +38,40 @@ #include "widgets/window.h" #include "widgetbuilder.h" #include "lua.h" -#include "netcom.h" extern QString cpr; extern QString user; extern QString host; extern quint16 port; -MacroWindow::MacroWindow(QDomNode &xml_doc) - : QObject() +MacroWindow::MacroWindow(NetCom &n, QDomNode &xml_doc, QString course) + : Collapser(), netcom(n) { - isclosed = false; + this->course = course; mainwidget = NULL; + setCollapsedWidget(new QLabel("Empty")); this->lua = new LUA(this); - initMacro(xml_doc); - - if(mainwidget) mainwidget->show(); + update(xml_doc); } MacroWindow::~MacroWindow() { delete lua; - /* - QVector< Widget* >::iterator i = widgets.begin(); - while (i != widgets.end()) { - Widget* w = *i; - delete w; - i++; - } +} - QVector< Widget* >::iterator j = auxwidgets.begin(); - while (j != auxwidgets.end()) { - Widget* w = *j; - delete w; - j++; - } - */ +void MacroWindow::update(QDomNode &node) +{ + // if(mainwidget) delete mainwidget; + // if(resumewidget) delete resumewidget; + + // mainwidget = new QLabel("Expanded"); + // resumewidget = new QLabel("Collapsed"); + + initMacro(node); + + if(mainwidget) setExpandedWidget(mainwidget); } void MacroWindow::initMacro(QDomNode &node) @@ -89,6 +85,9 @@ void MacroWindow::initMacro(QDomNode &node) } else if(xml_elem.tagName() == "scripts") { // Nothing to do here + } else if(xml_elem.tagName() == "resume") { + QString resume = xml_elem.text(); + ((QLabel*)collapsedWidget())->setText(resume); } else if(xml_elem.tagName() == "script") { if(xml_elem.hasAttribute("language") && @@ -102,6 +101,7 @@ void MacroWindow::initMacro(QDomNode &node) } else if(xml_elem.tagName() == "window") { Window *window = new Window(xml_elem, this); + macrotitle = xml_elem.attribute("caption"); mainwidget = window; QDomNodeList children = node.childNodes(); @@ -143,8 +143,9 @@ bool MacroWindow::doCommit() // If all entries passed validation, continue commit if(faulty == 0) { - Global::netcom->send(widgets, macro, version); - + netcom.send(widgets, course, macro, version); + emit updateOnCommit(); + setCollapsed(true); return true; } else { return false; @@ -153,14 +154,14 @@ bool MacroWindow::doCommit() void MacroWindow::close() { - mainwidget->close(); + // mainwidget->close(); isclosed = true; } void MacroWindow::commit() { if(doCommit()) { - close(); + // close(); } else { QMessageBox::critical(NULL, "Fejl", "Makroen er ikke udfyldt korrekt, prøv igen.\n" @@ -180,7 +181,7 @@ void MacroWindow::reset() void MacroWindow::cancel() { printf("MacroWindow -> cancelling...\n"); - close(); + // close(); } void MacroWindow::cont(QString name) @@ -198,13 +199,10 @@ void MacroWindow::cont(QString name) // FIXME: Hack to prevent XML clotching. // The server could not differentiate the commit and the request. - delete Global::netcom; - Global::netcom = new NetCom(host, port, user, cpr); - // TODO: Where to get the course var?? - new_macro("example", macro); - close(); + // new_macro("example", macro); + // close(); } else { QMessageBox::critical(NULL, "Fejl", "Makroen er ikke udfyldt korrekt, prøv igen.\n", @@ -228,13 +226,10 @@ void MacroWindow::cont_nocommit(QString name) // FIXME: Hack to prevent XML clotching. // The server could not differentiate the commit and the request. - delete Global::netcom; - Global::netcom = new NetCom(host, port, user, cpr); - // TODO: Where to get the course var?? - new_macro("example", macro); - close(); + // new_macro("example", macro); + // close(); } else { QMessageBox::critical(NULL, "Fejl", "Makroen er ikke udfyldt korrekt, prøv igen.\n", @@ -273,3 +268,49 @@ void MacroWindow::addAuxWidgets(QVector< Widget* > ws) { auxwidgets += ws; } + +void MacroWindow::toggleMacro() +{ + + if(isCollapsed()) { + widgets.clear(); + auxwidgets.clear(); + QDomDocument xml_doc = netcom.send(course, macro); + + // + // TODO: This is where the dependency checking should occur. + // + + // Initiate the new macro window with the xml document and push + // it to the window list + QDomNodeList courses = xml_doc.documentElement().childNodes(); + QDomNode coursenode = courses.at(0); // There can be only one! (Swush, flomp) + QDomNodeList macronodes = coursenode.childNodes(); + for(int j = 0; j < macronodes.count(); j++) { + QDomNode macronode = macronodes.at(j); + + if(true || macronode.childNodes().count()) { + // macrowindows.push_back( new MacroWindow( netcom, macronode ) ); + QDomElement xml_elem = macronode.toElement(); + + if(xml_elem.tagName() == "macro") { + + // Assign the macro name and version to QStrings for use when comitting + QString macroname; + if(xml_elem.hasAttribute("name")) { + if(xml_elem.attribute("name") == macro) { + // update me! + initMacro(macronode); + } + } + } + } + } + setExpandedWidget(mainwidget); + expand(); + + } else { + collapse(); + + } +} |