comparison data/fileio/FileFinder.cpp @ 316:3a6725f285d6

* Make RemoteFile far more pervasive, and use it for local files as well so that we can handle both transparently. Make it shallow copy with reference counting, so it can be used by value without having to worry about the cache file lifetime. Use RemoteFile for MainWindow file-open functions, etc
author Chris Cannam
date Thu, 18 Oct 2007 15:31:20 +0000
parents fc656505c573
children c324d410b096
comparison
equal deleted inserted replaced
315:96ef9746c560 316:3a6725f285d6
378 QString 378 QString
379 FileFinder::find(FileType type, QString location, QString lastKnownLocation) 379 FileFinder::find(FileType type, QString location, QString lastKnownLocation)
380 { 380 {
381 if (QFileInfo(location).exists()) return location; 381 if (QFileInfo(location).exists()) return location;
382 382
383 if (RemoteFile::canHandleScheme(QUrl(location))) { 383 if (RemoteFile::isRemote(location)) {
384 RemoteFile rf(location); 384 if (RemoteFile(location).isAvailable()) {
385 bool available = rf.isAvailable(); 385 std::cerr << "FileFinder::find: ok, it's available... returning" << std::endl;
386 rf.deleteLocalFile(); 386 return location;
387 if (available) return location; 387 }
388 } 388 }
389 389
390 QString foundAt = ""; 390 QString foundAt = "";
391 391
392 if ((foundAt = findRelative(location, lastKnownLocation)) != "") { 392 if ((foundAt = findRelative(location, lastKnownLocation)) != "") {
409 << relativeTo.toStdString() << "\"..." << std::endl; 409 << relativeTo.toStdString() << "\"..." << std::endl;
410 410
411 QString fileName; 411 QString fileName;
412 QString resolved; 412 QString resolved;
413 413
414 if (RemoteFile::canHandleScheme(QUrl(location))) { 414 if (RemoteFile::isRemote(location)) {
415 fileName = QUrl(location).path().section('/', -1, -1, 415 fileName = QUrl(location).path().section('/', -1, -1,
416 QString::SectionSkipEmpty); 416 QString::SectionSkipEmpty);
417 } else { 417 } else {
418 fileName = QFileInfo(location).fileName(); 418 fileName = QFileInfo(location).fileName();
419 } 419 }
420 420
421 if (RemoteFile::canHandleScheme(QUrl(relativeTo))) { 421 if (RemoteFile::isRemote(relativeTo)) {
422 resolved = QUrl(relativeTo).resolved(fileName).toString(); 422 resolved = QUrl(relativeTo).resolved(fileName).toString();
423 RemoteFile rf(resolved); 423 if (!RemoteFile(resolved).isAvailable()) resolved = "";
424 if (!rf.isAvailable()) resolved = "";
425 std::cerr << "resolved: " << resolved.toStdString() << std::endl; 424 std::cerr << "resolved: " << resolved.toStdString() << std::endl;
426 rf.deleteLocalFile();
427 } else { 425 } else {
428 resolved = QFileInfo(relativeTo).dir().filePath(fileName); 426 resolved = QFileInfo(relativeTo).dir().filePath(fileName);
429 if (!QFileInfo(resolved).exists() || 427 if (!QFileInfo(resolved).exists() ||
430 !QFileInfo(resolved).isFile() || 428 !QFileInfo(resolved).isFile() ||
431 !QFileInfo(resolved).isReadable()) { 429 !QFileInfo(resolved).isReadable()) {
479 (0, tr("Use URL"), 477 (0, tr("Use URL"),
480 tr("Please enter the URL to use for this file:"), 478 tr("Please enter the URL to use for this file:"),
481 QLineEdit::Normal, "", &ok); 479 QLineEdit::Normal, "", &ok);
482 480
483 if (ok && path != "") { 481 if (ok && path != "") {
484 RemoteFile rf(path); 482 if (RemoteFile(path).isAvailable()) {
485 if (rf.isAvailable()) {
486 done = true; 483 done = true;
487 } else { 484 } else {
488 QMessageBox::critical 485 QMessageBox::critical
489 (0, tr("Failed to open location"), 486 (0, tr("Failed to open location"),
490 tr("URL \"%1\" could not be opened").arg(path)); 487 tr("URL \"%1\" could not be opened").arg(path));
491 path = ""; 488 path = "";
492 } 489 }
493 rf.deleteLocalFile();
494 } 490 }
495 break; 491 break;
496 } 492 }
497 493
498 case 2: // Cancel 494 case 2: // Cancel