summaryrefslogtreecommitdiff
path: root/client/macrowindow.cc
diff options
context:
space:
mode:
authordeva <deva>2010-08-12 10:57:04 +0000
committerdeva <deva>2010-08-12 10:57:04 +0000
commitd9338083192084613e5530b02710b796252d342b (patch)
treee0ec2b36e0de62328e5fd5d3b597f6ee71d1b18f /client/macrowindow.cc
parentdbab8458dcce186e7eb7a114a83f759d7db5445a (diff)
New scripting system part2.
Diffstat (limited to 'client/macrowindow.cc')
-rw-r--r--client/macrowindow.cc261
1 files changed, 84 insertions, 177 deletions
diff --git a/client/macrowindow.cc b/client/macrowindow.cc
index 4c51c07..efabbd1 100644
--- a/client/macrowindow.cc
+++ b/client/macrowindow.cc
@@ -29,15 +29,14 @@
#include <QVBoxLayout>
#include <QDomDocument>
#include <QDomElement>
-#include <QDomNode>
#include <QByteArray>
#include "messagebox.h"
-
#include "widgets/widget.h"
#include "widgets/window.h"
#include "widgetbuilder.h"
#include "lua.h"
+#include "resumewidget.h"
extern QString cpr;
extern QString user;
@@ -48,36 +47,38 @@ MacroWindow::MacroWindow(NetCom &n, QDomNode &xml_doc, QString templ,
bool collapsed, bool compact)
: Collapser(), netcom(n)
{
+ mainwidget = NULL;
+
waschanged = false;
this->templ = templ;
setCollapsedWidget(new ResumeWidget(compact));
- this->lua = new LUA(&this->widgets, &this->auxwidgets);
+ this->lua = new LUA(&mainwidget);
update(xml_doc);
setCollapsed(collapsed);
active = true;
+
+ connect(this, SIGNAL(doneCollapsing()), this, SLOT(collapsed()));
+ connect(this, SIGNAL(doneExpanding()), this, SLOT(expanded()));
}
MacroWindow::~MacroWindow()
{
+ clear();
delete lua;
}
void MacroWindow::update(QDomNode &node)
{
- mainwidget = NULL;
-
- widgets.clear();
- auxwidgets.clear();
- luaprograms.clear();
-
+ // clear();
initMacro(node);
- if(mainwidget) setExpandedWidget(mainwidget);
+ if(mainwidget) setExpandedWidget(mainwidget->qwidget());
+ else setExpandedWidget(NULL);
}
void MacroWindow::initMacro(QDomNode &node)
@@ -85,9 +86,10 @@ void MacroWindow::initMacro(QDomNode &node)
QDomElement xml_elem = 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");
+ macro = xml_elem.attribute("name", "");
+ version = xml_elem.attribute("version", "");
} else if(xml_elem.tagName() == "scripts") {
// Nothing to do here
@@ -106,33 +108,42 @@ void MacroWindow::initMacro(QDomNode &node)
if(xml_elem.hasAttribute("language") &&
xml_elem.attribute("language") == "lua") {
// luaprograms.push_back(xml_elem.text());
- this->lua->runValidator(xml_elem.text(), NULL, "preload", "");
+ this->lua->runScript(xml_elem.text(), NULL, "preload");
} else {
- printf("Unknown script type %s\n", xml_elem.attribute("language").toStdString().c_str());
+ printf("Unknown script type %s\n",
+ xml_elem.attribute("language").toStdString().c_str());
}
} else if(xml_elem.tagName() == "widgets") {
+
+ if(mainwidget) {
+ printf("ERROR!!!!!!\n\tmainwidget already exists!\n");
+ }
+
Window *window = new Window(xml_elem, this);
+ connect(window, SIGNAL(wasChanged()), this, SLOT(macroChanged()));
macrotitle = xml_elem.attribute("caption");
+ //clear();
+ /*
+ if(mainwidget) {
+ setExpandedWidget(NULL);
+ delete mainwidget;
+ mainwidget = NULL;
+ }
+ */
mainwidget = window;
QDomNodeList children = node.childNodes();
- // Build widgets
- for (int i=0; i<children.count();i++) {
- QDomNode child = children.at(i);
- widgets += widgetBuilder(child, mainwidget, this);
- }
-
// Insert their values (this must be done last for scripts to work properly)
for (int i=0; i<children.count();i++) {
QDomNode child = children.at(i);
- setValues(child, this);
+ setValues(child, mainwidget);
}
if(waschanged == true) macroChanged();
- return;
+ return; // No further recursion.
}
QDomNodeList children = node.childNodes();
@@ -143,21 +154,12 @@ void MacroWindow::initMacro(QDomNode &node)
}
}
+#include <QApplication>
bool MacroWindow::doCommit()
{
- // 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->isDisabled() && !w->isValid()) faulty++; // Regexp check, returns valid if entry passed
- i++;
- }
-
- // If all entries passed validation, continue commit
- if(faulty == 0) {
- QDomDocument doc = netcom.send(widgets, templ, macro, version);
+ if(mainwidget->valid()) {
+ QDomDocument doc = netcom.send(mainwidget->widgetList(),
+ templ, macro, version);
QDomNodeList nl = doc.documentElement().childNodes();
QDomNode n = nl.at(0); // There can be only one! (Swush, flomp)
@@ -169,7 +171,9 @@ bool MacroWindow::doCommit()
}
emit updateOnCommit();
+
setCollapsed(true);
+
return true;
} else {
MessageBox::critical(NULL, "Fejl",
@@ -181,157 +185,32 @@ bool MacroWindow::doCommit()
}
}
-void MacroWindow::close()
-{
- // mainwidget->close();
- isclosed = true;
-}
-
void MacroWindow::commit()
{
doCommit();
}
-void MacroWindow::reset()
-{
- /*
- MessageBox::warning(NULL, tr("Reset"),
- tr("Du har valgt at nulstille de indtastede data.\n"
- "Er du sikker?"),
- MessageBox::Yes | MessageBox::Cancel);
- printf("MacroWindow -> resetting...\n");
- */
- QVector< Widget* >::iterator i = widgets.begin();
- while (i != widgets.end()) {
- Widget* w = *i;
- w->reset();
- i++;
- }
-
- QVector< Widget* >::iterator j = auxwidgets.begin();
- while (j != auxwidgets.end()) {
- Widget* w = *j;
- w->reset();
- j++;
- }
-
- waschanged = false;
-}
-
void MacroWindow::cancel()
{
collapseWrapper();
}
-void MacroWindow::cont(QString name)
-{
- QString macro;
- QVector< Widget* >::iterator i=widgets.begin();
- while (i != widgets.end()) {
- Widget* w = *i;
- if(w->name() == name) {
- macro = w->getValue();
- }
- i++;
- }
- if(doCommit()) {
-
- // FIXME: Hack to prevent XML clotching.
- // The server could not differentiate the commit and the request.
-
- // TODO: Where to get the template var??
- // new_macro("example", macro);
- // close();
- } else {
- MessageBox::critical(NULL, "Fejl",
- "Makroen " + macrotitle + " er ikke udfyldt korrekt, prøv igen.\n",
- MessageBox::Ok);
- }
- printf("%s : MacroWindow -> continuing...\n", macro.toStdString().c_str());
-}
-
-void MacroWindow::cont_nocommit(QString name)
-{
- QString macro;
- QVector< Widget* >::iterator i=widgets.begin();
- while (i != widgets.end()) {
- Widget* w = *i;
- if(w->name() == name) {
- macro = w->getValue();
- }
- i++;
- }
- if(true/*doCommit()*/) {
-
- // FIXME: Hack to prevent XML clotching.
- // The server could not differentiate the commit and the request.
-
- // TODO: Where to get the template var??
- // new_macro("example", macro);
- // close();
- } else {
- MessageBox::critical(NULL, "Fejl",
- "Makroen " + macrotitle + " er ikke udfyldt korrekt, prøv igen.\n",
- MessageBox::Ok);
- }
- printf("%s : MacroWindow -> continuing...\n", macro.toStdString().c_str());
-}
-
-bool MacroWindow::isClosed()
-{
- return isclosed || mainwidget->isVisible() == false;
-}
-
-Widget *MacroWindow::getWidget(QString name)
-{
- QVector< Widget* >::iterator i = widgets.begin();
- while (i != widgets.end()) {
- Widget* w = *i;
- if(name == w->name()) return w;
- i++;
- }
-
- QVector< Widget* >::iterator j = auxwidgets.begin();
- while (j != auxwidgets.end()) {
- Widget* w = *j;
- if(name == w->name()) return w;
- j++;
- }
-
- printf("WARNING: Widget %s not found\n", name.toStdString().c_str());
-
- return NULL;
-}
-
-void MacroWindow::addAuxWidgets(QVector< Widget* > ws)
-{
- auxwidgets += ws;
-}
-
-void MacroWindow::addWidgets(QVector< Widget* > ws)
-{
- widgets += ws;
-}
-
void MacroWindow::expandWrapper()
{
if(!isCollapsed()) return;
- widgets.clear();
- auxwidgets.clear();
- luaprograms.clear();
+ // clear();
+
waschanged = false;
QDomDocument xml_doc = netcom.send(templ, 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 templates = xml_doc.documentElement().childNodes();
- QDomNode templatenode = templates.at(0); // There can be only one! (Swush, flomp)
+
+ // There can be only one! (Swush, flomp)
+ QDomNode templatenode = templates.at(0);
QDomNodeList macronodes = templatenode.childNodes();
for(int j = 0; j < macronodes.count(); j++) {
QDomNode macronode = macronodes.at(j);
@@ -353,15 +232,18 @@ void MacroWindow::expandWrapper()
}
}
}
- setExpandedWidget(mainwidget);
+ if(mainwidget) setExpandedWidget(mainwidget->qwidget());
expand();
+ // Set keyboard focus on the first focusable widget in the macro.
+ QVector< Widget* > widgets = mainwidget->widgetList(true);
QVector< Widget* >::iterator i = widgets.begin();
while (i != widgets.end()) {
Widget* w = *i;
if(w->setKeyboardFocus()) break;
i++;
}
+
}
void MacroWindow::collapseWrapper()
@@ -370,24 +252,27 @@ void MacroWindow::collapseWrapper()
if(waschanged) {
switch(MessageBox::warning(NULL,
- "Gem ændringerne i makroen?",
- "Du har valgt at lukke makroen " + macrotitle + ".\n"
- "Ønsker du at gemme inden du lukker?",
- MessageBox::Save | MessageBox::Close | MessageBox::Cancel)) {
+ "Gem ændringerne i makroen?",
+ "Du har valgt at ukke makroen " +
+ macrotitle + ".\n"
+ "Ønsker du at gemme inden du lukker?",
+ MessageBox::Save | MessageBox::Close |
+ MessageBox::Cancel)) {
case MessageBox::Save:
- if(doCommit()) setCollapsed(true);
- else MessageBox::critical(NULL,
- "Fejl",
- "Makroen " + macrotitle + " er ikke udfyldt korrekt, prøv igen.\n",
- MessageBox::Ok);
-
+ if(doCommit()) {
+ setCollapsed(true);
+ } else {
+ MessageBox::critical(NULL, "Fejl",
+ "Makroen " + macrotitle +
+ " er ikke udfyldt korrekt, prøv igen.\n",
+ MessageBox::Ok);
+ }
break;
case MessageBox::Close:
collapse();
break;
case MessageBox::Cancel:
default:
- // emit expanding(); // signal the other to close again (if any)
break;
}
} else {
@@ -421,3 +306,25 @@ void MacroWindow::setActive(bool active)
emit activationChanged(active);
}
+
+void MacroWindow::clear()
+{
+ if(mainwidget) delete mainwidget;
+ mainwidget = NULL;
+
+ setExpandedWidget(NULL);
+
+ luaprograms.clear();
+}
+
+void MacroWindow::collapsed()
+{
+ printf("======== Collapsed ========\n");
+
+ clear();
+}
+
+void MacroWindow::expanded()
+{
+ printf("======== Expanded ========\n");
+}