00001
00002 #include "sz_transfer.h"
00003 #include <qfile.h>
00004 #include <stdio.h>
00005 #include <sys/termios.h>
00006
00007
00008
00009 using namespace Opie::Core;
00010 using namespace Opie::Core;
00011 SzTransfer::SzTransfer(Type t, IOLayer *layer) : FileTransferLayer(layer), m_t(t)
00012 {
00013 }
00014
00015 SzTransfer::~SzTransfer() {
00016 }
00017
00018 void SzTransfer::sendFile(const QFile& file) {
00019
00020 sendFile(file.name());
00021 }
00022
00023 void SzTransfer::sendFile(const QString& file) {
00024
00025
00026
00027 proc = new OProcess;
00028 *proc << "sz";
00029 *proc << "-v" << "-v" << "-b" << file;
00030 connect(proc, SIGNAL(processExited(Opie::Core::OProcess*)),
00031 this, SLOT(sent()));
00032 connect(proc, SIGNAL(receivedStdout(Opie::Core::OProcess*,char*,int)),
00033 this, SLOT(SzReceivedStdout(Opie::Core::OProcess*,char*,int)));
00034 connect(proc, SIGNAL(receivedStderr(Opie::Core::OProcess*,char*,int)),
00035 this, SLOT(SzReceivedStderr(Opie::Core::OProcess*,char*,int)));
00036 connect(layer(), SIGNAL(received(const QByteArray&)),
00037 this, SLOT(receivedStdin(const QByteArray&)));
00038 proc->start(OProcess::NotifyOnExit, OProcess::All);
00039
00040 }
00041
00042 void SzTransfer::SzReceivedStdout(OProcess *, char *buffer, int buflen) {
00043 QByteArray data(buflen);
00044 data.fill(*buffer, buflen);
00045
00046 #ifdef DEBUG_RECEIVE
00047 for (uint i = 0; i < data.count(); i++ ) {
00048 printf("%c", buffer[i] );
00049 }
00050 printf("\n");
00051 #endif
00052
00053
00054 layer()->send(data);
00055 }
00056
00057 void SzTransfer::SzReceivedStderr(OProcess *, char *buffer, int length) {
00058 }
00059
00060 void SzTransfer::receivedStdin(const QByteArray &data) {
00061
00062 proc->writeStdin(data.data(), data.size());
00063 }
00064
00065 void SzTransfer::sent() {
00066 delete proc;
00067 disconnect(layer(), SIGNAL(received(const QByteArray&)),
00068 this, SLOT(receivedStdin(const QByteArray&)));
00069 }