comparison data/fileio/FileSource.cpp @ 614:87b81f959706

* Convert strings to URLs in strict mode first; only try again in tolerant mode if this fails (and if the file is local)
author Chris Cannam
date Wed, 07 Oct 2009 13:10:49 +0000
parents d7f3dfe6f9a4
children 3a61a4df6d53
comparison
equal deleted inserted replaced
613:eb1b517f5eeb 614:87b81f959706
68 } 68 }
69 #endif 69 #endif
70 70
71 FileSource::FileSource(QString fileOrUrl, ProgressReporter *reporter, 71 FileSource::FileSource(QString fileOrUrl, ProgressReporter *reporter,
72 QString preferredContentType) : 72 QString preferredContentType) :
73 m_url(fileOrUrl), 73 m_url(fileOrUrl, QUrl::StrictMode),
74 m_ftp(0), 74 m_ftp(0),
75 m_http(0), 75 m_http(0),
76 m_localFile(0), 76 m_localFile(0),
77 m_preferredContentType(preferredContentType), 77 m_preferredContentType(preferredContentType),
78 m_ok(false), 78 m_ok(false),
93 m_errorString = tr("Unsupported scheme in URL"); 93 m_errorString = tr("Unsupported scheme in URL");
94 return; 94 return;
95 } 95 }
96 96
97 init(); 97 init();
98
99 if (!isRemote() &&
100 !isAvailable()) {
101 #ifdef DEBUG_FILE_SOURCE
102 std::cerr << "FileSource::FileSource: Failed to open local file with URL \"" << m_url.toString().toStdString() << "; trying again with tolerant encoding" << std::endl;
103 #endif
104 m_url = QUrl(fileOrUrl, QUrl::TolerantMode);
105 init();
106 }
98 107
99 if (isRemote() && 108 if (isRemote() &&
100 (fileOrUrl.contains('%') || 109 (fileOrUrl.contains('%') ||
101 fileOrUrl.contains("--"))) { // for IDNA 110 fileOrUrl.contains("--"))) { // for IDNA
102 111
261 #endif 270 #endif
262 m_ok = true; 271 m_ok = true;
263 m_lastStatus = 200; 272 m_lastStatus = 200;
264 273
265 if (!QFileInfo(m_localFilename).exists()) { 274 if (!QFileInfo(m_localFilename).exists()) {
266 #ifdef DEBUG_FILE_SOURCE
267 std::cerr << "FileSource::init: Local file of this name does not exist, trying URL as a literal filename" << std::endl;
268 #endif
269 if (literal) { 275 if (literal) {
270 m_lastStatus = 404; 276 m_lastStatus = 404;
271 } else { 277 } else {
278 #ifdef DEBUG_FILE_SOURCE
279 std::cerr << "FileSource::init: Local file of this name does not exist, trying URL as a literal filename" << std::endl;
280 #endif
272 // Again, QUrl may have been mistreating us -- 281 // Again, QUrl may have been mistreating us --
273 // e.g. dropping a part that looks like query data 282 // e.g. dropping a part that looks like query data
274 m_localFilename = m_url.toString(); 283 m_localFilename = m_url.toString();
275 literal = true; 284 literal = true;
276 if (!QFileInfo(m_localFilename).exists()) { 285 if (!QFileInfo(m_localFilename).exists()) {