summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-console/sz_transfer.cpp
blob: c47e73e8ec09a1abf464ba4980dc927753a03df4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84

#include "sz_transfer.h"
#include <qfile.h>
#include <stdio.h>
#include <sys/termios.h>



SzTransfer::SzTransfer(Type t, IOLayer *layer) : FileTransferLayer(layer), m_t(t)
{
}

SzTransfer::~SzTransfer() {
}

void SzTransfer::sendFile(const QFile& file) {

    sendFile(file.name());
}

void SzTransfer::sendFile(const QString& file) {

    //setcbreak(2); /* raw no echo */

    proc = new OProcess;
    *proc << "sz";
    *proc << "-v" << "-v" << "-b" << file;
    connect(proc, SIGNAL(processExited(OProcess *)),
            this, SLOT(sent()));
    connect(proc, SIGNAL(receivedStdout(OProcess *, char *, int)),
            this, SLOT(SzReceivedStdout(OProcess *, char *, int)));
    connect(proc, SIGNAL(receivedStderr(OProcess *, char *, int)),
            this, SLOT(SzReceivedStderr(OProcess *, char *, int)));
    connect(layer(), SIGNAL(received(const QByteArray &)),
            this, SLOT(receivedStdin(const QByteArray &)));
    proc->start(OProcess::NotifyOnExit, OProcess::All);

}

void SzTransfer::SzReceivedStdout(OProcess *, char *buffer, int buflen) {

    qWarning("recieved from sz on stdout %d bytes", buflen);

    QByteArray data(buflen);
    data.fill(*buffer, buflen);
    for (uint i = 0; i < data.count(); i++ ) {
        printf("%c", buffer[i] );
    }
    printf("\n");

    // send out through the io layer
    layer()->send(data);
}

void SzTransfer::SzReceivedStderr(OProcess *, char *buffer, int length) {

    // parse and show data in a progress dialog/widget
    printf("stderr:\n");
    //for (int i = 0; i < length; i++)
    //    printf("%c", buffer[i]);
    //printf("\n");
}

void SzTransfer::receivedStdin(const QByteArray &data) {

    qWarning("recieved from io_serial %d bytes", data.size());

    // recieved data from the io layer goes to sz
    proc->writeStdin(data.data(), data.size());

}

void SzTransfer::sent() {

    qWarning("sent file");

    //setcbreak(0); /* default */


    delete proc;
    disconnect(layer(), SIGNAL(received(const QByteArray &)),
            this, SLOT(receivedStdin(const QByteArray &)));

}