summaryrefslogtreecommitdiff
path: root/client/macrowindow.cc
diff options
context:
space:
mode:
Diffstat (limited to 'client/macrowindow.cc')
-rw-r--r--client/macrowindow.cc276
1 files changed, 106 insertions, 170 deletions
diff --git a/client/macrowindow.cc b/client/macrowindow.cc
index 0770021..7641fdc 100644
--- a/client/macrowindow.cc
+++ b/client/macrowindow.cc
@@ -36,15 +36,13 @@
#include "widgets/widget.h"
#include "widgets/window.h"
#include "lua.h"
+#include "mainwindow.h"
#include "debug.h"
-extern QString cpr;
-extern QString user;
-extern QString host;
-extern quint16 port;
+extern MainWindow *gmainwindow;
-MacroWindow::MacroWindow(NetCom &n, QDomNode &xml_doc, QString templ,
+MacroWindow::MacroWindow(NetCom &n, QString templ,
bool is_static, bool compact,
QScrollArea *scrollarea)
: Collapser(NULL, compact?NULL:scrollarea), netcom(n)
@@ -62,13 +60,6 @@ MacroWindow::MacroWindow(NetCom &n, QDomNode &xml_doc, QString templ,
resumewidget = new ResumeWidget(compact);
- // update(xml_doc);
- updateResume(xml_doc);
- initMacro(xml_doc);
-
- if(mainwidget) animateToWidget(mainwidget->qwidget(), true);
- else animateToWidget(resumewidget);
-
active = true;
connect(this, SIGNAL(doneAnimating(QWidget*)),
@@ -83,95 +74,75 @@ MacroWindow::~MacroWindow()
void MacroWindow::update(QDomNode &node)
{
- /*
- if(is_static || mainwidget == NULL) {
- clear();
- lua->clear();
+ QDomElement elem = node.toElement();
+ if(elem.tagName() != "macro") return;
+
+ if(macro == "") macro = elem.attribute("name", "");
+ if(version == "") version = elem.attribute("version", "");
- initMacro(node);
+ if(macro != elem.attribute("name", "")) return;
+ if(version != elem.attribute("version", "")) return;
- if(mainwidget) setExpandedWidget(mainwidget->qwidget());
- else setExpandedWidget(NULL);
+ QDomNodeList children = node.childNodes();
+
+ // No content reveals resumewidget with 'dummy' text.
+ if(children.count() == 0) {
+ animateToWidget(resumewidget);
+ return;
}
- */
- updateResume(node);
+
+ QDomNode childnode = children.at(0);
+ QDomElement childelem = childnode.toElement();
+ if(childelem.tagName() == "resume") {
+ updateResume(childnode);
+ return;
+ }
+
+ initMacro(node);
}
void MacroWindow::updateResume(QDomNode &node)
{
QDomElement elem = node.toElement();
- if(elem.tagName() == "resume") {
- QString resume = elem.text();
- ResumeWidget::state_t state = ResumeWidget::OLD;
- if(elem.hasAttribute("state")) {
- if(elem.attribute("state") == "old") state = ResumeWidget::OLD;
- if(elem.attribute("state") == "new") state = ResumeWidget::NEW;
- if(elem.attribute("state") == "dirty") state = ResumeWidget::DIRTY;
- }
- /*
- if(!mainwidget) { // Only call collapse if the macro is in resume state.
- collapse();
- }
- */
- resumewidget->setText(resume, state);
- updateHeight();
-
- return;
- }
-
- QDomNodeList children = node.childNodes();
+ if(elem.tagName() != "resume") return;
- for (int i=0; i<children.count();i++) {
- QDomNode child = children.at(i);
- updateResume(child);
+ QString resume = elem.text();
+ ResumeWidget::state_t state = ResumeWidget::OLD;
+ if(elem.hasAttribute("state")) {
+ if(elem.attribute("state") == "old") state = ResumeWidget::OLD;
+ if(elem.attribute("state") == "new") state = ResumeWidget::NEW;
+ if(elem.attribute("state") == "dirty") state = ResumeWidget::DIRTY;
}
+ resumewidget->setText(resume, state);
+ animateToWidget(resumewidget);
}
void MacroWindow::initMacro(QDomNode &node)
{
QDomElement elem = node.toElement();
- if(elem.tagName() == "macro") {
-
- // Assign the macro name and version to QStrings for use when comitting
- macro = elem.attribute("name", "");
- version = elem.attribute("version", "");
-
- } else if(elem.tagName() == "scripts") {
+ if(elem.tagName() == "scripts") {
// Nothing to do here
- } else if(elem.tagName() == "resume") {
- // Handled in updateResume
- } else if(elem.tagName() == "script") {
+ }
+ if(elem.tagName() == "script") {
lua->runScript(elem.text(), NULL, "preload");
-
- } else if(elem.tagName() == "widgets") {
-
- if(mainwidget) {
- WARN(macrowindow,
- "WARNING: mainwidget already exists! Calling clear().\n");
- clear();
- }
-
- DEBUG(mainwindow, "----------------------Before-----------------------\n");
+ }
+ if(elem.tagName() == "widgets") {
Window *window = new Window(elem, this);
-
- DEBUG(mainwindow, "----------------------After------------------------\n");
-
connect(window, SIGNAL(wasChanged()), this, SLOT(macroChanged()));
macrotitle = elem.attribute("caption");
-
- mainwidget = window;
-
- // Moved to expandWrapper (validation bugfix)
- // mainwidget->setValues();
- if(is_static) mainwidget->setValues();
+ window->setValues();
if(waschanged == true) macroChanged();
+ WARN(macrowindow, "New window.");
+ mainwidget = window;
+ animateToWidget(mainwidget->qwidget());
+
return; // No further recursion here.
}
@@ -186,29 +157,17 @@ void MacroWindow::initMacro(QDomNode &node)
bool MacroWindow::doCommit()
{
if(mainwidget->valid()) {
+
QVector< Widget* > wlist;
if(mainwidget) wlist = mainwidget->widgetList();
- QDomDocument doc = netcom.send(wlist, templ, macro, version);
-
- QDomNodeList nl = doc.documentElement().childNodes();
- QDomNode n = nl.at(0); // There can be only one! (Swush, flomp)
-
- if(n.toElement().tagName() == "error") {
- QMessageBox::critical(this, "Server Error", "Server Error: " +
- n.toElement().text());
- return false;
- }
-
- qApp->processEvents();
-
- animateToWidget(resumewidget);
- emit updateOnCommit();
+ netcom.send(wlist, templ, macro, version);
return true;
+
} else {
- MessageBox::critical(NULL, "Fejl",
- "Makroen " + macrotitle +
- " er ikke udfyldt korrekt, prøv igen.\n",
+ MessageBox::critical(NULL, tr("Error"),
+ tr("The macro ") + macrotitle +
+ tr(" was not filled out correctly, please try again.\n"),
MessageBox::Ok);
return false;
@@ -228,91 +187,51 @@ void MacroWindow::cancel()
void MacroWindow::expandWrapper()
{
if(currentWidget() != resumewidget) return;
-
- waschanged = false;
-
- QDomDocument xml_doc = netcom.send(templ, macro);
-
- // Initiate the new macro window with the xml document and push
- // it to the window list
- QDomNodeList templates = xml_doc.documentElement().childNodes();
-
- // 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);
-
- if(true || macronode.childNodes().count()) {
- // macrowindows.push_back( new MacroWindow( netcom, macronode ) );
- QDomElement elem = macronode.toElement();
-
- if(elem.tagName() == "macro") {
-
- // Assign the macro name and version to QStrings for use when comitting
- QString macroname;
- if(elem.hasAttribute("name")) {
- if(elem.attribute("name") == macro) {
- // update me!
- initMacro(macronode);
- }
- }
- }
- }
- }
-
- // Set values here, to be sure that the widgets are visible to the value
- // system and thereby validate correctly.
- if(mainwidget) mainwidget->setValues();
-
- if(mainwidget) animateToWidget(mainwidget->qwidget(), true);
-
- // Set keyboard focus on the first focusable widget in the macro.
- QVector< Widget* > widgets;
- if(mainwidget) widgets = mainwidget->widgetList(true);
- QVector< Widget* >::iterator i = widgets.begin();
- while (i != widgets.end()) {
- if(*i) {
- Widget* w = *i;
- if(w->setKeyboardFocus()) break;
- }
- i++;
- }
-
+ netcom.send(templ, macro);
}
void MacroWindow::collapseWrapper()
{
if(currentWidget() == resumewidget) return;
- 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)) {
- case MessageBox::Save:
- doCommit();
- break;
- case MessageBox::Close:
- animateToWidget(resumewidget);
- break;
- case MessageBox::Cancel:
- default:
- break;
- }
- } else {
- animateToWidget(resumewidget);
+ if(waschanged == false) {
+ netcom.send(templ);
+ return;
+ }
+
+ MessageBox::StandardButton res =
+ MessageBox::warning(NULL,
+ tr("Save the macro changes?"),
+ tr("you have choosen to close the macro ") +
+ macrotitle + ".\n" +
+ tr("do you want to save before closing?"),
+ MessageBox::Save | MessageBox::Close |
+ MessageBox::Cancel);
+
+ switch(res) {
+ case MessageBox::Save:
+ doCommit();
+ break;
+ case MessageBox::Close:
+ netcom.send(templ);
+ break;
+ case MessageBox::Cancel:
+ default:
+ break;
}
}
void MacroWindow::toggleMacro()
{
if(!active) return;
+
if(currentWidget() == resumewidget) {
- expandWrapper();
+ if(gmainwindow && !gmainwindow->hasOpen(this)) {
+ expandWrapper();
+ } else {
+ MessageBox::warning(this, tr("Close first"),
+ tr("Close other one first."));
+ }
} else {
collapseWrapper();
}
@@ -337,19 +256,36 @@ void MacroWindow::setActive(bool active)
void MacroWindow::clear()
{
- // DEBUG(macrowindow, "clear %p\n", this);
- //setExpandedWidget(NULL);
-
- if(mainwidget) delete mainwidget;
- mainwidget = NULL;
+ lua->clear();
- // lua->clear();
+ if(mainwidget) {
+ delete mainwidget;
+ mainwidget = NULL;
+ }
}
void MacroWindow::animated(QWidget *w)
{
if(w == resumewidget) {
- DEBUG(macrowindow, "collapsed %p\n", this);
+
clear();
+
+ } else {
+
+ if(mainwidget == NULL) return;
+
+ waschanged = false;
+ mainwidget->setValues();
+
+ // Set keyboard focus on the first focusable widget in the macro.
+ QVector< Widget* > widgets;
+ widgets = mainwidget->widgetList(true);
+ QVector< Widget* >::iterator i = widgets.begin();
+ while(i != widgets.end()) {
+ Widget *w = *i;
+ if(w && w->setKeyboardFocus()) break;
+ i++;
+ }
+
}
}