KstObject::UpdateType IndirectSource::update(int u) { if (KstObject::checkUpdateCounter(u)) { return lastUpdateResult(); } // recheck the indirect file for a changed filename QFile f(_filename); if (f.open(QIODevice::ReadOnly)) { char* data; if (0 < f.readLine(data,1000)) { QString ifn(data); KUrl url(ifn); if (url.isLocalFile() || url.protocol().isEmpty()) { if (QFileInfo(ifn).isRelative()) { ifn = QFileInfo(_filename).absolutePath() + QDir::separator() + ifn; } } if (!_child || ifn.trimmed() != _child->fileName()) { _child = 0L; // release KstDataSourcePtr p = KstDataSource::loadSource(ifn.trimmed()); if (p) { _child = p; _fieldList = p->fieldList(); _valid = true; } else { _valid = false; } } } } return setLastUpdateResult(_child ? _child->update(u) : KstObject::NO_CHANGE); }
void KstChangeFileDialog::sourceChanged(const QString& text) { delete _configWidget; _configWidget = 0L; _configureSource->setEnabled(false); _file = QString::null; if (!text.isEmpty() && text != "stdin" && text != "-") { KUrl url; QString txt = _dataFile->completionObject()->replacedPath(text); if (QFile::exists(txt) && QFileInfo(txt).isRelative()) { url.setPath(txt); } else { url = KUrl::fromPathOrURL(txt); } if (!url.isLocalFile() && url.protocol() != "file" && !url.protocol().isEmpty()) { _fileType->setText(QString::null); return; } if (!url.isValid()) { _fileType->setText(QString::null); return; } QString file = txt; KstDataSourcePtr ds = *KST::dataSourceList.findReusableFileName(file); QStringList fl; QString fileType; if (ds) { ds->readLock(); fl = ds->fieldList(); fileType = ds->fileType(); ds->unlock(); ds = 0L; } else { bool complete = false; fl = KstDataSource::fieldListForSource(file, QString::null, &fileType, &complete); } if (!fl.isEmpty() && !fileType.isEmpty()) { if (ds) { ds->writeLock(); _configWidget = ds->configWidget(); ds->unlock(); } else { _configWidget = KstDataSource::configWidgetForSource(file, fileType); } } _configureSource->setEnabled(_configWidget); _file = file; _fileType->setText(fileType.isEmpty() ? QString::null : tr("Data source of type: %1").arg(fileType)); } else { _fileType->setText(QString::null); } }
IndirectSource::IndirectSource(QSettings *cfg, const QString& filename, KstDataSourcePtr child) : KstDataSource(cfg, filename, QString::null), _child(child) { if (child) { _valid = true; _fieldList = child->fieldList(); } else { _valid = false; } }
KJS::Value KstBindDataSource::fieldList(KJS::ExecState *exec, const KJS::List& args) { Q_UNUSED(args) KJS::List rc; KstDataSourcePtr s = makeSource(_d); if (!s) { KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError); exec->setException(eobj); return KJS::Object(exec->interpreter()->builtinArray().construct(exec, rc)); } s->readLock(); QStringList l = s->fieldList(); s->unlock(); for (QStringList::ConstIterator i = l.begin(); i != l.end(); ++i) { rc.append(KJS::String(*i)); } return KJS::Object(exec->interpreter()->builtinArray().construct(exec, rc)); }
void KstVectorDialogI::updateCompletion() { QString current_text = Field->currentText(); Field->clear(); /* update filename list and ll axes combo boxes */ KST::dataSourceList.lock().readLock(); KstDataSourcePtr ds = *KST::dataSourceList.findFileName(FileName->url()); KST::dataSourceList.lock().readUnlock(); delete _configWidget; // FIXME: very inefficient!!!! _configWidget = 0L; QStringList list; if (ds) { ds->readLock(); list = ds->fieldList(); Field->setEditable(!ds->fieldListIsComplete()); _configWidget = ds->configWidget(); ds->readUnlock(); } else { QString type; bool complete = false; list = KstDataSource::fieldListForSource(FileName->url(), QString::null, &type, &complete); Field->setEditable(!complete); if (!list.isEmpty() && !type.isEmpty()) { _configWidget = KstDataSource::configWidgetForSource(FileName->url(), type); } } _configure->setEnabled(_configWidget); _fieldCompletion = Field->completionObject(); Field->insertStringList(list); if (_fieldCompletion) { _fieldCompletion->clear(); _fieldCompletion->insertItems(list); } if (!current_text.isEmpty() && (list.contains(current_text) || Field->editable())) { Field->setCurrentText(current_text); } _kstDataRange->setAllowTime(ds && ds->supportsTimeConversions()); }
void KstVectorDialogI::update(int new_index) { int i_vector, index, n_v; KstRVectorPtr vector; bool isNew = false; KstRVectorList vectorList = kstObjectSubList<KstVector,KstRVector>(KST::vectorList); if (new_index == -1) { if (vectorList.findTag(Select->currentText()) != vectorList.end()) { QString save = Select->currentText(); Select->blockSignals(true); Select->clear(); for (KstRVectorList::iterator i = vectorList.begin(); i != vectorList.end(); ++i) { Select->insertItem((*i)->tagName()); } Select->setCurrentText(save); Select->blockSignals(false); return; } } n_v = vectorList.count(); if (n_v < 1) { Select->clear(); Select->insertItem("V1-" + i18n("<New_Vector>")); Delete->setEnabled(false); return; } if (new_index == -2) { isNew = true; new_index = n_v-1; } if (new_index >= 0) { index = new_index; } else if (n_v > 0) { index = Select->currentItem(); } else { index = n_v-1; } /** fill VectorListBox with vector tags */ Select->clear(); for (KstRVectorList::iterator i = vectorList.begin(); i != vectorList.end(); ++i) { Select->insertItem((*i)->tagName()); } if (index >= 0 && index < n_v) { Select->setCurrentItem(index); } else if (n_v > 0) { Select->setCurrentItem(n_v - 1); } i_vector = Select->currentItem(); vector = vectorList[i_vector]; /* fill the fields */ Field->clear(); _fieldCompletion->clear(); KstDataSourcePtr tf; { KST::dataSourceList.lock().readLock(); KstDataSourceList::Iterator it = KST::dataSourceList.findFileName(vector->filename()); if (it != KST::dataSourceList.end()) { tf = *it; Field->insertStringList(tf->fieldList()); _fieldCompletion->insertItems(tf->fieldList()); //std::cout << "inserting string list: " << tf->fieldList().count() << "\n"; } KST::dataSourceList.lock().readUnlock(); } if (isNew) { Field->setCurrentText(QString::null); } else { Field->setCurrentText(vector->getField()); } /* select the proper file */ FileName->setURL(vector->filename()); /* fill the vector range entries */ if (vector->countFromEOF()) { CountFromEnd->setChecked(true); } else { CountFromEnd->setChecked(false); } F0->setValue(vector->reqStartFrame()); /* fill number of frames entries */ if (vector->readToEOF()) { ReadToEnd->setChecked(true); } else { ReadToEnd->setChecked(false); } N->setValue(vector->reqNumFrames()); /* fill in frames to skip box */ Skip->setValue(vector->skip()); DoSkip->setChecked(vector->doSkip()); DoFilter->setChecked(vector->doAve()); if (isNew) { QString new_label; new_label.sprintf("V%d-", n_v+1); new_label += i18n("<New_Vector>"); Select->insertItem(new_label); Select->setCurrentItem(n_v); Delete->setEnabled(false); } else { Delete->setEnabled(vector->getUsage() == 2); } }
void KstVectorDialogI::fillFieldsForRVEdit() { KstRVectorPtr rvp = kst_cast<KstRVector>(_dp); rvp->readLock(); _w->_readFromSource->setChecked(true); _w->_rvectorGroup->show(); _w->_kstDataRange->show(); _w->_kstDataRange->setEnabled(true); _w->_svectorGroup->hide(); _w->_svectorGroup->setEnabled(false); _w->sourceGroup->hide(); _tagName->setText(rvp->tagName()); _w->Field->clear(); if (_fieldCompletion) { _fieldCompletion->clear(); } { KstDataSourcePtr tf; KST::dataSourceList.lock().readLock(); KstDataSourceList::Iterator it = KST::dataSourceList.findReusableFileName(rvp->filename()); if (it != KST::dataSourceList.end()) { tf = *it; tf->readLock(); _w->Field->insertStringList(tf->fieldList()); if (_fieldCompletion) { _fieldCompletion->insertItems(tf->fieldList()); } tf->unlock(); } else { QStringList list = KstDataSource::fieldListForSource(_w->FileName->url()); _w->Field->insertStringList(list); if (_fieldCompletion) { _fieldCompletion->insertItems(list); } } KST::dataSourceList.lock().unlock(); } _w->Field->setEnabled(_w->Field->count() > 0); _ok->setEnabled(_w->Field->isEnabled()); _w->Field->setCurrentText(rvp->field()); // select the proper file _w->FileName->setURL(rvp->filename()); // fill the vector range entries _w->_kstDataRange->CountFromEnd->setChecked(rvp->countFromEOF()); _w->_kstDataRange->setF0Value(rvp->reqStartFrame()); // fill number of frames entries _w->_kstDataRange->ReadToEnd->setChecked(rvp->readToEOF()); _w->_kstDataRange->setNValue(rvp->reqNumFrames()); // fill in frames to skip box _w->_kstDataRange->Skip->setValue(rvp->skip()); _w->_kstDataRange->DoSkip->setChecked(rvp->doSkip()); _w->_kstDataRange->DoFilter->setChecked(rvp->doAve()); _w->_kstDataRange->updateEnables(); rvp->unlock(); }
void KstVectorDialogI::updateCompletion() { QString current_text = _w->Field->currentText(); _w->Field->clear(); // update filename list and ll axes combo boxes KST::dataSourceList.lock().readLock(); KstDataSourcePtr ds = *KST::dataSourceList.findReusableFileName(_w->FileName->url()); KST::dataSourceList.lock().unlock(); delete _configWidget; _configWidget = 0L; QStringList list; if (ds) { ds->readLock(); list = ds->fieldList(); _w->Field->setEditable(!ds->fieldListIsComplete()); _configWidget = ds->configWidget(); ds->unlock(); _w->Field->setEnabled(true); _w->_connect->hide(); _w->_kstDataRange->setAllowTime(ds->supportsTimeConversions()); } else { QString type; bool complete = false; QString u = _w->FileName->url(); KURL url; if (QFile::exists(u) && QFileInfo(u).isRelative()) { url.setPath(u); } else { url = KURL::fromPathOrURL(u); } if (!_inTest && !url.isLocalFile() && url.protocol() != "file" && !url.protocol().isEmpty()) { _w->_connect->show(); } else if (url.isValid()) { list = KstDataSource::fieldListForSource(u, QString::null, &type, &complete); if (!_inTest || (_inTest && !list.isEmpty())) { _w->_connect->hide(); } } _w->Field->setEditable(!complete); _w->Field->setEnabled(!list.isEmpty()); if (!list.isEmpty() && !type.isEmpty()) { _configWidget = KstDataSource::configWidgetForSource(u, type); } _w->_kstDataRange->setAllowTime(KstDataSource::supportsTime(u, type)); } _w->_configure->setEnabled(_configWidget); _fieldCompletion = _w->Field->completionObject(); _w->Field->insertStringList(list); if (_fieldCompletion) { _fieldCompletion->clear(); _fieldCompletion->insertItems(list); } if (!current_text.isEmpty() && (list.contains(current_text) || _w->Field->editable())) { _w->Field->setCurrentText(current_text); } _ok->setEnabled(_w->Field->isEnabled() || _editMultipleMode); }
void KstVectorDialogI::_fillFieldsForEdit() { if (DP == 0L) { return; // shouldn't be needed } DP->readLock(); _tagName->setText(DP->tagName()); /* fill the fields */ Field->clear(); if (_fieldCompletion) { _fieldCompletion->clear(); } { KstDataSourcePtr tf; KST::dataSourceList.lock().readLock(); KstDataSourceList::Iterator it = KST::dataSourceList.findFileName(DP->filename()); if (it != KST::dataSourceList.end()) { tf = *it; tf->readLock(); Field->insertStringList(tf->fieldList()); if (_fieldCompletion) { _fieldCompletion->insertItems(tf->fieldList()); } tf->readUnlock(); } else { QStringList list = KstDataSource::fieldListForSource(FileName->url()); Field->insertStringList(list); if (_fieldCompletion) { _fieldCompletion->insertItems(list); } } KST::dataSourceList.lock().readUnlock(); } Field->setCurrentText(DP->field()); /* select the proper file */ FileName->setURL(DP->filename()); /* fill the vector range entries */ if (DP->countFromEOF()) { _kstDataRange->CountFromEnd->setChecked(true); } else { _kstDataRange->CountFromEnd->setChecked(false); } _kstDataRange->setF0Value(DP->reqStartFrame()); /* fill number of frames entries */ if (DP->readToEOF()) { _kstDataRange->ReadToEnd->setChecked(true); } else { _kstDataRange->ReadToEnd->setChecked(false); } _kstDataRange->setNValue(DP->reqNumFrames()); /* fill in frames to skip box */ _kstDataRange->Skip->setValue(DP->skip()); _kstDataRange->DoSkip->setChecked(DP->doSkip()); _kstDataRange->DoFilter->setChecked(DP->doAve()); _kstDataRange->updateEnables(); DP->readUnlock(); }