summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
Diffstat (limited to 'client')
-rw-r--r--client/client.pro2
-rw-r--r--client/macro.cc145
-rw-r--r--client/macro.h43
-rw-r--r--client/macrowindow.cc10
-rw-r--r--client/macrowindow.h4
-rw-r--r--client/mainwindow.cc15
-rw-r--r--client/mainwindow.h2
-rw-r--r--client/netcom.cc21
-rw-r--r--client/resumewidget.cc32
9 files changed, 55 insertions, 219 deletions
diff --git a/client/client.pro b/client/client.pro
index 28b0709..9cc726b 100644
--- a/client/client.pro
+++ b/client/client.pro
@@ -26,7 +26,6 @@ HEADERS += \
collapser.h \
formatparser.h \
lua.h \
- macro.h \
macrowindow.h \
mainwindow.h \
netcom.h \
@@ -55,7 +54,6 @@ SOURCES += \
collapser.cc \
formatparser.cc \
lua.cc \
- macro.cc \
macrowindow.cc \
mainwindow.cc \
netcom.cc \
diff --git a/client/macro.cc b/client/macro.cc
deleted file mode 100644
index 8160c9f..0000000
--- a/client/macro.cc
+++ /dev/null
@@ -1,145 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/***************************************************************************
- * macro.cc
- *
- * Fri Aug 31 13:40:17 CEST 2007
- * Copyright 2007 Bent Bisballe Nyeng and Lars Bisballe Jensen
- * deva@aasimon.org and elsenator@gmail.com
- ****************************************************************************/
-
-/*
- * 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 <QApplication>
-#include <QDomDocument>
-#include <QObject>
-#include <QEvent>
-#include <QLinkedList>
-
-#include "macrowindow.h"
-#include "netcom.h"
-
-#define MACRO_EVENT_ID 65432
-
-QLinkedList< MacroWindow * > macrowindows;
-
-extern QString cpr;
-extern QString user;
-extern QString host;
-extern quint16 port;
-
-/**
- * Macro Event used to trigger the creation of a new macro
- */
-class MacroEvent : public QEvent {
-public:
- MacroEvent(QString course, QString macro) :
- QEvent((QEvent::Type)MACRO_EVENT_ID),
- macro(macro),
- course(course) {}
- QString macro;
- QString course;
-};
-
-/**
- * Macro Event Filter used to catch the Macro Events.
- */
-class MacroEventFilter : public QObject {
-protected:
- bool eventFilter( QObject *o, QEvent *e );
-};
-
-/**
- * The single global macro event filter.
- * It is created the first time new_macro is called.
- */
-static MacroEventFilter *macro_event_filter = NULL;
-
-/**
- * Create the new macro
- */
-static void create_macro(QString course, QString macro)
-{
- NetCom netcom("", 0, "", "");
- QDomDocument xml_doc = netcom.send(course, macro);
-
- cleanup_macros();
-
- //
- // 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 macros = coursenode.childNodes();
- for(int j = 0; j < macros.count(); j++) {
- QDomNode macronode = macros.at(j);
- // Only create if the macro contains something.
- if(macronode.childNodes().count())
- macrowindows.push_back( new MacroWindow( netcom, macronode, "dims" ) );
- }
-}
-
-/**
- * Event filter callback method
- */
-bool MacroEventFilter::eventFilter(QObject *, QEvent *e)
-{
- if(e->type() == MACRO_EVENT_ID) {
- MacroEvent *event = (MacroEvent*)e;
- create_macro(event->course, event->macro);
- return TRUE; // eat event
- } else {
- return FALSE;
- }
-}
-
-/**
- * Delete all closed windows from window list
- */
-void cleanup_macros()
-{
- QLinkedList< MacroWindow * >::iterator i = macrowindows.begin();
- while(i != macrowindows.end()) {
- if( (*i)->isClosed() ) {
- delete *i;
- i = macrowindows.erase(i);
- } else {
- i++;
- }
- }
-}
-
-/**
- * Public macro creation function.
- * Initiates the creation of a new macro.
- */
-void new_macro(QString course, QString macro)
-{
- if(macro_event_filter == NULL) {
- macro_event_filter = new MacroEventFilter();
- qApp->installEventFilter( macro_event_filter );
- }
-
- MacroEvent *event = new MacroEvent(course, macro);
- qApp->postEvent(qApp, event);
- qApp->processEvents(); // To prevent QT from closing when no windows are present
-}
diff --git a/client/macro.h b/client/macro.h
deleted file mode 100644
index f00f172..0000000
--- a/client/macro.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/***************************************************************************
- * macro.h
- *
- * Fri Aug 31 13:40:17 CEST 2007
- * Copyright 2007 Bent Bisballe Nyeng and Lars Bisballe Jensen
- * deva@aasimon.org and elsenator@gmail.com
- ****************************************************************************/
-
-/*
- * 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>
-
-/**
- * Public macro creation function.
- * Initiates the creation of a new macro.
- */
-void new_macro(QString course, QString name);
-
-/**
- * Delete all closed windows from window list
- */
-void cleanup_macros();
-
-#endif/*__PRACRO_MACRO_H__*/
diff --git a/client/macrowindow.cc b/client/macrowindow.cc
index 3a6d3c7..18ed218 100644
--- a/client/macrowindow.cc
+++ b/client/macrowindow.cc
@@ -33,7 +33,6 @@
#include <QDomNode>
#include <QByteArray>
-#include "macro.h"
#include "widgets/widget.h"
#include "widgets/window.h"
#include "widgetbuilder.h"
@@ -44,10 +43,11 @@ extern QString user;
extern QString host;
extern quint16 port;
-MacroWindow::MacroWindow(NetCom &n, QDomNode &xml_doc, QString course, bool collapsed)
- : Collapser(), netcom(n)
+MacroWindow::MacroWindow(NetCom *netcom, QDomNode &xml_doc, QString course, bool collapsed)
+ : Collapser()
{
this->course = course;
+ this->netcom = netcom;
setCollapsedWidget(new ResumeWidget());
@@ -145,7 +145,7 @@ bool MacroWindow::doCommit()
// If all entries passed validation, continue commit
if(faulty == 0) {
- netcom.send(widgets, macro, version);
+ netcom->send(widgets, macro, version);
emit updateOnCommit();
setCollapsed(true);
return true;
@@ -278,7 +278,7 @@ void MacroWindow::toggleMacro()
auxwidgets.clear();
luaprograms.clear();
- QDomDocument xml_doc = netcom.send(course, macro);
+ QDomDocument xml_doc = netcom->send(course, macro);
//
// TODO: This is where the dependency checking should occur.
diff --git a/client/macrowindow.h b/client/macrowindow.h
index aad54a9..f42a5a1 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, bool collapsed = true);
+ MacroWindow(NetCom *netcom, QDomNode &xml_doc, QString course, bool collapsed = true);
~MacroWindow();
bool isClosed();
@@ -90,7 +90,7 @@ private:
bool isclosed;
void close();
- NetCom &netcom;
+ NetCom *netcom;
};
#endif/*__PRACRO_MACROWINDOW_H__*/
diff --git a/client/mainwindow.cc b/client/mainwindow.cc
index efd4c31..619a24e 100644
--- a/client/mainwindow.cc
+++ b/client/mainwindow.cc
@@ -82,7 +82,7 @@ void MainWindow::update()
if(macros.find(macroname) == macros.end()) {
bool isstatic = false;
if(xml_elem.attribute("static", "false") == "true") isstatic = true;
- macros[macroname] = new MacroWindow(netcom, macronode, course, !isstatic);
+ macros[macroname] = new MacroWindow(&netcom, macronode, course, !isstatic);
QGroupBox *g = new QGroupBox(" " + xml_elem.attribute("caption", macroname));
g->setCheckable(false);
@@ -90,12 +90,11 @@ void MainWindow::update()
((QBoxLayout*)w->layout())->addWidget(g);
if(!isstatic) {
- QPushButton *b = new QPushButton(">>", g);
+ 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()));
}
@@ -118,13 +117,3 @@ void MainWindow::update()
}
}
-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
index 15c95f0..37afa5b 100644
--- a/client/mainwindow.h
+++ b/client/mainwindow.h
@@ -29,6 +29,7 @@
#include <QMainWindow>
#include <QMap>
+#include <QPushButton>
#include "netcom.h"
#include "macrowindow.h"
@@ -40,7 +41,6 @@ public:
public slots:
void update();
- void closeAll();
private:
QString course;
diff --git a/client/netcom.cc b/client/netcom.cc
index 755357e..ab2446e 100644
--- a/client/netcom.cc
+++ b/client/netcom.cc
@@ -37,6 +37,7 @@ NetCom::NetCom(QString host, quint16 port, QString user, QString cpr)
this->cpr = cpr;
socket.connectToHost(host, port);
connect(&socket, SIGNAL(readyRead()), this, SLOT(readyRead()));
+ socket.waitForConnected();
transmitting = false;
}
@@ -47,6 +48,9 @@ NetCom::~NetCom()
QDomDocument NetCom::send(QString course, QString macro)
{
+ printf("Socket state: %d\n", socket.state());
+ if(socket.state() != 3) printf("Socket state not connected: %s\n", socket.errorString().toStdString().c_str());
+
if(qApp->activeWindow()) qApp->activeWindow()->setEnabled(false);
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
@@ -66,10 +70,10 @@ QDomDocument NetCom::send(QString course, QString macro)
if(macro != "") request_elem.setAttribute("macro", macro);
pracro_elem.appendChild(request_elem);
- printf("\nSending:\n%s", doc.toString().toStdString().c_str());
+ printf("\nSending request:\n%s", doc.toString().toStdString().c_str());
socket.write(doc.toByteArray());
- socket.waitForReadyRead();
+ // socket.waitForReadyRead();
do {
qApp->processEvents();
@@ -79,7 +83,7 @@ QDomDocument NetCom::send(QString course, QString macro)
QDomElement elem = res_doc.documentElement();
- printf("\nRecieved:\n%s", res_doc.toString().toStdString().c_str());
+ printf("\nRecieved request:\n%s", res_doc.toString().toStdString().c_str());
QApplication::restoreOverrideCursor();
if(qApp->activeWindow()) qApp->activeWindow()->setEnabled(true);
@@ -94,6 +98,9 @@ void NetCom::readyRead()
void NetCom::send(QVector< Widget* > widgets, QString macro, QString version)
{
+ printf("Socket state: %d\n", socket.state());
+ if(socket.state() != 3) printf("Socket state not connected: %s\n", socket.errorString().toStdString().c_str());
+
qApp->activeWindow()->setEnabled(false);
if(qApp->activeWindow()) qApp->activeWindow()->setEnabled(false);
@@ -126,10 +133,10 @@ void NetCom::send(QVector< Widget* > widgets, QString macro, QString version)
i++;
}
- printf("\nSending:\n%s", doc.toString().toStdString().c_str());
+ printf("\nSending commit:\n%s", doc.toString().toStdString().c_str());
socket.write(doc.toByteArray());
- socket.waitForReadyRead();
+ // socket.waitForReadyRead();
//
// Wait for the (hopefully) empty answer.
@@ -140,9 +147,9 @@ void NetCom::send(QVector< Widget* > widgets, QString macro, QString version)
buffer = "";
- QDomElement elem = res_doc.documentElement();
+ //QDomElement elem = res_doc.documentElement();
- printf("\nRecieved:\n%s", res_doc.toString().toStdString().c_str());
+ printf("\nRecieved commit:\n%s", res_doc.toString().toStdString().c_str());
QApplication::restoreOverrideCursor();
if(qApp->activeWindow()) qApp->activeWindow()->setEnabled(true);
diff --git a/client/resumewidget.cc b/client/resumewidget.cc
index 80643db..b991ccf 100644
--- a/client/resumewidget.cc
+++ b/client/resumewidget.cc
@@ -27,16 +27,46 @@
#include "resumewidget.h"
#include <QHBoxLayout>
+#include <QBoxLayout>
+
+//#define RICH
ResumeWidget::ResumeWidget()
{
setLayout(new QHBoxLayout());
- resume = new QLabel();
+ layout()->setContentsMargins(10,2,2,2);
+ resume = new QLabel("Endnu ikke udfyldt");
+
+#ifdef RICH
+ resume->setTextFormat(Qt::RichText);
+#endif
+
resume->setWordWrap(true);
+ resume->setEnabled(false);
+ /*
+ resume->setFixedWidth(300);
+ ((QBoxLayout*)layout())->addStretch();
+ */
layout()->addWidget(resume);
}
void ResumeWidget::setText(QString text)
{
+ resume->setEnabled(true);
+
+#ifdef RICH
+ QString f;
+
+ for(int i = 0; i < text.length(); i++) {
+ if(text[i] >= '0' && text[i] <= '9') f += "<font style='color: #55F;'>" + text[i] + "</font>";
+ else if(text[i] == '\n') f += "<br/>";
+ else if(text[i] == ' ') f += "&nbsp;";
+ else f += text[i];
+ }
+
+ resume->setText(f);
+ resume->setWordWrap(true);
+#else
resume->setText(text);
+#endif
}