Just Intonation  Version 1.3.0 (18)
Explore scale-independent dynamically adapting tuning in just intonation
downloader.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * Copyright 2016-2017 Karolin Stange, Christoph Wick, and Haye Hinrichsen
3  *
4  * This file is part of JustIntonation.
5  *
6  * JustIntonation is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by the
8  * Free Software Foundation, either version 3 of the License, or (at your
9  * option) any later version.
10  *
11  * JustIntonation is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14  * for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with JustIntonation. If not, see http://www.gnu.org/licenses/.
18  *****************************************************************************/
19 
20 //=============================================================================
21 // Downloader
22 //=============================================================================
23 
24 #ifndef DOWNLOADER_H
25 #define DOWNLOADER_H
26 
27 #include <QObject>
28 #include <QByteArray>
29 #include <QNetworkAccessManager>
30 #include <QNetworkRequest>
31 #include <QNetworkReply>
32 #include <QVariant>
33 #include <QFile>
34 
35 #include "system/shared.h"
36 #include "system/log.h"
37 
47 
48 class Downloader : public QObject , public Log
49 {
50  Q_OBJECT
51 public:
52 
53  explicit Downloader(QString url, QObject *parent = 0);
54  virtual ~Downloader() {}
55 
56  void start(bool forced);
57  void stop();
58  bool isDownloading() { return mIsDownloading; }
59 
60  QStringList getPathsOfDownloadedFiles();
61 
62 signals:
63  void signalNoInternetConnection (QVariant forced);
64  void signalDownloading (QVariant downloading);
65  void signalProgress (QVariant filesRemaining, QVariant percent);
66  void signalNewFileDownloaded (QString localpath);
68 
69 private slots:
70  void downloadIndexFile();
71  void indexFileDownloadFinished (QNetworkReply* pReply);
74  void downloadProgress (qint64 bytesReceived, qint64 bytesTotal);
75  void downloadComplete (QNetworkReply* pReply);
76  void finalize();
77 
78 private:
79  QString fullPath (const QString &path, const QString &file) const;
80  bool isConnectedToInternet();
81 
82 private:
83  QString mLocalPath;
84  QString mRemotePath;
85  QString mIndexFileName;
86  QNetworkAccessManager mNetworkManager;
87  QStringList mIndexOfFiles;
88  QNetworkReply *pNetworkReply;
89  QFile mFile;
93 };
94 
95 #endif // DOWNLOADER_H
void signalNewFileDownloaded(QString localpath)
void checkWhetherFileExistsAndDownload()
Private slot: Start downloading if necessary.
Definition: downloader.cpp:361
QString mLocalPath
Local path of the file to be downloaded.
Definition: downloader.h:83
void downloadIndexFile()
Download index file.
Definition: downloader.cpp:164
void signalDownloading(QVariant downloading)
void stop()
Stop downloading.
Definition: downloader.cpp:220
void finalize()
Finalize download.
Definition: downloader.cpp:529
bool isConnectedToInternet()
Check internet connection.
Definition: downloader.cpp:73
bool mForcedDownload
Flag for forced download.
Definition: downloader.h:91
Downloader(QString url, QObject *parent=0)
Constructor, resetting the member variables.
Definition: downloader.cpp:48
void start(bool forced)
Start the downloading process in the background.
Definition: downloader.cpp:112
void signalNoInternetConnection(QVariant forced)
QNetworkAccessManager mNetworkManager
Instance of the Qt network access manager.
Definition: downloader.h:86
QString mRemotePath
Remote path of the file to be downloaded.
Definition: downloader.h:84
void downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
Private slot: Download a data chunk and report progress.
Definition: downloader.cpp:456
bool isDownloading()
Definition: downloader.h:58
QNetworkReply * pNetworkReply
Pointer to the network reply structure.
Definition: downloader.h:88
void initiateDownloadOfNextFile()
Private slot: Initiate download of next file.
Definition: downloader.cpp:336
QString fullPath(const QString &path, const QString &file) const
Helper function: Construct a full path out of a path and a file name.
Definition: downloader.cpp:553
Class managing the download of large files from a repository in the background.
Definition: downloader.h:48
QString mIndexFileName
Name of the remote index file.
Definition: downloader.h:85
QFile mFile
File to be written.
Definition: downloader.h:89
bool mIsWaitingForConnection
Flag indicating waiting status.
Definition: downloader.h:90
void signalProgress(QVariant filesRemaining, QVariant percent)
void signalAllFilesDownloaded()
Base class for managing log messages.
Definition: log.h:83
virtual ~Downloader()
Definition: downloader.h:54
QStringList getPathsOfDownloadedFiles()
Get a list of paths of all downloaded files.
Definition: downloader.cpp:242
void indexFileDownloadFinished(QNetworkReply *pReply)
Private slot: Index file downloaded.
Definition: downloader.cpp:277
QStringList mIndexOfFiles
The content of the index file as a QStringList.
Definition: downloader.h:87
void downloadComplete(QNetworkReply *pReply)
Private slot: Download completed.
Definition: downloader.cpp:480
bool mIsDownloading
Flag indicating active download.
Definition: downloader.h:92