Mercurial > hg > svcore
comparison data/fileio/FileSource.cpp @ 834:fcee7e040ab4
Merge
author | Chris Cannam |
---|---|
date | Tue, 30 Jul 2013 18:15:30 +0100 |
parents | 3cc81dbc31bb 12aff5a181bc |
children | e802e550a1f2 |
comparison
equal
deleted
inserted
replaced
833:3cc81dbc31bb | 834:fcee7e040ab4 |
---|---|
70 | 70 |
71 static QThreadStorage<QNetworkAccessManager *> nms; | 71 static QThreadStorage<QNetworkAccessManager *> nms; |
72 | 72 |
73 FileSource::FileSource(QString fileOrUrl, ProgressReporter *reporter, | 73 FileSource::FileSource(QString fileOrUrl, ProgressReporter *reporter, |
74 QString preferredContentType) : | 74 QString preferredContentType) : |
75 m_rawFileOrUrl(fileOrUrl), | |
75 m_url(fileOrUrl, QUrl::StrictMode), | 76 m_url(fileOrUrl, QUrl::StrictMode), |
76 m_localFile(0), | 77 m_localFile(0), |
77 m_reply(0), | 78 m_reply(0), |
78 m_preferredContentType(preferredContentType), | 79 m_preferredContentType(preferredContentType), |
79 m_ok(false), | 80 m_ok(false), |
110 !isAvailable()) { | 111 !isAvailable()) { |
111 #ifdef DEBUG_FILE_SOURCE | 112 #ifdef DEBUG_FILE_SOURCE |
112 std::cerr << "FileSource::FileSource: Failed to open local file with URL \"" << m_url.toString() << "\"; trying again assuming filename was encoded" << std::endl; | 113 std::cerr << "FileSource::FileSource: Failed to open local file with URL \"" << m_url.toString() << "\"; trying again assuming filename was encoded" << std::endl; |
113 #endif | 114 #endif |
114 m_url = QUrl::fromEncoded(fileOrUrl.toLatin1()); | 115 m_url = QUrl::fromEncoded(fileOrUrl.toLatin1()); |
116 #ifdef DEBUG_FILE_SOURCE | |
117 std::cerr << "FileSource::FileSource: URL is now \"" << m_url.toString() << "\"" << std::endl; | |
118 #endif | |
115 init(); | 119 init(); |
116 } | 120 } |
117 | 121 |
118 if (isRemote() && | 122 if (isRemote() && |
119 (fileOrUrl.contains('%') || | 123 (fileOrUrl.contains('%') || |
288 #ifdef DEBUG_FILE_SOURCE | 292 #ifdef DEBUG_FILE_SOURCE |
289 std::cerr << "FileSource::init: Not a remote URL" << std::endl; | 293 std::cerr << "FileSource::init: Not a remote URL" << std::endl; |
290 #endif | 294 #endif |
291 bool literal = false; | 295 bool literal = false; |
292 m_localFilename = m_url.toLocalFile(); | 296 m_localFilename = m_url.toLocalFile(); |
297 | |
293 if (m_localFilename == "") { | 298 if (m_localFilename == "") { |
294 // QUrl may have mishandled the scheme (e.g. in a DOS path) | 299 // QUrl may have mishandled the scheme (e.g. in a DOS path) |
295 m_localFilename = m_url.toString(); | 300 m_localFilename = m_rawFileOrUrl; |
301 #ifdef DEBUG_FILE_SOURCE | |
302 std::cerr << "FileSource::init: Trying literal local filename \"" | |
303 << m_localFilename << "\"" << std::endl; | |
304 #endif | |
296 literal = true; | 305 literal = true; |
297 } | 306 } |
298 m_localFilename = QFileInfo(m_localFilename).absoluteFilePath(); | 307 m_localFilename = QFileInfo(m_localFilename).absoluteFilePath(); |
299 | 308 |
300 #ifdef DEBUG_FILE_SOURCE | 309 #ifdef DEBUG_FILE_SOURCE |
301 std::cerr << "FileSource::init: URL translates to local filename \"" | 310 std::cerr << "FileSource::init: URL translates to absolute filename \"" |
302 << m_localFilename << "\" (with literal=" << literal << ")" | 311 << m_localFilename << "\" (with literal=" << literal << ")" |
303 << std::endl; | 312 << std::endl; |
304 #endif | 313 #endif |
305 m_ok = true; | 314 m_ok = true; |
306 m_lastStatus = 200; | 315 m_lastStatus = 200; |
312 #ifdef DEBUG_FILE_SOURCE | 321 #ifdef DEBUG_FILE_SOURCE |
313 std::cerr << "FileSource::init: Local file of this name does not exist, trying URL as a literal filename" << std::endl; | 322 std::cerr << "FileSource::init: Local file of this name does not exist, trying URL as a literal filename" << std::endl; |
314 #endif | 323 #endif |
315 // Again, QUrl may have been mistreating us -- | 324 // Again, QUrl may have been mistreating us -- |
316 // e.g. dropping a part that looks like query data | 325 // e.g. dropping a part that looks like query data |
317 m_localFilename = m_url.toString(); | 326 m_localFilename = m_rawFileOrUrl; |
318 literal = true; | 327 literal = true; |
319 if (!QFileInfo(m_localFilename).exists()) { | 328 if (!QFileInfo(m_localFilename).exists()) { |
320 m_lastStatus = 404; | 329 m_lastStatus = 404; |
321 } | 330 } |
322 } | 331 } |