void MrimContact::sendFile( const KUrl &sourceURL, const QString &fileName, uint fileSize ) { kDebug(kdeDebugArea()) << sourceURL << fileName << fileSize; QStringList fileNames; //If the file location is null, then get it from a file open dialog if( !sourceURL.isValid() ) { fileNames = KFileDialog::getOpenFileNames( KUrl() ,"*", 0l , tr( "Kopete File Transfer" )); } else { fileNames << sourceURL.path(KUrl::RemoveTrailingSlash); } kDebug(kdeDebugArea()) << "start transfer"; FileTransferTask *task = new FileTransferTask( dynamic_cast<MrimAccount*>( account() ) , this , fileNames , FileTransferTask::Outgoing , 0 , this); connect(task, SIGNAL(transferComplete()), this, SLOT(slotTransferFinished()) ); connect(task, SIGNAL(transferFailed()), this, SLOT(slotTransferFinished()) ); d->transferTasks[task->getSessionId()] = task; }
/** Waits for the queued bytes to be wrote and close the channel * * \param s The socket to flush and close * */ void RainbruRPG::Network::Ftp::FtpTransfer::writeBytes(QTcpSocket* s){ if (s->waitForBytesWritten(3000)){ emit(transferComplete(nextOnlyFilename)); s->disconnectFromHost(); emit(log("Transfer channel closed")); } else{ LOGE("An error occured during waitForBytesWritten execution"); } }
void MrimContact::receiveFile(const TransferRequestInfo &transferInfo) { /// @todo ask user's confirmation kDebug(kdeDebugArea()); FileTransferTask *task = new FileTransferTask( dynamic_cast<MrimAccount*>( account() ) , this , QStringList() , FileTransferTask::Incoming , &transferInfo , this); connect(task, SIGNAL(transferComplete()), this, SLOT(slotTransferFinished()) ); connect(task, SIGNAL(transferFailed()), this, SLOT(slotTransferFinished()) ); d->transferTasks[task->getSessionId()] = task; }
/** A file is requested by the host * * This function is called when the client retirieve a file. The file * is sent to the client from the \c uploaded directory. * * \param filename The filename without path * */ void RainbruRPG::Network::Ftp::FtpTransfer:: commandRETR(const QString& filename){ LOGI("Sending file..."); QString s("Sending file "); s+=filename; emit(log(s)); LOGI(s.toLatin1()); nextCommand=FTC_RETR; // Get the absolute filename GlobalURI gu; std::string stdFilename(filename.toLatin1()); std::string fullFileName=gu.getUploadFile(stdFilename); nextFilename=filename; nextOnlyFilename=filename; LOGCATS("Opening file '"); LOGCATS(fullFileName.c_str()); LOGCAT(); QFile f(fullFileName.c_str()); QIODevice::OpenMode om; // We are in Binary mode if (transferType==FTT_BINARY){ om=QIODevice::ReadOnly; } // We are in ASCII mode else if (transferType==FTT_ASCII){ om=QIODevice::ReadOnly|QIODevice::Text; } if(f.open(om)){ QTcpSocket sock; if (waitForConnection(&sock)){ emit(startTransferFile(filename, f.size())); int rep=0; while (!f.atEnd()){ rep=sock.write(f.read(MAX_READ_LENGTH)); if (rep==-1){ LOGE("An error occured during RETR command"); break; } else{ LOGCATS("Writing "); LOGCATI(rep); LOGCATS(" bytes"); LOGCAT(); sock.waitForBytesWritten(3000); } } // Transfer complete emit(log("Transfer channel closed")); emit(transferComplete(filename)); sock.disconnectFromHost(); LOGI("Transfer complete"); f.close(); } } else{ emit(log("An error occured during opening file :")); QFile::FileError fe=f.error(); QString feText; if (fe==QFile::OpenError){ feText=("5 The file could not be opened."); } else{ feText.setNum(fe); } emit(log(feText)); } }