comparison data/fileio/FileSource.h @ 392:183ee2a55fc7

* More work to abstract out interactive components used in the data library, so that it does not need to depend on QtGui.
author Chris Cannam
date Fri, 14 Mar 2008 17:14:21 +0000
parents b92513201610
children 93fb1ebff76b
comparison
equal deleted inserted replaced
391:5858cc462d0a 392:183ee2a55fc7
24 #include <map> 24 #include <map>
25 25
26 class QFtp; 26 class QFtp;
27 class QHttp; 27 class QHttp;
28 class QFile; 28 class QFile;
29 class QProgressDialog;
30 class QHttpResponseHeader; 29 class QHttpResponseHeader;
31 class ProgressPrinter; 30 class ProgressReporter;
32 31
33 /** 32 /**
34 * FileSource is a class used to refer to the contents of a file that 33 * FileSource is a class used to refer to the contents of a file that
35 * may be either local or at a remote location such as a HTTP URL. 34 * may be either local or at a remote location such as a HTTP URL.
36 * 35 *
60 class FileSource : public QObject 59 class FileSource : public QObject
61 { 60 {
62 Q_OBJECT 61 Q_OBJECT
63 62
64 public: 63 public:
65
66 enum ShowProgressType {
67 ProgressNone,
68 ProgressDialog,
69 ProgressToConsole
70 };
71
72 /** 64 /**
73 * Construct a FileSource using the given local file path or URL. 65 * Construct a FileSource using the given local file path or URL.
74 * The URL may be raw or encoded. 66 * The URL may be raw or encoded.
75 * 67 *
76 * If progressType is ProgressDialog, a progress dialog will be 68 * If a ProgressReporter is provided, it will be updated with
77 * shown for any network transfers; if it is ProgressToConsole, a 69 * progress status. Note that the progress() signal will also be
78 * progress indication will be sent to the console. 70 * emitted regularly during retrieval, even if no reporter is
79 * Note that the progress() signal will also be emitted regularly 71 * supplied here. Caller retains ownership of the reporter object.
80 * during retrieval, even if progressType is ProgressNone. 72 */
81 */ 73 FileSource(QString fileOrUrl, ProgressReporter *reporter = 0);
82 FileSource(QString fileOrUrl,
83 ShowProgressType progressType = ProgressNone);
84 74
85 /** 75 /**
86 * Construct a FileSource using the given remote URL. 76 * Construct a FileSource using the given remote URL.
87 * 77 *
88 * If progressType is ProgressDialog, a progress dialog will be 78 * If a ProgressReporter is provided, it will be updated with
89 * shown for any network transfers; if it is ProgressToConsole, a 79 * progress status. Note that the progress() signal will also be
90 * progress indication will be sent to the console. 80 * emitted regularly during retrieval, even if no reporter is
91 * Note that the progress() signal also will be emitted regularly 81 * supplied here. Caller retains ownership of the reporter object.
92 * during retrieval, even if progressType is ProgressNone. 82 */
93 */ 83 FileSource(QUrl url, ProgressReporter *reporter = 0);
94 FileSource(QUrl url,
95 ShowProgressType progressType = ProgressNone);
96 84
97 FileSource(const FileSource &); 85 FileSource(const FileSource &);
98 86
99 virtual ~FileSource(); 87 virtual ~FileSource();
100 88
210 void dataReadProgress(int done, int total); 198 void dataReadProgress(int done, int total);
211 void httpResponseHeaderReceived(const QHttpResponseHeader &resp); 199 void httpResponseHeaderReceived(const QHttpResponseHeader &resp);
212 void ftpCommandFinished(int, bool); 200 void ftpCommandFinished(int, bool);
213 void dataTransferProgress(qint64 done, qint64 total); 201 void dataTransferProgress(qint64 done, qint64 total);
214 void done(bool error); 202 void done(bool error);
215 void showProgressDialog();
216 void cancelled(); 203 void cancelled();
217 204
218 protected: 205 protected:
219 FileSource &operator=(const FileSource &); // not provided 206 FileSource &operator=(const FileSource &); // not provided
220 207
228 bool m_ok; 215 bool m_ok;
229 int m_lastStatus; 216 int m_lastStatus;
230 bool m_remote; 217 bool m_remote;
231 bool m_done; 218 bool m_done;
232 bool m_leaveLocalFile; 219 bool m_leaveLocalFile;
233 ShowProgressType m_progressType; 220 ProgressReporter *m_reporter;
234 ProgressPrinter *m_progressPrinter;
235 QProgressDialog *m_progressDialog;
236 QTimer m_progressShowTimer;
237 221
238 typedef std::map<QUrl, int> RemoteRefCountMap; 222 typedef std::map<QUrl, int> RemoteRefCountMap;
239 typedef std::map<QUrl, QString> RemoteLocalMap; 223 typedef std::map<QUrl, QString> RemoteLocalMap;
240 static RemoteRefCountMap m_refCountMap; 224 static RemoteRefCountMap m_refCountMap;
241 static RemoteLocalMap m_remoteLocalMap; 225 static RemoteLocalMap m_remoteLocalMap;