WSJT-X/SampleDownloader/FileNode.hpp
Bill Somerville 0efe9231bb Add a sample download dialog and upload sub-system
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
2015-12-24 11:41:05 +00:00

68 lines
2.0 KiB
C++

#ifndef FILE_NODE_HPP__
#define FILE_NODE_HPP__
#include <QTreeWidgetItem>
#include "RemoteFile.hpp"
class QNetworkAccessManager;
class QString;
class QUrl;
//
// A holder for a RemoteFile object linked to a QTreeWidget row.
//
// It renders the file name in first column and holds download
// progress data in the second column. The progress information is a
// 64 bit integer number of bytes in the DisplayRole and a total bytes
// expected in the UserRole. The first column also renders a check box
// that downloads the file when checked and removes the downloaded
// file when unchecked. The URL and local absolute file path are
// stored in the UserData and UserData+1 roles of the first column.
//
class FileNode final
: public QTreeWidgetItem
, protected RemoteFile::ListenerInterface
{
public:
explicit FileNode (QTreeWidgetItem * parent
, QNetworkAccessManager * network_manager
, QString const& local_path
, QUrl const& url);
bool local () const {return remote_file_.local ();}
bool sync (bool local);
void abort ();
static int const Type {UserType + 1};
//
// Clients may use this RAII class to block nested calls to sync
// which may be troublesome, e.g. when UI updates cause recursion.
//
struct sync_blocker
{
sync_blocker (FileNode * node) : node_ {node} {node_->block_sync_ = true;}
sync_blocker (sync_blocker const&) = delete;
sync_blocker& operator = (sync_blocker const&) = delete;
~sync_blocker () {node_->block_sync_ = false;}
private:
FileNode * node_;
};
protected:
void error (QString const& title, QString const& message) override;
bool redirect_request (QUrl const&) override {return true;} // allow
void download_progress (qint64 bytes_received, qint64 total_bytes) override;
void download_finished (bool success) override;
private:
QNetworkAccessManager * network_manager_;
RemoteFile remote_file_; // active download
bool block_sync_;
friend struct sync_blocker;
};
#endif