trim some whitespace

This commit is contained in:
Nicolas Fella 2020-05-09 16:46:52 +02:00
parent 15cbe32259
commit 4254b23d5d
2 changed files with 34 additions and 34 deletions

View file

@ -64,21 +64,21 @@ void CompositeUploadJob::start() {
qCWarning(KDECONNECT_CORE) << "CompositeUploadJob::start() - already running"; qCWarning(KDECONNECT_CORE) << "CompositeUploadJob::start() - already running";
return; return;
} }
if (!hasSubjobs()) { if (!hasSubjobs()) {
qCWarning(KDECONNECT_CORE) << "CompositeUploadJob::start() - there are no subjobs to start"; qCWarning(KDECONNECT_CORE) << "CompositeUploadJob::start() - there are no subjobs to start";
emitResult(); emitResult();
return; return;
} }
if (!startListening()) { if (!startListening()) {
return; return;
} }
connect(m_server, &QTcpServer::newConnection, this, &CompositeUploadJob::newConnection); connect(m_server, &QTcpServer::newConnection, this, &CompositeUploadJob::newConnection);
m_running = true; m_running = true;
//Give SharePlugin some time to add subjobs //Give SharePlugin some time to add subjobs
QMetaObject::invokeMethod(this, "startNextSubJob", Qt::QueuedConnection); QMetaObject::invokeMethod(this, "startNextSubJob", Qt::QueuedConnection);
} }
@ -97,7 +97,7 @@ bool CompositeUploadJob::startListening()
return false; return false;
} }
} }
qCDebug(KDECONNECT_CORE) << "CompositeUploadJob::startListening() - listening on port: " << m_port; qCDebug(KDECONNECT_CORE) << "CompositeUploadJob::startListening() - listening on port: " << m_port;
return true; return true;
} }
@ -115,7 +115,7 @@ void CompositeUploadJob::startNextSubJob()
#endif #endif
//Already done by KCompositeJob //Already done by KCompositeJob
//connect(m_currentJob, &KJob::result, this, &CompositeUploadJob::slotResult); //connect(m_currentJob, &KJob::result, this, &CompositeUploadJob::slotResult);
//TODO: Create a copy of the networkpacket that can be re-injected if sending via lan fails? //TODO: Create a copy of the networkpacket that can be re-injected if sending via lan fails?
NetworkPacket np = m_currentJob->getNetworkPacket(); NetworkPacket np = m_currentJob->getNetworkPacket();
#if QT_VERSION < QT_VERSION_CHECK(5,8,0) #if QT_VERSION < QT_VERSION_CHECK(5,8,0)
@ -126,7 +126,7 @@ void CompositeUploadJob::startNextSubJob()
np.setPayloadTransferInfo({{QStringLiteral("port"), m_port}}); np.setPayloadTransferInfo({{QStringLiteral("port"), m_port}});
np.set<int>(QStringLiteral("numberOfFiles"), m_totalJobs); np.set<int>(QStringLiteral("numberOfFiles"), m_totalJobs);
np.set<quint64>(QStringLiteral("totalPayloadSize"), m_totalPayloadSize); np.set<quint64>(QStringLiteral("totalPayloadSize"), m_totalPayloadSize);
if (Daemon::instance()->getDevice(m_deviceId)->sendPacket(np)) { if (Daemon::instance()->getDevice(m_deviceId)->sendPacket(np)) {
m_server->resumeAccepting(); m_server->resumeAccepting();
} else { } else {
@ -140,21 +140,21 @@ void CompositeUploadJob::startNextSubJob()
void CompositeUploadJob::newConnection() void CompositeUploadJob::newConnection()
{ {
m_server->pauseAccepting(); m_server->pauseAccepting();
m_socket = m_server->nextPendingConnection(); m_socket = m_server->nextPendingConnection();
if (!m_socket) { if (!m_socket) {
qCDebug(KDECONNECT_CORE) << "CompositeUploadJob::newConnection() - m_server->nextPendingConnection() returned a nullptr"; qCDebug(KDECONNECT_CORE) << "CompositeUploadJob::newConnection() - m_server->nextPendingConnection() returned a nullptr";
return; return;
} }
m_currentJob->setSocket(m_socket); m_currentJob->setSocket(m_socket);
connect(m_socket, &QSslSocket::disconnected, this, &CompositeUploadJob::socketDisconnected); connect(m_socket, &QSslSocket::disconnected, this, &CompositeUploadJob::socketDisconnected);
connect(m_socket, QOverload<QAbstractSocket::SocketError>::of(&QAbstractSocket::error), this, &CompositeUploadJob::socketError); connect(m_socket, QOverload<QAbstractSocket::SocketError>::of(&QAbstractSocket::error), this, &CompositeUploadJob::socketError);
connect(m_socket, QOverload<const QList<QSslError> &>::of(&QSslSocket::sslErrors), this, &CompositeUploadJob::sslError); connect(m_socket, QOverload<const QList<QSslError> &>::of(&QSslSocket::sslErrors), this, &CompositeUploadJob::sslError);
connect(m_socket, &QSslSocket::encrypted, this, &CompositeUploadJob::encrypted); connect(m_socket, &QSslSocket::encrypted, this, &CompositeUploadJob::encrypted);
LanLinkProvider::configureSslSocket(m_socket, m_deviceId, true); LanLinkProvider::configureSslSocket(m_socket, m_deviceId, true);
m_socket->startServerEncryption(); m_socket->startServerEncryption();
@ -168,7 +168,7 @@ void CompositeUploadJob::socketDisconnected()
void CompositeUploadJob::socketError(QAbstractSocket::SocketError error) void CompositeUploadJob::socketError(QAbstractSocket::SocketError error)
{ {
Q_UNUSED(error); Q_UNUSED(error);
//Do not close the socket because when android closes the socket (share is cancelled) closing the socket leads to a cyclic socketError and eventually a segv //Do not close the socket because when android closes the socket (share is cancelled) closing the socket leads to a cyclic socketError and eventually a segv
setError(SocketError); setError(SocketError);
emitResult(); emitResult();
@ -179,7 +179,7 @@ void CompositeUploadJob::socketError(QAbstractSocket::SocketError error)
void CompositeUploadJob::sslError(const QList<QSslError>& errors) void CompositeUploadJob::sslError(const QList<QSslError>& errors)
{ {
Q_UNUSED(errors); Q_UNUSED(errors);
m_socket->close(); m_socket->close();
setError(SslError); setError(SslError);
emitResult(); emitResult();
@ -192,7 +192,7 @@ void CompositeUploadJob::encrypted()
if (!m_timer.isValid()) { if (!m_timer.isValid()) {
m_timer.start(); m_timer.start();
} }
m_currentJob->start(); m_currentJob->start();
} }
@ -200,30 +200,30 @@ bool CompositeUploadJob::addSubjob(KJob* job)
{ {
if (UploadJob *uploadJob = qobject_cast<UploadJob*>(job)) { if (UploadJob *uploadJob = qobject_cast<UploadJob*>(job)) {
NetworkPacket np = uploadJob->getNetworkPacket(); NetworkPacket np = uploadJob->getNetworkPacket();
m_totalJobs++; m_totalJobs++;
if (np.payloadSize() >= 0 ) { if (np.payloadSize() >= 0 ) {
m_totalPayloadSize += np.payloadSize(); m_totalPayloadSize += np.payloadSize();
setTotalAmount(Bytes, m_totalPayloadSize); setTotalAmount(Bytes, m_totalPayloadSize);
} }
QString filename; QString filename;
QString filenameArg = QStringLiteral("filename"); QString filenameArg = QStringLiteral("filename");
if (m_currentJob) { if (m_currentJob) {
filename = m_currentJob->getNetworkPacket().get<QString>(filenameArg); filename = m_currentJob->getNetworkPacket().get<QString>(filenameArg);
} else { } else {
filename = np.get<QString>(filenameArg); filename = np.get<QString>(filenameArg);
} }
emitDescription(filename); emitDescription(filename);
if (m_running && m_currentJob && !m_updatePacketPending) { if (m_running && m_currentJob && !m_updatePacketPending) {
m_updatePacketPending = true; m_updatePacketPending = true;
QMetaObject::invokeMethod(this, "sendUpdatePacket", Qt::QueuedConnection); QMetaObject::invokeMethod(this, "sendUpdatePacket", Qt::QueuedConnection);
} }
return KCompositeJob::addSubjob(job); return KCompositeJob::addSubjob(job);
} else { } else {
qCDebug(KDECONNECT_CORE) << "CompositeUploadJob::addSubjob() - you can only add UploadJob's, ignoring"; qCDebug(KDECONNECT_CORE) << "CompositeUploadJob::addSubjob() - you can only add UploadJob's, ignoring";
@ -235,9 +235,9 @@ void CompositeUploadJob::sendUpdatePacket() {
NetworkPacket np(PACKET_TYPE_SHARE_REQUEST_UPDATE); NetworkPacket np(PACKET_TYPE_SHARE_REQUEST_UPDATE);
np.set<int>(QStringLiteral("numberOfFiles"), m_totalJobs); np.set<int>(QStringLiteral("numberOfFiles"), m_totalJobs);
np.set<quint64>(QStringLiteral("totalPayloadSize"), m_totalPayloadSize); np.set<quint64>(QStringLiteral("totalPayloadSize"), m_totalPayloadSize);
Daemon::instance()->getDevice(m_deviceId)->sendPacket(np); Daemon::instance()->getDevice(m_deviceId)->sendPacket(np);
m_updatePacketPending = false; m_updatePacketPending = false;
} }
@ -245,23 +245,23 @@ bool CompositeUploadJob::doKill()
{ {
if (m_running) { if (m_running) {
m_running = false; m_running = false;
return m_currentJob->stop(); return m_currentJob->stop();
} }
return true; return true;
} }
void CompositeUploadJob::slotProcessedAmount(KJob *job, KJob::Unit unit, qulonglong amount) { void CompositeUploadJob::slotProcessedAmount(KJob *job, KJob::Unit unit, qulonglong amount) {
Q_UNUSED(job); Q_UNUSED(job);
m_currentJobSendPayloadSize = amount; m_currentJobSendPayloadSize = amount;
quint64 uploaded = m_totalSendPayloadSize + m_currentJobSendPayloadSize; quint64 uploaded = m_totalSendPayloadSize + m_currentJobSendPayloadSize;
if (uploaded == m_totalPayloadSize || m_prevElapsedTime == 0 || m_timer.elapsed() - m_prevElapsedTime >= 100) { if (uploaded == m_totalPayloadSize || m_prevElapsedTime == 0 || m_timer.elapsed() - m_prevElapsedTime >= 100) {
m_prevElapsedTime = m_timer.elapsed(); m_prevElapsedTime = m_timer.elapsed();
setProcessedAmount(unit, uploaded); setProcessedAmount(unit, uploaded);
const auto elapsed = m_timer.elapsed(); const auto elapsed = m_timer.elapsed();
if (elapsed > 0) { if (elapsed > 0) {
emitSpeed((1000 * uploaded) / elapsed); emitSpeed((1000 * uploaded) / elapsed);
@ -272,13 +272,13 @@ void CompositeUploadJob::slotProcessedAmount(KJob *job, KJob::Unit unit, qulongl
void CompositeUploadJob::slotResult(KJob *job) { void CompositeUploadJob::slotResult(KJob *job) {
//Copies job error and errorText and emits result if job is in error otherwise removes job from subjob list //Copies job error and errorText and emits result if job is in error otherwise removes job from subjob list
KCompositeJob::slotResult(job); KCompositeJob::slotResult(job);
if (error() || !m_running) { if (error() || !m_running) {
return; return;
} }
m_totalSendPayloadSize += m_currentJobSendPayloadSize; m_totalSendPayloadSize += m_currentJobSendPayloadSize;
if (hasSubjobs()) { if (hasSubjobs()) {
m_currentJobNum++; m_currentJobNum++;
startNextSubJob(); startNextSubJob();

View file

@ -96,7 +96,7 @@ void FileTransferJob::startTransfer()
if (elapsed > 0) { if (elapsed > 0) {
emitSpeed((1000 * bytesSent) / elapsed); emitSpeed((1000 * bytesSent) / elapsed);
} }
m_written = bytesSent; m_written = bytesSent;
}); });
connect(m_reply, static_cast<void (QNetworkReply::*)(QNetworkReply::NetworkError)>(&QNetworkReply::error), connect(m_reply, static_cast<void (QNetworkReply::*)(QNetworkReply::NetworkError)>(&QNetworkReply::error),
@ -122,7 +122,7 @@ void FileTransferJob::transferFinished()
emitResult(); emitResult();
} else { } else {
qCDebug(KDECONNECT_CORE) << "Received incomplete file ("<< m_written << "/" << m_size << "bytes ), deleting"; qCDebug(KDECONNECT_CORE) << "Received incomplete file ("<< m_written << "/" << m_size << "bytes ), deleting";
deleteDestinationFile(); deleteDestinationFile();
setError(3); setError(3);