diff data/fileio/RemoteFile.h @ 316:3a6725f285d6

* Make RemoteFile far more pervasive, and use it for local files as well so that we can handle both transparently. Make it shallow copy with reference counting, so it can be used by value without having to worry about the cache file lifetime. Use RemoteFile for MainWindow file-open functions, etc
author Chris Cannam
date Thu, 18 Oct 2007 15:31:20 +0000
parents 96ef9746c560
children
line wrap: on
line diff
--- a/data/fileio/RemoteFile.h	Thu Oct 18 10:24:26 2007 +0000
+++ b/data/fileio/RemoteFile.h	Thu Oct 18 15:31:20 2007 +0000
@@ -34,23 +34,30 @@
     Q_OBJECT
 
 public:
-    RemoteFile(QUrl url);
+    RemoteFile(QString fileOrUrl, bool showProgress = true);
+    RemoteFile(QUrl url, bool showProgress = true);
+    RemoteFile(const RemoteFile &);
+
     virtual ~RemoteFile();
 
     bool isAvailable();
 
-    void wait();
+    void waitForStatus();
+    void waitForData();
+
+    void setLeaveLocalFile(bool leave);
 
     bool isOK() const;
     bool isDone() const;
+    bool isRemote() const;
 
+    QString getLocation() const;
+    QString getLocalFilename() const;
     QString getContentType() const;
+    QString getExtension() const;
 
-    QString getLocalFilename() const;
     QString getErrorString() const;
 
-    void deleteLocalFile();
-
     static bool isRemote(QString fileOrUrl);
     static bool canHandleScheme(QUrl url);
 
@@ -68,6 +75,8 @@
     void cancelled();
 
 protected:
+    RemoteFile &operator=(const RemoteFile &); // not provided
+
     QUrl m_url;
     QFtp *m_ftp;
     QHttp *m_http;
@@ -77,7 +86,9 @@
     QString m_contentType;
     bool m_ok;
     int m_lastStatus;
+    bool m_remote;
     bool m_done;
+    bool m_leaveLocalFile;
     QProgressDialog *m_progressDialog;
     QTimer m_progressShowTimer;
 
@@ -86,11 +97,18 @@
     static RemoteRefCountMap m_refCountMap;
     static RemoteLocalMap m_remoteLocalMap;
     static QMutex m_mapMutex;
-    bool m_referenced;
+    bool m_refCounted;
+
+    void init(bool showProgress);
+    void initHttp();
+    void initFtp();
 
     void cleanup();
 
-    QString createLocalFile(QUrl url);
+    // Create a local file for m_url.  If it already existed, return true.
+    // The local filename is stored in m_localFilename.
+    bool createCacheFile();
+    void deleteCacheFile();
 
     static QMutex m_fileCreationMutex;
     static int m_count;