Chris@208
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@208
|
2
|
Chris@208
|
3 /*
|
Chris@208
|
4 Sonic Visualiser
|
Chris@208
|
5 An audio file viewer and annotation editor.
|
Chris@208
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@208
|
7 This file copyright 2007 QMUL.
|
Chris@208
|
8
|
Chris@208
|
9 This program is free software; you can redistribute it and/or
|
Chris@208
|
10 modify it under the terms of the GNU General Public License as
|
Chris@208
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@208
|
12 License, or (at your option) any later version. See the file
|
Chris@208
|
13 COPYING included with this distribution for more information.
|
Chris@208
|
14 */
|
Chris@208
|
15
|
Chris@208
|
16 #ifndef _REMOTE_FILE_H_
|
Chris@208
|
17 #define _REMOTE_FILE_H_
|
Chris@208
|
18
|
Chris@208
|
19 #include <QUrl>
|
Chris@208
|
20 #include <QMutex>
|
Chris@208
|
21 #include <QString>
|
Chris@210
|
22 #include <QTimer>
|
Chris@208
|
23
|
Chris@304
|
24 #include <map>
|
Chris@304
|
25
|
Chris@208
|
26 class QFtp;
|
Chris@208
|
27 class QHttp;
|
Chris@208
|
28 class QFile;
|
Chris@208
|
29 class QProgressDialog;
|
Chris@210
|
30 class QHttpResponseHeader;
|
Chris@208
|
31
|
Chris@317
|
32 class FileSource : public QObject
|
Chris@208
|
33 {
|
Chris@208
|
34 Q_OBJECT
|
Chris@208
|
35
|
Chris@208
|
36 public:
|
Chris@317
|
37 FileSource(QString fileOrUrl, bool showProgress = true);
|
Chris@317
|
38 FileSource(QUrl url, bool showProgress = true);
|
Chris@317
|
39 FileSource(const FileSource &);
|
Chris@316
|
40
|
Chris@317
|
41 virtual ~FileSource();
|
Chris@208
|
42
|
Chris@210
|
43 bool isAvailable();
|
Chris@210
|
44
|
Chris@316
|
45 void waitForStatus();
|
Chris@316
|
46 void waitForData();
|
Chris@316
|
47
|
Chris@316
|
48 void setLeaveLocalFile(bool leave);
|
Chris@208
|
49
|
Chris@208
|
50 bool isOK() const;
|
Chris@208
|
51 bool isDone() const;
|
Chris@316
|
52 bool isRemote() const;
|
Chris@210
|
53
|
Chris@316
|
54 QString getLocation() const;
|
Chris@316
|
55 QString getLocalFilename() const;
|
Chris@315
|
56 QString getContentType() const;
|
Chris@316
|
57 QString getExtension() const;
|
Chris@315
|
58
|
Chris@208
|
59 QString getErrorString() const;
|
Chris@208
|
60
|
Chris@304
|
61 static bool isRemote(QString fileOrUrl);
|
Chris@208
|
62 static bool canHandleScheme(QUrl url);
|
Chris@208
|
63
|
Chris@208
|
64 signals:
|
Chris@208
|
65 void progress(int percent);
|
Chris@208
|
66 void ready();
|
Chris@208
|
67
|
Chris@208
|
68 protected slots:
|
Chris@208
|
69 void dataReadProgress(int done, int total);
|
Chris@214
|
70 void httpResponseHeaderReceived(const QHttpResponseHeader &resp);
|
Chris@214
|
71 void ftpCommandFinished(int, bool);
|
Chris@208
|
72 void dataTransferProgress(qint64 done, qint64 total);
|
Chris@208
|
73 void done(bool error);
|
Chris@210
|
74 void showProgressDialog();
|
Chris@210
|
75 void cancelled();
|
Chris@208
|
76
|
Chris@208
|
77 protected:
|
Chris@317
|
78 FileSource &operator=(const FileSource &); // not provided
|
Chris@316
|
79
|
Chris@304
|
80 QUrl m_url;
|
Chris@208
|
81 QFtp *m_ftp;
|
Chris@208
|
82 QHttp *m_http;
|
Chris@208
|
83 QFile *m_localFile;
|
Chris@208
|
84 QString m_localFilename;
|
Chris@208
|
85 QString m_errorString;
|
Chris@315
|
86 QString m_contentType;
|
Chris@208
|
87 bool m_ok;
|
Chris@210
|
88 int m_lastStatus;
|
Chris@316
|
89 bool m_remote;
|
Chris@208
|
90 bool m_done;
|
Chris@316
|
91 bool m_leaveLocalFile;
|
Chris@208
|
92 QProgressDialog *m_progressDialog;
|
Chris@210
|
93 QTimer m_progressShowTimer;
|
Chris@208
|
94
|
Chris@304
|
95 typedef std::map<QUrl, int> RemoteRefCountMap;
|
Chris@304
|
96 typedef std::map<QUrl, QString> RemoteLocalMap;
|
Chris@304
|
97 static RemoteRefCountMap m_refCountMap;
|
Chris@304
|
98 static RemoteLocalMap m_remoteLocalMap;
|
Chris@304
|
99 static QMutex m_mapMutex;
|
Chris@316
|
100 bool m_refCounted;
|
Chris@316
|
101
|
Chris@316
|
102 void init(bool showProgress);
|
Chris@316
|
103 void initHttp();
|
Chris@316
|
104 void initFtp();
|
Chris@304
|
105
|
Chris@211
|
106 void cleanup();
|
Chris@211
|
107
|
Chris@316
|
108 // Create a local file for m_url. If it already existed, return true.
|
Chris@316
|
109 // The local filename is stored in m_localFilename.
|
Chris@316
|
110 bool createCacheFile();
|
Chris@316
|
111 void deleteCacheFile();
|
Chris@208
|
112
|
Chris@208
|
113 static QMutex m_fileCreationMutex;
|
Chris@208
|
114 static int m_count;
|
Chris@208
|
115 };
|
Chris@208
|
116
|
Chris@208
|
117 #endif
|