comparison data/fileio/FileSource.h @ 357:b92513201610

* better progress reporting in FileSource * fix set-to-default for audio dials with mappers
author Chris Cannam
date Fri, 04 Jan 2008 17:08:10 +0000
parents 1d656dcda8ef
children 183ee2a55fc7
comparison
equal deleted inserted replaced
356:ca3b91119482 357:b92513201610
26 class QFtp; 26 class QFtp;
27 class QHttp; 27 class QHttp;
28 class QFile; 28 class QFile;
29 class QProgressDialog; 29 class QProgressDialog;
30 class QHttpResponseHeader; 30 class QHttpResponseHeader;
31 class ProgressPrinter;
31 32
32 /** 33 /**
33 * FileSource is a class used to refer to the contents of a file that 34 * FileSource is a class used to refer to the contents of a file that
34 * may be either local or at a remote location such as a HTTP URL. 35 * may be either local or at a remote location such as a HTTP URL.
35 * 36 *
60 { 61 {
61 Q_OBJECT 62 Q_OBJECT
62 63
63 public: 64 public:
64 65
66 enum ShowProgressType {
67 ProgressNone,
68 ProgressDialog,
69 ProgressToConsole
70 };
71
65 /** 72 /**
66 * Construct a FileSource using the given local file path or URL. 73 * Construct a FileSource using the given local file path or URL.
67 * The URL may be raw or encoded. If showProgress is true, a 74 * The URL may be raw or encoded.
68 * progress dialog will be shown for any network transfers. 75 *
69 */ 76 * If progressType is ProgressDialog, a progress dialog will be
70 FileSource(QString fileOrUrl, bool showProgress = false); 77 * shown for any network transfers; if it is ProgressToConsole, a
71 78 * progress indication will be sent to the console.
72 /** 79 * Note that the progress() signal will also be emitted regularly
73 * Construct a FileSource using the given remote URL. If 80 * during retrieval, even if progressType is ProgressNone.
74 * showProgress is true, a progress dialog will be shown for any 81 */
75 * network transfers. 82 FileSource(QString fileOrUrl,
76 */ 83 ShowProgressType progressType = ProgressNone);
77 FileSource(QUrl url, bool showProgress = false); 84
85 /**
86 * Construct a FileSource using the given remote URL.
87 *
88 * If progressType is ProgressDialog, a progress dialog will be
89 * shown for any network transfers; if it is ProgressToConsole, a
90 * progress indication will be sent to the console.
91 * Note that the progress() signal also will be emitted regularly
92 * during retrieval, even if progressType is ProgressNone.
93 */
94 FileSource(QUrl url,
95 ShowProgressType progressType = ProgressNone);
78 96
79 FileSource(const FileSource &); 97 FileSource(const FileSource &);
80 98
81 virtual ~FileSource(); 99 virtual ~FileSource();
82 100
210 bool m_ok; 228 bool m_ok;
211 int m_lastStatus; 229 int m_lastStatus;
212 bool m_remote; 230 bool m_remote;
213 bool m_done; 231 bool m_done;
214 bool m_leaveLocalFile; 232 bool m_leaveLocalFile;
233 ShowProgressType m_progressType;
234 ProgressPrinter *m_progressPrinter;
215 QProgressDialog *m_progressDialog; 235 QProgressDialog *m_progressDialog;
216 QTimer m_progressShowTimer; 236 QTimer m_progressShowTimer;
217 237
218 typedef std::map<QUrl, int> RemoteRefCountMap; 238 typedef std::map<QUrl, int> RemoteRefCountMap;
219 typedef std::map<QUrl, QString> RemoteLocalMap; 239 typedef std::map<QUrl, QString> RemoteLocalMap;
220 static RemoteRefCountMap m_refCountMap; 240 static RemoteRefCountMap m_refCountMap;
221 static RemoteLocalMap m_remoteLocalMap; 241 static RemoteLocalMap m_remoteLocalMap;
222 static QMutex m_mapMutex; 242 static QMutex m_mapMutex;
223 bool m_refCounted; 243 bool m_refCounted;
224 244
225 void init(bool showProgress); 245 void init();
226 void initHttp(); 246 void initHttp();
227 void initFtp(); 247 void initFtp();
228 248
229 void cleanup(); 249 void cleanup();
230 250
235 255
236 static QMutex m_fileCreationMutex; 256 static QMutex m_fileCreationMutex;
237 static int m_count; 257 static int m_count;
238 }; 258 };
239 259
240 class FileSourceProgressPrinter : public QObject
241 {
242 Q_OBJECT
243
244 public:
245 FileSourceProgressPrinter();
246 virtual ~FileSourceProgressPrinter();
247
248 public slots:
249 void progress(int);
250
251 protected:
252 int m_lastProgress;
253 };
254
255 #endif 260 #endif