diff options
Diffstat (limited to 'client')
34 files changed, 490 insertions, 116 deletions
| diff --git a/client/client.pro b/client/client.pro index ba1544b..4d4f82d 100644 --- a/client/client.pro +++ b/client/client.pro @@ -8,10 +8,14 @@ DEPENDPATH += . widgets  INCLUDEPATH += . widgets  QT += core gui network xml +# For debugging +QMAKE_CXXFLAGS += -g -Wall -Werror +  win32 {    LIBPATH += lua/lib    INCLUDEPATH += lua/include    LIBS += -llua51 +  DEFINES += HOST_WIN32  }  unix { @@ -19,9 +23,9 @@ unix {  }  HEADERS += \ -        builder.h \          lua.h \          macro.h \ +        macrowindow.h \          sendrecieve.h \          widgets.h \  	widgets/widget.h \ @@ -40,9 +44,9 @@ HEADERS += \  SOURCES += \          pracro.cc \ -        builder.cc \          lua.cc \          macro.cc \ +        macrowindow.cc \          sendrecieve.cc \          widgets/widget.cc \          widgets/label.cc \ @@ -57,7 +61,3 @@ SOURCES += \          widgets/radiobuttons.cc \          widgets/checkbox.cc \          widgets/window.cc - -win32 { -	DEFINES += HOST_WIN32 -} diff --git a/client/lua.h b/client/lua.h index e5eda5b..0c69b04 100644 --- a/client/lua.h +++ b/client/lua.h @@ -30,10 +30,7 @@  #include <lua.hpp>  #include <lauxlib.h> -#include <string> -#include <map> - -typedef std::map< std::string, std::string > Variables; +#include "variables.h"  class LUA {  public: diff --git a/client/macro.cc b/client/macro.cc index 82c68a4..d4ae0c0 100644 --- a/client/macro.cc +++ b/client/macro.cc @@ -25,13 +25,14 @@   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.   */  #include "macro.h" -#include "builder.h"  #include "sendrecieve.h"  #include <QDomDocument>  #include <QApplication>  #define MACRO_EVENT_ID 65432 +QLinkedList< MacroWindow * > macrowindows; +  extern QString cpr;  extern QString user;  extern QString host; @@ -117,11 +118,14 @@ static void create_macro(QString course, QString macro)    if (!xml_doc.setContent(ba)) {      printf("ERROR: Invalid XML recieved!\n");      fwrite(ba.data(), ba.size(), 1, stdout); +    return;    } -  // Initiate the macro builder with the xml document -  // FIXME: This should be done in some other way, to prevent the memory leak. -  new Builder(&xml_doc); +  cleanup_macros(); + +  // Initiate the new macro window with the xml document and push +  //  it to the window list +  macrowindows.push_back( new MacroWindow(&xml_doc) );  }  bool MacroEventFilter::eventFilter( QObject *, QEvent *e ) @@ -135,6 +139,26 @@ bool MacroEventFilter::eventFilter( QObject *, QEvent *e )    }  } +// Delete all closed windows from window list +void cleanup_macros() +{ +  int dead = 0; +  int live = 0; + +  QLinkedList< MacroWindow * >::iterator i = macrowindows.begin(); +  while(i != macrowindows.end()) { +    if( (*i)->isClosed() ) { +      dead++; +      delete *i; +      i = macrowindows.erase(i); +    } else { +      live++; +      i++; +    } +  } +  printf("Found %d live ones and %d dead ones.\n", live, dead); +} +  void new_macro(QString course, QString macro)  {    if(macro_event_filter == NULL) { diff --git a/client/macro.h b/client/macro.h index f372762..4cd7109 100644 --- a/client/macro.h +++ b/client/macro.h @@ -30,7 +30,13 @@  #include <QString>  #include <QObject>  #include <QEvent> +#include <QLinkedList> + +#include "macrowindow.h" + +extern QLinkedList< MacroWindow * > macrowindows;  void new_macro(QString course, QString name); +void cleanup_macros();  #endif/*__PRACRO_MACRO_H__*/ diff --git a/client/macrowindow.cc b/client/macrowindow.cc new file mode 100644 index 0000000..74e8d54 --- /dev/null +++ b/client/macrowindow.cc @@ -0,0 +1,256 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + *            macrowindow.cc + * + *  Fri Aug 31 12:27:45 CEST 2007 + *  Copyright 2007 Lars Bisballe Jensen and Bent Bisballe Nyeng + *  elsenator@gmail.com and deva@aasimon.org + ****************************************************************************/ + +/* + *  This file is part of Pracro. + * + *  Pracro is free software; you can redistribute it and/or modify + *  it under the terms of the GNU General Public License as published by + *  the Free Software Foundation; either version 2 of the License, or + *  (at your option) any later version. + * + *  Pracro is distributed in the hope that it will be useful, + *  but WITHOUT ANY WARRANTY; without even the implied warranty of + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + *  GNU General Public License for more details. + * + *  You should have received a copy of the GNU General Public License + *  along with Pracro; if not, write to the Free Software + *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA. + */ +#include "macrowindow.h" +#include "sendrecieve.h" +#include "widgets.h" +#include "macro.h" +#include <QVBoxLayout> +#include <QMessageBox> +#include <QDomDocument> +#include <QDomElement> +#include <QDomNode> +#include <QByteArray> + +extern QString cpr; +extern QString user; +extern QString host; +extern quint16 port; + +MacroWindow::MacroWindow(QDomDocument *xml_doc) +  : QObject() +{ +  isclosed = false; + +  // Execute the recursive function with documentElement +  recurser(xml_doc->documentElement(), NULL); +} + +MacroWindow::~MacroWindow() +{ +} + +void MacroWindow::recurser(QDomNode xml_node, QWidget *parent) +{ +  QWidget *widget = NULL; +  QDomElement xml_elem = xml_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"); + +  } 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")) { +      GroupBox *frame = new GroupBox(xml_elem); +      widget = frame; +    } else { +      Frame *frame = new Frame(xml_elem); +      widget = frame; +    } + +  } else if(xml_elem.tagName() == "label") { +    Label *label = new Label(xml_elem); +    widget = label; + +  } else if(xml_elem.tagName() == "lineedit") { +    LineEdit *lineedit = new LineEdit(xml_elem); +    widgets.push_back(lineedit); +    widget = lineedit; + +  } else if(xml_elem.tagName() == "button") { +    PushButton *pushbutton = new PushButton(xml_elem); +    //connect(pushbutton, SIGNAL(act_continue()), main, SLOT(get_macro())); +    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(QString)), this, SLOT(cont(QString))); +    widget = pushbutton; + +  } else if(xml_elem.tagName() == "textedit") { +    TextEdit *textedit = new TextEdit(xml_elem); +    widgets.push_back(textedit); +    widget = textedit; + +  } else if(xml_elem.tagName() == "checkbox") { +    CheckBox *checkbox = new CheckBox(xml_elem); +    widgets.push_back(checkbox); +    widget = checkbox; + +  } else if(xml_elem.tagName() == "radiobuttons") { +    RadioButtons *radiobuttons = new RadioButtons(xml_elem); +    widgets.push_back(radiobuttons); +    widget = radiobuttons; +    //return; // Don't iterate children + +  } else if(xml_elem.tagName() == "combobox") { +    ComboBox *combobox = new ComboBox(xml_elem); +    widgets.push_back(combobox); +    widget = combobox; +    //return; // Don't iterate children + +  } else if(xml_elem.tagName() == "listbox") { +    ListBox *listbox = new ListBox(xml_elem); +    widgets.push_back(listbox); +    widget = listbox; +    //return; // Don't iterate children +  } + +  QDomNodeList children = xml_node.childNodes(); + +  for (int i=0; i<children.count();i++) { +    QDomNode child = children.at(i); +    recurser(child, widget); +  } + +  if(parent != NULL && widget != NULL) parent->layout()->addWidget(widget); +  if(widget != NULL) widget->show(); +} + +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->isValid()) faulty++; // Regexp check, returns valid if entry passed +    i++; +  } + +  // If all entries passed validation, continue commit +  if(faulty == 0) { +    printf("MacroWindow -> committing...\n"); +     +    // 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=\"" + cpr + "\" user=\"" + user + "\">\n"); +    xml_string.append("  <commit macro=\"" + macro + "\" version=\"" +  +		      version + "\">\n"); + +    // Iterate the different entries, and append their results to the commit string +    QVector< Widget* >::iterator i=widgets.begin(); +    while (i != widgets.end()) { +      Widget* w = *i; +       +      xml_string.append("    <field name=\"" + w->getName() +		     + "\" value=\"" + w->getValue() + "\"/>\n"); +      i++; +    } +     +    xml_string.append("  </commit>\n"); +    xml_string.append("</pracro>\n"); +     +    // Print commit to stdout for debug purposes +    printf("%s\n", xml_string.toStdString().c_str()); + +    // Convert the commit to Utf-8 charset +    QByteArray xml_array = xml_string.toUtf8(); +    QDomDocument xml_result; + +    // Use setContent of QDomDocument to validate the xml commit +    if (!xml_result.setContent(xml_array)) { +      printf("Parse error: Invalid XML\n"); +    } +     +    // Commit the xml data to the server +    SendRecieve macro_commit(host, port); +    macro_commit.makeConnection(&xml_result); +    // Recieve answer from server whether successful or not +    //QByteArray ba = macro_commit.getResult(); +    QString ba = macro_commit.getResult(); +    printf("Server returned result: %s", ba.toStdString().c_str()); +    return true; +  } else { +    return false; +  } +} + +void MacroWindow::close() +{ +  mainwidget->close(); +  isclosed = true; +} + +void MacroWindow::commit() +{ +  if(doCommit()) { +    close(); +  } else { +   QMessageBox::critical(NULL, "Fejl", +			  "Makroen er ikke udfyldt korrekt, prøv igen.\n" +			  , QMessageBox::Ok); +  } +} + +void MacroWindow::reset() +{ +  QMessageBox::warning(NULL, tr("Reset"), +                   tr("Du har valgt at nulstille de indtastede data.\n" +                      "Er du sikker?"), +                   QMessageBox::Yes | QMessageBox::Cancel); +  printf("MacroWindow -> resetting...\n"); +} + +void MacroWindow::cancel() +{ +  printf("MacroWindow -> cancelling...\n"); +  close(); +} + +void MacroWindow::cont(QString name) +{ +  QString macro; +  QVector< Widget* >::iterator i=widgets.begin(); +  while (i != widgets.end()) { +    Widget* w = *i; +    if(w->getName() == name) { +      macro = w->getValue(); +    } +    i++; +  } +  if(doCommit()) { +    new_macro("FIXME", macro); +    close(); +  } else { +   QMessageBox::critical(NULL, "Fejl", +			 "Makroen er ikke udfyldt korrekt, prøv igen.\n", +			 QMessageBox::Ok); +  } +  printf("%s : MacroWindow -> continuing...\n", macro.toStdString().c_str()); +} + +bool MacroWindow::isClosed() +{ +  return isclosed; +} diff --git a/client/macrowindow.h b/client/macrowindow.h new file mode 100644 index 0000000..cad6124 --- /dev/null +++ b/client/macrowindow.h @@ -0,0 +1,64 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + *            macrowindow.h + * + *  Fri Aug 31 12:27:45 CEST 2007 + *  Copyright 2007 Lars Bisballe Jensen and Bent Bisballe Nyeng + *  elsenator@gmail.com and deva@aasimon.org + ****************************************************************************/ + +/* + *  This file is part of Pracro. + * + *  Pracro is free software; you can redistribute it and/or modify + *  it under the terms of the GNU General Public License as published by + *  the Free Software Foundation; either version 2 of the License, or + *  (at your option) any later version. + * + *  Pracro is distributed in the hope that it will be useful, + *  but WITHOUT ANY WARRANTY; without even the implied warranty of + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + *  GNU General Public License for more details. + * + *  You should have received a copy of the GNU General Public License + *  along with Pracro; if not, write to the Free Software + *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA. + */ +#ifndef __PRACRO_MACROWINDOW_H__ +#define __PRACRO_MACROWINDOW_H__ + +#include "widgets/widget.h" +#include <QDomDocument> +#include <QWidget> +#include <QDomNode> +#include <QObject> +#include <QVector> + +class MacroWindow : public QObject +{ +Q_OBJECT +public: +  MacroWindow(QDomDocument *xml_doc); +  ~MacroWindow(); + +  bool isClosed(); +                 +public slots: +  void commit(); +  void reset(); +  void cancel(); +  void cont(QString name); + +private: +  bool doCommit(); +  void recurser(QDomNode xml_node, QWidget *parent); +  QVector< Widget* > widgets; +  QString macro; +  QString version; +  QWidget *mainwidget; + +  bool isclosed; +  void close(); +}; + +#endif/*__PRACRO_MACROWINDOW_H__*/ diff --git a/client/pracro.cc b/client/pracro.cc index 6aca830..d0fbbf2 100644 --- a/client/pracro.cc +++ b/client/pracro.cc @@ -137,5 +137,9 @@ int main(int argc, char *argv[])    new_macro(course, macro);    //app.setQuitOnLastWindowClosed(false); -  return app.exec(); +  int ret = app.exec(); + +  cleanup_macros(); + +  return ret;  } diff --git a/client/variables.h b/client/variables.h new file mode 100644 index 0000000..b58ab72 --- /dev/null +++ b/client/variables.h @@ -0,0 +1,35 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + *            variables.h + * + *  Mon Jun  2 09:58:52 CEST 2008 + *  Copyright 2008 Bent Bisballe Nyeng + *  deva@aasimon.org + ****************************************************************************/ + +/* + *  This file is part of Pracro. + * + *  Pracro is free software; you can redistribute it and/or modify + *  it under the terms of the GNU General Public License as published by + *  the Free Software Foundation; either version 2 of the License, or + *  (at your option) any later version. + * + *  Pracro is distributed in the hope that it will be useful, + *  but WITHOUT ANY WARRANTY; without even the implied warranty of + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + *  GNU General Public License for more details. + * + *  You should have received a copy of the GNU General Public License + *  along with Pracro; if not, write to the Free Software + *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA. + */ +#ifndef __PRACRO_VARIABLES_H__ +#define __PRACRO_VARIABLES_H__ + +#include <string> +#include <map> + +typedef std::map< std::string, std::string > Variables; + +#endif/*__PRACRO_VARIABLES_H__*/ diff --git a/client/widgets/checkbox.cc b/client/widgets/checkbox.cc index 222d879..2ce3802 100644 --- a/client/widgets/checkbox.cc +++ b/client/widgets/checkbox.cc @@ -26,7 +26,7 @@   */  #include "checkbox.h" -CheckBox::CheckBox(QDomNode node) +CheckBox::CheckBox(QDomNode &node)    : QCheckBox(), Widget(node)  {    QDomElement elem = node.toElement(); @@ -63,3 +63,8 @@ QString CheckBox::getValue()    if(checkState() == Qt::Checked) return "true";    return "false";  } + +bool CheckBox::isValid() +{ +  return true; +} diff --git a/client/widgets/checkbox.h b/client/widgets/checkbox.h index c57f235..228723e 100644 --- a/client/widgets/checkbox.h +++ b/client/widgets/checkbox.h @@ -33,9 +33,10 @@  class CheckBox : public QCheckBox, public Widget  { -    public: -  CheckBox(QDomNode node); +  CheckBox(QDomNode &node); + +  bool isValid();  public slots:    QString getValue(); diff --git a/client/widgets/combobox.cc b/client/widgets/combobox.cc index 799b05d..480cada 100644 --- a/client/widgets/combobox.cc +++ b/client/widgets/combobox.cc @@ -27,7 +27,7 @@  #include "combobox.h"  #include <QDomNodeList> -ComboBox::ComboBox(QDomNode node) +ComboBox::ComboBox(QDomNode &node)    : QComboBox(), Widget(node)  {    QDomElement elem = node.toElement(); diff --git a/client/widgets/combobox.h b/client/widgets/combobox.h index 06d3856..ab92e64 100644 --- a/client/widgets/combobox.h +++ b/client/widgets/combobox.h @@ -33,9 +33,8 @@  class ComboBox : public QComboBox, public Widget  { -  public: -  ComboBox(QDomNode); +  ComboBox(QDomNode &node);  public slots:    bool isValid(); diff --git a/client/widgets/frame.cc b/client/widgets/frame.cc index 37f035e..e2227cc 100644 --- a/client/widgets/frame.cc +++ b/client/widgets/frame.cc @@ -28,7 +28,7 @@  #include <QVBoxLayout>  #include <QHBoxLayout> -Frame::Frame(QDomNode node) +Frame::Frame(QDomNode &node)    : QFrame(), Widget(node)  {    QDomElement elem = node.toElement(); diff --git a/client/widgets/frame.h b/client/widgets/frame.h index ff1a9f2..80aeded 100644 --- a/client/widgets/frame.h +++ b/client/widgets/frame.h @@ -33,9 +33,8 @@  class Frame : public QFrame, public Widget  { -  public: -  Frame(QDomNode node); +  Frame(QDomNode &node);  public slots:    QString getValue(); diff --git a/client/widgets/groupbox.cc b/client/widgets/groupbox.cc index a2a818c..dba97cd 100644 --- a/client/widgets/groupbox.cc +++ b/client/widgets/groupbox.cc @@ -28,7 +28,7 @@  #include <QVBoxLayout>  #include <QHBoxLayout> -GroupBox::GroupBox(QDomNode node) +GroupBox::GroupBox(QDomNode &node)    : QGroupBox(), Widget(node)  {    QDomElement elem = node.toElement(); diff --git a/client/widgets/groupbox.h b/client/widgets/groupbox.h index aa51aea..0cc1890 100644 --- a/client/widgets/groupbox.h +++ b/client/widgets/groupbox.h @@ -33,9 +33,8 @@  class GroupBox : public QGroupBox, public Widget  { -  public: -  GroupBox(QDomNode node); +  GroupBox(QDomNode &node);  public slots:    QString getValue(); diff --git a/client/widgets/label.cc b/client/widgets/label.cc index 8b6c19b..95d53ac 100644 --- a/client/widgets/label.cc +++ b/client/widgets/label.cc @@ -27,7 +27,7 @@  #include "label.h"  #include <stdio.h> -Label::Label(QDomNode node) +Label::Label(QDomNode &node)    : QLabel(), Widget(node)  {    QDomElement elem = node.toElement(); diff --git a/client/widgets/label.h b/client/widgets/label.h index edf5cb8..9c539e7 100644 --- a/client/widgets/label.h +++ b/client/widgets/label.h @@ -34,16 +34,12 @@  class Label : public QLabel, public Widget  { -  Q_OBJECT -  public: -  Label(QDomNode node); +  Label(QDomNode &node);  public slots:    QString getValue(); - -private: -  }; +  #endif/*__PRACRO_LABEL_H__*/ diff --git a/client/widgets/lineedit.cc b/client/widgets/lineedit.cc index 83f8d3e..26c2760 100644 --- a/client/widgets/lineedit.cc +++ b/client/widgets/lineedit.cc @@ -27,25 +27,20 @@  #include "lineedit.h"  #include <stdio.h> -LineEdit::LineEdit(QDomNode node) +LineEdit::LineEdit(QDomNode &node)    : QLineEdit(), Widget(node)  {    QDomElement elem = node.toElement();    if(elem.hasAttribute("width")) { -    //resize(elem.attribute("width").toInt(), height());      setMinimumWidth(elem.attribute("width").toInt());    }    if(elem.hasAttribute("height")) { -    //resize(width(), elem.attribute("height").toInt());      setMinimumHeight(elem.attribute("height").toInt());    } -  if(elem.hasAttribute("regexp")) { -    rx = QRegExp(elem.attribute("regexp")); -    connect(this, SIGNAL(textChanged(QString)), this, SLOT(changed(QString))); -  } +  connect(this, SIGNAL(textChanged(QString)), this, SLOT(changed()));    if(elem.hasAttribute("value")) {      setText(elem.attribute("value")); @@ -56,29 +51,19 @@ LineEdit::LineEdit(QDomNode node)    }  } -void LineEdit::changed(QString new_text) +void LineEdit::changed()  {    QPalette palette; -  if(rx.exactMatch(new_text)) { +  if(regexpValidator()) {      // valid string      palette.setBrush(QPalette::Base, QBrush(QColor(255, 255, 255))); -    valid = true;    } else {      // invalid string      palette.setBrush(QPalette::Base, QBrush(QColor(230, 200, 200))); -    valid = false;    } -  setPalette(palette); -} -bool LineEdit::isValid() -{ -  if(rx.exactMatch(text())) { -    return true; -  } else { -    return false; -  } +  setPalette(palette);  }  QString LineEdit::getValue() diff --git a/client/widgets/lineedit.h b/client/widgets/lineedit.h index 99574c2..faea440 100644 --- a/client/widgets/lineedit.h +++ b/client/widgets/lineedit.h @@ -34,19 +34,15 @@  class LineEdit : public QLineEdit, public Widget  { -  Q_OBJECT -  public: -  LineEdit(QDomNode node); -  bool isValid(); +  LineEdit(QDomNode &node);  public slots: -  void changed(QString text); +  void changed();    QString getValue();  private: -  QRegExp rx;    bool valid;  }; diff --git a/client/widgets/listbox.cc b/client/widgets/listbox.cc index edaa5a2..c7151cc 100644 --- a/client/widgets/listbox.cc +++ b/client/widgets/listbox.cc @@ -27,7 +27,7 @@  #include "listbox.h"  #include <QListWidgetItem> -ListBox::ListBox(QDomNode node) +ListBox::ListBox(QDomNode &node)    : QListWidget(), Widget(node)  {    QDomElement elem = node.toElement(); diff --git a/client/widgets/listbox.h b/client/widgets/listbox.h index 658847e..e41838b 100644 --- a/client/widgets/listbox.h +++ b/client/widgets/listbox.h @@ -33,9 +33,8 @@  class ListBox : public QListWidget, public Widget  { -  public: -  ListBox(QDomNode); +  ListBox(QDomNode &node);  public slots:    bool isValid(); diff --git a/client/widgets/pushbutton.cc b/client/widgets/pushbutton.cc index 1fa7589..d674162 100644 --- a/client/widgets/pushbutton.cc +++ b/client/widgets/pushbutton.cc @@ -27,7 +27,7 @@  #include "pushbutton.h"  #include <stdio.h> -PushButton::PushButton(QDomNode node) +PushButton::PushButton(QDomNode &node)    : QPushButton(), Widget(node)  {    QDomElement elem = node.toElement(); diff --git a/client/widgets/pushbutton.h b/client/widgets/pushbutton.h index ce6769b..42e3156 100644 --- a/client/widgets/pushbutton.h +++ b/client/widgets/pushbutton.h @@ -34,11 +34,9 @@  class PushButton : public QPushButton, public Widget  { -  Q_OBJECT -  public: -  PushButton(QDomNode node); +  PushButton(QDomNode &node);    QString field;  public slots: diff --git a/client/widgets/radiobutton.cc b/client/widgets/radiobutton.cc index 1a4287f..6de030d 100644 --- a/client/widgets/radiobutton.cc +++ b/client/widgets/radiobutton.cc @@ -27,7 +27,7 @@  #include "radiobutton.h"  #include <QRadioButton> -RadioButton::RadioButton(QDomNode node, bool radio_bool) +RadioButton::RadioButton(QDomNode &node, bool radio_bool)    : QRadioButton()  {    QDomElement elem = node.toElement(); diff --git a/client/widgets/radiobutton.h b/client/widgets/radiobutton.h index c2b7264..66c971e 100644 --- a/client/widgets/radiobutton.h +++ b/client/widgets/radiobutton.h @@ -35,9 +35,8 @@  class RadioButton : public QRadioButton  { -  public: -  RadioButton(QDomNode, bool); +  RadioButton(QDomNode &node, bool radio_bool);  public slots:    QString getValue(); diff --git a/client/widgets/radiobuttons.cc b/client/widgets/radiobuttons.cc index a6218d2..8c87a0c 100644 --- a/client/widgets/radiobuttons.cc +++ b/client/widgets/radiobuttons.cc @@ -30,7 +30,7 @@  #include <QHBoxLayout>  #include <QVBoxLayout> -RadioButtons::RadioButtons(QDomNode node) +RadioButtons::RadioButtons(QDomNode &node)    : QFrame(), Widget(node)  {    QDomElement elem = node.toElement(); diff --git a/client/widgets/radiobuttons.h b/client/widgets/radiobuttons.h index 4ee447b..454d159 100644 --- a/client/widgets/radiobuttons.h +++ b/client/widgets/radiobuttons.h @@ -36,9 +36,8 @@  class RadioButtons : public QFrame, public Widget  { -  public: -  RadioButtons(QDomNode); +  RadioButtons(QDomNode &node);  public slots:    bool isValid(); diff --git a/client/widgets/textedit.cc b/client/widgets/textedit.cc index 28ca010..e217cc6 100644 --- a/client/widgets/textedit.cc +++ b/client/widgets/textedit.cc @@ -28,7 +28,7 @@  #include <stdio.h>  #include <QPalette> -TextEdit::TextEdit(QDomNode node) +TextEdit::TextEdit(QDomNode &node)    : QTextEdit(), Widget(node)  {    //setAutoFillBackground(true); /* Default is false, which disables background @@ -37,23 +37,19 @@ TextEdit::TextEdit(QDomNode node)    QDomElement elem = node.toElement();    if(elem.hasAttribute("width")) { -    //resize(elem.attribute("width").toInt(), height());      setMinimumWidth(elem.attribute("width").toInt());    }    if(elem.hasAttribute("height")) { -    //resize(width(), elem.attribute("height").toInt());      setMinimumHeight(elem.attribute("height").toInt());    } -  if(elem.hasAttribute("regexp")) { -    rx = QRegExp(elem.attribute("regexp")); -    connect(this, SIGNAL(textChanged()), this, SLOT(changed())); -  } +  connect(this, SIGNAL(textChanged()), this, SLOT(changed()));    if(elem.hasAttribute("value")) {      setText(elem.attribute("value"));    } else { +    setText(" ");      setText("");    }  } @@ -62,26 +58,14 @@ void TextEdit::changed()  {    QPalette palette; -  if(rx.exactMatch(QTextEdit::toPlainText())) { +  if(regexpValidator()) {      // valid string      palette.setBrush(QPalette::Base, QBrush(QColor(255, 255, 255))); -    valid = true;    } else {      // invalid string      palette.setBrush(QPalette::Base, QBrush(QColor(230, 200, 200))); -    valid = false;    }    setPalette(palette);  -  //printf("%s\n", text.toStdString().c_str()); -} - -bool TextEdit::isValid() -{ -   if(rx.exactMatch(QTextEdit::toPlainText())) { -    return true; -  } else { -     return false; -  }  }  QString TextEdit::getValue() diff --git a/client/widgets/textedit.h b/client/widgets/textedit.h index 0ddb15d..466af0f 100644 --- a/client/widgets/textedit.h +++ b/client/widgets/textedit.h @@ -34,20 +34,13 @@  class TextEdit : public QTextEdit, public Widget  { -  Q_OBJECT -  public: -  TextEdit(QDomNode node); -  bool isValid(); +  TextEdit(QDomNode &node);  public slots:    void changed();    QString getValue(); - -private: -  QRegExp rx; -  bool valid; -  }; +  #endif/*__PRACRO_TEXTEDIT_H__*/ diff --git a/client/widgets/widget.cc b/client/widgets/widget.cc index 5a433e9..b128a53 100644 --- a/client/widgets/widget.cc +++ b/client/widgets/widget.cc @@ -26,20 +26,31 @@   */  #include "widget.h" -//Widget::Widget(QString parent_name, QDomNode node) -Widget::Widget(QDomNode node) +Widget::Widget(QDomNode &node)  {    QDomElement elem = node.toElement();    if(elem.hasAttribute("name")) { -    //if(parent_name != "") -    //  widget_name = parent_name + "." + elem.attribute("name"); -    //else -      widget_name = elem.attribute("name"); +    widget_name = elem.attribute("name");    } else {      printf("XML ERROR!! Unnamed widget of type: %s\n",              elem.tagName().toStdString().c_str());    } + +  if(elem.hasAttribute("lua_validator")) { +    //      lua_validator = elem.attribute("lua_validator"); +    hasluavalidator = true; +  } else { +    hasluavalidator = false; +  } +   +  if(elem.hasAttribute("regexp")) { +    rx = QRegExp(elem.attribute("regexp")); +    hasregexpvalidator = true; +  } else { +    hasregexpvalidator = false; +  } +    }  QString Widget::getName() @@ -47,7 +58,22 @@ QString Widget::getName()    return widget_name;  } +QString Widget::getValue() +{ +  return ""; +} +  bool Widget::isValid()  { -  return true; +  return regexpValidator() && luaValidator(); +} + +bool Widget::regexpValidator() +{ +  return !hasregexpvalidator || rx.exactMatch(getValue()); +} + +bool Widget::luaValidator() +{ +  return !hasluavalidator || true;  } diff --git a/client/widgets/widget.h b/client/widgets/widget.h index 1f92ea9..89610bb 100644 --- a/client/widgets/widget.h +++ b/client/widgets/widget.h @@ -29,18 +29,29 @@  #include <QString>  #include <QDomNode> +#include <QRegExp> -class Widget { +#include "lua.h" +class Widget {  public: -  //Widget(QString parent_name, QDomNode node); -  Widget(QDomNode node); +  Widget(QDomNode &node);    virtual ~Widget(){} -  virtual QString getValue() = 0; +  virtual QString getValue();    virtual bool isValid();    QString getName();  protected:    QString widget_name; + +  bool luaValidator(); +  bool regexpValidator(); + +private: +  QRegExp rx; +  LUA *lua; +  bool hasregexpvalidator; +  bool hasluavalidator;  }; +  #endif/*__PRACRO_WIDGET_H__*/ diff --git a/client/widgets/window.cc b/client/widgets/window.cc index 8cb39ab..5d15733 100644 --- a/client/widgets/window.cc +++ b/client/widgets/window.cc @@ -28,7 +28,7 @@  #include <QVBoxLayout>  #include <QHBoxLayout> -Window::Window(QDomNode node) +Window::Window(QDomNode &node)    : QWidget(NULL), Widget(node)  {    QDomElement elem = node.toElement(); diff --git a/client/widgets/window.h b/client/widgets/window.h index e15a715..93c48ab 100644 --- a/client/widgets/window.h +++ b/client/widgets/window.h @@ -33,9 +33,8 @@  class Window : public QWidget, public Widget  { -  public: -  Window(QDomNode node); +  Window(QDomNode &node);  public slots:    QString getValue(); | 
