diff options
-rw-r--r-- | client/client.pro | 2 | ||||
-rw-r--r-- | client/collapser.cc | 105 | ||||
-rw-r--r-- | client/collapser.h | 13 | ||||
-rw-r--r-- | client/macro.cc | 5 | ||||
-rw-r--r-- | client/macrowindow.cc | 113 | ||||
-rw-r--r-- | client/macrowindow.h | 22 | ||||
-rw-r--r-- | client/mainwindow.cc | 124 | ||||
-rw-r--r-- | client/mainwindow.h | 56 | ||||
-rw-r--r-- | client/netcom.cc | 21 | ||||
-rw-r--r-- | client/netcom.h | 11 | ||||
-rw-r--r-- | client/pracro.cc | 16 |
11 files changed, 398 insertions, 90 deletions
diff --git a/client/client.pro b/client/client.pro index 2ce4fa7..3821a0c 100644 --- a/client/client.pro +++ b/client/client.pro @@ -28,6 +28,7 @@ HEADERS += \ lua.h \ macro.h \ macrowindow.h \ + mainwindow.h \ netcom.h \ widgetbuilder.h \ widgets.h \ @@ -55,6 +56,7 @@ SOURCES += \ lua.cc \ macro.cc \ macrowindow.cc \ + mainwindow.cc \ netcom.cc \ widgetbuilder.cc \ widgets/common.cc \ diff --git a/client/collapser.cc b/client/collapser.cc index 391f9b1..7faf175 100644 --- a/client/collapser.cc +++ b/client/collapser.cc @@ -33,25 +33,55 @@ Collapser::Collapser(QWidget *collapsed, QWidget *expanded, bool setcollapsed) { + this->collapsed = NULL; + this->expanded = NULL; + setLayout(new QHBoxLayout()); layout()->setContentsMargins(0,0,0,0); + setWidgets(collapsed, expanded); + + is_collapsed = !setcollapsed; // Make sure setCollapsed actually does something. + setCollapsed(setcollapsed); +} + +void Collapser::setWidgets(QWidget *collapsed, QWidget *expanded) +{ + setCollapsedWidget(collapsed); + setExpandedWidget(expanded); +} + +void Collapser::setCollapsedWidget(QWidget *collapsed) +{ + if(this->collapsed) { + // delete this->collapsed; + this->collapsed = NULL; + } + this->collapsed = collapsed; - collapsed->show(); - c_height = collapsed->height(); - collapsed->setVisible(false); +} + +void Collapser::setExpandedWidget(QWidget *expanded) +{ + if(this->expanded) { + // delete this->expanded; + this->expanded = NULL; + } this->expanded = expanded; - expanded->show(); - e_height = expanded->height(); - expanded->setVisible(false); +} - collapsed->setVisible(false); - expanded->setVisible(false); +QWidget *Collapser::collapsedWidget() +{ + return collapsed; +} - setCollapsed(setcollapsed); +QWidget *Collapser::expandedWidget() +{ + return expanded; } + bool Collapser::isCollapsed() { return is_collapsed; @@ -69,7 +99,6 @@ void Collapser::collapse() { t_anim.start(); - is_collapsed = true; timer_id = startTimer(ANIM_INTERVAL); } @@ -79,10 +108,14 @@ void Collapser::expand() t_anim.start(); // show expanded - collapsed->setVisible(false); - layout()->removeWidget(collapsed); - layout()->addWidget(expanded); - expanded->setVisible(true); + if(collapsed) { + collapsed->setVisible(false); + layout()->removeWidget(collapsed); + } + if(expanded) { + layout()->addWidget(expanded); + expanded->setVisible(true); + } is_collapsed = false; timer_id = startTimer(ANIM_INTERVAL); @@ -91,12 +124,25 @@ void Collapser::expand() void Collapser::toggleCollapse() { if(!is_collapsed) collapse(); - else expand(); } void Collapser::anim() { + int c_height = 16; + int e_height = 16; + if(collapsed) { + QSize sz = collapsed->minimumSizeHint(); + c_height = sz.height(); + //c_height = collapsed->minimumHeight(); + } + + if(expanded) { + QSize sz = expanded->minimumSizeHint(); + e_height = sz.height(); + //e_height = expanded->minimumHeight(); + } + killTimer(timer_id); double x = (double)(t_anim.elapsed()) / ANIM_TIME; @@ -105,25 +151,32 @@ void Collapser::anim() if(x < 1) { y = x * x * x; + if(!is_collapsed) { + setFixedHeight((1 - y) * c_height + y * e_height); + } else { + setFixedHeight((1 - y) * e_height + y * c_height); + } + timer_id = startTimer(ANIM_INTERVAL); } else { if(is_collapsed) { // show collapsed - expanded->setVisible(false); - layout()->removeWidget(expanded); - layout()->addWidget(collapsed); - collapsed->setVisible(true); - + if(expanded) { + expanded->setVisible(false); + layout()->removeWidget(expanded); + } + if(collapsed) { + layout()->addWidget(collapsed); + collapsed->setVisible(true); + } + + setFixedHeight(c_height); + } else { + setFixedHeight(e_height); } } - - if(!is_collapsed) { - setFixedHeight((1 - y) * c_height + y * e_height); - } else { - setFixedHeight((1 - y) * e_height + y * c_height); - } } void Collapser::timerEvent(QTimerEvent *) diff --git a/client/collapser.h b/client/collapser.h index 6e9c8b4..fa25dd5 100644 --- a/client/collapser.h +++ b/client/collapser.h @@ -33,11 +33,19 @@ class Collapser : public QWidget { Q_OBJECT public: - Collapser(QWidget *collapsed, QWidget *expanded, bool setcollapsed = true); + Collapser(QWidget *collapsed = NULL, QWidget *expanded = NULL, bool setcollapsed = true); bool isCollapsed(); void setCollapsed(bool setcollapsed); + void setWidgets(QWidget *collapsed, QWidget *expanded); + + QWidget *collapsedWidget(); + QWidget *expandedWidget(); + + void setCollapsedWidget(QWidget *collapsed); + void setExpandedWidget(QWidget *expanded); + public slots: void collapse(); void expand(); @@ -48,10 +56,7 @@ protected: private: QWidget *collapsed; - int c_height; - QWidget *expanded; - int e_height; bool is_collapsed; diff --git a/client/macro.cc b/client/macro.cc index 7f3286c..8160c9f 100644 --- a/client/macro.cc +++ b/client/macro.cc @@ -76,7 +76,8 @@ static MacroEventFilter *macro_event_filter = NULL; */ static void create_macro(QString course, QString macro) { - QDomDocument xml_doc = Global::netcom->send(course, macro); + NetCom netcom("", 0, "", ""); + QDomDocument xml_doc = netcom.send(course, macro); cleanup_macros(); @@ -93,7 +94,7 @@ static void create_macro(QString course, QString macro) QDomNode macronode = macros.at(j); // Only create if the macro contains something. if(macronode.childNodes().count()) - macrowindows.push_back( new MacroWindow( macronode ) ); + macrowindows.push_back( new MacroWindow( netcom, macronode, "dims" ) ); } } 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(); + + } +} diff --git a/client/macrowindow.h b/client/macrowindow.h index f1388b2..4e040da 100644 --- a/client/macrowindow.h +++ b/client/macrowindow.h @@ -33,15 +33,20 @@ #include <QObject> #include <QVector> #include <QMap> +#include <QLabel> +#include "collapser.h" +#include "netcom.h" + +class NetCom; class LUA; class Widget; -class MacroWindow : public QObject +class MacroWindow : public Collapser { Q_OBJECT public: - MacroWindow(QDomNode &xml_doc); + MacroWindow(NetCom &netcom, QDomNode &xml_doc, QString course); ~MacroWindow(); bool isClosed(); @@ -53,6 +58,10 @@ public: Widget *getWidget(QString name); void addAuxWidgets(QVector< Widget* >); + void update(QDomNode &xml_doc); + + QString macrotitle; + public slots: void commit(); void reset(); @@ -60,6 +69,11 @@ public slots: void cont(QString name); void cont_nocommit(QString name); + void toggleMacro(); + +signals: + void updateOnCommit(); + private: void initMacro(QDomNode &node); @@ -67,11 +81,15 @@ private: QVector< Widget* > widgets; QVector< Widget* > auxwidgets; QString macro; + QString course; QString version; QWidget *mainwidget; + QLabel *resumewidget; bool isclosed; void close(); + + NetCom &netcom; }; #endif/*__PRACRO_MACROWINDOW_H__*/ diff --git a/client/mainwindow.cc b/client/mainwindow.cc new file mode 100644 index 0000000..06207a5 --- /dev/null +++ b/client/mainwindow.cc @@ -0,0 +1,124 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * mainwindow.cc + * + * Wed Sep 17 09:41:09 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. + */ +#include "mainwindow.h" + +#include <QApplication> +#include <QDomDocument> +#include <QDomNodeList> +#include <QDomNode> +#include <QVBoxLayout> +#include <QHBoxLayout> +#include <QLabel> +#include <QPushButton> +#include <QGroupBox> +#include <QScrollArea> + +MainWindow::MainWindow(QString cpr, QString course, QString host, quint16 port, QString user) + : netcom(host, port, user, cpr) +{ + resize(768, 1024); + + QScrollArea *s = new QScrollArea(); + setCentralWidget(s); + w = new QWidget(); + s->setWidget(w); + s->setWidgetResizable(true); + + w->setLayout(new QVBoxLayout()); + this->course = course; + init(); +} + +MainWindow::~MainWindow() +{ +} + +void MainWindow::init() +{ + update(); +} + +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) + QDomNodeList macronodes = coursenode.childNodes(); + for(int j = 0; j < macronodes.count(); j++) { + QDomNode macronode = macronodes.at(j); + + QDomElement xml_elem = macronode.toElement(); + + if(xml_elem.tagName() == "macro") { + + QString macroname; + if(xml_elem.hasAttribute("name")) macroname = xml_elem.attribute("name"); + + if(macros.find(macroname) == macros.end()) { + macros[macroname] = new MacroWindow(netcom, macronode, course); + + QGroupBox *g = new QGroupBox(" " + macroname); + g->setCheckable(false); + g->setChecked(false); + + QPushButton *b = new QPushButton(">>", g); + b->setFixedSize(16,16); + b->show(); + b->move(0,0); + + connect(b, SIGNAL(clicked()), this, SLOT(closeAll())); + connect(b, SIGNAL(clicked()), 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())); + macros[macroname]->show(); + + } else { + + macros[macroname]->update(macronode); + macros[macroname]->setCollapsed(true); + + } + } + } +} + +void MainWindow::closeAll() +{ + /* + QMap<QString, MacroWindow*>::iterator i = macros.begin(); + while(i != macros.end()) { + i.value()->setCollapsed(true); + i++; + } + */ +} diff --git a/client/mainwindow.h b/client/mainwindow.h new file mode 100644 index 0000000..15c95f0 --- /dev/null +++ b/client/mainwindow.h @@ -0,0 +1,56 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * mainwindow.h + * + * Wed Sep 17 09:41:08 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_MAINWINDOW_H__ +#define __PRACRO_MAINWINDOW_H__ + +#include <QMainWindow> +#include <QMap> +#include "netcom.h" +#include "macrowindow.h" + +class MainWindow : public QMainWindow { +Q_OBJECT +public: + MainWindow(QString cpr, QString course, QString host, quint16 port, QString user); + ~MainWindow(); + +public slots: + void update(); + void closeAll(); + +private: + QString course; + NetCom netcom; + + QMap< QString, MacroWindow* > macros; + QWidget *w; + + void init(); + +}; + +#endif/*__PRACRO_MAINWINDOW_H__*/ diff --git a/client/netcom.cc b/client/netcom.cc index a4d1fb3..8ff62b3 100644 --- a/client/netcom.cc +++ b/client/netcom.cc @@ -28,7 +28,7 @@ #include <QApplication> -NetCom *Global::netcom = NULL; +#include "widgets/widget.h" NetCom::NetCom(QString host, quint16 port, QString user, QString cpr) { @@ -55,7 +55,7 @@ QDomDocument NetCom::send(QString course, QString macro) QDomElement request_elem = doc.createElement("request"); request_elem.setAttribute("course", course); - request_elem.setAttribute("macro", macro); + if(macro != "") request_elem.setAttribute("macro", macro); pracro_elem.appendChild(request_elem); printf(doc.toString().toStdString().c_str()); @@ -81,7 +81,7 @@ void NetCom::readyRead() buffer.append(socket.readAll()); } -void NetCom::send(QVector< Widget* > widgets, QString macro, QString version) +void NetCom::send(QVector< Widget* > widgets, QString course, QString macro, QString version) { QDomDocument doc; @@ -96,6 +96,11 @@ void NetCom::send(QVector< Widget* > widgets, QString macro, QString version) commit_elem.setAttribute("version", version); pracro_elem.appendChild(commit_elem); + QDomElement request_elem = doc.createElement("request"); + request_elem.setAttribute("course", course); + //if(macro != "") request_elem.setAttribute("macro", macro); + pracro_elem.appendChild(request_elem); + // Iterate the different entries, and append their results to the commit string QVector< Widget* >::iterator i = widgets.begin(); while (i != widgets.end()) { @@ -112,6 +117,14 @@ void NetCom::send(QVector< Widget* > widgets, QString macro, QString version) printf(doc.toString().toStdString().c_str()); socket.write(doc.toByteArray()); - // qApp->processEvents(); socket.waitForBytesWritten(10000); + + do { + qApp->processEvents(); + } while(!res_doc.setContent(buffer)); + + buffer = ""; + + QDomElement elem = res_doc.documentElement(); + } diff --git a/client/netcom.h b/client/netcom.h index 33a57f4..8f8b007 100644 --- a/client/netcom.h +++ b/client/netcom.h @@ -32,7 +32,8 @@ #include <QTcpSocket> #include <QDomDocument> -#include "widgets/widget.h" +//#include "widgets/widget.h" +class Widget; class NetCom : public QObject { Q_OBJECT @@ -40,8 +41,8 @@ public: NetCom(QString host, quint16 port, QString user, QString cpr); ~NetCom(); - QDomDocument send(QString course, QString macro); - void send(QVector< Widget* > widgets, QString macro, QString version); + QDomDocument send(QString course, QString macro = ""); + void send(QVector< Widget* > widgets, QString course, QString macro, QString version); public slots: void readyRead(); @@ -56,8 +57,4 @@ private: QString cpr; }; -namespace Global { - extern NetCom *netcom; -}; - #endif/*__PRACRO_NETCOM_H__*/ diff --git a/client/pracro.cc b/client/pracro.cc index fdb0d7d..e33ebfc 100644 --- a/client/pracro.cc +++ b/client/pracro.cc @@ -31,8 +31,8 @@ #include <QStringList> #include <QSettings> -#include "macro.h" #include "netcom.h" +#include "mainwindow.h" #define VERSION "1.0" @@ -54,8 +54,10 @@ static void print_usage() printf("Executes the requested Pracro MACRO using supplied CPR and USER.\n"); printf("\n"); printf(" -h, --help Displays this help text.\n"); + /* printf(" -m, --macro MACRO Requests macro MACRO from the Pracro \n" " Server, defaults to \""MACRO_DEFAULT"\".\n"); + */ printf(" -c, --course COURSE Requests course COURSE from the Pracro \n" " Server, defaults to \""COURSE_DEFAULT"\".\n"); printf(" -C, --cpr CPR Defines the cpr for use with the macro,\n" @@ -107,10 +109,12 @@ int main(int argc, char *argv[]) *arg == "-u") { user = getParam(args,arg); } + /* else if(*arg == "--macro" || *arg == "-m") { macro = getParam(args, arg); } + */ else if(*arg == "--course" || *arg == "-c") { course = getParam(args, arg); @@ -138,16 +142,10 @@ int main(int argc, char *argv[]) port = settings.value("port").toInt(); settings.endGroup(); - Global::netcom = new NetCom(host, port, user, cpr); + MainWindow mainwindow(cpr, course, host, port, user); + mainwindow.show(); - new_macro(course, macro); - - //app.setQuitOnLastWindowClosed(false); int ret = app.exec(); - cleanup_macros(); - - delete Global::netcom; - return ret; } |