qTbot 0.89.ee6949a
qTbot is base back end library for your c++ Qt projects.
ifile.cpp
Go to the documentation of this file.
1//#
2//# Copyright (C) 2023-2024 QuasarApp.
3//# Distributed under the GPLv3 software license, see the accompanying
4//# Everyone is permitted to copy and distribute verbatim copies
5//# of this license document, but changing it is not allowed.
6//#
7
8#include "ifile.h"
9
10namespace qTbot {
11
12iFile::iFile(const QSharedPointer<QNetworkReply>& replay) {
14}
15
16float iFile::uploadProgress() const {
17 return _uploadProgress;
18}
19
20void iFile::setUploadProgress(float newUploadProgress) {
21 if (qFuzzyCompare(_uploadProgress, newUploadProgress))
22 return;
23
24 _uploadProgress = newUploadProgress;
26}
27
29 return _downloadProgress;
30}
31
32void iFile::setDownloadProgress(float newDownloadProgress) {
33 if (qFuzzyCompare(_downloadProgress, newDownloadProgress))
34 return;
35
36 _downloadProgress = newDownloadProgress;
38}
39
40int iFile::error() const {
41 return _error;
42}
43
44void iFile::setError(int newError) {
45 if (_error == newError)
46 return;
47 _error = newError;
48 emit errorChanged();
49}
50
51const QSharedPointer<QNetworkReply> &iFile::replay() const {
52 return _replay;
53}
54
55bool iFile::isFinished() const {
56 return _finished;
57}
58
59void iFile::handleError(QNetworkReply::NetworkError error) {
63
64}
65
66void iFile::handleUploadProgressChanged(qint64 bytesSent, qint64 bytesTotal) {
67 setUploadProgress(bytesSent / static_cast<float>(bytesTotal));
68}
69
70void iFile::handleDownloadProgressChanged(qint64 bytesReceived, qint64 bytesTotal) {
71 setDownloadProgress(bytesReceived / static_cast<float>(bytesTotal));
72}
73
74void iFile::setDownloadRequest(const QSharedPointer<QNetworkReply> &replay) {
75
76 if (_replay) {
77 disconnect(_replay.get(), &QNetworkReply::finished,
79
80 disconnect(_replay.get(), &QNetworkReply::errorOccurred,
81 this, &iFile::handleError);
82
83 disconnect(_replay.get(), &QNetworkReply::readyRead,
85
86 disconnect(_replay.get(), &QNetworkReply::uploadProgress,
87 this, &iFile::handleUploadProgressChanged);
88
89 disconnect(_replay.get(), &QNetworkReply::downloadProgress,
90 this, &iFile::handleDownloadProgressChanged);
91 }
92
93 _replay = replay;
94
95 if (_replay) {
96 connect(replay.get(), &QNetworkReply::finished,
97 this, &iFile::handleFinished, Qt::DirectConnection);
98
99 connect(replay.get(), &QNetworkReply::errorOccurred,
100 this, &iFile::handleError, Qt::DirectConnection);
101
102 connect(replay.get(), &QNetworkReply::readyRead,
103 this, &iFile::handleReadReady, Qt::DirectConnection);
104
105 connect(replay.get(), &QNetworkReply::uploadProgress,
106 this, &iFile::handleUploadProgressChanged, Qt::DirectConnection);
107
108 connect(replay.get(), &QNetworkReply::downloadProgress,
109 this, &iFile::handleDownloadProgressChanged, Qt::DirectConnection);
110 }
111
112}
113
114void iFile::setFinished(bool newFinished) {
115
116 if (newFinished != _finished) {
117 _finished = newFinished;
118 emit finishedChanged();
119 }
120}
121
123 setFinished(true);
124}
125}
void errorChanged()
Signal emitted when the error code changes.
void uploadProgressChanged()
Signal emitted when the upload progress changes.
void downloadProgressChanged()
Signal emitted when the download progress changes.
float downloadProgress() const
Get the current download progress.
Definition ifile.cpp:28
virtual void handleReadReady()=0
Slot to handle when data is ready to be read.
iFile(const QSharedPointer< QNetworkReply > &replay)
Definition ifile.cpp:12
void setError(int newError)
Set the error code for this file.
Definition ifile.cpp:44
void setDownloadRequest(const QSharedPointer< QNetworkReply > &replay)
setDownloadRequest This method sets replay for the file.
Definition ifile.cpp:74
const QSharedPointer< QNetworkReply > & replay() const
Get the shared pointer to the associated QNetworkReply.
Definition ifile.cpp:51
virtual void handleError(QNetworkReply::NetworkError error)
Slot to handle errors in the network operation.
Definition ifile.cpp:59
void setUploadProgress(float newUploadProgress)
Set the upload progress.
Definition ifile.cpp:20
bool isFinished() const
finished return true if the request was finished else false.
Definition ifile.cpp:55
void finishedChanged()
Signal emitted when the associated finished changes.
void setDownloadProgress(float newDownloadProgress)
Set the download progress.
Definition ifile.cpp:32
int error() const
Get the error code associated with this file.
Definition ifile.cpp:40
void setFinished(bool newFinished)
setFinished monual sets finished flag.
Definition ifile.cpp:114
virtual void handleFinished()
Slot to handle when the network operation is finished.
Definition ifile.cpp:122
float uploadProgress() const
Get the current upload progress.
Definition ifile.cpp:16