From 8aaae9e3eca7853e9c693d2401f721d75209acf7 Mon Sep 17 00:00:00 2001 From: skyhusker Date: Thu, 03 Feb 2005 21:47:50 +0000 Subject: Added DCC receive support --- (limited to 'noncore/net/opieirc/dcctransferrecv.cpp') diff --git a/noncore/net/opieirc/dcctransferrecv.cpp b/noncore/net/opieirc/dcctransferrecv.cpp new file mode 100644 index 0000000..58e8d09 --- a/dev/null +++ b/noncore/net/opieirc/dcctransferrecv.cpp @@ -0,0 +1,53 @@ +#include + +#include +#include +#include + +#include + + +#include "dcctransferrecv.h" + + +DCCTransferRecv::DCCTransferRecv(Q_UINT32 ip4Addr, Q_UINT16 port, const QString &filename, unsigned int size) + : DCCTransfer(ip4Addr, port, filename, size) +{ + QHostAddress ip(ip4Addr); + m_socket->connectToHost(ip.toString(), m_port); + connect(m_socket, SIGNAL(readyRead()), this, SLOT(slotProcess())); + connect(m_socket, SIGNAL(connectionClosed()), this, SLOT(slotFinished())); + + m_file->open(IO_WriteOnly); +} + + +void DCCTransferRecv::slotProcess() +{ + int availableBytes = m_socket->bytesAvailable(); + int receivedBytes = 0; + + while(receivedBytes < availableBytes) { + int bytes = m_socket->readBlock(m_buffer, m_bufSize); + receivedBytes += bytes; + m_file->writeBlock(m_buffer, bytes); + } + + m_file->flush(); + m_processedSize += availableBytes; + unsigned long value = htonl(m_processedSize); + m_socket->writeBlock((char*)&value, sizeof(unsigned long)); + + emit (progress((m_processedSize * 100) / m_totalSize)); +} + +void DCCTransferRecv::slotFinished() +{ + m_file->close(); + + if(m_processedSize == m_totalSize) + emit(finished(this, DCCTransfer::Successfull)); + else + emit(finished(this, DCCTransfer::PeerAborted)); +} + -- cgit v0.9.0.2