lbarthelemy@247
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
lbarthelemy@247
|
2
|
lbarthelemy@247
|
3 /* Sound Access
|
lbarthelemy@247
|
4 EASAIER client application.
|
lbarthelemy@247
|
5 Silogic 2007. Laure Bajard.
|
lbarthelemy@247
|
6
|
lbarthelemy@247
|
7 This program is free software; you can redistribute it and/or
|
lbarthelemy@247
|
8 modify it under the terms of the GNU General Public License as
|
lbarthelemy@247
|
9 published by the Free Software Foundation; either version 2 of the
|
lbarthelemy@247
|
10 License, or (at your option) any later version. See the file
|
lbarthelemy@247
|
11 COPYING included with this distribution for more information.
|
lbarthelemy@247
|
12 */
|
lbarthelemy@247
|
13
|
lbarthelemy@247
|
14 #include "EasaierSessionManager.h"
|
lbarthelemy@247
|
15
|
lbarthelemy@247
|
16 #include <QUrl>
|
lbarthelemy@247
|
17 #include <QMessageBox>
|
lbarthelemy@247
|
18 #include <QTextStream>
|
lbarthelemy@247
|
19 #include <iostream>
|
lbarthelemy@247
|
20 #include <QStatusBar>
|
lbarthelemy@247
|
21 #include <vector>
|
lbarthelemy@247
|
22
|
lbarthelemy@247
|
23 #include <QApplication>
|
lbarthelemy@247
|
24 #include <Qt>
|
lbarthelemy@247
|
25 #include <QUrl>
|
lbarthelemy@247
|
26
|
lbarthelemy@247
|
27 #include "layer/Layer.h"
|
lbarthelemy@247
|
28 #include "base/TempDirectory.h"
|
lbarthelemy@247
|
29 #include "data/fileio/AudioSourceInfoReader.h"
|
lbarthelemy@247
|
30 #include "data/fileio/ModelReader.h"
|
lbarthelemy@247
|
31 #include "data/fileio/QueryConfigReader.h"
|
lbarthelemy@247
|
32 #include "data/fileio/SparqlResultsReader.h"
|
lbarthelemy@247
|
33 #include "data/fileio/SparqlRelatedMediaReader.h"
|
lbarthelemy@247
|
34 #include "data/fileio/VideoFileReaderFactory.h"
|
lbarthelemy@247
|
35 #include "data/model/WaveFileModel.h"
|
lbarthelemy@247
|
36 #include "main/MainWindow.h"
|
lbarthelemy@247
|
37 #include "widgets/QueryResultsWidget.h"
|
lbarthelemy@247
|
38 #include "widgets/RelatedMediaWidget.h"
|
lbarthelemy@247
|
39 #include "base/PropertyContainer.h"
|
lbarthelemy@247
|
40 #include "data/fileio/AudioFileReaderFactory.h"
|
benoitrigolleau@263
|
41 #include "widgets/SpeechRecognitionUI.h"
|
lbarthelemy@247
|
42
|
benoitrigolleau@262
|
43 #include "widgets/SpeechFileHandler.h"
|
benoitrigolleau@262
|
44 #include <QMessageBox>
|
benoitrigolleau@262
|
45
|
lbarthelemy@247
|
46 EasaierSessionManager::EasaierSessionManager(HttpClient* httpClient) : QObject(),
|
lbarthelemy@247
|
47 m_fileName(""),
|
lbarthelemy@247
|
48 m_httpClient(httpClient),
|
lbarthelemy@247
|
49 m_document(0),
|
lbarthelemy@247
|
50 m_audioSourceInfoModel(0),
|
lbarthelemy@247
|
51 m_queryModel(0),
|
lbarthelemy@247
|
52 m_currentPane(0)
|
lbarthelemy@247
|
53 {
|
lbarthelemy@247
|
54 connect(m_httpClient, SIGNAL(requestFinished(int, bool)), this, SLOT(fileLoaded(int, bool)));
|
lbarthelemy@247
|
55 }
|
lbarthelemy@247
|
56
|
lbarthelemy@247
|
57 EasaierSessionManager::~EasaierSessionManager()
|
lbarthelemy@247
|
58 {
|
lbarthelemy@247
|
59 closeSession();
|
lbarthelemy@247
|
60 m_httpClient = 0;
|
lbarthelemy@247
|
61 }
|
lbarthelemy@247
|
62
|
lbarthelemy@247
|
63 bool EasaierSessionManager::newSession()
|
lbarthelemy@247
|
64 {
|
lbarthelemy@247
|
65 closeSession();
|
lbarthelemy@247
|
66
|
lbarthelemy@247
|
67 m_queryModel = new QueryModel();
|
lbarthelemy@247
|
68 QString filename = "/data/query/queryfield.xml";
|
lbarthelemy@247
|
69 QString query = m_httpClient->getServletName() + "?theme=getFile&fileName=data/query/queryfield.xml";
|
lbarthelemy@247
|
70 loadFile(query, filename, LoadedFile::QUERY_CONFIG);
|
lbarthelemy@247
|
71
|
lbarthelemy@247
|
72 return true;
|
lbarthelemy@247
|
73 }
|
lbarthelemy@247
|
74
|
lbarthelemy@247
|
75 bool EasaierSessionManager::openSession(Document *document)
|
lbarthelemy@247
|
76 {
|
lbarthelemy@247
|
77 newSession();
|
lbarthelemy@247
|
78
|
lbarthelemy@247
|
79 m_fileName = document->getAudioSourceInfoFileName();
|
lbarthelemy@247
|
80 m_document = document;
|
lbarthelemy@247
|
81
|
lbajardsilogic@250
|
82 //QString params = "&identification=" + m_fileName;
|
lbajardsilogic@250
|
83 QString params = "&signal=" + m_fileName;
|
lbarthelemy@247
|
84
|
lbajardsilogic@250
|
85 //QString query = m_httpClient->getServletName() + "?theme=infoFile"+params;
|
lbajardsilogic@250
|
86 QString query = m_httpClient->getServletName() + "?theme=musicBySignal"+params;
|
lbajardsilogic@250
|
87 QString filename = "/easaier/servlet/musicBySignal";
|
lbarthelemy@247
|
88 loadFile(query, filename, LoadedFile::AUDIO_SOURCE_INFO);
|
lbarthelemy@247
|
89
|
lbarthelemy@247
|
90 //get related media
|
lbajardsilogic@257
|
91 query = m_httpClient->getServletName() + "?theme=relatedMedia" + params;
|
lbarthelemy@247
|
92 filename = "/easaier/servlet/relatedMedia";
|
lbajardsilogic@257
|
93 loadFile(query, filename, LoadedFile::RELATED_MEDIA_LIST);
|
lbarthelemy@247
|
94
|
lbarthelemy@247
|
95 return true;
|
lbarthelemy@247
|
96 }
|
lbarthelemy@247
|
97
|
lbarthelemy@247
|
98 bool EasaierSessionManager::openAudioInfoFile(Document *document)
|
lbarthelemy@247
|
99 {
|
lbarthelemy@247
|
100 closeFile();
|
lbarthelemy@247
|
101
|
lbarthelemy@247
|
102 m_fileName = document->getAudioSourceInfoFileName();
|
lbarthelemy@247
|
103 m_document = document;
|
lbarthelemy@247
|
104
|
lbajardsilogic@250
|
105 //QString params = "&identification=" + m_fileName;
|
lbajardsilogic@250
|
106 QString params = "&signal=" + m_fileName;
|
lbarthelemy@247
|
107
|
lbarthelemy@247
|
108 //get infofile
|
lbajardsilogic@250
|
109 //QString query = m_httpClient->getServletName() + "?theme=infoFile" + params;
|
lbajardsilogic@250
|
110 QString query = m_httpClient->getServletName() + "?theme=musicBySignal" + params;
|
lbajardsilogic@250
|
111
|
lbajardsilogic@250
|
112 //QString filename = "/easaier/servlet/infoFile";
|
lbajardsilogic@250
|
113 QString filename = "/easaier/servlet/musicBySignal";
|
lbajardsilogic@250
|
114
|
lbarthelemy@247
|
115 loadFile(query, filename, LoadedFile::AUDIO_SOURCE_INFO);
|
lbarthelemy@247
|
116
|
lbarthelemy@247
|
117 //get related media
|
lbarthelemy@247
|
118
|
lbajardsilogic@257
|
119 query = m_httpClient->getServletName() + "?theme=relatedMedia" + params;
|
lbarthelemy@247
|
120 filename = "/easaier/servlet/relatedMedia";
|
lbajardsilogic@257
|
121 loadFile(query, filename, LoadedFile::RELATED_MEDIA_LIST);
|
lbarthelemy@247
|
122
|
lbarthelemy@247
|
123 return true;
|
lbarthelemy@247
|
124 }
|
lbarthelemy@247
|
125
|
lbarthelemy@247
|
126 void EasaierSessionManager::closeFile()
|
lbarthelemy@247
|
127 {
|
lbarthelemy@247
|
128 m_audioSourceInfoModel = 0;
|
lbarthelemy@247
|
129
|
lbarthelemy@247
|
130 while (!m_loadFile.empty())
|
lbarthelemy@247
|
131 {
|
lbarthelemy@247
|
132 m_loadFile.begin()->second->close();
|
lbarthelemy@247
|
133 delete m_loadFile.begin()->second;
|
lbarthelemy@247
|
134 m_loadFile.erase(m_loadFile.begin());
|
lbarthelemy@247
|
135 }
|
lbarthelemy@247
|
136
|
lbarthelemy@247
|
137 m_modelLoaded.clear();
|
lbarthelemy@247
|
138 }
|
lbarthelemy@247
|
139
|
lbarthelemy@247
|
140 void EasaierSessionManager::closeSession()
|
lbarthelemy@247
|
141 {
|
lbarthelemy@247
|
142 closeFile();
|
lbarthelemy@247
|
143
|
lbarthelemy@247
|
144 m_fileName = "";
|
lbarthelemy@247
|
145 m_document = 0;
|
lbarthelemy@247
|
146
|
lbarthelemy@247
|
147 if (m_queryModel)
|
lbarthelemy@247
|
148 {
|
lbarthelemy@247
|
149 delete m_queryModel;
|
lbarthelemy@247
|
150 m_queryModel = 0;
|
lbarthelemy@247
|
151 }
|
lbarthelemy@247
|
152 }
|
lbarthelemy@247
|
153
|
lbarthelemy@247
|
154 void EasaierSessionManager::loadFile(const QString& queryAux, const QString& filename, LoadedFile::FileType type, const QString& postPath)
|
lbarthelemy@247
|
155 {
|
lbarthelemy@247
|
156 QFile * postFile = 0;
|
lbarthelemy@247
|
157
|
lbarthelemy@247
|
158 if ((queryAux == 0) || (filename == 0))
|
lbarthelemy@247
|
159 return;
|
lbarthelemy@247
|
160
|
lbarthelemy@247
|
161 if (m_httpClient->getHost() == "")
|
lbarthelemy@247
|
162 return;
|
lbarthelemy@247
|
163
|
lbarthelemy@247
|
164 QUrl url(queryAux);
|
lbarthelemy@247
|
165 QString query = QString(url.toEncoded());
|
lbarthelemy@247
|
166
|
lbarthelemy@247
|
167 QString directory = filename.left(filename.lastIndexOf("/"));
|
lbarthelemy@247
|
168 QString file = filename.right(filename.length() - filename.lastIndexOf("/"));
|
lbarthelemy@247
|
169
|
lbarthelemy@247
|
170 if (directory.left(1) == "/")
|
lbarthelemy@247
|
171 {
|
lbarthelemy@247
|
172 directory.remove(0, 1);
|
lbajardsilogic@250
|
173 }else if (directory.left(6) == "file:/")
|
lbajardsilogic@250
|
174 {
|
lbajardsilogic@250
|
175 directory.remove(0, 6);
|
lbarthelemy@247
|
176 }
|
lbarthelemy@247
|
177
|
lbarthelemy@247
|
178 //create the subdirectory in local
|
lbarthelemy@247
|
179 QString localPath = TempDirectory::getInstance()->getSubDirectoryPath(directory);
|
lbarthelemy@247
|
180 localPath.append(file);
|
lbarthelemy@247
|
181
|
lbarthelemy@247
|
182 LoadedFile* newFile = new LoadedFile(localPath);
|
lbarthelemy@247
|
183 newFile->setFileType(type);
|
lbarthelemy@247
|
184 newFile->setUri(filename);
|
lbarthelemy@247
|
185
|
lbarthelemy@247
|
186 if (postPath != "")
|
lbarthelemy@247
|
187 {
|
lbarthelemy@247
|
188 postFile = new QFile(postPath);
|
lbarthelemy@247
|
189 }
|
lbarthelemy@247
|
190 int index;
|
lbarthelemy@247
|
191 index = m_httpClient->get(query,newFile );
|
lbarthelemy@247
|
192
|
lbarthelemy@247
|
193 std::cerr << "Ask for file : GET " << query.toStdString() << " - index : " << index << std::endl;
|
lbarthelemy@247
|
194
|
lbarthelemy@247
|
195 m_loadFile[index] = newFile;
|
lbarthelemy@247
|
196
|
lbarthelemy@247
|
197 if (type == LoadedFile::QUERY_RESULTS)
|
lbarthelemy@247
|
198 MainWindow::instance()->statusBar()->showMessage(tr("Querying database..."));
|
lbarthelemy@247
|
199 else if (type == LoadedFile::QUERY_CONFIG)
|
lbarthelemy@247
|
200 MainWindow::instance()->statusBar()->showMessage(tr("Asking for query config..."));
|
lbarthelemy@247
|
201 else
|
lbarthelemy@247
|
202 MainWindow::instance()->statusBar()->showMessage(tr("Loading File : %1").arg(filename));
|
lbarthelemy@247
|
203 }
|
lbarthelemy@247
|
204
|
lbarthelemy@247
|
205 void EasaierSessionManager::loadFile(const QByteArray& payload , const QString& filename, LoadedFile::FileType type, const QString& postPath)
|
lbarthelemy@247
|
206 {
|
lbarthelemy@247
|
207 QFile * postFile = 0;
|
lbarthelemy@247
|
208
|
lbarthelemy@247
|
209 if (m_httpClient->getHost() == "")
|
lbarthelemy@247
|
210 return;
|
lbarthelemy@247
|
211
|
lbarthelemy@247
|
212
|
lbarthelemy@247
|
213 QString directory = filename.left(filename.lastIndexOf("/"));
|
lbarthelemy@247
|
214 QString file = filename.right(filename.length() - filename.lastIndexOf("/"));
|
lbarthelemy@247
|
215
|
lbarthelemy@247
|
216 if (directory.left(1) == "/")
|
lbarthelemy@247
|
217 {
|
lbarthelemy@247
|
218 directory.remove(0, 1);
|
lbarthelemy@247
|
219 }
|
lbarthelemy@247
|
220
|
lbarthelemy@247
|
221 //create the subdirectory in local
|
lbarthelemy@247
|
222 QString localPath = TempDirectory::getInstance()->getSubDirectoryPath(directory);
|
lbarthelemy@247
|
223 localPath.append(file);
|
lbarthelemy@247
|
224
|
lbarthelemy@247
|
225 LoadedFile* newFile = new LoadedFile(localPath);
|
lbarthelemy@247
|
226 newFile->setFileType(type);
|
lbarthelemy@247
|
227 newFile->setUri(filename);
|
lbarthelemy@247
|
228
|
lbarthelemy@247
|
229 int index;
|
lbarthelemy@247
|
230
|
lbarthelemy@247
|
231 // build the header
|
lbajardsilogic@248
|
232 QHttpRequestHeader header("POST", m_httpClient->getServletName());
|
lbajardsilogic@248
|
233 header.setValue("Host", m_httpClient->getHost());
|
lbajardsilogic@248
|
234 header.setValue("Port", QString::number(m_httpClient->getHostPort()));
|
lbarthelemy@249
|
235 header.setContentType("multipart/form-data; boundary=7d44e178b0434");
|
lbarthelemy@247
|
236 header.setValue("Cache-Control", "no-cache");
|
lbarthelemy@247
|
237 header.setValue("Accept","*/*");
|
lbarthelemy@247
|
238 header.setContentLength(payload.length());
|
lbarthelemy@247
|
239 //
|
lbarthelemy@247
|
240
|
lbarthelemy@247
|
241 index = m_httpClient->request(header, payload, newFile);
|
lbarthelemy@247
|
242
|
lbarthelemy@247
|
243 std::cerr << "Ask for file : POST " << " - index : " << index << std::endl;
|
lbarthelemy@247
|
244
|
lbarthelemy@247
|
245 m_loadFile[index] = newFile;
|
lbarthelemy@247
|
246
|
lbarthelemy@247
|
247 if (type == LoadedFile::QUERY_RESULTS)
|
lbarthelemy@247
|
248 MainWindow::instance()->statusBar()->showMessage(tr("Querying database..."));
|
lbarthelemy@247
|
249 else if (type == LoadedFile::QUERY_CONFIG)
|
lbarthelemy@247
|
250 MainWindow::instance()->statusBar()->showMessage(tr("Asking for query config..."));
|
lbarthelemy@247
|
251 else
|
lbarthelemy@247
|
252 MainWindow::instance()->statusBar()->showMessage(tr("Loading File : %1").arg(filename));
|
lbarthelemy@247
|
253 }
|
lbarthelemy@247
|
254
|
lbarthelemy@247
|
255 void EasaierSessionManager::fileLoaded(int index, bool error)
|
lbarthelemy@247
|
256 {
|
lbarthelemy@247
|
257 QString errorString = m_httpClient->errorString();
|
lbarthelemy@247
|
258 std::map<int , LoadedFile*>::iterator iter = m_loadFile.find(index);
|
lbarthelemy@247
|
259 if (iter == m_loadFile.end())
|
lbarthelemy@247
|
260 {
|
lbarthelemy@247
|
261 std::cerr << "fileLoaded() : file " << index << " not found. " << std::endl;
|
lbarthelemy@247
|
262 return;
|
lbarthelemy@247
|
263 }
|
lbarthelemy@247
|
264 if (error)
|
lbarthelemy@247
|
265 {
|
lbarthelemy@247
|
266 QApplication::restoreOverrideCursor();
|
lbarthelemy@247
|
267 QMessageBox::critical(MainWindow::instance(), tr("Download Failed"), m_httpClient->errorString());
|
lbarthelemy@247
|
268 return;
|
lbarthelemy@247
|
269 }
|
lbarthelemy@247
|
270 bool read = false;
|
lbarthelemy@247
|
271
|
lbarthelemy@247
|
272 //retreive loaded file
|
lbarthelemy@247
|
273 LoadedFile* loadedFile = iter->second;
|
lbarthelemy@247
|
274 loadedFile->close();
|
lbarthelemy@247
|
275
|
lbarthelemy@247
|
276 //save type and filename for reading
|
lbarthelemy@247
|
277 LoadedFile::FileType type = loadedFile->getFileType();
|
lbarthelemy@247
|
278 QString filename = loadedFile->fileName();
|
lbarthelemy@247
|
279 QString uri = loadedFile->getUri();
|
lbajardsilogic@261
|
280
|
lbarthelemy@247
|
281 //delete de file and erase from the loaded file queue
|
lbarthelemy@247
|
282 delete loadedFile;
|
lbarthelemy@247
|
283 m_loadFile.erase(iter);
|
lbarthelemy@247
|
284 loadedFile = 0;
|
lbarthelemy@247
|
285
|
lbarthelemy@247
|
286 std::cerr << "fileLoaded() : file loaded, start to read file " << index << std::endl;
|
lbarthelemy@247
|
287
|
lbarthelemy@247
|
288 if ((type == LoadedFile::QUERY_RESULTS) || (type == LoadedFile::QUERY_CONFIG))
|
lbarthelemy@247
|
289 {
|
lbarthelemy@247
|
290 MainWindow::instance()->statusBar()->clearMessage();
|
lbarthelemy@247
|
291 }
|
lbarthelemy@247
|
292 else
|
lbarthelemy@247
|
293 {
|
lbarthelemy@247
|
294 QString name = filename.right(filename.length() - filename.lastIndexOf("/"));
|
lbarthelemy@247
|
295 MainWindow::instance()->statusBar()->showMessage(tr("File Loaded : %1").arg(name), 3000);
|
lbarthelemy@247
|
296 }
|
lbarthelemy@247
|
297
|
lbarthelemy@247
|
298 //read and load (in m_document) the file according to its type
|
lbarthelemy@247
|
299 switch (type) {
|
lbarthelemy@247
|
300
|
lbarthelemy@247
|
301 case LoadedFile::AUDIO_SOURCE_INFO :
|
lbarthelemy@247
|
302 {
|
lbarthelemy@247
|
303 m_audioSourceInfoModel = new AudioSourceInfoModel();
|
lbarthelemy@247
|
304 AudioSourceInfoReader audioSourceInfoReader(m_audioSourceInfoModel);
|
lbarthelemy@247
|
305 read = audioSourceInfoReader.parse(filename);
|
lbajardsilogic@259
|
306 if (read && !m_audioSourceInfoModel->isEmpty() )
|
lbarthelemy@247
|
307 {
|
lbarthelemy@247
|
308 m_document->setAudioSourceInfoModel(m_audioSourceInfoModel);
|
lbarthelemy@247
|
309 loadRelatedModel();
|
lbarthelemy@247
|
310 }
|
lbarthelemy@247
|
311 break;
|
lbarthelemy@247
|
312 }
|
lbarthelemy@247
|
313 case LoadedFile::MODEL :
|
lbarthelemy@247
|
314 {
|
lbajardsilogic@261
|
315 QString modelName = "";
|
lbajardsilogic@261
|
316 if (uri.left(5) == "/data")
|
lbajardsilogic@261
|
317 {
|
lbajardsilogic@261
|
318 modelName = m_audioSourceInfoModel->getKey("file:/" + uri);
|
lbajardsilogic@261
|
319 }
|
lbajardsilogic@261
|
320 else
|
lbajardsilogic@261
|
321 {
|
lbajardsilogic@261
|
322 modelName = uri.right(uri.length() - uri.lastIndexOf('/') -1);
|
lbajardsilogic@261
|
323 modelName.remove(".txt");
|
lbajardsilogic@261
|
324 }
|
lbarthelemy@247
|
325
|
lbarthelemy@247
|
326 read = addModelToLayers(modelName, filename);
|
lbarthelemy@247
|
327
|
lbarthelemy@247
|
328 break;
|
lbarthelemy@247
|
329 }
|
lbarthelemy@247
|
330 case LoadedFile::METADATA :
|
lbarthelemy@247
|
331 {
|
lbarthelemy@247
|
332 ModelReader modelReader(m_document,0, m_currentPane);
|
lbarthelemy@247
|
333 read = modelReader.parse(filename);
|
lbarthelemy@247
|
334
|
lbarthelemy@247
|
335 break;
|
lbarthelemy@247
|
336 }
|
lbarthelemy@247
|
337 case LoadedFile::QUERY_CONFIG :
|
lbarthelemy@247
|
338 {
|
lbarthelemy@247
|
339 QueryConfigReader reader(m_queryModel);
|
lbarthelemy@247
|
340 bool ok = reader.parse(filename);
|
lbarthelemy@247
|
341
|
lbarthelemy@247
|
342 if (ok)
|
lbarthelemy@247
|
343 emit queryModelLoaded(m_queryModel);
|
lbarthelemy@247
|
344
|
lbarthelemy@247
|
345 read = ok;
|
lbarthelemy@247
|
346 break;
|
lbarthelemy@247
|
347 }
|
lbarthelemy@247
|
348 case LoadedFile::QUERY_RESULTS :
|
lbarthelemy@247
|
349 {
|
benoitrigolleau@280
|
350 QueryResultsWidget* resultsWidget = MainWindow::instance()->getQueryResultsWidget();
|
lbarthelemy@247
|
351 resultsWidget->reset();
|
lbarthelemy@247
|
352
|
lbarthelemy@247
|
353 if (resultsWidget)
|
lbarthelemy@247
|
354 {
|
benoitrigolleau@280
|
355 SparqlResultsReader reader(resultsWidget);
|
benoitrigolleau@280
|
356 read = reader.parse(filename);
|
benoitrigolleau@280
|
357 }
|
lbarthelemy@247
|
358 break;
|
lbarthelemy@247
|
359 }
|
lbarthelemy@247
|
360 case LoadedFile::RELATED_MEDIA_LIST :
|
lbarthelemy@247
|
361 {
|
lbajardsilogic@257
|
362 m_relMediaList.clear();
|
lbajardsilogic@257
|
363 SparqlRelatedMediaReader reader(&m_relMediaList);
|
lbarthelemy@247
|
364 read = reader.parse(filename);
|
lbajardsilogic@257
|
365 importRelatedMedia(&m_relMediaList);
|
lbarthelemy@247
|
366 break;
|
lbarthelemy@247
|
367 }
|
lbarthelemy@247
|
368 case LoadedFile::RELATED_MEDIA :
|
lbarthelemy@247
|
369 {
|
lbarthelemy@247
|
370 read = true;
|
lbarthelemy@247
|
371 RelatedMediaWidget* relMediaWidget = MainWindow::instance()->getRelatedMediaWidget();
|
lbajardsilogic@257
|
372 relMediaWidget->addRelatedMedia(filename, m_relMediaList);
|
lbarthelemy@247
|
373 break;
|
lbarthelemy@247
|
374 }
|
benoitrigolleau@262
|
375 case LoadedFile::VOCAL_QUERY :
|
benoitrigolleau@262
|
376 {
|
benoitrigolleau@262
|
377 QFile file;
|
benoitrigolleau@262
|
378 QXmlInputSource *inputSource;
|
benoitrigolleau@262
|
379 QXmlSimpleReader reader;
|
benoitrigolleau@262
|
380 SpeechFileHandler handler;
|
benoitrigolleau@262
|
381 file.setFileName(filename);
|
benoitrigolleau@262
|
382 inputSource= new QXmlInputSource(&file);
|
benoitrigolleau@262
|
383 reader.setContentHandler(&handler);
|
benoitrigolleau@263
|
384 read=reader.parse(inputSource);
|
benoitrigolleau@263
|
385 MainWindow::instance()->getSpeechRecognitionUI()->setResult(handler.getResult());
|
benoitrigolleau@262
|
386 }
|
lbarthelemy@247
|
387 default: break;
|
lbarthelemy@247
|
388 }
|
lbarthelemy@247
|
389
|
lbarthelemy@247
|
390 //if the file could not be read by any reader
|
lbarthelemy@247
|
391 if (!read)
|
lbarthelemy@247
|
392 {
|
lbarthelemy@247
|
393 QFile file(filename);
|
lbarthelemy@247
|
394 if (file.open(QFile::ReadOnly)) {
|
lbarthelemy@247
|
395 QApplication::restoreOverrideCursor();
|
lbarthelemy@247
|
396 QMessageBox::critical(MainWindow::instance(), tr("Download Error"), file.readAll());
|
lbarthelemy@247
|
397 }
|
lbarthelemy@247
|
398 }
|
lbarthelemy@247
|
399 else {
|
lbarthelemy@247
|
400 std::cerr << "fileLoaded() : " << index << " all successful. " << std::endl;
|
lbarthelemy@247
|
401 }
|
lbarthelemy@247
|
402 QApplication::restoreOverrideCursor();
|
lbarthelemy@247
|
403 }
|
lbarthelemy@247
|
404
|
lbarthelemy@247
|
405 void EasaierSessionManager::loadRelatedModel()
|
lbarthelemy@247
|
406 {
|
lbarthelemy@247
|
407 std::set<Layer *> layers = m_document->getLayers();
|
lbarthelemy@247
|
408 std::set<Layer *>::iterator iter;
|
lbarthelemy@247
|
409
|
lbarthelemy@247
|
410 std::set<QString> loadedModel;
|
lbarthelemy@247
|
411
|
lbarthelemy@247
|
412 for (iter=layers.begin(); iter != layers.end(); iter++)
|
lbarthelemy@247
|
413 {
|
lbarthelemy@247
|
414 Layer * layer = *iter;
|
lbarthelemy@247
|
415
|
lbarthelemy@247
|
416 QString modelName = layer->getModelName();
|
lbajardsilogic@261
|
417 if (layer->getLayerPresentationName() == "Waveform")
|
lbarthelemy@247
|
418 {
|
lbarthelemy@247
|
419 modelName = "available_as";
|
lbarthelemy@247
|
420 int modelId = 1;
|
lbarthelemy@247
|
421 layer->setModelName(modelName);
|
lbarthelemy@247
|
422 layer->setModelId(modelId);
|
lbajardsilogic@261
|
423
|
lbajardsilogic@259
|
424 QStringList* uriList = m_audioSourceInfoModel->getInfo(modelName);
|
lbajardsilogic@259
|
425 if (!uriList)
|
lbajardsilogic@259
|
426 return;
|
lbajardsilogic@259
|
427 QString uri = uriList->at(0);
|
lbajardsilogic@250
|
428 uri.remove("file:/");
|
lbajardsilogic@250
|
429 uri.replace(".wma", ".mp3");
|
lbarthelemy@247
|
430
|
lbarthelemy@247
|
431 QString query = m_httpClient->getServletName() + "?theme=getFile&fileName="+uri;
|
lbarthelemy@247
|
432
|
lbarthelemy@247
|
433 std::set<QString>::iterator iterModel = m_modelLoaded.find(uri);
|
lbarthelemy@247
|
434
|
lbarthelemy@247
|
435 if (iterModel == m_modelLoaded.end())
|
lbarthelemy@247
|
436 {
|
lbajardsilogic@250
|
437 m_modelLoaded.insert(uri);
|
lbarthelemy@247
|
438 loadFile(query, uri, LoadedFile::MODEL);
|
lbarthelemy@247
|
439 }
|
lbajardsilogic@261
|
440 } else if (modelName != "")
|
lbajardsilogic@261
|
441 {
|
lbajardsilogic@261
|
442 std::set<QString>::iterator iterModel = m_modelLoaded.find(modelName);
|
lbajardsilogic@261
|
443
|
lbajardsilogic@261
|
444 if (iterModel == m_modelLoaded.end())
|
lbajardsilogic@261
|
445 {
|
lbajardsilogic@261
|
446 QString query = m_httpClient->getServletName() + "?theme=getTimeLine&signal="+m_document->getAudioSourceInfoFileName()+"&event_label="+modelName;
|
lbajardsilogic@261
|
447 QString file = "metadata/" + modelName + ".txt";
|
lbajardsilogic@261
|
448
|
lbajardsilogic@261
|
449 m_modelLoaded.insert(modelName);
|
lbajardsilogic@261
|
450 loadFile(query, file, LoadedFile::MODEL);
|
lbajardsilogic@261
|
451 }
|
lbarthelemy@247
|
452 }
|
lbarthelemy@247
|
453 }
|
lbarthelemy@247
|
454 }
|
lbarthelemy@247
|
455
|
lbarthelemy@247
|
456 bool EasaierSessionManager::addModelToLayers(const QString& name, const QString& filename)
|
lbarthelemy@247
|
457 {
|
lbarthelemy@247
|
458 std::set<Layer *> layers = m_document->getLayers();
|
lbarthelemy@247
|
459 std::set<Layer *>::iterator iter;
|
lbarthelemy@247
|
460
|
lbarthelemy@247
|
461 std::map<QString, Model *> addedModel;
|
lbarthelemy@247
|
462
|
lbarthelemy@247
|
463 bool ok = false;
|
lbarthelemy@247
|
464
|
lbarthelemy@247
|
465 for (iter=layers.begin(); iter != layers.end(); iter++)
|
lbarthelemy@247
|
466 {
|
lbarthelemy@247
|
467 Layer * layer = *iter;
|
lbarthelemy@247
|
468
|
lbarthelemy@247
|
469 QString modelName = layer->getModelName();
|
lbarthelemy@247
|
470 QString modelId = QString::number(layer->getModelId());
|
lbarthelemy@247
|
471
|
lbarthelemy@247
|
472 if (modelName == name)
|
lbarthelemy@247
|
473 {
|
lbarthelemy@247
|
474 std::map<QString, Model *>::iterator iterModel;
|
lbarthelemy@247
|
475 iterModel = addedModel.find(modelName);
|
lbarthelemy@247
|
476
|
lbarthelemy@247
|
477 if (iterModel == addedModel.end())
|
lbarthelemy@247
|
478 {
|
lbarthelemy@247
|
479 QString extension = filename.right(filename.length()-filename.lastIndexOf(".")-1);
|
lbajardsilogic@259
|
480 extension = extension.toLower();
|
lbarthelemy@247
|
481 if (AudioFileReaderFactory::isKnownExtensions(extension))
|
lbarthelemy@247
|
482 {
|
lbarthelemy@247
|
483 WaveFileModel *model = new WaveFileModel(filename);
|
lbarthelemy@247
|
484 m_document->setMainModel(model);
|
lbarthelemy@247
|
485 addedModel[modelName] = (Model* ) model;
|
lbarthelemy@247
|
486 ok = true;
|
lbarthelemy@247
|
487 emit audioFileLoaded();
|
lbarthelemy@247
|
488 }
|
lbarthelemy@247
|
489 #ifdef HAVE_VIDEO
|
lbarthelemy@247
|
490 else if (VideoFileReaderFactory::isKnownExtensions(extension))
|
lbarthelemy@247
|
491 {
|
lbarthelemy@247
|
492 ok = !(MainWindow::instance()->openVideoFile(filename, MainWindow::ReplaceMainModel));
|
lbarthelemy@247
|
493 emit audioFileLoaded();
|
lbarthelemy@247
|
494 }
|
lbarthelemy@247
|
495 #endif
|
lbarthelemy@247
|
496 else
|
lbarthelemy@247
|
497 {
|
lbarthelemy@247
|
498 ModelReader modelReader(m_document, layer);
|
lbarthelemy@247
|
499 ok = modelReader.parse(filename);
|
lbarthelemy@247
|
500 }
|
lbarthelemy@247
|
501 }
|
lbarthelemy@247
|
502 else
|
lbarthelemy@247
|
503 {
|
lbarthelemy@247
|
504 Model* model = iterModel->second;
|
lbarthelemy@247
|
505 m_document->addImportedModel(model);
|
lbarthelemy@247
|
506 m_document->setModel(layer, model);
|
lbarthelemy@247
|
507 }
|
lbarthelemy@247
|
508 }
|
lbarthelemy@247
|
509 }
|
lbarthelemy@247
|
510
|
lbarthelemy@247
|
511 return ok;
|
lbarthelemy@247
|
512 }
|
lbarthelemy@247
|
513
|
lbarthelemy@247
|
514 void EasaierSessionManager::importMetadata(const QString& filename, Pane* pane)
|
lbarthelemy@247
|
515 {
|
lbajardsilogic@251
|
516 QString query = m_httpClient->getServletName() + "?theme=getTimeLine&signal="+m_document->getAudioSourceInfoFileName()+"&event_label="+filename;
|
lbarthelemy@247
|
517
|
lbajardsilogic@251
|
518 QString file = "metadata/" + filename + ".txt";
|
lbajardsilogic@251
|
519
|
lbajardsilogic@251
|
520 loadFile( query, file, LoadedFile::METADATA);
|
lbarthelemy@247
|
521
|
lbarthelemy@247
|
522 m_currentPane = pane;
|
lbarthelemy@247
|
523 }
|
lbarthelemy@247
|
524
|
lbajardsilogic@257
|
525 void EasaierSessionManager::importRelatedMedia(std::map<QString, QString> *relMediaList)
|
lbarthelemy@247
|
526 {
|
lbarthelemy@247
|
527 QString filename;
|
lbarthelemy@247
|
528 QString query;
|
lbarthelemy@247
|
529
|
lbajardsilogic@257
|
530 std::map<QString, QString>::iterator iter;
|
lbarthelemy@247
|
531 for (iter = relMediaList->begin(); iter != relMediaList->end(); iter++)
|
lbarthelemy@247
|
532 {
|
lbajardsilogic@257
|
533 filename = iter->first;
|
lbajardsilogic@261
|
534 filename.remove("file:/");
|
lbarthelemy@247
|
535
|
lbarthelemy@247
|
536 query = m_httpClient->getServletName() + "?theme=getFile&fileName=" + filename;
|
lbarthelemy@247
|
537
|
lbarthelemy@247
|
538 loadFile( query, filename, LoadedFile::RELATED_MEDIA);
|
lbarthelemy@247
|
539 }
|
lbarthelemy@247
|
540 }
|
lbarthelemy@247
|
541
|
lbarthelemy@247
|
542 void EasaierSessionManager::queryDatabase(const QString& themeName)
|
lbarthelemy@247
|
543 {
|
lbarthelemy@247
|
544
|
lbarthelemy@247
|
545 QueryThemeModel *themeModel = (m_queryModel->getThemes()).find(themeName)->second;
|
lbarthelemy@247
|
546 QString postFilePath = "";
|
lbarthelemy@247
|
547
|
lbarthelemy@247
|
548 //for the post
|
lbarthelemy@247
|
549 QString boundary="7d44e178b0434";
|
lbarthelemy@247
|
550 QString endline="\r\n";
|
lbarthelemy@247
|
551 QString start_delim="--"+boundary+endline;
|
lbarthelemy@249
|
552 QString cont_disp_str="Content-Disposition: form-data;";
|
lbarthelemy@247
|
553
|
lbarthelemy@247
|
554 QByteArray *payload = new QByteArray();
|
lbarthelemy@247
|
555 QDataStream data_stream(payload, QFile::WriteOnly | QFile::Unbuffered);
|
lbarthelemy@247
|
556 /////////
|
lbarthelemy@247
|
557
|
lbarthelemy@249
|
558 QString param = start_delim + cont_disp_str + "name=" + "\"theme\"" + endline+endline+themeName+endline;
|
lbarthelemy@247
|
559 data_stream.writeRawData(param.toStdString().c_str(),param.toStdString().length());
|
lbarthelemy@247
|
560
|
lbarthelemy@247
|
561 if(themeModel!=0){
|
lbarthelemy@247
|
562
|
lbarthelemy@247
|
563 PropertyContainer::PropertyList propertyList = themeModel->getProperties();
|
lbarthelemy@247
|
564 for(int i=0; i< ((int) propertyList.size());i++){
|
lbarthelemy@247
|
565 if (themeModel->getPropertyType(propertyList[i]) == PropertyContainer::FileProperty)
|
lbarthelemy@247
|
566 {
|
lbarthelemy@249
|
567 // We are here dealing with a filePath
|
lbarthelemy@247
|
568 postFilePath = themeModel->getPropertyValue(propertyList[i]);
|
lbarthelemy@247
|
569 if(postFilePath!=""){
|
lbarthelemy@247
|
570 QString only_filename = postFilePath.section( '/', -1 );
|
lbarthelemy@247
|
571 QString param = start_delim + cont_disp_str + "name=" + "\""+propertyList[i]+"\""+"; filename="+"\""+only_filename+"\""+endline+"Content-Type: application/octet-stream"+endline+endline;
|
lbarthelemy@247
|
572 data_stream.writeRawData(param.toStdString().c_str(),param.toStdString().length());
|
lbarthelemy@247
|
573
|
lbarthelemy@247
|
574 QFile file(postFilePath);
|
lbarthelemy@249
|
575 if (file.open( QFile::ReadOnly )) {
|
lbarthelemy@249
|
576 while (!file.atEnd()) {
|
lbarthelemy@249
|
577 QByteArray line = file.readLine();
|
lbarthelemy@249
|
578 data_stream.writeRawData(line.data(),line.length());
|
lbarthelemy@249
|
579 }
|
lbarthelemy@249
|
580 file.close();
|
lbarthelemy@247
|
581 }
|
lbarthelemy@247
|
582 }
|
lbarthelemy@247
|
583 }
|
lbarthelemy@247
|
584 else{
|
lbarthelemy@249
|
585 // Normal parameter
|
lbarthelemy@249
|
586 QString param = start_delim + cont_disp_str + "name=" + "\"" + propertyList[i]+ "\"" + endline+endline+themeModel->getPropertyValue(propertyList[i])+endline;
|
lbarthelemy@247
|
587 data_stream.writeRawData(param.toStdString().c_str(),param.toStdString().length());
|
lbarthelemy@247
|
588 }
|
lbarthelemy@247
|
589 }
|
lbajardsilogic@255
|
590 //bug for the last field - add an unused field
|
lbajardsilogic@255
|
591 QString param = start_delim + cont_disp_str + "name=" + "\"toto\"" + endline+endline+""+endline;
|
lbajardsilogic@255
|
592 data_stream.writeRawData(param.toStdString().c_str(),param.toStdString().length());
|
lbajardsilogic@255
|
593
|
lbarthelemy@247
|
594 QString stop_delim=endline+"--"+boundary+"--"+endline;
|
lbarthelemy@247
|
595 data_stream.writeRawData(stop_delim.toStdString().c_str(),stop_delim.toStdString().length());
|
lbarthelemy@247
|
596 }
|
lbarthelemy@247
|
597 QString filename = "/easaier/servlet/"+themeName;
|
lbarthelemy@247
|
598
|
lbarthelemy@247
|
599 QApplication::setOverrideCursor( Qt::WaitCursor );
|
lbarthelemy@247
|
600 loadFile(*payload, filename, LoadedFile::QUERY_RESULTS, postFilePath);
|
lbarthelemy@247
|
601 }
|
benoitrigolleau@262
|
602
|
benoitrigolleau@262
|
603
|
benoitrigolleau@262
|
604 void EasaierSessionManager::speechRecognition(const QString& themeName)
|
benoitrigolleau@262
|
605 {
|
benoitrigolleau@262
|
606
|
benoitrigolleau@262
|
607 QString postFilePath = "";
|
benoitrigolleau@262
|
608
|
benoitrigolleau@262
|
609 //for the post
|
benoitrigolleau@262
|
610 QString boundary="7d44e178b0434";
|
benoitrigolleau@262
|
611 QString endline="\r\n";
|
benoitrigolleau@262
|
612 QString start_delim="--"+boundary+endline;
|
benoitrigolleau@262
|
613 QString cont_disp_str="Content-Disposition: form-data;";
|
benoitrigolleau@262
|
614
|
benoitrigolleau@262
|
615 QByteArray *payload = new QByteArray();
|
benoitrigolleau@262
|
616 QDataStream data_stream(payload, QFile::WriteOnly | QFile::Unbuffered);
|
benoitrigolleau@262
|
617 /////////
|
benoitrigolleau@262
|
618
|
benoitrigolleau@262
|
619
|
benoitrigolleau@262
|
620 QString param = start_delim + cont_disp_str + "name=" + "\"theme\"" + endline+endline+themeName+endline;
|
benoitrigolleau@262
|
621 data_stream.writeRawData(param.toStdString().c_str(),param.toStdString().length());
|
benoitrigolleau@262
|
622
|
benoitrigolleau@270
|
623 param = start_delim + cont_disp_str + "name=" + "\"" + "language"+ "\"" + endline+endline+MainWindow::instance()->getSpeechRecognitionUI()->getLanguage().toStdString().c_str()+endline;
|
benoitrigolleau@270
|
624 data_stream.writeRawData(param.toStdString().c_str(),param.toStdString().length());
|
benoitrigolleau@270
|
625
|
benoitrigolleau@262
|
626 // We are here dealing with a filePath
|
benoitrigolleau@262
|
627 postFilePath = "c:/test.wav";
|
benoitrigolleau@262
|
628 if(postFilePath!=""){
|
benoitrigolleau@262
|
629 QString only_filename = postFilePath.section( '/', -1 );
|
benoitrigolleau@263
|
630 QString param = start_delim + cont_disp_str + "name=" + "\"file\""+"; filename="+"\""+only_filename+"\""+endline+"Content-Type: application/octet-stream"+endline+endline;
|
benoitrigolleau@262
|
631 data_stream.writeRawData(param.toStdString().c_str(),param.toStdString().length());
|
benoitrigolleau@262
|
632
|
benoitrigolleau@262
|
633 QFile file(postFilePath);
|
benoitrigolleau@262
|
634 if (file.open( QFile::ReadOnly )) {
|
benoitrigolleau@262
|
635 while (!file.atEnd()) {
|
benoitrigolleau@262
|
636 QByteArray line = file.readLine();
|
benoitrigolleau@262
|
637 data_stream.writeRawData(line.data(),line.length());
|
benoitrigolleau@262
|
638 }
|
benoitrigolleau@262
|
639 file.close();
|
benoitrigolleau@262
|
640 }
|
benoitrigolleau@262
|
641 }
|
benoitrigolleau@262
|
642
|
benoitrigolleau@262
|
643 data_stream.writeRawData(param.toStdString().c_str(),param.toStdString().length());
|
benoitrigolleau@262
|
644
|
benoitrigolleau@262
|
645 QString stop_delim=endline+"--"+boundary+"--"+endline;
|
benoitrigolleau@262
|
646 data_stream.writeRawData(stop_delim.toStdString().c_str(),stop_delim.toStdString().length());
|
benoitrigolleau@262
|
647
|
benoitrigolleau@262
|
648 QString filename = "/easaier/servlet/"+themeName;
|
benoitrigolleau@262
|
649
|
benoitrigolleau@262
|
650 QApplication::setOverrideCursor( Qt::WaitCursor );
|
benoitrigolleau@262
|
651 loadFile(*payload, filename, LoadedFile::VOCAL_QUERY, postFilePath);
|
benoitrigolleau@280
|
652
|
benoitrigolleau@262
|
653 } |