Changeset View
Changeset View
Standalone View
Standalone View
core/backends/lan/downloadjob.cpp
Context not available. | |||||
31 | #include "lanlinkprovider.h" | 31 | #include "lanlinkprovider.h" | ||
---|---|---|---|---|---|
32 | #include "core/core_debug.h" | 32 | #include "core/core_debug.h" | ||
33 | 33 | | |||
34 | DownloadJob::DownloadJob(const QHostAddress &address, const QVariantMap &transferInfo) | 34 | DownloadJob::DownloadJob(const QHostAddress& address, const QVariantMap& transferInfo) | ||
35 | : KJob() | 35 | : KJob() | ||
36 | , mAddress(address) | 36 | , m_address(address) | ||
37 | , mPort(transferInfo[QStringLiteral("port")].toInt()) | 37 | , m_port(transferInfo[QStringLiteral("port")].toInt()) | ||
38 | , mSocket(new QSslSocket) | 38 | , m_socket(new QSslSocket) | ||
39 | , mBuffer(new QBuffer) | 39 | , m_buffer(new QBuffer) | ||
40 | { | 40 | { | ||
41 | LanLinkProvider::configureSslSocket(mSocket.data(), transferInfo.value(QStringLiteral("deviceId")).toString(), true); | 41 | LanLinkProvider::configureSslSocket(m_socket.data(), transferInfo.value(QStringLiteral("deviceId")).toString(), true); | ||
42 | 42 | | |||
43 | connect(mSocket.data(), SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(socketFailed(QAbstractSocket::SocketError))); | 43 | connect(m_socket.data(), SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(socketFailed(QAbstractSocket::SocketError))); | ||
44 | // connect(mSocket.data(), &QAbstractSocket::stateChanged, [](QAbstractSocket::SocketState state){ qDebug() << "statechange" << state; }); | 44 | // connect(mSocket.data(), &QAbstractSocket::stateChanged, [](QAbstractSocket::SocketState state){ qDebug() << "statechange" << state; }); | ||
45 | } | 45 | } | ||
46 | 46 | | |||
Context not available. | |||||
53 | { | 53 | { | ||
54 | //TODO: Timeout? | 54 | //TODO: Timeout? | ||
55 | // Cannot use read only, might be due to ssl handshake, getting QIODevice::ReadOnly error and no connection | 55 | // Cannot use read only, might be due to ssl handshake, getting QIODevice::ReadOnly error and no connection | ||
56 | mSocket->connectToHostEncrypted(mAddress.toString(), mPort, QIODevice::ReadWrite); | 56 | m_socket->connectToHostEncrypted(m_address.toString(), m_port, QIODevice::ReadWrite); | ||
57 | 57 | | |||
58 | bool b = mBuffer->open(QBuffer::ReadWrite); | 58 | bool b = m_buffer->open(QBuffer::ReadWrite); | ||
59 | Q_ASSERT(b); | 59 | Q_ASSERT(b); | ||
60 | } | 60 | } | ||
61 | 61 | | |||
62 | void DownloadJob::socketFailed(QAbstractSocket::SocketError error) | 62 | void DownloadJob::socketFailed(QAbstractSocket::SocketError error) | ||
63 | { | 63 | { | ||
64 | if (error != QAbstractSocket::RemoteHostClosedError) { //remote host closes when finishes | 64 | if (error != QAbstractSocket::RemoteHostClosedError) { //remote host closes when finishes | ||
65 | qWarning(KDECONNECT_CORE) << "error..." << mSocket->errorString(); | 65 | qWarning(KDECONNECT_CORE) << "error..." << m_socket->errorString(); | ||
66 | setError(error + 1); | 66 | setError(error + 1); | ||
67 | setErrorText(mSocket->errorString()); | 67 | setErrorText(m_socket->errorString()); | ||
68 | } else { | 68 | } else { | ||
69 | auto ba = mSocket->readAll(); | 69 | auto ba = m_socket->readAll(); | ||
70 | mBuffer->write(ba); | 70 | m_buffer->write(ba); | ||
71 | mBuffer->seek(0); | 71 | m_buffer->seek(0); | ||
72 | } | 72 | } | ||
73 | emitResult(); | 73 | emitResult(); | ||
74 | } | 74 | } | ||
75 | 75 | | |||
76 | QSharedPointer<QIODevice> DownloadJob::getPayload() | 76 | QSharedPointer<QIODevice> DownloadJob::getPayload() | ||
77 | { | 77 | { | ||
78 | return mBuffer.staticCast<QIODevice>(); | 78 | return m_buffer.staticCast<QIODevice>(); | ||
79 | } | 79 | } | ||
Context not available. |