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/SoftwareService.h>
35#include <NDEVR/BaseValues.h>
36#include <NDEVR/TimeSpan.h>
37#include <NDEVR/String.h>
38#include <QObject>
39#include <QByteArray>
40class QNetworkRequest;
41class QNetworkReply;
42class QNetworkAccessManager;
43namespace NDEVR
44{
45 class ReplyTimeout;
46 class String;
47 /**--------------------------------------------------------------------------------------------------
48 \brief A request for data or information from a network.
49 **/
50 class NDEVR_WIDGETS_API NetworkRequest : public QObject
51 {
52 Q_OBJECT
53 public:
54 virtual void close() = 0;
55 virtual void abort() = 0;
56 virtual bool isRunning() = 0;
57 virtual bool start() = 0;
58 virtual QByteArray data() = 0;
59 signals:
64 void errorOccurredSignal(int error);
65 //void encryptedSignal();
66 //void sslErrorsSignal(const QList<QSslError>& errors);
67 //void preSharedKeyAuthenticationRequiredSignal(QSslPreSharedKeyAuthenticator* authenticator);
68 //void redirectedSignal(const QUrl& url);
70 void uploadProgressSignal(qint64 bytesSent, qint64 bytesTotal);
71 void downloadProgressSignal(qint64 bytesReceived, qint64 bytesTotal);
72 };
73 /**--------------------------------------------------------------------------------------------------
74 \brief A request to get the time from the network.
75 **/
76 class NDEVR_WIDGETS_API TimeRequest : public QObject
77 {
78 Q_OBJECT
79 public:
80 virtual Time serverTime() const = 0;
81 virtual Time txTime() const = 0;
82 virtual Time rxTime() const = 0;
84 {
85 return rxTime() - txTime();
86 }
88 {
89 return ((serverTime() - rxTime()) - (serverTime() - txTime())) / 2.0;
90 }
91 signals:
93 void errorOccurredSignal(int error);
94 };
95 /**--------------------------------------------------------------------------------------------------
96 \brief A url target and optional username and password for a network request.
97 **/
105 /**--------------------------------------------------------------------------------------------------
106 \brief Provides an interface for accessing resources on the internet.
107 **/
109 {
110 public:
111 virtual NetworkRequest* downloadFromURL(const WebTarget& url) = 0;
112 virtual NetworkRequest* uploadToURL(const WebTarget& request, const Buffer<uint01>& data) = 0;
113 virtual NetworkRequest* uploadToURL(const WebTarget& request, const File& data) = 0;
114 virtual TimeRequest* networkTimeFromURL(const String& url, uint02 port = 123) = 0;
115 };
116 /**--------------------------------------------------------------------------------------------------
117 \brief Used for Downloading resources from a network.
118 **/
120 {
121 Q_OBJECT
122 public:
123 explicit ItemDownloader(const String& url, QObject* parent = nullptr);
124 explicit ItemDownloader(QUrl url, QObject* parent = nullptr);
126 [[nodiscard]] const QByteArray& downloadedData() const;
127 [[nodiscard]] uint08 currentDownloadSize() const { return m_current_download_size; }
128 [[nodiscard]] uint08 totalDownloadSize() const { return m_total_download_size; }
129 [[nodiscard]] fltp08 downloadPercent() const;
132 static bool HasNetworkManager();
133 void start();
134 signals:
138 protected:
139 void setNetworkRequest(const String& url);
140 private slots:
141 void fileDownloadedSlot();
142 void downloadedErrorSlot(int error);
143 void updateDownloadProgressSlot(qint64 ist, qint64 max);
144 private:
145 static NetworkAccessManager* s_web_ctrl;
146 NetworkRequest* m_request;
147 ReplyTimeout* m_reply_timeout;
148 //QNetworkAccessManager* m_web_ctrl;
149 QByteArray m_data;
150 uint08 m_current_download_size;
151 uint08 m_total_download_size;
152 bool m_failed;
153 };
154
155}
#define NDEVR_WIDGETS_API
Definition DLLInfo.h:59
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:56
Logic for reading or writing to a file as well as navigating filesystems.
Definition File.h:48
Used for Downloading resources from a network.
Definition ItemDownloader.h:120
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:127
void setNetworkRequest(const String &url)
static bool HasNetworkManager()
void downloadFailedSignal(int)
ItemDownloader(const String &url, QObject *parent=nullptr)
uint08 totalDownloadSize() const
Definition ItemDownloader.h:128
Provides an interface for accessing resources on the internet.
Definition ItemDownloader.h:109
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
A request for data or information from a network.
Definition ItemDownloader.h:51
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
Software Services provide an interface for adding to or changing the software behavior via functional...
Definition SoftwareService.h:9
Software Service Managers take a Software service to modify the behavior of the software.
Definition SoftwareService.h:15
The core String class for the NDEVR API.
Definition String.h:69
Represents a timestamp with utilities for manipulation and conversion.
Definition Time.h:54
A request to get the time from the network.
Definition ItemDownloader.h:77
TimeSpan roundTripDelay() const
Definition ItemDownloader.h:83
void errorOccurredSignal(int error)
virtual Time serverTime() const =0
TimeSpan localClockOffset() const
Definition ItemDownloader.h:87
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:106
uint16_t uint02
-Defines an alias representing a 2 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:88
double fltp08
Defines an alias representing an 8 byte floating-point number.
Definition BaseValues.hpp:149
Defines for a given type (such as sint04, fltp08, UUID, etc) a maximum, minimum, and reserved 'invali...
Definition BaseValues.hpp:233
A url target and optional username and password for a network request.
Definition ItemDownloader.h:99
uint02 port
Definition ItemDownloader.h:103
String url
Definition ItemDownloader.h:100
String password
Definition ItemDownloader.h:102
String username
Definition ItemDownloader.h:101