API Documentation
Loading...
Searching...
No Matches
ItemDownloader.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: Widgets
28File: ItemDownloader
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include "DLLInfo.h"
34#include <NDEVR/BaseValues.h>
35#include <NDEVR/TimeSpan.h>
36#include <NDEVR/String.h>
37#include <QObject>
38#include <QByteArray>
39class QNetworkRequest;
40class QNetworkReply;
41class QNetworkAccessManager;
42namespace NDEVR
43{
44 class ReplyTimeout;
45 class String;
46 class NDEVR_WIDGETS_API NetworkRequest : public QObject
47 {
48 Q_OBJECT
49 public:
50 virtual void close() = 0;
51 virtual void abort() = 0;
52 virtual bool isRunning() = 0;
53 virtual bool start() = 0;
54 virtual QByteArray data() = 0;
55 signals:
60 void errorOccurredSignal(int error);
61 //void encryptedSignal();
62 //void sslErrorsSignal(const QList<QSslError>& errors);
63 //void preSharedKeyAuthenticationRequiredSignal(QSslPreSharedKeyAuthenticator* authenticator);
64 //void redirectedSignal(const QUrl& url);
66 void uploadProgressSignal(qint64 bytesSent, qint64 bytesTotal);
67 void downloadProgressSignal(qint64 bytesReceived, qint64 bytesTotal);
68 };
69 class NDEVR_WIDGETS_API TimeRequest : public QObject
70 {
71 Q_OBJECT
72 public:
73 virtual Time serverTime() const = 0;
74 virtual Time txTime() const = 0;
75 virtual Time rxTime() const = 0;
77 {
78 return rxTime() - txTime();
79 }
81 {
82 return ((serverTime() - rxTime()) - (serverTime() - txTime())) / 2.0;
83 }
84 signals:
86 void errorOccurredSignal(int error);
87 };
96 {
97 public:
98 virtual NetworkRequest* downloadFromURL(const WebTarget& url) = 0;
99 virtual NetworkRequest* uploadToURL(const WebTarget& request, const Buffer<uint01>& data) = 0;
100 virtual NetworkRequest* uploadToURL(const WebTarget& request, const File& data) = 0;
101 virtual TimeRequest* networkTimeFromURL(const String& url, uint02 port = 123) = 0;
102 };
103 class NDEVR_WIDGETS_API ItemDownloader : public QObject
104 {
105 Q_OBJECT
106 public:
107 explicit ItemDownloader(const String& url, QObject* parent = nullptr);
108 explicit ItemDownloader(QUrl url, QObject* parent = nullptr);
110 [[nodiscard]] const QByteArray& downloadedData() const;
111 [[nodiscard]] uint08 currentDownloadSize() const { return m_current_download_size; }
112 [[nodiscard]] uint08 totalDownloadSize() const { return m_total_download_size; }
113 [[nodiscard]] fltp08 downloadPercent() const;
116 static bool HasNetworkManager();
117 void start();
118 signals:
122 protected:
123 void setNetworkRequest(const String& url);
124 private slots:
125 void fileDownloadedSlot();
126 void downloadedErrorSlot(int error);
127 void updateDownloadProgressSlot(qint64 ist, qint64 max);
128 private:
129 static NetworkAccessManager* s_web_ctrl;
130 NetworkRequest* m_request;
131 ReplyTimeout* m_reply_timeout;
132 //QNetworkAccessManager* m_web_ctrl;
133 QByteArray m_data;
134 uint08 m_current_download_size;
135 uint08 m_total_download_size;
136 bool m_failed;
137 };
138
139}
#define NDEVR_WIDGETS_API
Definition DLLInfo.h:81
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:59
Logic for reading or writing to a file as well as navigating filesystems.
Definition File.h:48
Definition ItemDownloader.h:104
ItemDownloader(QUrl url, QObject *parent=nullptr)
const QByteArray & downloadedData() const
fltp08 downloadPercent() const
static NetworkAccessManager * NetworkManager()
static void SetAccessManager(NetworkAccessManager *manager)
uint08 currentDownloadSize() const
Definition ItemDownloader.h:111
void setNetworkRequest(const String &url)
static bool HasNetworkManager()
void downloadFailedSignal(int)
ItemDownloader(const String &url, QObject *parent=nullptr)
uint08 totalDownloadSize() const
Definition ItemDownloader.h:112
Definition ItemDownloader.h:96
virtual TimeRequest * networkTimeFromURL(const String &url, uint02 port=123)=0
virtual NetworkRequest * uploadToURL(const WebTarget &request, const File &data)=0
virtual NetworkRequest * uploadToURL(const WebTarget &request, const Buffer< uint01 > &data)=0
virtual NetworkRequest * downloadFromURL(const WebTarget &url)=0
Definition ItemDownloader.h:47
void errorOccurredSignal(int error)
void downloadProgressSignal(qint64 bytesReceived, qint64 bytesTotal)
void uploadProgressSignal(qint64 bytesSent, qint64 bytesTotal)
void socketStartedConnectingSignal()
virtual void abort()=0
virtual QByteArray data()=0
virtual bool start()=0
virtual bool isRunning()=0
virtual void close()=0
Handles timing out certain operations such as downloads.
Definition ReplyTimeout.h:11
The core String class for the software.
Definition String.h:47
Represents a timestamp with utilities for manipulation and conversion.
Definition Time.h:54
Definition ItemDownloader.h:70
TimeSpan roundTripDelay() const
Definition ItemDownloader.h:76
void errorOccurredSignal(int error)
virtual Time serverTime() const =0
TimeSpan localClockOffset() const
Definition ItemDownloader.h:80
virtual Time rxTime() const =0
virtual Time txTime() const =0
Stores a time span, or difference between two times, with an optional start time.
Definition TimeSpan.h:46
Definition ACIColor.h:37
uint64_t uint08
-Defines an alias representing an 8 byte, unsigned integer
Definition BaseValues.hpp:104
uint16_t uint02
-Defines an alias representing a 2 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:86
double fltp08
Defines an alias representing an 8 byte floating-point number.
Definition BaseValues.hpp:146
Defines for a given type (such as sint04, fltp08, UUID, etc) a maximum, minimum, and reserved.
Definition BaseValues.hpp:230
Definition ItemDownloader.h:89
uint02 port
Definition ItemDownloader.h:93
String url
Definition ItemDownloader.h:90
String password
Definition ItemDownloader.h:92
String username
Definition ItemDownloader.h:91