From 9b697d2d3e34962385cd85a14d4cb14d5b1763ce Mon Sep 17 00:00:00 2001 From: deva Date: Wed, 8 Oct 2008 11:58:34 +0000 Subject: Removed obsolete macro.{cc,h}. Made the passing of the Netcom class, use a pointer. --- client/client.pro | 2 - client/macro.cc | 145 ------------------------------------------------- client/macro.h | 43 --------------- client/macrowindow.cc | 10 ++-- client/macrowindow.h | 4 +- client/mainwindow.cc | 15 +---- client/mainwindow.h | 2 +- client/netcom.cc | 21 ++++--- client/resumewidget.cc | 32 ++++++++++- 9 files changed, 55 insertions(+), 219 deletions(-) delete mode 100644 client/macro.cc delete mode 100644 client/macro.h (limited to 'client') 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 -#include -#include -#include -#include - -#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 - -/** - * 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 #include -#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::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 #include +#include #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 +#include + +//#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 += "" + text[i] + ""; + else if(text[i] == '\n') f += "
"; + else if(text[i] == ' ') f += " "; + else f += text[i]; + } + + resume->setText(f); + resume->setWordWrap(true); +#else resume->setText(text); +#endif } -- cgit v1.2.3