lbarthelemy@247: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ lbarthelemy@247: lbarthelemy@247: /* Sound Access lbarthelemy@247: EASAIER client application. lbarthelemy@247: Silogic 2007. Laure Bajard. lbarthelemy@247: lbarthelemy@247: This program is free software; you can redistribute it and/or lbarthelemy@247: modify it under the terms of the GNU General Public License as lbarthelemy@247: published by the Free Software Foundation; either version 2 of the lbarthelemy@247: License, or (at your option) any later version. See the file lbarthelemy@247: COPYING included with this distribution for more information. lbarthelemy@247: */ lbarthelemy@247: lbarthelemy@247: #include "EasaierSessionManager.h" lbarthelemy@247: lbarthelemy@247: #include lbarthelemy@247: #include lbarthelemy@247: #include lbarthelemy@247: #include lbarthelemy@247: #include lbarthelemy@247: #include lbarthelemy@247: lbarthelemy@247: #include lbarthelemy@247: #include lbarthelemy@247: #include lbarthelemy@247: lbarthelemy@247: #include "layer/Layer.h" lbarthelemy@247: #include "base/TempDirectory.h" lbarthelemy@247: #include "data/fileio/AudioSourceInfoReader.h" lbarthelemy@247: #include "data/fileio/ModelReader.h" lbarthelemy@247: #include "data/fileio/QueryConfigReader.h" lbarthelemy@247: #include "data/fileio/SparqlResultsReader.h" lbarthelemy@247: #include "data/fileio/SparqlRelatedMediaReader.h" lbarthelemy@247: #include "data/fileio/VideoFileReaderFactory.h" lbarthelemy@247: #include "data/model/WaveFileModel.h" lbarthelemy@247: #include "main/MainWindow.h" lbarthelemy@247: #include "widgets/QueryResultsWidget.h" lbarthelemy@247: #include "widgets/RelatedMediaWidget.h" lbarthelemy@247: #include "base/PropertyContainer.h" lbarthelemy@247: #include "data/fileio/AudioFileReaderFactory.h" lbarthelemy@247: lbarthelemy@247: EasaierSessionManager::EasaierSessionManager(HttpClient* httpClient) : QObject(), lbarthelemy@247: m_fileName(""), lbarthelemy@247: m_httpClient(httpClient), lbarthelemy@247: m_document(0), lbarthelemy@247: m_audioSourceInfoModel(0), lbarthelemy@247: m_queryModel(0), lbarthelemy@247: m_currentPane(0) lbarthelemy@247: { lbarthelemy@247: connect(m_httpClient, SIGNAL(requestFinished(int, bool)), this, SLOT(fileLoaded(int, bool))); lbarthelemy@247: } lbarthelemy@247: lbarthelemy@247: EasaierSessionManager::~EasaierSessionManager() lbarthelemy@247: { lbarthelemy@247: closeSession(); lbarthelemy@247: m_httpClient = 0; lbarthelemy@247: } lbarthelemy@247: lbarthelemy@247: bool EasaierSessionManager::newSession() lbarthelemy@247: { lbarthelemy@247: closeSession(); lbarthelemy@247: lbarthelemy@247: m_queryModel = new QueryModel(); lbarthelemy@247: QString filename = "/data/query/queryfield.xml"; lbarthelemy@247: QString query = m_httpClient->getServletName() + "?theme=getFile&fileName=data/query/queryfield.xml"; lbarthelemy@247: loadFile(query, filename, LoadedFile::QUERY_CONFIG); lbarthelemy@247: lbarthelemy@247: return true; lbarthelemy@247: } lbarthelemy@247: lbarthelemy@247: bool EasaierSessionManager::openSession(Document *document) lbarthelemy@247: { lbarthelemy@247: newSession(); lbarthelemy@247: lbarthelemy@247: m_fileName = document->getAudioSourceInfoFileName(); lbarthelemy@247: m_document = document; lbarthelemy@247: lbajardsilogic@250: //QString params = "&identification=" + m_fileName; lbajardsilogic@250: QString params = "&signal=" + m_fileName; lbarthelemy@247: lbajardsilogic@250: //QString query = m_httpClient->getServletName() + "?theme=infoFile"+params; lbajardsilogic@250: QString query = m_httpClient->getServletName() + "?theme=musicBySignal"+params; lbajardsilogic@250: QString filename = "/easaier/servlet/musicBySignal"; lbarthelemy@247: loadFile(query, filename, LoadedFile::AUDIO_SOURCE_INFO); lbarthelemy@247: lbarthelemy@247: //get related media lbajardsilogic@250: /*query = m_httpClient->getServletName() + "?theme=relatedMedia" + params; lbarthelemy@247: filename = "/easaier/servlet/relatedMedia"; lbajardsilogic@250: loadFile(query, filename, LoadedFile::RELATED_MEDIA_LIST);*/ lbarthelemy@247: lbarthelemy@247: return true; lbarthelemy@247: } lbarthelemy@247: lbarthelemy@247: bool EasaierSessionManager::openAudioInfoFile(Document *document) lbarthelemy@247: { lbarthelemy@247: closeFile(); lbarthelemy@247: lbarthelemy@247: m_fileName = document->getAudioSourceInfoFileName(); lbarthelemy@247: m_document = document; lbarthelemy@247: lbajardsilogic@250: //QString params = "&identification=" + m_fileName; lbajardsilogic@250: QString params = "&signal=" + m_fileName; lbarthelemy@247: lbarthelemy@247: //get infofile lbajardsilogic@250: //QString query = m_httpClient->getServletName() + "?theme=infoFile" + params; lbajardsilogic@250: QString query = m_httpClient->getServletName() + "?theme=musicBySignal" + params; lbajardsilogic@250: lbajardsilogic@250: //QString filename = "/easaier/servlet/infoFile"; lbajardsilogic@250: QString filename = "/easaier/servlet/musicBySignal"; lbajardsilogic@250: lbarthelemy@247: loadFile(query, filename, LoadedFile::AUDIO_SOURCE_INFO); lbarthelemy@247: lbarthelemy@247: //get related media lbarthelemy@247: lbajardsilogic@250: /*query = m_httpClient->getServletName() + "?theme=relatedMedia" + params; lbarthelemy@247: filename = "/easaier/servlet/relatedMedia"; lbajardsilogic@250: loadFile(query, filename, LoadedFile::RELATED_MEDIA_LIST);*/ lbarthelemy@247: lbarthelemy@247: return true; lbarthelemy@247: } lbarthelemy@247: lbarthelemy@247: void EasaierSessionManager::closeFile() lbarthelemy@247: { lbarthelemy@247: m_audioSourceInfoModel = 0; lbarthelemy@247: lbarthelemy@247: while (!m_loadFile.empty()) lbarthelemy@247: { lbarthelemy@247: m_loadFile.begin()->second->close(); lbarthelemy@247: delete m_loadFile.begin()->second; lbarthelemy@247: m_loadFile.erase(m_loadFile.begin()); lbarthelemy@247: } lbarthelemy@247: lbarthelemy@247: m_modelLoaded.clear(); lbarthelemy@247: } lbarthelemy@247: lbarthelemy@247: void EasaierSessionManager::closeSession() lbarthelemy@247: { lbarthelemy@247: closeFile(); lbarthelemy@247: lbarthelemy@247: m_fileName = ""; lbarthelemy@247: m_document = 0; lbarthelemy@247: lbarthelemy@247: if (m_queryModel) lbarthelemy@247: { lbarthelemy@247: delete m_queryModel; lbarthelemy@247: m_queryModel = 0; lbarthelemy@247: } lbarthelemy@247: } lbarthelemy@247: lbarthelemy@247: void EasaierSessionManager::loadFile(const QString& queryAux, const QString& filename, LoadedFile::FileType type, const QString& postPath) lbarthelemy@247: { lbarthelemy@247: QFile * postFile = 0; lbarthelemy@247: lbarthelemy@247: if ((queryAux == 0) || (filename == 0)) lbarthelemy@247: return; lbarthelemy@247: lbarthelemy@247: if (m_httpClient->getHost() == "") lbarthelemy@247: return; lbarthelemy@247: lbarthelemy@247: QUrl url(queryAux); lbarthelemy@247: QString query = QString(url.toEncoded()); lbarthelemy@247: lbarthelemy@247: QString directory = filename.left(filename.lastIndexOf("/")); lbarthelemy@247: QString file = filename.right(filename.length() - filename.lastIndexOf("/")); lbarthelemy@247: lbarthelemy@247: if (directory.left(1) == "/") lbarthelemy@247: { lbarthelemy@247: directory.remove(0, 1); lbajardsilogic@250: }else if (directory.left(6) == "file:/") lbajardsilogic@250: { lbajardsilogic@250: directory.remove(0, 6); lbarthelemy@247: } lbarthelemy@247: lbarthelemy@247: //create the subdirectory in local lbarthelemy@247: QString localPath = TempDirectory::getInstance()->getSubDirectoryPath(directory); lbarthelemy@247: localPath.append(file); lbarthelemy@247: lbarthelemy@247: LoadedFile* newFile = new LoadedFile(localPath); lbarthelemy@247: newFile->setFileType(type); lbarthelemy@247: newFile->setUri(filename); lbarthelemy@247: lbarthelemy@247: if (postPath != "") lbarthelemy@247: { lbarthelemy@247: postFile = new QFile(postPath); lbarthelemy@247: } lbarthelemy@247: int index; lbarthelemy@247: index = m_httpClient->get(query,newFile ); lbarthelemy@247: lbarthelemy@247: std::cerr << "Ask for file : GET " << query.toStdString() << " - index : " << index << std::endl; lbarthelemy@247: lbarthelemy@247: m_loadFile[index] = newFile; lbarthelemy@247: lbarthelemy@247: if (type == LoadedFile::QUERY_RESULTS) lbarthelemy@247: MainWindow::instance()->statusBar()->showMessage(tr("Querying database...")); lbarthelemy@247: else if (type == LoadedFile::QUERY_CONFIG) lbarthelemy@247: MainWindow::instance()->statusBar()->showMessage(tr("Asking for query config...")); lbarthelemy@247: else lbarthelemy@247: MainWindow::instance()->statusBar()->showMessage(tr("Loading File : %1").arg(filename)); lbarthelemy@247: } lbarthelemy@247: lbarthelemy@247: void EasaierSessionManager::loadFile(const QByteArray& payload , const QString& filename, LoadedFile::FileType type, const QString& postPath) lbarthelemy@247: { lbarthelemy@247: QFile * postFile = 0; lbarthelemy@247: lbarthelemy@247: if (m_httpClient->getHost() == "") lbarthelemy@247: return; lbarthelemy@247: lbarthelemy@247: lbarthelemy@247: QString directory = filename.left(filename.lastIndexOf("/")); lbarthelemy@247: QString file = filename.right(filename.length() - filename.lastIndexOf("/")); lbarthelemy@247: lbarthelemy@247: if (directory.left(1) == "/") lbarthelemy@247: { lbarthelemy@247: directory.remove(0, 1); lbarthelemy@247: } lbarthelemy@247: lbarthelemy@247: //create the subdirectory in local lbarthelemy@247: QString localPath = TempDirectory::getInstance()->getSubDirectoryPath(directory); lbarthelemy@247: localPath.append(file); lbarthelemy@247: lbarthelemy@247: LoadedFile* newFile = new LoadedFile(localPath); lbarthelemy@247: newFile->setFileType(type); lbarthelemy@247: newFile->setUri(filename); lbarthelemy@247: lbarthelemy@247: int index; lbarthelemy@247: lbarthelemy@247: // build the header lbajardsilogic@248: /*QHttpRequestHeader header("POST", "/easaier/RetrieverService"); lbarthelemy@247: header.setValue("Host", "192.168.0.115"); //"easaier.silogic.fr"); lbajardsilogic@248: header.setValue("Port", "8080"); //"9875");*/ lbajardsilogic@248: QHttpRequestHeader header("POST", m_httpClient->getServletName()); lbajardsilogic@248: header.setValue("Host", m_httpClient->getHost()); lbajardsilogic@248: header.setValue("Port", QString::number(m_httpClient->getHostPort())); lbarthelemy@249: header.setContentType("multipart/form-data; boundary=7d44e178b0434"); lbarthelemy@247: header.setValue("Cache-Control", "no-cache"); lbarthelemy@247: header.setValue("Accept","*/*"); lbarthelemy@247: header.setContentLength(payload.length()); lbarthelemy@247: // lbarthelemy@247: lbarthelemy@247: index = m_httpClient->request(header, payload, newFile); lbarthelemy@247: lbarthelemy@247: std::cerr << "Ask for file : POST " << " - index : " << index << std::endl; lbarthelemy@247: lbarthelemy@247: m_loadFile[index] = newFile; lbarthelemy@247: lbarthelemy@247: if (type == LoadedFile::QUERY_RESULTS) lbarthelemy@247: MainWindow::instance()->statusBar()->showMessage(tr("Querying database...")); lbarthelemy@247: else if (type == LoadedFile::QUERY_CONFIG) lbarthelemy@247: MainWindow::instance()->statusBar()->showMessage(tr("Asking for query config...")); lbarthelemy@247: else lbarthelemy@247: MainWindow::instance()->statusBar()->showMessage(tr("Loading File : %1").arg(filename)); lbarthelemy@247: } lbarthelemy@247: lbarthelemy@247: void EasaierSessionManager::fileLoaded(int index, bool error) lbarthelemy@247: { lbarthelemy@247: QString errorString = m_httpClient->errorString(); lbarthelemy@247: std::map::iterator iter = m_loadFile.find(index); lbarthelemy@247: if (iter == m_loadFile.end()) lbarthelemy@247: { lbarthelemy@247: std::cerr << "fileLoaded() : file " << index << " not found. " << std::endl; lbarthelemy@247: return; lbarthelemy@247: } lbarthelemy@247: if (error) lbarthelemy@247: { lbarthelemy@247: QApplication::restoreOverrideCursor(); lbarthelemy@247: QMessageBox::critical(MainWindow::instance(), tr("Download Failed"), m_httpClient->errorString()); lbarthelemy@247: return; lbarthelemy@247: } lbarthelemy@247: bool read = false; lbarthelemy@247: lbarthelemy@247: //retreive loaded file lbarthelemy@247: LoadedFile* loadedFile = iter->second; lbarthelemy@247: loadedFile->close(); lbarthelemy@247: lbarthelemy@247: //save type and filename for reading lbarthelemy@247: LoadedFile::FileType type = loadedFile->getFileType(); lbarthelemy@247: QString filename = loadedFile->fileName(); lbarthelemy@247: QString uri = loadedFile->getUri(); lbarthelemy@247: lbarthelemy@247: //delete de file and erase from the loaded file queue lbarthelemy@247: delete loadedFile; lbarthelemy@247: m_loadFile.erase(iter); lbarthelemy@247: loadedFile = 0; lbarthelemy@247: lbarthelemy@247: std::cerr << "fileLoaded() : file loaded, start to read file " << index << std::endl; lbarthelemy@247: lbarthelemy@247: if ((type == LoadedFile::QUERY_RESULTS) || (type == LoadedFile::QUERY_CONFIG)) lbarthelemy@247: { lbarthelemy@247: MainWindow::instance()->statusBar()->clearMessage(); lbarthelemy@247: } lbarthelemy@247: else lbarthelemy@247: { lbarthelemy@247: QString name = filename.right(filename.length() - filename.lastIndexOf("/")); lbarthelemy@247: MainWindow::instance()->statusBar()->showMessage(tr("File Loaded : %1").arg(name), 3000); lbarthelemy@247: } lbarthelemy@247: lbarthelemy@247: //read and load (in m_document) the file according to its type lbarthelemy@247: switch (type) { lbarthelemy@247: lbarthelemy@247: case LoadedFile::AUDIO_SOURCE_INFO : lbarthelemy@247: { lbarthelemy@247: m_audioSourceInfoModel = new AudioSourceInfoModel(); lbarthelemy@247: AudioSourceInfoReader audioSourceInfoReader(m_audioSourceInfoModel); lbarthelemy@247: read = audioSourceInfoReader.parse(filename); lbarthelemy@247: if (read) lbarthelemy@247: { lbarthelemy@247: m_document->setAudioSourceInfoModel(m_audioSourceInfoModel); lbarthelemy@247: loadRelatedModel(); lbarthelemy@247: } lbarthelemy@247: break; lbarthelemy@247: } lbarthelemy@247: case LoadedFile::MODEL : lbarthelemy@247: { lbarthelemy@247: QString modelName = m_audioSourceInfoModel->getKey(uri); lbarthelemy@247: lbarthelemy@247: read = addModelToLayers(modelName, filename); lbarthelemy@247: lbarthelemy@247: break; lbarthelemy@247: } lbarthelemy@247: case LoadedFile::METADATA : lbarthelemy@247: { lbarthelemy@247: ModelReader modelReader(m_document,0, m_currentPane); lbarthelemy@247: read = modelReader.parse(filename); lbarthelemy@247: lbarthelemy@247: break; lbarthelemy@247: } lbarthelemy@247: case LoadedFile::QUERY_CONFIG : lbarthelemy@247: { lbarthelemy@247: QueryConfigReader reader(m_queryModel); lbarthelemy@247: bool ok = reader.parse(filename); lbarthelemy@247: lbarthelemy@247: if (ok) lbarthelemy@247: emit queryModelLoaded(m_queryModel); lbarthelemy@247: lbarthelemy@247: read = ok; lbarthelemy@247: break; lbarthelemy@247: } lbarthelemy@247: case LoadedFile::QUERY_RESULTS : lbarthelemy@247: { lbarthelemy@247: QueryResultsWidget* resultsWidget = MainWindow::instance()->getQueryResultsWidget(); lbarthelemy@247: resultsWidget->reset(); lbarthelemy@247: lbarthelemy@247: if (resultsWidget) lbarthelemy@247: { lbarthelemy@247: SparqlResultsReader reader(resultsWidget); lbarthelemy@247: read = reader.parse(filename); lbarthelemy@247: } lbarthelemy@247: break; lbarthelemy@247: } lbarthelemy@247: case LoadedFile::RELATED_MEDIA_LIST : lbarthelemy@247: { lbarthelemy@247: std::list relMediaList; lbarthelemy@247: SparqlRelatedMediaReader reader(&relMediaList); lbarthelemy@247: read = reader.parse(filename); lbarthelemy@247: importRelatedMedia(&relMediaList); lbarthelemy@247: break; lbarthelemy@247: } lbarthelemy@247: case LoadedFile::RELATED_MEDIA : lbarthelemy@247: { lbarthelemy@247: read = true; lbarthelemy@247: RelatedMediaWidget* relMediaWidget = MainWindow::instance()->getRelatedMediaWidget(); lbarthelemy@247: relMediaWidget->addRelatedMedia(filename); lbarthelemy@247: break; lbarthelemy@247: } lbarthelemy@247: default: break; lbarthelemy@247: } lbarthelemy@247: lbarthelemy@247: //if the file could not be read by any reader lbarthelemy@247: if (!read) lbarthelemy@247: { lbarthelemy@247: QFile file(filename); lbarthelemy@247: if (file.open(QFile::ReadOnly)) { lbarthelemy@247: QApplication::restoreOverrideCursor(); lbarthelemy@247: QMessageBox::critical(MainWindow::instance(), tr("Download Error"), file.readAll()); lbarthelemy@247: } lbarthelemy@247: } lbarthelemy@247: else { lbarthelemy@247: std::cerr << "fileLoaded() : " << index << " all successful. " << std::endl; lbarthelemy@247: } lbarthelemy@247: QApplication::restoreOverrideCursor(); lbarthelemy@247: } lbarthelemy@247: lbarthelemy@247: void EasaierSessionManager::loadRelatedModel() lbarthelemy@247: { lbarthelemy@247: std::set layers = m_document->getLayers(); lbarthelemy@247: std::set::iterator iter; lbarthelemy@247: lbarthelemy@247: std::set loadedModel; lbarthelemy@247: lbarthelemy@247: for (iter=layers.begin(); iter != layers.end(); iter++) lbarthelemy@247: { lbarthelemy@247: Layer * layer = *iter; lbarthelemy@247: lbarthelemy@247: QString modelName = layer->getModelName(); lbarthelemy@247: if (modelName != "") lbarthelemy@247: { lbarthelemy@247: QString modelId = QString::number(layer->getModelId()); lbarthelemy@247: //modelName.append(modelId); lbarthelemy@247: lbarthelemy@247: } else if (layer->getLayerPresentationName() == "Waveform") lbarthelemy@247: { lbarthelemy@247: //modelName = "http://purl.org/dc/elements/1.1/source"; lbarthelemy@247: modelName = "available_as"; lbarthelemy@247: int modelId = 1; lbarthelemy@247: layer->setModelName(modelName); lbarthelemy@247: layer->setModelId(modelId); lbarthelemy@247: //modelName.append(QString::number(modelId)); lbarthelemy@247: } lbarthelemy@247: lbarthelemy@247: if (modelName != "") lbarthelemy@247: { lbarthelemy@247: QString uri = m_audioSourceInfoModel->getInfo(modelName)->at(0); lbajardsilogic@250: uri.remove("file:/"); lbajardsilogic@250: uri.replace(".wma", ".mp3"); lbarthelemy@247: lbarthelemy@247: QString query = m_httpClient->getServletName() + "?theme=getFile&fileName="+uri; lbarthelemy@247: lbarthelemy@247: std::set::iterator iterModel = m_modelLoaded.find(uri); lbarthelemy@247: lbarthelemy@247: if (iterModel == m_modelLoaded.end()) lbarthelemy@247: { lbajardsilogic@250: m_modelLoaded.insert(uri); lbarthelemy@247: loadFile(query, uri, LoadedFile::MODEL); lbarthelemy@247: } lbarthelemy@247: } lbarthelemy@247: } lbarthelemy@247: } lbarthelemy@247: lbarthelemy@247: bool EasaierSessionManager::addModelToLayers(const QString& name, const QString& filename) lbarthelemy@247: { lbarthelemy@247: std::set layers = m_document->getLayers(); lbarthelemy@247: std::set::iterator iter; lbarthelemy@247: lbarthelemy@247: std::map addedModel; lbarthelemy@247: lbarthelemy@247: bool ok = false; lbarthelemy@247: lbarthelemy@247: for (iter=layers.begin(); iter != layers.end(); iter++) lbarthelemy@247: { lbarthelemy@247: Layer * layer = *iter; lbarthelemy@247: lbarthelemy@247: QString modelName = layer->getModelName(); lbarthelemy@247: QString modelId = QString::number(layer->getModelId()); lbarthelemy@247: lbarthelemy@247: //modelName.append(modelId); lbarthelemy@247: modelName = modelName.toLower(); lbarthelemy@247: lbarthelemy@247: if (modelName == name) lbarthelemy@247: { lbarthelemy@247: std::map::iterator iterModel; lbarthelemy@247: iterModel = addedModel.find(modelName); lbarthelemy@247: lbarthelemy@247: if (iterModel == addedModel.end()) lbarthelemy@247: { lbarthelemy@247: QString extension = filename.right(filename.length()-filename.lastIndexOf(".")-1); lbarthelemy@247: if (AudioFileReaderFactory::isKnownExtensions(extension)) lbarthelemy@247: { lbarthelemy@247: WaveFileModel *model = new WaveFileModel(filename); lbarthelemy@247: m_document->setMainModel(model); lbarthelemy@247: addedModel[modelName] = (Model* ) model; lbarthelemy@247: ok = true; lbarthelemy@247: emit audioFileLoaded(); lbarthelemy@247: } lbarthelemy@247: #ifdef HAVE_VIDEO lbarthelemy@247: else if (VideoFileReaderFactory::isKnownExtensions(extension)) lbarthelemy@247: { lbarthelemy@247: ok = !(MainWindow::instance()->openVideoFile(filename, MainWindow::ReplaceMainModel)); lbarthelemy@247: emit audioFileLoaded(); lbarthelemy@247: } lbarthelemy@247: #endif lbarthelemy@247: else lbarthelemy@247: { lbarthelemy@247: ModelReader modelReader(m_document, layer); lbarthelemy@247: ok = modelReader.parse(filename); lbarthelemy@247: } lbarthelemy@247: } lbarthelemy@247: else lbarthelemy@247: { lbarthelemy@247: Model* model = iterModel->second; lbarthelemy@247: m_document->addImportedModel(model); lbarthelemy@247: m_document->setModel(layer, model); lbarthelemy@247: } lbarthelemy@247: } lbarthelemy@247: } lbarthelemy@247: lbarthelemy@247: return ok; lbarthelemy@247: } lbarthelemy@247: lbarthelemy@247: void EasaierSessionManager::importMetadata(const QString& filename, Pane* pane) lbarthelemy@247: { lbajardsilogic@251: QString query = m_httpClient->getServletName() + "?theme=getTimeLine&signal="+m_document->getAudioSourceInfoFileName()+"&event_label="+filename; lbarthelemy@247: lbajardsilogic@251: QString file = "metadata/" + filename + ".txt"; lbajardsilogic@251: lbajardsilogic@251: loadFile( query, file, LoadedFile::METADATA); lbarthelemy@247: lbarthelemy@247: m_currentPane = pane; lbarthelemy@247: } lbarthelemy@247: lbarthelemy@247: void EasaierSessionManager::importRelatedMedia(std::list *relMediaList) lbarthelemy@247: { lbarthelemy@247: QString filename; lbarthelemy@247: QString query; lbarthelemy@247: lbarthelemy@247: std::list::iterator iter; lbarthelemy@247: for (iter = relMediaList->begin(); iter != relMediaList->end(); iter++) lbarthelemy@247: { lbarthelemy@247: filename = *iter; lbarthelemy@247: lbarthelemy@247: query = m_httpClient->getServletName() + "?theme=getFile&fileName=" + filename; lbarthelemy@247: lbarthelemy@247: loadFile( query, filename, LoadedFile::RELATED_MEDIA); lbarthelemy@247: } lbarthelemy@247: } lbarthelemy@247: lbarthelemy@247: void EasaierSessionManager::queryDatabase(const QString& themeName) lbarthelemy@247: { lbarthelemy@247: lbarthelemy@247: QueryThemeModel *themeModel = (m_queryModel->getThemes()).find(themeName)->second; lbarthelemy@247: QString postFilePath = ""; lbarthelemy@247: lbarthelemy@247: //for the post lbarthelemy@247: QString boundary="7d44e178b0434"; lbarthelemy@247: QString endline="\r\n"; lbarthelemy@247: QString start_delim="--"+boundary+endline; lbarthelemy@249: QString cont_disp_str="Content-Disposition: form-data;"; lbarthelemy@247: lbarthelemy@247: QByteArray *payload = new QByteArray(); lbarthelemy@247: QDataStream data_stream(payload, QFile::WriteOnly | QFile::Unbuffered); lbarthelemy@247: ///////// lbarthelemy@247: lbarthelemy@249: QString param = start_delim + cont_disp_str + "name=" + "\"theme\"" + endline+endline+themeName+endline; lbarthelemy@247: data_stream.writeRawData(param.toStdString().c_str(),param.toStdString().length()); lbarthelemy@247: lbarthelemy@247: if(themeModel!=0){ lbarthelemy@247: lbarthelemy@247: PropertyContainer::PropertyList propertyList = themeModel->getProperties(); lbarthelemy@247: for(int i=0; i< ((int) propertyList.size());i++){ lbarthelemy@247: if (themeModel->getPropertyType(propertyList[i]) == PropertyContainer::FileProperty) lbarthelemy@247: { lbarthelemy@249: // We are here dealing with a filePath lbarthelemy@247: postFilePath = themeModel->getPropertyValue(propertyList[i]); lbarthelemy@247: if(postFilePath!=""){ lbarthelemy@247: QString only_filename = postFilePath.section( '/', -1 ); lbarthelemy@247: QString param = start_delim + cont_disp_str + "name=" + "\""+propertyList[i]+"\""+"; filename="+"\""+only_filename+"\""+endline+"Content-Type: application/octet-stream"+endline+endline; lbarthelemy@247: data_stream.writeRawData(param.toStdString().c_str(),param.toStdString().length()); lbarthelemy@247: lbarthelemy@247: QFile file(postFilePath); lbarthelemy@249: if (file.open( QFile::ReadOnly )) { lbarthelemy@249: while (!file.atEnd()) { lbarthelemy@249: QByteArray line = file.readLine(); lbarthelemy@249: data_stream.writeRawData(line.data(),line.length()); lbarthelemy@249: } lbarthelemy@249: file.close(); lbarthelemy@247: } lbarthelemy@247: } lbarthelemy@247: } lbarthelemy@247: else{ lbarthelemy@249: // Normal parameter lbarthelemy@249: QString param = start_delim + cont_disp_str + "name=" + "\"" + propertyList[i]+ "\"" + endline+endline+themeModel->getPropertyValue(propertyList[i])+endline; lbarthelemy@247: data_stream.writeRawData(param.toStdString().c_str(),param.toStdString().length()); lbarthelemy@247: } lbarthelemy@247: } lbajardsilogic@255: //bug for the last field - add an unused field lbajardsilogic@255: QString param = start_delim + cont_disp_str + "name=" + "\"toto\"" + endline+endline+""+endline; lbajardsilogic@255: data_stream.writeRawData(param.toStdString().c_str(),param.toStdString().length()); lbajardsilogic@255: lbarthelemy@247: QString stop_delim=endline+"--"+boundary+"--"+endline; lbarthelemy@247: data_stream.writeRawData(stop_delim.toStdString().c_str(),stop_delim.toStdString().length()); lbarthelemy@247: } lbarthelemy@247: QString filename = "/easaier/servlet/"+themeName; lbarthelemy@247: lbarthelemy@247: QApplication::setOverrideCursor( Qt::WaitCursor ); lbarthelemy@247: loadFile(*payload, filename, LoadedFile::QUERY_RESULTS, postFilePath); lbarthelemy@247: }