Ejemplo n.º 1
0
bool KstEventMonitorI::newObject() {
  QString tag_name = _tagName->text();
  tag_name.replace("<New_Event>", _w->lineEditEquation->text());

  // verify that the event name is unique
  if (KstData::self()->dataTagNameNotUnique(tag_name)) {
    _tagName->setFocus();
    return false;
  }

  EventMonitorEntryPtr event = new EventMonitorEntry(tag_name);
  fillEvent(event);

  if (!event->isValid()) {
    event = 0L;

    KMessageBox::sorry(this, i18n("There is a syntax error in the equation you entered."));
    return false;
  }

  KST::dataObjectList.lock().writeLock();
  KST::dataObjectList.append(event.data());
  KST::dataObjectList.lock().unlock();

  event = 0L; // drop the reference before we update
  emit modified();
  return true;
}
Ejemplo n.º 2
0
KstDataObjectPtr EventMonitorEntry::makeDuplicate(KstDataObjectDataObjectMap& duplicatedMap) {
  QString name(tagName() + '\'');
  while (KstData::self()->dataTagNameNotUnique(name, false)) {
    name += '\'';
  }
  EventMonitorEntryPtr event = new EventMonitorEntry(name);
  event->setEvent(_event);
  event->setDescription(_description);
  event->setLevel(_level);
  event->setLogKstDebug(_logKstDebug);
  event->setLogEMail(_logEMail);
  event->setLogELOG(_logELOG);
  event->setEMailRecipients(_eMailRecipients);

  duplicatedMap.insert(this, KstDataObjectPtr(event));
  return KstDataObjectPtr(event);
}
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;
}
Ejemplo n.º 4
0
void KstEventMonitorI::fillFieldsForEdit() {
  EventMonitorEntryPtr ep = kst_cast<EventMonitorEntry>(_dp);
  if (!ep) {
    return; // shouldn't be needed
  }
  ep->readLock();
  _tagName->setText(ep->tagName());

  _w->lineEditEquation->setText(ep->event());
  _w->lineEditDescription->setText(ep->description());
  _w->checkBoxDebug->setChecked(ep->logKstDebug());
  _w->checkBoxEMailNotify->setChecked(ep->logEMail());
  _w->checkBoxELOGNotify->setChecked(ep->logELOG());
  _w->lineEditEMailRecipients->setText(ep->eMailRecipients());
  _w->_useScript->setEnabled(!ep->scriptCode().isEmpty());
  _w->_script->setText(ep->scriptCode());

  switch (ep->level()) {
    case KstDebug::Notice:
      _w->radioButtonLogNotice->setChecked(true);
      break;
    case KstDebug::Warning:
      _w->radioButtonLogWarning->setChecked(true);
      break;
    case KstDebug::Error:
      _w->radioButtonLogError->setChecked(true);
      break;
    default:
      _w->radioButtonLogWarning->setChecked(true);
      break;
  }

  ep->unlock();
  adjustSize();
  resize(minimumSizeHint());
  setFixedHeight(height());
}
Ejemplo n.º 5
0
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;
}
Ejemplo n.º 6
0
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;
}
Ejemplo n.º 7
0
void KstEventMonitorI::fillEvent(EventMonitorEntryPtr& event) {
  event->setEvent(_w->lineEditEquation->text());
  event->setDescription(_w->lineEditDescription->text());
  event->setLogKstDebug(_w->checkBoxDebug->isChecked());
  event->setLogEMail(_w->checkBoxEMailNotify->isChecked());
  event->setLogELOG(_w->checkBoxELOGNotify->isChecked());
  event->setEMailRecipients(_w->lineEditEMailRecipients->text());
  event->setScriptCode(_w->_useScript->isChecked() ? _w->_script->text() : QString::null);

  if (_w->radioButtonLogNotice->isChecked()) {
    event->setLevel(KstDebug::Notice);
  } else if (_w->radioButtonLogWarning->isChecked()) {
    event->setLevel(KstDebug::Warning);
  } else if (_w->radioButtonLogError->isChecked()) {
    event->setLevel(KstDebug::Error);
  }

  event->reparse();
}
Ejemplo n.º 8
0
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());
}
Ejemplo n.º 9
0
QString KstIfaceImpl::createEvent(const QString& name,
    const QString& expression,
    const QString& description,
    int debugLogType,
    const QString& email) {

  //suggest a name if not supplied
  QString evtag_end;
  if (name.isEmpty())
    evtag_end = QString(expression);
  else
    evtag_end = QString(name);

  //count number of events and make a unique name
  KstEventMonitorEntryList evlist = kstObjectSubList<KstDataObject,EventMonitorEntry>(KST::dataObjectList);
  int i = evlist.count() + 1;
  QString stringnum;
  stringnum = stringnum.setNum(i);

  QString evtag = "E" + stringnum + "-" + evtag_end;

  while (KstData::self()->dataTagNameNotUnique(evtag, false)) {
    stringnum.setNum(++i);
    evtag = "E" + stringnum + "-" + evtag_end;
  }

  EventMonitorEntryPtr event = new EventMonitorEntry(evtag);

  event->setEvent(expression);
  event->setDescription(description);

  if (debugLogType <= 3 && debugLogType >= 1) {
    event->setLogKstDebug(true);
    switch (debugLogType) {
      case 1:
        event->setLevel(KstDebug::Notice);
      break;
      case 2:
        event->setLevel(KstDebug::Warning);
      break;
      case 3:
        event->setLevel(KstDebug::Error);
      break;
      default:
        event->setLevel(KstDebug::Notice);
      break;
    }
  }
  else {
    event->setLogKstDebug(false);
  }

  if (email.isEmpty()) {
    event->setLogEMail(false);
  } else {
    event->setLogEMail(true);
    event->setEMailRecipients(email);
  }

  KST::dataObjectList.lock().writeLock();
  KST::dataObjectList.append(KstDataObjectPtr(event));
  KST::dataObjectList.lock().unlock();

  _doc->forceUpdate();
  _doc->setModified();

  return evtag;

}
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);
}