qTbot 0.89.ee6949a
qTbot is base back end library for your c++ Qt projects.
file.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 "file.h"
9
10namespace qTbot {
11
12
13File::File(const QSharedPointer<QNetworkReply> &replay, const QString &filePath): iFile(replay) {
14 _localFile.setFileName(filePath);
15
16 if (!_localFile.isOpen()) {
17 _localFile.open(QIODevice::Truncate | QIODevice::WriteOnly | QIODevice::Append);
18 }
19
20}
21
22File::File(const QString &filePath):File(nullptr, filePath) {
23
24}
25
26const QFile & File::localFile() const {
27 return _localFile;
28}
29
31 return Type::Local;
32}
33
35 auto&& bytes = replay()->readAll();
36
37 if (bytes.size()) {
38 _localFile.write(bytes);
39 _localFile.flush();
40 }
41}
42
45 _localFile.close();
47}
48
49void File::handleError(QNetworkReply::NetworkError error) {
51 _localFile.close();
52
53 _localFile.remove();
54}
55
56}
The File class is implementations for local files.
Definition file.h:20
void handleError(QNetworkReply::NetworkError error) override
Definition file.cpp:49
void handleFinished() override
Definition file.cpp:43
void handleReadReady() override
Definition file.cpp:34
Type type() const override
type This is type of the file object.
Definition file.cpp:30
File(const QSharedPointer< QNetworkReply > &replay, const QString &filePath)
Definition file.cpp:13
const QFile & localFile() const
Definition file.cpp:26
The iFile class This is main interface for all implementations of the files.
Definition ifile.h:21
Type
The Type enum is type of the file object.
Definition ifile.h:28
@ Local
This is local file, all receive bytes will be save directed into file.
Definition ifile.h:30
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
int error() const
Get the error code associated with this file.
Definition ifile.cpp:40
virtual void handleFinished()
Slot to handle when the network operation is finished.
Definition ifile.cpp:122