svcore
1.9
|
00001 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ 00002 00003 /* 00004 Sonic Visualiser 00005 An audio file viewer and annotation editor. 00006 Centre for Digital Music, Queen Mary, University of London. 00007 This file copyright 2008 QMUL. 00008 00009 This program is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU General Public License as 00011 published by the Free Software Foundation; either version 2 of the 00012 License, or (at your option) any later version. See the file 00013 COPYING included with this distribution for more information. 00014 */ 00015 00016 #ifndef _CACHED_FILE_H_ 00017 #define _CACHED_FILE_H_ 00018 00019 #include <QString> 00020 #include <QUrl> 00021 #include <QDateTime> 00022 #include <map> 00023 00024 class ProgressReporter; 00025 00026 class CachedFile 00027 { 00028 public: 00029 CachedFile(QString fileOrUrl, 00030 ProgressReporter *reporter = 0, 00031 QString preferredContentType = ""); 00032 CachedFile(QUrl url, 00033 ProgressReporter *reporter = 0, 00034 QString preferredContentType = ""); 00035 00036 virtual ~CachedFile(); 00037 00038 bool isOK() const; 00039 00040 QString getLocalFilename() const; 00041 00042 protected: 00043 QString m_origin; 00044 QString m_localFilename; 00045 QString m_preferredContentType; 00046 ProgressReporter *m_reporter; 00047 bool m_ok; 00048 00049 void checkFile(); 00050 bool retrieve(); 00051 00052 QDateTime getLastRetrieval(); 00053 void updateLastRetrieval(bool successful); 00054 00055 static QString getCacheDirectory(); 00056 static QString getLocalFilenameFor(QUrl url); 00057 00058 typedef std::map<QString, QString> OriginLocalFilenameMap; 00059 static OriginLocalFilenameMap m_knownGoodCaches; 00060 }; 00061 00062 #endif