DataObjectPtr EventMonitorFactory::generateObject(ObjectStore *store, QXmlStreamReader& xml) { Q_ASSERT(store); QString equation, description, emailRecipients, script; bool logDebug=false, logEmail=false, logELOG=false; int logLevel=1; while (!xml.atEnd()) { const QString n = xml.name().toString(); if (xml.isStartElement()) { if (n == EventMonitorEntry::staticTypeTag) { QXmlStreamAttributes attrs = xml.attributes(); equation = attrs.value("equation").toString(); description = attrs.value("description").toString(); emailRecipients = attrs.value("emailrecipients").toString(); script = attrs.value("script").toString(); logLevel = attrs.value("loglevel").toString().toInt(); logDebug = attrs.value("logdebug").toString() == "true" ? true : false; logEmail = attrs.value("logemail").toString() == "true" ? true : false; logELOG = attrs.value("logelog").toString() == "true" ? true : false; } else { return 0; } } else if (xml.isEndElement()) { if (n == EventMonitorEntry::staticTypeTag) { break; } else { Debug::self()->log(QObject::tr("Error creating EventMonitorEntry from Kst file."), Debug::Warning); return 0; } } xml.readNext(); } if (xml.hasError()) { return 0; } EventMonitorEntryPtr eventMonitor = store->createObject<EventMonitorEntry>(); Q_ASSERT(eventMonitor); eventMonitor->setScriptCode(script); eventMonitor->setEvent(equation); eventMonitor->setDescription(description); eventMonitor->setLevel((Debug::LogLevel)logLevel); eventMonitor->setLogDebug(logDebug); eventMonitor->setLogEMail(logEmail); eventMonitor->setLogELOG(logELOG); eventMonitor->setEMailRecipients(emailRecipients); eventMonitor->reparse(); eventMonitor->writeLock(); eventMonitor->registerChange(); eventMonitor->unlock(); return eventMonitor; }
bool KstEventMonitorI::editSingleObject(EventMonitorEntryPtr emPtr) { emPtr->writeLock(); if (_lineEditEquationDirty) { emPtr->setEvent(_w->lineEditEquation->text()); } if (_lineEditDescriptionDirty) { emPtr->setDescription(_w->lineEditDescription->text()); } if (_checkBoxDebugDirty) { if (!(_w->radioButtonLogNotice->isChecked() || _w->radioButtonLogWarning->isChecked() || _w->radioButtonLogError->isChecked()) && _w->checkBoxDebug->isChecked()) { KMessageBox::sorry(this, i18n("Select a Debug Log type.")); emPtr->unlock(); return false; } emPtr->setLogKstDebug(_w->checkBoxDebug->isChecked()); } if (_checkBoxEMailNotifyDirty) { emPtr->setLogEMail(_w->checkBoxEMailNotify->isChecked()); } if (_checkBoxELOGNotifyDirty) { emPtr->setLogELOG(_w->checkBoxELOGNotify->isChecked()); } if (_lineEditEMailRecipientsDirty) { emPtr->setEMailRecipients(_w->lineEditEMailRecipients->text()); } if (_scriptDirty) { if (_w->_useScript->isChecked()) { emPtr->setScriptCode(_w->_script->text()); } else { emPtr->setScriptCode(QString::null); } } if (_w->radioButtonLogNotice->isChecked()) { emPtr->setLevel(KstDebug::Notice); } else if (_w->radioButtonLogWarning->isChecked()) { emPtr->setLevel(KstDebug::Warning); } else if (_w->radioButtonLogError->isChecked()) { emPtr->setLevel(KstDebug::Error); } emPtr->reparse(); emPtr->unlock(); return true; }
ObjectPtr EventMonitorDialog::createNewDataObject() const { Q_ASSERT(_document && _document->objectStore()); EventMonitorEntryPtr eventMonitor = _document->objectStore()->createObject<EventMonitorEntry>(ObjectTag::fromString(tagString())); eventMonitor->setScriptCode(_eventMonitorTab->script()); eventMonitor->setEvent(_eventMonitorTab->event()); eventMonitor->setDescription(_eventMonitorTab->description()); eventMonitor->setLevel(_eventMonitorTab->logLevel()); eventMonitor->setLogKstDebug(_eventMonitorTab->logKstDebug()); eventMonitor->setLogEMail(_eventMonitorTab->logEMail()); eventMonitor->setLogELOG(_eventMonitorTab->logELOG()); eventMonitor->setEMailRecipients(_eventMonitorTab->emailRecipients()); eventMonitor->reparse(); eventMonitor->writeLock(); eventMonitor->update(0); eventMonitor->unlock(); return ObjectPtr(eventMonitor.data()); }
DataObjectPtr EventMonitorEntry::makeDuplicate() const { EventMonitorEntryPtr eventMonitor = store()->createObject<EventMonitorEntry>(); eventMonitor->setScriptCode(_script); eventMonitor->setEvent(_event); eventMonitor->setDescription(_description); eventMonitor->setLevel(_level); eventMonitor->setLogDebug(_logDebug); eventMonitor->setLogEMail(_logEMail); eventMonitor->setLogELOG(_logELOG); eventMonitor->setEMailRecipients(_eMailRecipients); if (descriptiveNameIsManual()) { eventMonitor->setDescriptiveName(descriptiveName()); } eventMonitor->reparse(); eventMonitor->writeLock(); eventMonitor->registerChange(); eventMonitor->unlock(); return DataObjectPtr(eventMonitor); }
bool KstEventMonitorI::editObject() { KstEventMonitorEntryList emList = kstObjectSubList<KstDataObject,EventMonitorEntry>(KST::dataObjectList); // if editing multiple objects, edit each one if (_editMultipleMode) { // if text fields are empty, treat as non-dirty _lineEditEquationDirty = !_w->lineEditEquation->text().isEmpty(); _lineEditDescriptionDirty = !_w->lineEditDescription->text().isEmpty(); _lineEditEMailRecipientsDirty = !_w->lineEditEMailRecipients->text().isEmpty(); bool didEdit = false; for (uint i = 0; i < _editMultipleWidget->_objectList->count(); i++) { if (_editMultipleWidget->_objectList->isSelected(i)) { // get the pointer to the object KstEventMonitorEntryList::Iterator emIter = emList.findTag(_editMultipleWidget->_objectList->text(i)); if (emIter == emList.end()) { return false; } EventMonitorEntryPtr emPtr = *emIter; if (!editSingleObject(emPtr)) { return false; } didEdit = true; } } if (!didEdit) { KMessageBox::sorry(this, i18n("Select one or more objects to edit.")); return false; } } else { EventMonitorEntryPtr ep = kst_cast<EventMonitorEntry>(_dp); // verify that the curve name is unique QString tag_name = _tagName->text(); if (!ep || (tag_name != ep->tagName() && KstData::self()->dataTagNameNotUnique(tag_name))) { _tagName->setFocus(); return false; } ep->writeLock(); ep->setTagName(tag_name); ep->unlock(); // then edit the object _lineEditEquationDirty = true; _lineEditDescriptionDirty = true; _checkBoxDebugDirty = true; _radioButtonLogNoticeDirty = true; _radioButtonLogWarningDirty = true; _radioButtonLogErrorDirty = true; _checkBoxEMailNotifyDirty = true; _lineEditEMailRecipientsDirty = true; _checkBoxELOGNotifyDirty = true; _scriptDirty = true; if (!editSingleObject(ep)) { return false; } } emit modified(); return true; }