From 322a83c48618b2f58e1014daff6f3956af8070ea Mon Sep 17 00:00:00 2001 From: deva Date: Mon, 2 Jun 2008 13:03:33 +0000 Subject: A large number of small changes in widgets, primarily validation oriented. --- client/macro.cc | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) (limited to 'client/macro.cc') 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 #include #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) { -- cgit v1.2.3