summaryrefslogtreecommitdiff
path: root/client/macro.cc
diff options
context:
space:
mode:
Diffstat (limited to 'client/macro.cc')
-rw-r--r--client/macro.cc32
1 files changed, 28 insertions, 4 deletions
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 <QDomDocument>
#include <QApplication>
#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) {