changeset 90:87495ac7710a

support audio source info from boca
author lbajardsilogic
date Thu, 28 Jun 2007 16:57:29 +0000
parents 4fd3274908a5
children 8e0ba77ecdf4
files base/RealTime.cpp data/fileio/AudioSourceInfoReader.cpp data/fileio/AudioSourceInfoReader.h sv/filter/TimeStretchFilter.cpp sv/main/EasaierSessionManager.cpp sv/main/EasaierSessionManager.h sv/main/MainWindow.cpp widgets/InfoWidget.cpp widgets/QueryResultsWidget.cpp
diffstat 9 files changed, 226 insertions(+), 63 deletions(-) [+]
line wrap: on
line diff
--- a/base/RealTime.cpp	Thu Jun 28 16:19:29 2007 +0000
+++ b/base/RealTime.cpp	Thu Jun 28 16:57:29 2007 +0000
@@ -263,9 +263,17 @@
     if (frame < 0) return -frame2RealTime(-frame, sampleRate);
 
     RealTime rt;
-    rt.sec = frame / long(sampleRate);
-    frame -= rt.sec * long(sampleRate);
-    rt.nsec = (int)(((float(frame) * 1000000) / long(sampleRate)) * 1000);
+	if (sampleRate == 0)
+	{
+		rt.sec = 0;
+		rt.nsec = 0;
+	}
+	else
+	{
+		rt.sec = frame / long(sampleRate);
+		frame -= rt.sec * long(sampleRate);
+		rt.nsec = (int)(((float(frame) * 1000000) / long(sampleRate)) * 1000);
+	}
     return rt;
 }
 
--- a/data/fileio/AudioSourceInfoReader.cpp	Thu Jun 28 16:19:29 2007 +0000
+++ b/data/fileio/AudioSourceInfoReader.cpp	Thu Jun 28 16:57:29 2007 +0000
@@ -43,15 +43,16 @@
 	return false;
 }
 
-AudioSourceInfoHandler::AudioSourceInfoHandler(AudioSourceInfoModel* model) : QXmlDefaultHandler()
-{
-	m_model = model;
-}
+AudioSourceInfoHandler::AudioSourceInfoHandler(AudioSourceInfoModel* model) : QXmlDefaultHandler(),
+	m_model(model),
+	m_inBinding(false),
+	m_curBindingName("")
+{}
 
 bool AudioSourceInfoHandler::startElement(const QString &namespaceURI, const QString &localName,
 						  const QString &qName, const QXmlAttributes &attributes)
 {
-	QString name = qName.toLower();
+	/*QString name = qName.toLower();
     bool ok = false;
 
     // Valid element names:
@@ -77,18 +78,99 @@
 		  << name.toLocal8Bit().data() << "\"" << std::endl;
     }
 
+    return true;*/
+	QString name = qName.toLower();
+
+    bool ok = false;
+
+    // Valid element names:
+    //
+    // sparql
+    // head
+    // variable
+    // results
+	// result
+	// binding
+    
+    if (name == "sparql") {
+
+		// nothing needed
+		ok = true;
+
+    } else if (name == "head") {
+
+		// nothing needed
+		ok = true;
+
+    } else if (name == "variable") {
+
+		// nothing needed
+		ok = true;
+    
+    } else if (name == "results") {
+	
+		// nothing needed
+		ok = true;
+
+    } else if (name == "result") {
+	
+		ok = true;
+
+    } else if (name == "binding") {
+	
+		m_curBindingName = attributes.value("name");
+		ok = true;
+
+    } else if ( (name == "uri") || (name == "literal") ) {
+		m_inBinding = true;	
+		ok = true;
+	}
+
+    if (!ok) {
+		std::cerr << "WARNING: SparqlResultsHandler-XML: Failed to completely process element \""
+		  << name.toLocal8Bit().data() << "\"" << std::endl;
+    }
+
     return true;
 }
 
 bool AudioSourceInfoHandler::endElement(const QString &namespaceURI, const QString &localName,
 						const QString &qName)
 {
+	QString name = qName.toLower();
+
+	if ( (name == "uri") || (name == "literal") )
+	{
+		m_inBinding = false;
+		m_curBindingName = "";
+
+	} else if (name == "result")
+	{
+		m_model->addInfo(m_property, m_value);
+	}
+
 	return true;
 }
 
 bool AudioSourceInfoHandler::characters(const QString &str)
 {
-	return true;
+	if (m_inBinding)
+	{
+		if (m_curBindingName == "value")
+		{
+			m_value = str;
+		}
+		else if (m_curBindingName == "property")
+		{
+			m_property = str;
+		}
+		else 
+		{
+			m_model->addInfo(m_curBindingName, str);
+		}
+	}
+
+    return true;
 }
 
 bool AudioSourceInfoHandler::error(const QXmlParseException &exception)
--- a/data/fileio/AudioSourceInfoReader.h	Thu Jun 28 16:19:29 2007 +0000
+++ b/data/fileio/AudioSourceInfoReader.h	Thu Jun 28 16:57:29 2007 +0000
@@ -48,6 +48,13 @@
 
 	AudioSourceInfoModel	*m_model;
 
+	bool		m_inBinding;
+	QString		m_curBindingName;
+
+
+	QString		m_property;
+	QString		m_value;
+
 };
 
 #endif
\ No newline at end of file
--- a/sv/filter/TimeStretchFilter.cpp	Thu Jun 28 16:19:29 2007 +0000
+++ b/sv/filter/TimeStretchFilter.cpp	Thu Jun 28 16:57:29 2007 +0000
@@ -124,7 +124,7 @@
 TimeStretchFilter::PropertyList TimeStretchFilter::getProperties() const
 {
 	PropertyList list;
-    list.push_back("Time");
+    //list.push_back("Time");
 	list.push_back("Pitch");
 	list.push_back("Bypass");
 	list.push_back("Transdetect");
--- a/sv/main/EasaierSessionManager.cpp	Thu Jun 28 16:19:29 2007 +0000
+++ b/sv/main/EasaierSessionManager.cpp	Thu Jun 28 16:57:29 2007 +0000
@@ -19,10 +19,10 @@
 #include <iostream>
 #include <QStatusBar>
 #include <vector>
+
 #include <QApplication>
 #include <Qt>
 
-
 #include "layer/Layer.h"
 #include "base/TempDirectory.h"
 #include "data/fileio/AudioSourceInfoReader.h"
@@ -57,7 +57,9 @@
 
 	m_queryModel = new QueryModel();
 	QString filename = "http://" + m_httpClient->getHost() + "/data/query/queryfield.xml";
-	loadFile(filename, LoadedFile::QUERY_CONFIG);
+	QString query = "http://" + m_httpClient->getHost() + "/data/query/queryfield.xml";
+
+	loadFile(query, filename, LoadedFile::QUERY_CONFIG);
 
 	return true;
 }
@@ -69,8 +71,17 @@
 	m_fileName = document->getAudioSourceInfoFileName();
 	m_document = document;
 
-	loadFile(m_fileName, LoadedFile::AUDIO_SOURCE_INFO );
+	QString params = "&identification=" + m_fileName;
+
+	QString query = "http://"+ m_httpClient->getHost() + ":" + QString::number(m_httpClient->getHostPort())+ 
+						"/easaier/servlet/MOQueryServlet?theme=infoFile"+params;
+
+	QString filename = "http://"+ m_httpClient->getHost() + ":" + QString::number(m_httpClient->getHostPort())+ 
+						"/easaier/servlet/infoFile";
 	
+	
+	loadFile(query, filename, LoadedFile::AUDIO_SOURCE_INFO);
+
 	return true;
 }
 
@@ -81,7 +92,16 @@
 	m_fileName = document->getAudioSourceInfoFileName();
 	m_document = document;
 
-	loadFile(m_fileName, LoadedFile::AUDIO_SOURCE_INFO);
+	QString params = "&identification=" + m_fileName;
+
+	QString query = "http://"+ m_httpClient->getHost() + ":" + QString::number(m_httpClient->getHostPort())+ 
+						"/easaier/servlet/MOQueryServlet?theme=infoFile"+params;
+
+	QString filename = "http://"+ m_httpClient->getHost() + ":" + QString::number(m_httpClient->getHostPort())+ 
+						"/easaier/servlet/infoFile";
+	
+	
+	loadFile(query, filename, LoadedFile::AUDIO_SOURCE_INFO);
 	
 	return true;
 }
@@ -114,20 +134,18 @@
 	}
 }
 
-void EasaierSessionManager::loadFile(const QString& uri, LoadedFile::FileType type)
+void EasaierSessionManager::loadFile(const QString& query, const QString& filename, LoadedFile::FileType type)
 {
-	if (uri == 0)
+	if ((query == 0) || (filename == 0))
 		return;
 
 	if (m_httpClient->getHost() == "")
-	{
 		return;
-	}
 
-	QUrl url(uri);
+	QUrl url(filename);
 	QString path = url.path();
 	QString directory = path.left(path.lastIndexOf("/"));
-	QString filename = path.right(path.length() - path.lastIndexOf("/"));
+	QString file = path.right(path.length() - path.lastIndexOf("/"));
 
 	if (directory.left(1) == "/")
 	{
@@ -136,14 +154,13 @@
 
 	//create the subdirectory in local
 	QString localPath = TempDirectory::getInstance()->getSubDirectoryPath(directory);
-	localPath.append(filename);
+	localPath.append(file);
 
 	LoadedFile* newFile = new LoadedFile(localPath);
-	newFile->setFileType(type);
-	newFile->setUri(uri);
+	newFile->setFileType(type);
+	newFile->setUri(query);
 
-	int index = m_httpClient->get(uri, newFile);
-	//connect(m_httpClient,SIGNAL(requestFinished ( int, bool)),this, SLOT(getFinished(int, bool)));
+	int index = m_httpClient->get(query, newFile);
 
 	std::cerr << "Ask for file : GET " << path.toStdString() << " - index : " << index << std::endl;
 
@@ -285,27 +302,30 @@
 		if (modelName != "")
 		{
 			QString modelId		= QString::number(layer->getModelId());
-			modelName.append(modelId);
+			//modelName.append(modelId);
 
 		} else if (layer->getLayerPresentationName() == "Waveform")
 		{
-			modelName = "audiofile";
+			modelName = "http://purl.org/dc/elements/1.1/source";
 			int modelId = 1;
 			layer->setModelName(modelName);
 			layer->setModelId(modelId);
-			modelName.append(QString::number(modelId));
+			//modelName.append(QString::number(modelId));
 		} 
 		
 		if (modelName != "")
 		{
 			QString uri = m_audioSourceInfoModel->getInfo(modelName);
-				
+			
+			uri = "http://" + m_httpClient->getHost() + uri;
+			m_audioSourceInfoModel->addInfo(modelName, uri);
+			
 			std::set<QString>::iterator iterModel = m_modelLoaded.find(uri);
 
 			if (iterModel == m_modelLoaded.end())
 			{
 				m_modelLoaded.insert(uri);
-				loadFile(uri, LoadedFile::MODEL);
+				loadFile(uri, uri, LoadedFile::MODEL);
 			}
 		}
 	}
@@ -327,7 +347,7 @@
 		QString modelName	= layer->getModelName();
 		QString modelId		= QString::number(layer->getModelId());
 
-		modelName.append(modelId);
+		//modelName.append(modelId);
 		modelName = modelName.toLower();
 
 		if (modelName == name)
@@ -364,7 +384,10 @@
 
 void EasaierSessionManager::importMetadata(const QString& filename, Pane* pane)
 {
-	loadFile(filename, LoadedFile::METADATA);
+	QString file = "http://" + m_httpClient->getHost() + filename;
+
+	loadFile(file, file, LoadedFile::METADATA);
+
 	m_currentPane = pane;
 }
 
@@ -380,9 +403,10 @@
 		}
 	}
 	
-	QString filename = "http://"+ m_httpClient->getHost() + ":" + QString::number(m_httpClient->getHostPort())+ "/easaier/servlet/MOQueryServlet?theme="+themeName+""+params;
-
+	QString query = "http://"+ m_httpClient->getHost() + ":" + QString::number(m_httpClient->getHostPort())+ "/easaier/servlet/MOQueryServlet?theme="+themeName+""+params;
+	QString filename = "http://"+ m_httpClient->getHost() + ":" + QString::number(m_httpClient->getHostPort())+ "/easaier/servlet/"+themeName;
 
 	QApplication::setOverrideCursor( Qt::WaitCursor );
-	loadFile(filename, LoadedFile::QUERY_RESULTS);
+	loadFile(query, filename, LoadedFile::QUERY_RESULTS);
+	
 }
--- a/sv/main/EasaierSessionManager.h	Thu Jun 28 16:19:29 2007 +0000
+++ b/sv/main/EasaierSessionManager.h	Thu Jun 28 16:57:29 2007 +0000
@@ -65,7 +65,7 @@
 
 	inline void setHttpClient(HttpClient* httpClient) {m_httpClient = httpClient;}
 
-	void loadFile(const QString& uri, LoadedFile::FileType type);
+	void loadFile(const QString& query, const QString& filename, LoadedFile::FileType type);
 
 	bool newSession();
 	void closeSession();
--- a/sv/main/MainWindow.cpp	Thu Jun 28 16:19:29 2007 +0000
+++ b/sv/main/MainWindow.cpp	Thu Jun 28 16:57:29 2007 +0000
@@ -2832,6 +2832,8 @@
 
 	m_toolBox->removeItem(0);
 	m_multiPaneLayerContainer = 0;
+
+	TempDirectory::getInstance()->cleanup();
 }
 
 void
--- a/widgets/InfoWidget.cpp	Thu Jun 28 16:19:29 2007 +0000
+++ b/widgets/InfoWidget.cpp	Thu Jun 28 16:57:29 2007 +0000
@@ -49,33 +49,60 @@
 }
 void InfoWidget::displayAudioSourceInfo(AudioSourceInfoModel* model)
 {
+	reset();
+
 	std::map<QString, QString> info = model->getInfo();
 	std::map<QString, QString>::iterator iterInfo;
 	QLabel* proper;
 	QLabel* value;
 
 	int row = 0;
-	for (iterInfo = info.begin(); iterInfo != info.end(); iterInfo++)
+
+	//display author and title at first
+	iterInfo = info.find("title");
+	if (iterInfo!= info.end())
 	{
 		proper = new QLabel(iterInfo->first);
-
-		QString valueText(iterInfo->second);
-
-		if ((valueText.left(4) == "http") && (valueText.right(4) == ".xml"))
-		{
-			value = new QLabel();
-			value->setText("<a href=\"" + iterInfo->second + "\">" + iterInfo->second + "</a>");
-			//connect the main window to the linkActivated signal
-			connect(value, SIGNAL(linkActivated(QString)), MainWindow::instance(), SLOT(importEasaierLayer(QString)));
-
-		} else {
-			value = new QLabel(iterInfo->second);
-		}
-		
+		value = new QLabel(iterInfo->second);
+		m_infoLayout->addWidget(proper, row, 0);
+		m_infoLayout->addWidget(value, row, 1);
+		row++;
+	}
+	iterInfo = info.find("author");
+	if (iterInfo!= info.end())
+	{
+		proper = new QLabel(iterInfo->first);
+		value = new QLabel(iterInfo->second);
 		m_infoLayout->addWidget(proper, row, 0);
 		m_infoLayout->addWidget(value, row, 1);
 		row++;
 	}
 
+	//display other info
+	for (iterInfo = info.begin(); iterInfo != info.end(); iterInfo++)
+	{
+		if ((iterInfo->first != "title") && (iterInfo->first != "author"))
+		{
+			proper = new QLabel(iterInfo->first);
+
+			QString valueText(iterInfo->second);
+
+			if (valueText.right(4) == ".xml")
+			{
+				value = new QLabel();
+				value->setText("<a href=\"" + iterInfo->second + "\">" + iterInfo->second + "</a>");
+				//connect the main window to the linkActivated signal
+				connect(value, SIGNAL(linkActivated(QString)), MainWindow::instance(), SLOT(importEasaierLayer(QString)));
+
+			} else {
+				value = new QLabel(iterInfo->second);
+			}
+			
+			m_infoLayout->addWidget(proper, row, 0);
+			m_infoLayout->addWidget(value, row, 1);
+			row++;
+		}
+	}
+
 	m_infoLayout->setColumnStretch( 1, 1);
 }
--- a/widgets/QueryResultsWidget.cpp	Thu Jun 28 16:19:29 2007 +0000
+++ b/widgets/QueryResultsWidget.cpp	Thu Jun 28 16:57:29 2007 +0000
@@ -73,24 +73,37 @@
 	QLabel* result = new QLabel();
 
 	QString text;
+	QString uri = "";
 
 	for (iter = m_curResult.begin(); iter != m_curResult.end(); iter++)
 	{
-		text += "<br>" ;
-		text += (*iter).name;
-		text += " : " ;
-		if (((*iter).value.left(4) == "http") && ((*iter).value.right(4) == ".xml"))
+		if ((*iter).name == "identification")
 		{
-			text += "<a href=\"";
-			text += (*iter).value;
-			text += "\">";
-			text += (*iter).value;
-			text += "</a>";
-		} else 
+			uri = (*iter).value;
+			uri = uri.right(uri.length() - uri.lastIndexOf("#") - 1);
+		}
+	}
+
+	for (iter = m_curResult.begin(); iter != m_curResult.end(); iter++)
+	{
+		if ((*iter).name != "identification")
 		{
-			text += (*iter).value;
+			text += "<br>" ;
+			text += (*iter).name;
+			text += " : " ;
+			if ((*iter).name == "title")
+			{
+				text += "<a href=\"";
+				text += uri;
+				text += "\">";
+				text += (*iter).value;
+				text += "</a>";
+			} else 
+			{
+				text += (*iter).value;
+			}
+			text += "</br>" ;
 		}
-		text += "</br>" ;
 	}
 	
 	connect(result, SIGNAL(linkActivated(QString)), MainWindow::instance(), SLOT(importEasaierFile(QString)));