KJS::Value KstBindDataSource::samplesPerFrame(KJS::ExecState *exec, const KJS::List& args) { if (args.size() != 1) { KJS::Object eobj = KJS::Error::create(exec, KJS::SyntaxError, "Requires exactly one argument."); exec->setException(eobj); return KJS::Number(0); } if (args[0].type() != KJS::StringType) { KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError); exec->setException(eobj); return KJS::Number(0); } KstDataSourcePtr s = makeSource(_d); if (!s) { KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError); exec->setException(eobj); return KJS::Number(0); } s->writeLock(); int rc = s->samplesPerFrame(args[0].toString(exec).qstring()); s->writeUnlock(); return KJS::Number(rc); }
KJS::Value KstBindDataSource::frameCount(KJS::ExecState *exec, const KJS::List& args) { QString field; if (args.size() == 1) { if (args[0].type() != KJS::StringType) { KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError); exec->setException(eobj); return KJS::Number(0); } field = args[0].toString(exec).qstring(); } else if (args.size() != 0) { KJS::Object eobj = KJS::Error::create(exec, KJS::SyntaxError, "Requires at most one argument."); exec->setException(eobj); return KJS::Number(0); } KstDataSourcePtr s = makeSource(_d); if (!s) { KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError); exec->setException(eobj); return KJS::Number(0); } s->writeLock(); int rc = s->frameCount(field); s->writeUnlock(); return KJS::Number(rc); }
KJS::Value KstBindDataSource::isValidField(KJS::ExecState *exec, const KJS::List& args) { if (args.size() != 1) { KJS::Object eobj = KJS::Error::create(exec, KJS::SyntaxError, "Requires exactly one argument."); exec->setException(eobj); return KJS::Boolean(false); } if (args[0].type() != KJS::StringType) { KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError); exec->setException(eobj); return KJS::Boolean(false); } KstDataSourcePtr s = makeSource(_d); if (!s) { KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError); exec->setException(eobj); return KJS::Boolean(false); } s->writeLock(); bool rc = s->isValidField(args[0].toString(exec).qstring()); s->writeUnlock(); return KJS::Boolean(rc); }
const QString& KstIfaceImpl::loadVector(const QString& file, const QString& field) { KstDataSourcePtr src; /* generate or find the kstfile */ KST::dataSourceList.lock().writeLock(); KstDataSourceList::Iterator it = KST::dataSourceList.findFileName(file); if (it == KST::dataSourceList.end()) { src = KstDataSource::loadSource(file); if (!src || !src->isValid()) { KST::dataSourceList.lock().writeUnlock(); return QString::null; } if (src->frameCount() < 1) { KST::dataSourceList.lock().writeUnlock(); return QString::null; } KST::dataSourceList.append(src); } else { src = *it; } src->writeLock(); KST::dataSourceList.lock().writeUnlock(); KST::vectorList.lock().readLock(); QString vname = "V" + QString::number(KST::vectorList.count() + 1); while (KST::vectorTagNameNotUnique(vname, false)) { vname = "V" + QString::number(KST::vectorList.count() + 1); } KST::vectorList.lock().readUnlock(); KstVectorPtr p = new KstRVector(src, field, vname, 0, -1, 0, false, false); KST::addVectorToList(p); src->writeUnlock(); if (p) { _doc->forceUpdate(); _doc->setModified(); return p->tagName(); } return QString::null; }
KJS::Value KstBindDataVector::changeFile(KJS::ExecState *exec, const KJS::List& args) { KstRVectorPtr v = makeDataVector(_d); if (!v) { KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError); exec->setException(eobj); return KJS::Undefined(); } if (args.size() != 1) { KJS::Object eobj = KJS::Error::create(exec, KJS::SyntaxError, "Requires exactly one argument."); exec->setException(eobj); return KJS::Undefined(); } if (args[0].type() != KJS::ObjectType) { KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError); exec->setException(eobj); return KJS::Undefined(); } KstBindDataSource *imp = dynamic_cast<KstBindDataSource*>(args[0].toObject(exec).imp()); if (!imp) { KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError); exec->setException(eobj); return KJS::Undefined(); } #define makeSource(X) dynamic_cast<KstDataSource*>(const_cast<KstObject*>(X.data())) KstDataSourcePtr s = makeSource(imp->_d); if (!s) { KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError); exec->setException(eobj); return KJS::Undefined(); } v->writeLock(); s->writeLock(); v->changeFile(s); s->writeUnlock(); v->writeUnlock(); #undef makeSource return KJS::Undefined(); }
bool KstVectorDialogI::editSingleObjectRV(KstVectorPtr vcPtr) { KstRVectorPtr rvp = kst_cast<KstRVector>(vcPtr); KstDataSourcePtr file; if (_fileNameDirty) { /* if there is not an active KstFile, create one */ KST::dataSourceList.lock().writeLock(); KstDataSourceList::Iterator it = KST::dataSourceList.findReusableFileName(_w->FileName->url()); if (it == KST::dataSourceList.end()) { file = KstDataSource::loadSource(_w->FileName->url()); if (!file || !file->isValid()) { KST::dataSourceList.lock().writeUnlock(); KMessageBox::sorry(this, i18n("The file could not be opened.")); return false; } if (file->isEmpty()) { KST::dataSourceList.lock().writeUnlock(); KMessageBox::sorry(this, i18n("The file does not contain data.")); return false; } KST::dataSourceList.append(file); } else { file = *it; } KST::dataSourceList.lock().writeUnlock(); } else { KstRVectorList vcList = kstObjectSubList<KstVector,KstRVector>(KST::vectorList); for (uint i = 0; i < _editMultipleWidget->_objectList->count(); i++) { if (_editMultipleWidget->_objectList->isSelected(i)) { // get the pointer to the object KstRVectorList::Iterator vcIter = vcList.findTag(_editMultipleWidget->_objectList->text(i)); if (vcIter == vcList.end()) { return false; } KstRVectorPtr rvp = *vcIter; rvp->readLock(); file = rvp->dataSource(); rvp->readUnlock(); } } } file->writeLock(); if (rvp) { QString pField; if (_fileNameDirty) { pField = _w->Field->currentText(); if (!file->isValidField(pField)) { KMessageBox::sorry(this, i18n("The requested field is not defined for the requested file.")); file->writeUnlock(); return false; } } else { pField = rvp->field(); } int f0 = 0, n = 0; if (_f0Dirty) { if (_w->_kstDataRange->isStartRelativeTime()) { f0 = file->sampleForTime(_w->_kstDataRange->f0Value()); } else if (_w->_kstDataRange->isStartAbsoluteTime()) { bool ok = false; f0 = file->sampleForTime(_w->_kstDataRange->f0DateTimeValue(), &ok); if (!ok) { file->writeUnlock(); KMessageBox::sorry(this, i18n("The requested field or file could not use the specified date.")); return false; } } else { f0 = int(_w->_kstDataRange->f0Value()); } } if (_nDirty) { if (_w->_kstDataRange->isRangeRelativeTime()) { double nValStored = _w->_kstDataRange->nValue(); if (_w->_kstDataRange->CountFromEnd->isChecked()) { int frameCount = file->frameCount(_w->Field->currentText()); double msCount = file->relativeTimeForSample(frameCount - 1); n = frameCount - 1 - file->sampleForTime(msCount - nValStored); } else { double fTime = file->relativeTimeForSample(f0); n = file->sampleForTime(fTime + nValStored) - file->sampleForTime(fTime); } } else { n = int(_w->_kstDataRange->nValue()); } } // use existing requested start and number of frames if not dirty rvp->readLock(); if (!_f0Dirty) { f0 = rvp->reqStartFrame(); } if (!_nDirty) { n = rvp->reqNumFrames(); } // other parameters for multiple edit bool pCountFromEnd, pReadToEnd, pDoSkip, pDoFilter; int pSkip; if (_countFromEndDirty) { pCountFromEnd = _w->_kstDataRange->CountFromEnd->isChecked(); } else { pCountFromEnd = rvp->countFromEOF(); } if (_readToEndDirty) { pReadToEnd = _w->_kstDataRange->ReadToEnd->isChecked(); } else { pReadToEnd = rvp->readToEOF(); } if (_skipDirty) { pSkip = _w->_kstDataRange->Skip->value(); } else { pSkip = rvp->skip(); } if (_doSkipDirty) { pDoSkip = _w->_kstDataRange->DoSkip->isChecked(); } else { pDoSkip = rvp->doSkip(); } if (_doFilterDirty) { pDoFilter = _w->_kstDataRange->DoFilter->isChecked(); } else { pDoFilter = rvp->doAve(); } QString pTagName = rvp->tagName(); rvp->readUnlock(); /* change the vector */ rvp->writeLock(); rvp->change(file, pField, pTagName, pCountFromEnd ? -1 : f0, pReadToEnd ? -1 : n, pSkip, pDoSkip, pDoFilter); rvp->writeUnlock(); } else { KstSVectorPtr svp = kst_cast<KstSVector>(_dp); if (!svp) { file->writeUnlock(); return true; // shouldn't be needed } double x0 = _w->_xMin->text().toDouble(); double x1 = _w->_xMax->text().toDouble(); int n = _w->_N->value(); QString tagname = _tagName->text(); svp->writeLock(); svp->changeRange(x0, x1, n); svp->setTagName(_tagName->text()); // FIXME: doesn't verify uniqueness svp->writeUnlock(); } file->writeUnlock(); return true; }