Mercurial > hg > svcore
changeset 520:e340b2fb9471
* Make FileSource able to indicate its preferred content type (e.g.
application/rdf+xml in preference to text/html for rdf content)
* Temp directory on Windows -- make $HOME expand to homedrive+homepath
instead of user profile location (which may be networked)
author | Chris Cannam |
---|---|
date | Thu, 11 Dec 2008 15:18:10 +0000 |
parents | 21f86744d38e |
children | 5ebcf099dab0 |
files | base/TempDirectory.cpp data/fileio/CachedFile.cpp data/fileio/CachedFile.h data/fileio/FileSource.cpp data/fileio/FileSource.h rdf/PluginRDFDescription.cpp rdf/PluginRDFIndexer.cpp rdf/PluginRDFIndexer.h rdf/RDFImporter.cpp |
diffstat | 9 files changed, 106 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/base/TempDirectory.cpp Thu Dec 11 12:37:16 2008 +0000 +++ b/base/TempDirectory.cpp Thu Dec 11 15:18:10 2008 +0000 @@ -62,7 +62,17 @@ QString svDirParent = settings.value("create-in", "$HOME").toString(); settings.endGroup(); +#ifdef Q_OS_WIN32 + char *homedrive = getenv("HOMEDRIVE"); + char *homepath = getenv("HOMEPATH"); + if (homedrive && homepath) { + svDirParent.replace("$HOME", QString("%1%2").arg(homedrive).arg(homepath)); + } else { + svDirParent.replace("$HOME", QDir::home().absolutePath()); + } +#else svDirParent.replace("$HOME", QDir::home().absolutePath()); +#endif QString svDirBase = ".sv1"; QString svDir = QDir(svDirParent).filePath(svDirBase);
--- a/data/fileio/CachedFile.cpp Thu Dec 11 12:37:16 2008 +0000 +++ b/data/fileio/CachedFile.cpp Thu Dec 11 15:18:10 2008 +0000 @@ -68,8 +68,11 @@ return fi.filePath(); } -CachedFile::CachedFile(QString origin, ProgressReporter *reporter) : +CachedFile::CachedFile(QString origin, + ProgressReporter *reporter, + QString preferredContentType) : m_origin(origin), + m_preferredContentType(preferredContentType), m_reporter(reporter), m_ok(false) { @@ -80,8 +83,11 @@ check(); } -CachedFile::CachedFile(QUrl url, ProgressReporter *reporter) : +CachedFile::CachedFile(QUrl url, + ProgressReporter *reporter, + QString preferredContentType) : m_origin(url.toString()), + m_preferredContentType(preferredContentType), m_reporter(reporter), m_ok(false) { @@ -182,7 +188,7 @@ //!!! using Qt classes, but a plain delete then copy is probably //!!! good enough) - FileSource fs(m_origin, m_reporter); + FileSource fs(m_origin, m_reporter, m_preferredContentType); if (!fs.isOK() || !fs.isAvailable()) { std::cerr << "CachedFile::retrieve: ERROR: FileSource reported unavailable or failure" << std::endl;
--- a/data/fileio/CachedFile.h Thu Dec 11 12:37:16 2008 +0000 +++ b/data/fileio/CachedFile.h Thu Dec 11 15:18:10 2008 +0000 @@ -26,8 +26,12 @@ class CachedFile { public: - CachedFile(QString fileOrUrl, ProgressReporter *reporter = 0); - CachedFile(QUrl url, ProgressReporter *reporter = 0); + CachedFile(QString fileOrUrl, + ProgressReporter *reporter = 0, + QString preferredContentType = ""); + CachedFile(QUrl url, + ProgressReporter *reporter = 0, + QString preferredContentType = ""); virtual ~CachedFile(); @@ -38,6 +42,7 @@ protected: QString m_origin; QString m_localFilename; + QString m_preferredContentType; ProgressReporter *m_reporter; bool m_ok;
--- a/data/fileio/FileSource.cpp Thu Dec 11 12:37:16 2008 +0000 +++ b/data/fileio/FileSource.cpp Thu Dec 11 15:18:10 2008 +0000 @@ -30,7 +30,7 @@ #include <iostream> #include <cstdlib> -//#define DEBUG_FILE_SOURCE 1 +#define DEBUG_FILE_SOURCE 1 int FileSource::m_count = 0; @@ -47,11 +47,13 @@ QMutex FileSource::m_mapMutex; -FileSource::FileSource(QString fileOrUrl, ProgressReporter *reporter) : +FileSource::FileSource(QString fileOrUrl, ProgressReporter *reporter, + QString preferredContentType) : m_url(fileOrUrl), m_ftp(0), m_http(0), m_localFile(0), + m_preferredContentType(preferredContentType), m_ok(false), m_lastStatus(0), m_remote(isRemote(fileOrUrl)), @@ -276,7 +278,9 @@ if (scheme == "http") { initHttp(); +#ifdef DEBUG_FILE_SOURCE std::cerr << "FileSource: initHttp succeeded" << std::endl; +#endif } else if (scheme == "ftp") { initFtp(); } else { @@ -381,7 +385,18 @@ << path.toStdString() << "\"" << std::endl; #endif - m_http->get(path, m_localFile); + if (m_preferredContentType == "") { + m_http->get(path, m_localFile); + } else { +#ifdef DEBUG_FILE_SOURCE + std::cerr << "FileSource: indicating preferred content type of \"" + << m_preferredContentType.toStdString() << "\"" << std::endl; +#endif + QHttpRequestHeader header("GET", path); + header.setValue("Host", m_url.host()); + header.setValue("Accept", QString("%1, */*").arg(m_preferredContentType)); + m_http->request(header, 0, m_localFile); + } } void @@ -560,7 +575,9 @@ void FileSource::httpResponseHeaderReceived(const QHttpResponseHeader &resp) { +#ifdef DEBUG_FILE_SOURCE std::cerr << "FileSource::httpResponseHeaderReceived" << std::endl; +#endif if (resp.statusCode() / 100 == 3) { QString location = resp.value("Location"); @@ -695,6 +712,7 @@ } m_ok = !error; + if (m_localFile) m_localFile->flush(); m_done = true; emit ready(); }
--- a/data/fileio/FileSource.h Thu Dec 11 12:37:16 2008 +0000 +++ b/data/fileio/FileSource.h Thu Dec 11 15:18:10 2008 +0000 @@ -70,7 +70,9 @@ * emitted regularly during retrieval, even if no reporter is * supplied here. Caller retains ownership of the reporter object. */ - FileSource(QString fileOrUrl, ProgressReporter *reporter = 0); + FileSource(QString fileOrUrl, + ProgressReporter *reporter = 0, + QString preferredContentType = ""); /** * Construct a FileSource using the given remote URL. @@ -212,6 +214,7 @@ QString m_localFilename; QString m_errorString; QString m_contentType; + QString m_preferredContentType; bool m_ok; int m_lastStatus; bool m_remote;
--- a/rdf/PluginRDFDescription.cpp Thu Dec 11 12:37:16 2008 +0000 +++ b/rdf/PluginRDFDescription.cpp Thu Dec 11 15:18:10 2008 +0000 @@ -18,9 +18,6 @@ #include "PluginRDFIndexer.h" #include "SimpleSPARQLQuery.h" -#include "data/fileio/FileSource.h" -#include "data/fileio/CachedFile.h" - #include "base/Profiler.h" #include "plugin/PluginIdentifier.h"
--- a/rdf/PluginRDFIndexer.cpp Thu Dec 11 12:37:16 2008 +0000 +++ b/rdf/PluginRDFIndexer.cpp Thu Dec 11 15:18:10 2008 +0000 @@ -43,6 +43,9 @@ PluginRDFIndexer * PluginRDFIndexer::m_instance = 0; +bool +PluginRDFIndexer::m_prefixesLoaded = false; + PluginRDFIndexer * PluginRDFIndexer::getInstance() { @@ -236,6 +239,8 @@ { Profiler profiler("PluginRDFIndexer::indexURL"); + loadPrefixes(); + // std::cerr << "PluginRDFIndexer::indexURL(" << urlString.toStdString() << ")" << std::endl; QMutexLocker locker(&m_mutex); @@ -245,7 +250,7 @@ if (FileSource::isRemote(urlString) && FileSource::canHandleScheme(urlString)) { - CachedFile cf(urlString); + CachedFile cf(urlString, 0, "application/rdf+xml"); if (!cf.isOK()) { return false; } @@ -367,5 +372,22 @@ return addedSomething; } +void +PluginRDFIndexer::loadPrefixes() +{ + return; +//!!! + if (m_prefixesLoaded) return; + const char *prefixes[] = { + "http://purl.org/ontology/vamp/" + }; + for (size_t i = 0; i < sizeof(prefixes)/sizeof(prefixes[0]); ++i) { + CachedFile cf(prefixes[i], 0, "application/rdf+xml"); + if (!cf.isOK()) continue; + SimpleSPARQLQuery::addSourceToModel + (QUrl::fromLocalFile(cf.getLocalFilename()).toString()); + } + m_prefixesLoaded = true; +}
--- a/rdf/PluginRDFIndexer.h Thu Dec 11 12:37:16 2008 +0000 +++ b/rdf/PluginRDFIndexer.h Thu Dec 11 15:18:10 2008 +0000 @@ -64,6 +64,8 @@ bool pullURL(QString urlString); bool reindex(); + static void loadPrefixes(); + static bool m_prefixesLoaded; static PluginRDFIndexer *m_instance; };
--- a/rdf/RDFImporter.cpp Thu Dec 11 12:37:16 2008 +0000 +++ b/rdf/RDFImporter.cpp Thu Dec 11 15:18:10 2008 +0000 @@ -35,6 +35,7 @@ #include "data/model/WaveFileModel.h" #include "data/fileio/FileSource.h" +#include "data/fileio/CachedFile.h" using std::cerr; using std::endl; @@ -58,6 +59,9 @@ std::map<QString, Model *> m_audioModelMap; int m_sampleRate; + static bool m_prefixesLoaded; + static void loadPrefixes(ProgressReporter *reporter); + void getDataModelsAudio(std::vector<Model *> &, ProgressReporter *); void getDataModelsSparse(std::vector<Model *> &, ProgressReporter *); void getDataModelsDense(std::vector<Model *> &, ProgressReporter *); @@ -71,6 +75,7 @@ void fillModel(Model *, long, long, bool, std::vector<float> &, QString); }; +bool RDFImporterImpl::m_prefixesLoaded = false; QString RDFImporter::getKnownExtensions() @@ -138,6 +143,8 @@ std::vector<Model *> RDFImporterImpl::getDataModels(ProgressReporter *reporter) { + loadPrefixes(reporter); + std::vector<Model *> models; getDataModelsAudio(models, reporter); @@ -663,6 +670,7 @@ } else { QString timestring = SimpleSPARQLQuery::singleResultQuery (s, timeQueryString.arg(thinguri), "time").value; +// std::cerr << "timestring = " << timestring.toStdString() << std::endl; if (timestring != "") { time = RealTime::fromXsdDuration(timestring.toStdString()); haveTime = true; @@ -963,4 +971,25 @@ SimpleSPARQLQuery::closeSingleSource(url); } - +void +RDFImporterImpl::loadPrefixes(ProgressReporter *reporter) +{ + return; +//!!! + if (m_prefixesLoaded) return; + const char *prefixes[] = { + "http://purl.org/NET/c4dm/event.owl", + "http://purl.org/NET/c4dm/timeline.owl", + "http://purl.org/ontology/mo/", + "http://purl.org/ontology/af/", + "http://www.w3.org/2000/01/rdf-schema", + "http://purl.org/dc/elements/1.1/", + }; + for (size_t i = 0; i < sizeof(prefixes)/sizeof(prefixes[0]); ++i) { + CachedFile cf(prefixes[i], reporter, "application/rdf+xml"); + if (!cf.isOK()) continue; + SimpleSPARQLQuery::addSourceToModel + (QUrl::fromLocalFile(cf.getLocalFilename()).toString()); + } + m_prefixesLoaded = true; +}