comparison data/fileio/FileSource.cpp @ 831:12aff5a181bc

When switching to "literal mode" for a local file path, use the original file path as passed to the FileSource ctor rather than going through QUrl. This avoids filename becoming encoded and QUrl::toString failing to decode it (as is happening with Windows paths using Qt5 currently).
author Chris Cannam <chris.cannam@eecs.qmul.ac.uk>
date Wed, 24 Jul 2013 18:12:57 +0100
parents 95d4a59295b7
children fcee7e040ab4
comparison
equal deleted inserted replaced
824:420ade1cb6da 831:12aff5a181bc
69 69
70 static QNetworkAccessManager nm; 70 static QNetworkAccessManager nm;
71 71
72 FileSource::FileSource(QString fileOrUrl, ProgressReporter *reporter, 72 FileSource::FileSource(QString fileOrUrl, ProgressReporter *reporter,
73 QString preferredContentType) : 73 QString preferredContentType) :
74 m_rawFileOrUrl(fileOrUrl),
74 m_url(fileOrUrl, QUrl::StrictMode), 75 m_url(fileOrUrl, QUrl::StrictMode),
75 m_localFile(0), 76 m_localFile(0),
76 m_reply(0), 77 m_reply(0),
77 m_preferredContentType(preferredContentType), 78 m_preferredContentType(preferredContentType),
78 m_ok(false), 79 m_ok(false),
109 !isAvailable()) { 110 !isAvailable()) {
110 #ifdef DEBUG_FILE_SOURCE 111 #ifdef DEBUG_FILE_SOURCE
111 std::cerr << "FileSource::FileSource: Failed to open local file with URL \"" << m_url.toString() << "\"; trying again assuming filename was encoded" << std::endl; 112 std::cerr << "FileSource::FileSource: Failed to open local file with URL \"" << m_url.toString() << "\"; trying again assuming filename was encoded" << std::endl;
112 #endif 113 #endif
113 m_url = QUrl::fromEncoded(fileOrUrl.toLatin1()); 114 m_url = QUrl::fromEncoded(fileOrUrl.toLatin1());
115 #ifdef DEBUG_FILE_SOURCE
116 std::cerr << "FileSource::FileSource: URL is now \"" << m_url.toString() << "\"" << std::endl;
117 #endif
114 init(); 118 init();
115 } 119 }
116 120
117 if (isRemote() && 121 if (isRemote() &&
118 (fileOrUrl.contains('%') || 122 (fileOrUrl.contains('%') ||
280 #ifdef DEBUG_FILE_SOURCE 284 #ifdef DEBUG_FILE_SOURCE
281 std::cerr << "FileSource::init: Not a remote URL" << std::endl; 285 std::cerr << "FileSource::init: Not a remote URL" << std::endl;
282 #endif 286 #endif
283 bool literal = false; 287 bool literal = false;
284 m_localFilename = m_url.toLocalFile(); 288 m_localFilename = m_url.toLocalFile();
289
285 if (m_localFilename == "") { 290 if (m_localFilename == "") {
286 // QUrl may have mishandled the scheme (e.g. in a DOS path) 291 // QUrl may have mishandled the scheme (e.g. in a DOS path)
287 m_localFilename = m_url.toString(); 292 m_localFilename = m_rawFileOrUrl;
293 #ifdef DEBUG_FILE_SOURCE
294 std::cerr << "FileSource::init: Trying literal local filename \""
295 << m_localFilename << "\"" << std::endl;
296 #endif
288 literal = true; 297 literal = true;
289 } 298 }
290 m_localFilename = QFileInfo(m_localFilename).absoluteFilePath(); 299 m_localFilename = QFileInfo(m_localFilename).absoluteFilePath();
291 300
292 #ifdef DEBUG_FILE_SOURCE 301 #ifdef DEBUG_FILE_SOURCE
293 std::cerr << "FileSource::init: URL translates to local filename \"" 302 std::cerr << "FileSource::init: URL translates to absolute filename \""
294 << m_localFilename << "\" (with literal=" << literal << ")" 303 << m_localFilename << "\" (with literal=" << literal << ")"
295 << std::endl; 304 << std::endl;
296 #endif 305 #endif
297 m_ok = true; 306 m_ok = true;
298 m_lastStatus = 200; 307 m_lastStatus = 200;
304 #ifdef DEBUG_FILE_SOURCE 313 #ifdef DEBUG_FILE_SOURCE
305 std::cerr << "FileSource::init: Local file of this name does not exist, trying URL as a literal filename" << std::endl; 314 std::cerr << "FileSource::init: Local file of this name does not exist, trying URL as a literal filename" << std::endl;
306 #endif 315 #endif
307 // Again, QUrl may have been mistreating us -- 316 // Again, QUrl may have been mistreating us --
308 // e.g. dropping a part that looks like query data 317 // e.g. dropping a part that looks like query data
309 m_localFilename = m_url.toString(); 318 m_localFilename = m_rawFileOrUrl;
310 literal = true; 319 literal = true;
311 if (!QFileInfo(m_localFilename).exists()) { 320 if (!QFileInfo(m_localFilename).exists()) {
312 m_lastStatus = 404; 321 m_lastStatus = 404;
313 } 322 }
314 } 323 }