summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordeva <deva>2009-06-30 17:31:53 +0000
committerdeva <deva>2009-06-30 17:31:53 +0000
commit9a773bc9ed736301b5ac6f6f8798056194398011 (patch)
treea113908743936aea97975adb6f4f1c7f49e6b007
parentb31e7fba17d1e5c1264c0829c4da258c32aa80c3 (diff)
Removed console on win32 unless, compiled in debug mode. First attempt on a macro dependency system.
-rw-r--r--client/client.pro62
-rw-r--r--client/macro.cc132
-rw-r--r--client/macro.h68
-rw-r--r--client/macrodrawer.cc16
-rw-r--r--client/macrodrawer.h8
-rw-r--r--client/macrowindow.cc21
-rw-r--r--client/macrowindow.h9
-rw-r--r--client/mainwindow.cc109
-rw-r--r--client/mainwindow.h8
9 files changed, 319 insertions, 114 deletions
diff --git a/client/client.pro b/client/client.pro
index 38279b8..772bbd3 100644
--- a/client/client.pro
+++ b/client/client.pro
@@ -1,5 +1,7 @@
# -*- Makefile -*-
+CONFIG += debug
+
TEMPLATE = app
TARGET = pracro
DEPENDPATH += . widgets
@@ -8,16 +10,20 @@ RESOURCES += client.qrc
QT += core gui network xml sql
# For debugging
-QMAKE_CXXFLAGS += -g -Wall -Werror
+debug {
+ QMAKE_CXXFLAGS += -g -Wall -Werror
+}
-DEFINES+=VERSION=\\\"1.0.1\\\"
+DEFINES+=VERSION=\\\"1.0.2\\\"
win32 {
LIBPATH += lua/lib
INCLUDEPATH += lua/include
LIBS += -llua51
DEFINES += HOST_WIN32
- CONFIG += console release
+ debug {
+ CONFIG += console
+ }
}
unix {
@@ -26,21 +32,22 @@ unix {
HEADERS += \
collapser.h \
- formatparser.h \
- lua.h \
- macrowindow.h \
+ formatparser.h \
+ lua.h \
+ macro.h \
+ macrowindow.h \
mainwindow.h \
macrodrawer.h \
messagebox.h \
netcom.h \
resumewidget.h \
- widgetbuilder.h \
- widgets.h \
+ widgetbuilder.h \
+ widgets.h \
widgets/common.h \
widgets/widget.h \
widgets/label.h \
widgets/lineedit.h \
- widgets/multilist.h \
+ widgets/multilist.h \
widgets/textedit.h \
widgets/button.h \
widgets/datetime.h \
@@ -53,39 +60,40 @@ HEADERS += \
widgets/radiobuttons.h \
widgets/checkbox.h \
widgets/window.h \
- widgets/altcombobox.h \
+ widgets/altcombobox.h \
widgets/metawidget.h
SOURCES += \
- pracro.cc \
+ pracro.cc \
collapser.cc \
- formatparser.cc \
- lua.cc \
- macrowindow.cc \
+ formatparser.cc \
+ lua.cc \
+ macro.cc \
+ macrowindow.cc \
mainwindow.cc \
macrodrawer.cc \
messagebox.cc \
netcom.cc \
resumewidget.cc \
- widgetbuilder.cc \
+ widgetbuilder.cc \
widgets/common.cc \
- widgets/widget.cc \
- widgets/label.cc \
- widgets/lineedit.cc \
- widgets/multilist.cc \
- widgets/textedit.cc \
- widgets/button.cc \
- widgets/combobox.cc \
+ widgets/widget.cc \
+ widgets/label.cc \
+ widgets/lineedit.cc \
+ widgets/multilist.cc \
+ widgets/textedit.cc \
+ widgets/button.cc \
+ widgets/combobox.cc \
widgets/datetime.cc \
widgets/dbwidget.cc \
widgets/listbox.cc \
- widgets/frame.cc \
+ widgets/frame.cc \
widgets/groupbox.cc \
widgets/radiobutton.cc \
- widgets/radiobuttons.cc \
- widgets/checkbox.cc \
- widgets/window.cc \
- widgets/altcombobox.cc \
+ widgets/radiobuttons.cc \
+ widgets/checkbox.cc \
+ widgets/window.cc \
+ widgets/altcombobox.cc \
widgets/metawidget.cc
TRANSLATIONS=pracro_dk.ts \ No newline at end of file
diff --git a/client/macro.cc b/client/macro.cc
new file mode 100644
index 0000000..dbe34f5
--- /dev/null
+++ b/client/macro.cc
@@ -0,0 +1,132 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set et sw=2 ts=2: */
+/***************************************************************************
+ * macro.cc
+ *
+ * Tue Jun 30 11:49:46 CEST 2009
+ * Copyright 2009 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.
+ */
+#include "macro.h"
+
+#include <QDomElement>
+#include <QHBoxLayout>
+
+#include "macrodrawer.h"
+
+Macro::Macro(QDomNode &n)
+{
+ window = NULL;
+
+ node = n.cloneNode(true);
+
+ QDomElement xml_elem = node.toElement();
+
+ if(xml_elem.tagName() != "macro") return;
+ if(xml_elem.hasAttribute("header")) return;
+
+ name = xml_elem.attribute("name");
+
+ iscompleted = xml_elem.attribute("completed", "false") == "true";
+}
+
+void Macro::init(QBoxLayout *layout, Macros &macros, bool initialising, NetCom &netcom, QString course)
+{
+ QDomElement xml_elem = node.toElement();
+
+ if(xml_elem.tagName() != "macro") return;
+
+ isstatic = xml_elem.attribute("static", "false") == "true";
+ iscompact = xml_elem.attribute("compact", "false") == "true";
+
+ if(xml_elem.hasAttribute("requires")) {
+ // Read and parse requirement list.
+ requires = xml_elem.attribute("requires").split(",");
+ }
+
+ if(xml_elem.hasAttribute("header")) {
+ // Macro is a special headline macro.
+ // Simply create a headline, and ignore the rest.
+
+ // Only add header on initial contruction.
+ if(initialising == true) {
+ QLabel *header = new QLabel();
+ header->setText(xml_elem.attribute("header"));
+ QFont headerfont = header->font();
+ headerfont.setBold(true);
+ headerfont.setPointSize(headerfont.pointSize() + 2);
+ header->setFont(headerfont);
+ layout->addWidget(header);
+ }
+
+ return;
+ }
+
+ // if(macros.find(name) == macros.end()) {
+ if(window == NULL) {
+ window = new MacroWindow(netcom, node, course, !isstatic, iscompact);
+
+ MacroDrawer *g = new MacroDrawer(this, xml_elem.attribute("caption", name));
+ g->connect(g, SIGNAL(toggle()), window, SLOT(toggleMacro()));
+ g->connect(window, SIGNAL(activationChanged(bool)), g, SLOT(activationChange(bool)));
+ window->setActive(false);
+
+ layout->addWidget(g);
+
+ QHBoxLayout *l = new QHBoxLayout();
+ l->setContentsMargins(10,0,10,0);
+ g->setLayout(l);
+ l->addWidget(window);
+ {
+ QFont f = window->font();
+ f.setBold(false);
+ f.setItalic(false);
+ window->setFont(f);
+ }
+
+ } else {
+
+ window->update(node);
+ if(xml_elem.attribute("static", "false") == "false") {
+ window->setCollapsed(true);
+ }
+ }
+
+ QStringList::iterator rs = requires.begin();
+ bool active = true;
+ while(rs != requires.end()) {
+ printf("Testing if %s is completed...", rs->toStdString().c_str());
+
+ Macros::iterator ms = macros.begin();
+ while(ms != macros.end()) {
+ if(ms->name == *rs) {
+ printf("Found it %d", ms->iscompleted);
+ active = active && ms->iscompleted;
+ }
+ ms++;
+ }
+
+ printf("\n");
+ rs++;
+ }
+ window->setActive(active);
+
+}
diff --git a/client/macro.h b/client/macro.h
new file mode 100644
index 0000000..f79583c
--- /dev/null
+++ b/client/macro.h
@@ -0,0 +1,68 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set et sw=2 ts=2: */
+/***************************************************************************
+ * macro.h
+ *
+ * Tue Jun 30 11:49:46 CEST 2009
+ * Copyright 2009 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_MACRO_H__
+#define __PRACRO_MACRO_H__
+
+#include <QString>
+#include <QStringList>
+#include <QMap>
+#include <QDomNode>
+#include <QBoxLayout>
+
+#include "macrowindow.h"
+
+class Macro;
+typedef QMap<QString, Macro> Macros;
+
+class Macro {
+public:
+ Macro() {}
+ Macro(QDomNode &node);
+
+ void init(QBoxLayout *layout, Macros &macros, bool initialising, NetCom &netcom, QString course);
+
+ QString name;
+ QString caption;
+
+ // Dependency system
+ QStringList requires;
+ // bool isrequired;
+ bool iscompleted;
+
+ QString resume;
+
+ bool isstatic;
+ bool iscompact;
+
+ MacroWindow *window;
+
+private:
+ QDomNode node;
+};
+
+#endif/*__PRACRO_MACRO_H__*/
diff --git a/client/macrodrawer.cc b/client/macrodrawer.cc
index 85cab3f..f3fcab1 100644
--- a/client/macrodrawer.cc
+++ b/client/macrodrawer.cc
@@ -28,11 +28,9 @@
#include <QPushButton>
-MacroDrawer::MacroDrawer(MacroWindow *p, QString title)
+MacroDrawer::MacroDrawer(Macro *macro, QString title)
{
- mw = p;
-
- if(!mw->isstatic) setTitle(" " + title);
+ if(!macro->isstatic) setTitle(" " + title);
setFlat(true);
{
@@ -41,7 +39,7 @@ MacroDrawer::MacroDrawer(MacroWindow *p, QString title)
setFont(f);
}
- if(!mw->isstatic) {
+ if(!macro->isstatic) {
QPushButton *b = new QPushButton("±", this);
b->setFixedSize(16,16);
b->move(0,0);
@@ -61,7 +59,7 @@ bool MacroDrawer::eventFilter(QObject *obj, QEvent *event)
{
if(event->type() == QEvent::MouseButtonRelease) {
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
- if(mouseEvent->y() < 16 && isEnabled()) toggle();
+ if(mouseEvent->y() < 16 && isEnabled()) emit toggle();
}
return QObject::eventFilter(obj, event);
}
@@ -70,3 +68,9 @@ void MacroDrawer::toggleMe()
{
emit toggle();
}
+
+void MacroDrawer::activationChange(bool active)
+{
+ //printf("Active %d\n", (int)active);
+ setEnabled(active);
+}
diff --git a/client/macrodrawer.h b/client/macrodrawer.h
index a6a5d6d..0ad09f5 100644
--- a/client/macrodrawer.h
+++ b/client/macrodrawer.h
@@ -29,24 +29,22 @@
#include <QGroupBox>
#include <QString>
-#include "macrowindow.h"
+#include "macro.h"
class MacroDrawer : public QGroupBox {
Q_OBJECT
public:
- MacroDrawer(MacroWindow *p, QString title);
+ MacroDrawer(Macro *macro, QString title);
protected:
bool eventFilter(QObject *obj, QEvent *event);
public slots:
void toggleMe();
+ void activationChange(bool active);
signals:
void toggle();
-
-private:
- MacroWindow *mw;
};
#endif/*__PRACRO_MACRODRAWER_H__*/
diff --git a/client/macrowindow.cc b/client/macrowindow.cc
index e3e3bac..db6ad53 100644
--- a/client/macrowindow.cc
+++ b/client/macrowindow.cc
@@ -44,14 +44,13 @@ extern QString user;
extern QString host;
extern quint16 port;
-MacroWindow::MacroWindow(NetCom *netcom, QDomNode &xml_doc, QString course,
+MacroWindow::MacroWindow(NetCom &n, QDomNode &xml_doc, QString course,
bool collapsed, bool compact)
- : Collapser()
+ : Collapser(), netcom(n)
{
waschanged = false;
this->course = course;
- this->netcom = netcom;
setCollapsedWidget(new ResumeWidget(compact));
@@ -60,6 +59,7 @@ MacroWindow::MacroWindow(NetCom *netcom, QDomNode &xml_doc, QString course,
update(xml_doc);
setCollapsed(collapsed);
+ active = true;
}
MacroWindow::~MacroWindow()
@@ -149,7 +149,7 @@ bool MacroWindow::doCommit()
// If all entries passed validation, continue commit
if(faulty == 0) {
- netcom->send(widgets, course, macro, version);
+ netcom.send(widgets, course, macro, version);
emit updateOnCommit();
setCollapsed(true);
return true;
@@ -305,7 +305,7 @@ void MacroWindow::expandWrapper()
luaprograms.clear();
waschanged = false;
- QDomDocument xml_doc = netcom->send(course, macro);
+ QDomDocument xml_doc = netcom.send(course, macro);
//
// TODO: This is where the dependency checking should occur.
@@ -380,6 +380,7 @@ void MacroWindow::collapseWrapper()
void MacroWindow::toggleMacro()
{
+ if(!active) return;
if(isCollapsed()) {
expandWrapper();
} else {
@@ -393,3 +394,13 @@ void MacroWindow::macroChanged()
emit macroHasChanged();
waschanged = true;
}
+
+void MacroWindow::setActive(bool active)
+{
+ if(this->active == active) return;
+
+ this->active = active;
+ if(active == false) setEnabled(false);
+ else setEnabled(true);
+ emit activationChanged(active);
+}
diff --git a/client/macrowindow.h b/client/macrowindow.h
index c34c978..fad467b 100644
--- a/client/macrowindow.h
+++ b/client/macrowindow.h
@@ -47,7 +47,7 @@ class MacroWindow : public Collapser
{
Q_OBJECT
public:
- MacroWindow(NetCom *netcom, QDomNode &xml_doc, QString course,
+ MacroWindow(NetCom &netcom, QDomNode &xml_doc, QString course,
bool collapsed = true, bool compact = false);
~MacroWindow();
@@ -67,8 +67,9 @@ public:
void update(QDomNode &xml_doc);
+ void setActive(bool active);
+
QString macrotitle;
- bool isstatic;
public slots:
void commit();
@@ -87,6 +88,7 @@ public slots:
signals:
void updateOnCommit();
void macroHasChanged();
+ void activationChanged(bool);
private:
void initMacro(QDomNode &node);
@@ -103,9 +105,10 @@ private:
bool isclosed;
void close();
- NetCom *netcom;
+ NetCom &netcom;
bool waschanged;
+ bool active;
};
#endif/*__PRACRO_MACROWINDOW_H__*/
diff --git a/client/mainwindow.cc b/client/mainwindow.cc
index fd55ba0..c59a877 100644
--- a/client/mainwindow.cc
+++ b/client/mainwindow.cc
@@ -60,7 +60,6 @@ MainWindow::MainWindow(QString cpr, QString course, QString host, quint16 port,
w->setLayout(new QVBoxLayout());
this->course = course;
- // status->showMessage("Makroen blev succesfuldt indlęst.");
setStatusBar(status);
init();
@@ -94,13 +93,8 @@ void MainWindow::init()
initialising = false;
}
-void MainWindow::update()
+void MainWindow::updateCourseHeaders(QDomNode coursenode)
{
- QDomDocument xml_doc = netcom.send(course);
-
- QDomNodeList courses = xml_doc.documentElement().childNodes();
- QDomNode coursenode = courses.at(0); // There can be only one! (Swush, flomp)
-
QDomElement course_elem = coursenode.toElement();
QString course_title = course_elem.attribute("title");
QString course_name = course_elem.attribute("name");
@@ -117,82 +111,63 @@ void MainWindow::update()
}
statusBar()->showMessage(course_title + " (" + course_name + ")");
+}
+
+
+void MainWindow::update()
+{
+ QDomDocument xml_doc = netcom.send(course);
+
+ QDomNodeList courses = xml_doc.documentElement().childNodes();
+ QDomNode coursenode = courses.at(0); // There can be only one! (Swush, flomp)
+
+ updateCourseHeaders(coursenode);
QDomNodeList macronodes = coursenode.childNodes();
for(int j = 0; j < macronodes.count(); j++) {
QDomNode macronode = macronodes.at(j);
+ QDomElement macroelement = macronode.toElement();
- QDomElement xml_elem = macronode.toElement();
-
- if(xml_elem.tagName() == "macro") {
-
- if(xml_elem.hasAttribute("header")) {
- // Macro is a special headline macro.
- // Simply create a headline, and ignore the rest.
+ QString macroname = macroelement.attribute("name");
- // Only add header on initial contruction.
- if(initialising == true) {
- QLabel *header = new QLabel();
- header->setText(xml_elem.attribute("header"));
- QFont headerfont = header->font();
- headerfont.setBold(true);
- headerfont.setPointSize(headerfont.pointSize() + 2);
- header->setFont(headerfont);
- w->layout()->addWidget(header);
- }
+ bool found = false;
- continue;
- }
+ Macros::iterator i = macros.begin();
+ while(i != macros.end()) {
+ if(i->name == macroname) found |= true;
+ i++;
+ }
- QString macroname;
- if(xml_elem.hasAttribute("name")) macroname = xml_elem.attribute("name");
-
- if(macros.find(macroname) == macros.end()) {
- bool isstatic = false;
- bool iscompact = false;
- if(xml_elem.attribute("static", "false") == "true") isstatic = true;
- if(xml_elem.attribute("compact", "false") == "true") iscompact = true;
- macros[macroname] = new MacroWindow(&netcom, macronode, course, !isstatic, iscompact);
- macros[macroname]->isstatic = isstatic;
-
- MacroDrawer *g = new MacroDrawer(macros[macroname], xml_elem.attribute("caption", macroname));
- connect(g, SIGNAL(toggle()), macros[macroname], SLOT(toggleMacro()));
-
- ((QBoxLayout*)w->layout())->addWidget(g);
-
- QHBoxLayout *l = new QHBoxLayout();
- l->setContentsMargins(10,0,10,0);
- g->setLayout(l);
- l->addWidget(macros[macroname]);
- connect(macros[macroname], SIGNAL(updateOnCommit()), this, SLOT(update()));
- {
- QFont f = macros[macroname]->font();
- f.setBold(false);
- f.setItalic(false);
- macros[macroname]->setFont(f);
- }
-
- } else {
-
- macros[macroname]->update(macronode);
- if(xml_elem.attribute("static", "false") == "false") {
- macros[macroname]->setCollapsed(true);
- }
+ if(found == false || macroelement.hasAttribute("header")) {
+ QString num;
+ num.sprintf("%4d", j);
+ Macro macro(macronode);
+ macros[num + macro.name] = macro;
+ }
+ }
- }
+ {
+ Macros::iterator i = macros.begin();
+ while(i != macros.end()) {
+ Macro &macro = i.value();
+ macro.init((QBoxLayout*)w->layout(), macros, initialising, netcom, course);
+ if(macro.window != NULL) connect(macro.window, SIGNAL(updateOnCommit()), this, SLOT(update()));
+ i++;
}
}
// Make sure that all macros will collapse when a new one is expanded.
- QMap< QString, MacroWindow* >::iterator i = macros.begin();
+ Macros::iterator i = macros.begin();
while(i != macros.end()) {
- MacroWindow *m1 = i.value();
-
- QMap< QString, MacroWindow* >::iterator j = macros.begin();
+ Macro &_m1 = i.value();
+ MacroWindow *m1 = _m1.window;
+
+ Macros::iterator j = macros.begin();
while(j != macros.end()) {
- MacroWindow *m2 = j.value();
+ Macro &_m2 = j.value();
+ MacroWindow *m2 = _m2.window;
- if(m1 != m2 && m2->isstatic == false) {
+ if(m1 && m2 && m1 != m2 && _m2.isstatic == false) {
// Remove old connection (if any), to avoid multiple connections.
disconnect(m1, SIGNAL(expanding()), m2, SLOT(collapseWrapper()));
diff --git a/client/mainwindow.h b/client/mainwindow.h
index 00300f4..d60db9d 100644
--- a/client/mainwindow.h
+++ b/client/mainwindow.h
@@ -29,10 +29,13 @@
#include <QMainWindow>
#include <QMap>
+#include <QVector>
#include <QPushButton>
#include "netcom.h"
#include "macrowindow.h"
+#include "macro.h"
+
class MainWindow : public QMainWindow {
Q_OBJECT
public:
@@ -45,10 +48,13 @@ public slots:
void update();
private:
+ void updateCourseHeaders(QDomNode coursenode);
+
QString course;
NetCom netcom;
- QMap< QString, MacroWindow* > macros;
+ // QMap< QString, MacroWindow* > macros;
+ Macros macros;
QWidget *w;
QLabel *header;