annotate data/fileio/FileFinder.cpp @ 210:a06afefe45ee

* Cancel when downloading file * Handle status codes (404 etc) * Add RemoteFile::isAvailable * Start on FileFinder for looking up files referred to in distant sessions
author Chris Cannam
date Wed, 10 Jan 2007 17:26:39 +0000
parents
children e2bbb58e6df6
rev   line source
Chris@210 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@210 2
Chris@210 3 /*
Chris@210 4 Sonic Visualiser
Chris@210 5 An audio file viewer and annotation editor.
Chris@210 6 Centre for Digital Music, Queen Mary, University of London.
Chris@210 7 This file copyright 2007 QMUL.
Chris@210 8
Chris@210 9 This program is free software; you can redistribute it and/or
Chris@210 10 modify it under the terms of the GNU General Public License as
Chris@210 11 published by the Free Software Foundation; either version 2 of the
Chris@210 12 License, or (at your option) any later version. See the file
Chris@210 13 COPYING included with this distribution for more information.
Chris@210 14 */
Chris@210 15
Chris@210 16 #include "FileFinder.h"
Chris@210 17 #include "RemoteFile.h"
Chris@210 18
Chris@210 19 #include <QFileInfo>
Chris@210 20 #include <QMessageBox>
Chris@210 21 #include <QFileDialog>
Chris@210 22
Chris@210 23
Chris@210 24 FileFinder::FileFinder(QString location, QString lastKnownLocation) :
Chris@210 25 m_location(location),
Chris@210 26 m_lastKnownLocation(lastKnownLocation),
Chris@210 27 m_lastLocatedLocation("")
Chris@210 28 {
Chris@210 29 }
Chris@210 30
Chris@210 31 FileFinder::~FileFinder()
Chris@210 32 {
Chris@210 33 }
Chris@210 34
Chris@210 35 QString
Chris@210 36 FileFinder::getLocation()
Chris@210 37 {
Chris@210 38 if (QFileInfo(m_location).exists()) return m_location;
Chris@210 39
Chris@210 40 if (QMessageBox::question(0,
Chris@210 41 QMessageBox::tr("Failed to open file"),
Chris@210 42 QMessageBox::tr("Audio file \"%1\" could not be opened.\nLocate it?").arg(m_location),
Chris@210 43 //!!! QMessageBox::tr("File \"%1\" could not be opened.\nLocate it?").arg(location),
Chris@210 44 QMessageBox::Ok,
Chris@210 45 QMessageBox::Cancel) == QMessageBox::Ok) {
Chris@210 46
Chris@210 47 //!!! This uses QFileDialog::getOpenFileName, while other
Chris@210 48 //files are located using specially built file dialogs in
Chris@210 49 //MainWindow::getOpenFileName -- pull out MainWindow
Chris@210 50 //functions into another class?
Chris@210 51 QString path = QFileDialog::getOpenFileName
Chris@210 52 (0,
Chris@210 53 QFileDialog::tr("Locate file \"%1\"").arg(QFileInfo(m_location).fileName()), m_location,
Chris@210 54 QFileDialog::tr("All files (*.*)"));
Chris@210 55 /*!!!
Chris@210 56 QFileDialog::tr("Audio files (%1)\nAll files (*.*)")
Chris@210 57 .arg(AudioFileReaderFactory::getKnownExtensions()));
Chris@210 58 */
Chris@210 59
Chris@210 60 if (path != "") {
Chris@210 61 return path;
Chris@210 62 }
Chris@210 63 }
Chris@210 64
Chris@210 65 return "";
Chris@210 66 }
Chris@210 67
Chris@210 68