File indexing completed on 2024-12-22 04:17:55

0001 /***************************************************************************
0002  *                                                                         *
0003  *   copyright : (C) 2007 The University of Toronto                        *
0004  *                   netterfield@astro.utoronto.ca                         *
0005  *                                                                         *
0006  *   This program is free software; you can redistribute it and/or modify  *
0007  *   it under the terms of the GNU General Public License as published by  *
0008  *   the Free Software Foundation; either version 2 of the License, or     *
0009  *   (at your option) any later version.                                   *
0010  *                                                                         *
0011  ***************************************************************************/
0012 
0013 #include "eventmonitorfactory.h"
0014 
0015 #include "debug.h"
0016 #include "eventmonitorentry.h"
0017 #include "datacollection.h"
0018 #include "objectstore.h"
0019 
0020 namespace Kst {
0021 
0022 EventMonitorFactory::EventMonitorFactory()
0023 : ObjectFactory() {
0024   registerFactory(EventMonitorEntry::staticTypeTag, this);
0025 }
0026 
0027 
0028 EventMonitorFactory::~EventMonitorFactory() {
0029 }
0030 
0031 
0032 DataObjectPtr EventMonitorFactory::generateObject(ObjectStore *store, QXmlStreamReader& xml) {
0033   Q_ASSERT(store);
0034 
0035   QString equation, description, emailRecipients, script;
0036   bool logDebug=false, logEmail=false, logELOG=false;
0037   int logLevel=1;
0038 
0039   while (!xml.atEnd()) {
0040       const QString n = xml.name().toString();
0041     if (xml.isStartElement()) {
0042       if (n == EventMonitorEntry::staticTypeTag) {
0043         QXmlStreamAttributes attrs = xml.attributes();
0044         equation = attrs.value("equation").toString();
0045         description = attrs.value("description").toString();
0046         emailRecipients = attrs.value("emailrecipients").toString();
0047         script = attrs.value("script").toString();
0048         logLevel = attrs.value("loglevel").toString().toInt();
0049 
0050         logDebug = attrs.value("logdebug").toString() == "true" ? true : false;
0051         logEmail = attrs.value("logemail").toString() == "true" ? true : false;
0052         logELOG = attrs.value("logelog").toString() == "true" ? true : false;
0053       } else {
0054         return 0;
0055       }
0056     } else if (xml.isEndElement()) {
0057       if (n == EventMonitorEntry::staticTypeTag) {
0058         break;
0059       } else {
0060         Debug::self()->log(QObject::tr("Error creating EventMonitorEntry from Kst file."), Debug::Warning);
0061         return 0;
0062       }
0063     }
0064     xml.readNext();
0065   }
0066 
0067   if (xml.hasError()) {
0068     return 0;
0069   }
0070 
0071   EventMonitorEntryPtr eventMonitor = store->createObject<EventMonitorEntry>();
0072   Q_ASSERT(eventMonitor);
0073 
0074   eventMonitor->setScriptCode(script);
0075   eventMonitor->setEvent(equation);
0076   eventMonitor->setDescription(description);
0077   eventMonitor->setLevel((Debug::LogLevel)logLevel);
0078   eventMonitor->setLogDebug(logDebug);
0079   eventMonitor->setLogEMail(logEmail);
0080   eventMonitor->setLogELOG(logELOG);
0081   eventMonitor->setEMailRecipients(emailRecipients);
0082 
0083   eventMonitor->reparse();
0084 
0085   eventMonitor->writeLock();
0086   eventMonitor->registerChange();
0087   eventMonitor->unlock();
0088 
0089   return eventMonitor;
0090 }
0091 
0092 }
0093 
0094 // vim: ts=2 sw=2 et