LeechCraft
0.6.70-18450-gabe19ee3b0
Modular cross-platform feature rich live environment.
Toggle main menu visibility
Loading...
Searching...
No Matches
customnetworkreply.cpp
Go to the documentation of this file.
1
/**********************************************************************
2
* LeechCraft - modular cross-platform feature rich internet client.
3
* Copyright (C) 2006-2014 Georg Rudoy
4
*
5
* Distributed under the Boost Software License, Version 1.0.
6
* (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7
**********************************************************************/
8
9
#include "
customnetworkreply.h
"
10
#include <cstring>
11
#include <QTimer>
12
13
namespace
LC::Util
14
{
15
CustomNetworkReply::CustomNetworkReply
(
const
QUrl& url, QObject *parent)
16
: QNetworkReply (parent)
17
{
18
setUrl (url);
19
}
20
21
void
CustomNetworkReply::SetContentType
(
const
QByteArray& ct)
22
{
23
setHeader (QNetworkRequest::ContentTypeHeader, ct);
24
}
25
26
void
CustomNetworkReply::SetContent
(
const
QString& content)
27
{
28
SetContent
(content.toUtf8 ());
29
}
30
31
void
CustomNetworkReply::SetContent
(
const
QByteArray& content)
32
{
33
Content_ = content;
34
Offset_ = 0;
35
36
open (ReadOnly | Unbuffered);
37
38
setHeader (QNetworkRequest::ContentLengthHeader, Content_.size ());
39
40
QTimer::singleShot (0,
41
this
,
42
&CustomNetworkReply::readyRead);
43
QTimer::singleShot (0,
44
this
,
45
&CustomNetworkReply::finished);
46
}
47
48
void
CustomNetworkReply::abort
()
49
{
50
}
51
52
qint64
CustomNetworkReply::bytesAvailable
()
const
53
{
54
return
Content_.size () - Offset_;
55
}
56
57
bool
CustomNetworkReply::isSequential
()
const
58
{
59
return
true
;
60
}
61
62
qint64
CustomNetworkReply::readData
(
char
*data, qint64 maxSize)
63
{
64
if
(Offset_ >= Content_.size ())
65
return
-1;
66
67
qint64 number = std::min (maxSize,
bytesAvailable
());
68
std::memcpy (data, Content_.constData () + Offset_, number);
69
Offset_ += number;
70
71
return
number;
72
}
73
}
LC::Util::CustomNetworkReply::SetContentType
void SetContentType(const QByteArray &type)
Sets the content type of this reply.
Definition
customnetworkreply.cpp:21
LC::Util::CustomNetworkReply::bytesAvailable
qint64 bytesAvailable() const override
Reimplemented from QNetworkReply::bytesAvailable().
Definition
customnetworkreply.cpp:52
LC::Util::CustomNetworkReply::abort
void abort() override
Reimplemented from QNetworkReply::abort().
Definition
customnetworkreply.cpp:48
LC::Util::CustomNetworkReply::CustomNetworkReply
CustomNetworkReply(const QUrl &url, QObject *parent=nullptr)
Creates the reply with the given url and parent.
Definition
customnetworkreply.cpp:15
LC::Util::CustomNetworkReply::SetContent
void SetContent(const QString &string)
Sets content of this reply to the given string.
Definition
customnetworkreply.cpp:26
LC::Util::CustomNetworkReply::readData
qint64 readData(char *, qint64) override
Definition
customnetworkreply.cpp:62
LC::Util::CustomNetworkReply::isSequential
bool isSequential() const override
Reimplemented from QNetworkReply::isSequential().
Definition
customnetworkreply.cpp:57
customnetworkreply.h
LC::Util
Definition
icoreproxy.h:34
src
util
network
customnetworkreply.cpp
Generated by
1.17.0