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@208
|
32 class RemoteFile : public QObject
|
Chris@208
|
33 {
|
Chris@208
|
34 Q_OBJECT
|
Chris@208
|
35
|
Chris@208
|
36 public:
|
Chris@208
|
37 RemoteFile(QUrl url);
|
Chris@208
|
38 virtual ~RemoteFile();
|
Chris@208
|
39
|
Chris@210
|
40 bool isAvailable();
|
Chris@210
|
41
|
Chris@208
|
42 void wait();
|
Chris@208
|
43
|
Chris@208
|
44 bool isOK() const;
|
Chris@208
|
45 bool isDone() const;
|
Chris@210
|
46
|
Chris@208
|
47 QString getLocalFilename() const;
|
Chris@208
|
48 QString getErrorString() const;
|
Chris@208
|
49
|
Chris@211
|
50 void deleteLocalFile();
|
Chris@211
|
51
|
Chris@304
|
52 static bool isRemote(QString fileOrUrl);
|
Chris@208
|
53 static bool canHandleScheme(QUrl url);
|
Chris@208
|
54
|
Chris@208
|
55 signals:
|
Chris@208
|
56 void progress(int percent);
|
Chris@208
|
57 void ready();
|
Chris@208
|
58
|
Chris@208
|
59 protected slots:
|
Chris@208
|
60 void dataReadProgress(int done, int total);
|
Chris@214
|
61 void httpResponseHeaderReceived(const QHttpResponseHeader &resp);
|
Chris@214
|
62 void ftpCommandFinished(int, bool);
|
Chris@208
|
63 void dataTransferProgress(qint64 done, qint64 total);
|
Chris@208
|
64 void done(bool error);
|
Chris@210
|
65 void showProgressDialog();
|
Chris@210
|
66 void cancelled();
|
Chris@208
|
67
|
Chris@208
|
68 protected:
|
Chris@304
|
69 QUrl m_url;
|
Chris@208
|
70 QFtp *m_ftp;
|
Chris@208
|
71 QHttp *m_http;
|
Chris@208
|
72 QFile *m_localFile;
|
Chris@208
|
73 QString m_localFilename;
|
Chris@208
|
74 QString m_errorString;
|
Chris@208
|
75 bool m_ok;
|
Chris@210
|
76 int m_lastStatus;
|
Chris@208
|
77 bool m_done;
|
Chris@208
|
78 QProgressDialog *m_progressDialog;
|
Chris@210
|
79 QTimer m_progressShowTimer;
|
Chris@208
|
80
|
Chris@304
|
81 typedef std::map<QUrl, int> RemoteRefCountMap;
|
Chris@304
|
82 typedef std::map<QUrl, QString> RemoteLocalMap;
|
Chris@304
|
83 static RemoteRefCountMap m_refCountMap;
|
Chris@304
|
84 static RemoteLocalMap m_remoteLocalMap;
|
Chris@304
|
85 static QMutex m_mapMutex;
|
Chris@304
|
86 bool m_referenced;
|
Chris@304
|
87
|
Chris@211
|
88 void cleanup();
|
Chris@211
|
89
|
Chris@208
|
90 QString createLocalFile(QUrl url);
|
Chris@208
|
91
|
Chris@208
|
92 static QMutex m_fileCreationMutex;
|
Chris@208
|
93 static int m_count;
|
Chris@208
|
94 };
|
Chris@208
|
95
|
Chris@208
|
96 #endif
|