mirror of
https://github.com/saitohirga/WSJT-X.git
synced 2024-11-26 22:28:41 -05:00
924e20efa8
Samples are downloaded from a web server, currently the SF download server. The samples are stored in the source controlled samples directory and the CMake script there builds a suitable directory tree for upload to the web server under samples/web containing the samples hierarchy and the generated JSON contents database file. The samples CMake script also defines an 'upload-samples' target that uses rsync to efficiently upload the samples and the accompanying contents JSON database file. Any directory structure under the samples directory may be created, to add a new sample file simply add the file to source control and amend the list of sample files (SAMPLE_FILES) in samples/CMakeLists.txt. git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@6308 ab8295b8-cf94-4d9e-aec4-7959e3be5d79
79 lines
2.0 KiB
C++
79 lines
2.0 KiB
C++
#ifndef REMOTE_FILE_HPP__
|
|
#define REMOTE_FILE_HPP__
|
|
|
|
#include <QObject>
|
|
#include <QString>
|
|
#include <QUrl>
|
|
#include <QFileInfo>
|
|
#include <QSaveFile>
|
|
|
|
class QNetworkAccessManager;
|
|
class QNetworkReply;
|
|
|
|
//
|
|
// Synchronize an individual file specified by a URL to the local file
|
|
// system
|
|
//
|
|
class RemoteFile final
|
|
: public QObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
//
|
|
// Clients of RemoteFile must provide an instance of this
|
|
// interface. It may be used to receive information and requests
|
|
// from the RemoteFile instance as it does its work.
|
|
//
|
|
class ListenerInterface
|
|
{
|
|
protected:
|
|
ListenerInterface () {}
|
|
|
|
public:
|
|
virtual void error (QString const& title, QString const& message) = 0;
|
|
virtual bool redirect_request (QUrl const&) {return false;} // disallow
|
|
virtual void download_progress (qint64 /* bytes_received */, qint64 /* total_bytes */) {}
|
|
virtual void download_finished (bool /* success */) {}
|
|
};
|
|
|
|
explicit RemoteFile (ListenerInterface * listener, QNetworkAccessManager * network_manager
|
|
, QString const& local_file_path, QObject * parent = nullptr);
|
|
|
|
// true if local file exists or will do very soon
|
|
bool local () const;
|
|
|
|
// download/remove the local file
|
|
bool sync (QUrl const& url, bool local = true, bool force = false);
|
|
|
|
// abort an active download
|
|
void abort ();
|
|
|
|
// change the local location, this will rename if the file exists locally
|
|
void local_file_path (QString const&);
|
|
|
|
QString local_file_path () const {return local_file_.absoluteFilePath ();}
|
|
QUrl url () const {return url_;}
|
|
|
|
private:
|
|
void download (QUrl const& url);
|
|
void reply_finished ();
|
|
|
|
Q_SLOT void store ();
|
|
|
|
Q_SIGNAL void redirect (QUrl const&, unsigned redirect_count);
|
|
Q_SIGNAL void downloadProgress (qint64 bytes_received, qint64 total_bytes);
|
|
Q_SIGNAL void finished ();
|
|
|
|
ListenerInterface * listener_;
|
|
QNetworkAccessManager * network_manager_;
|
|
QFileInfo local_file_;
|
|
QUrl url_;
|
|
QNetworkReply * reply_;
|
|
bool is_valid_;
|
|
unsigned redirect_count_;
|
|
QSaveFile file_;
|
|
};
|
|
|
|
#endif
|