summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-console/file_layer.cpp
blob: 4830f3bd70b405ceb9d3e99a1622bdc024684794 (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
/* 
 * <zecke> what you would simply do is connect stdout of the sz process
 * <zecke> to the send slot of the IOLayer
 * <zecke> and stdin to the receive signal of IOlayer
 * <zecke> on stderr you can see the progress
 */

#include "file_layer.h"
#include <qfile.h>
#include <opie/oprocess.h>

FileTransferLayer::FileTransferLayer(IOLayer *layer)
    : QObject(), m_layer( layer )
{
}

FileTransferLayer::~FileTransferLayer() {
}

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

    sendFile(file.name());
}

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

    proc = new OProcess;
    *proc << "sz";
    *proc << "-vv" << file;
    connect(proc, SIGNAL(processExited(OProcess *)), 
            this, SLOT(sent()));
    connect(proc, SIGNAL(processRecievedStdout(OProcess *, char *, int)), 
            this, SLOT(SzRecievedStdout(OProcess *, char *, int)));
    connect(proc, SIGNAL(processRecievedStderr(OProcess *, char *, int)),
            this, SLOT(SzRecievedStderr(OProcess *, char *, int)));
    connect(m_layer, SIGNAL(received(QByteArray &)),
            this, SLOT(recievedStdin(QByteArray &)));
    proc->start(OProcess::NotifyOnExit, OProcess::All);

}

IOLayer* FileTransferLayer::layer() {
    return m_layer;
}


void FileTransferLayer::SzRecievedStdout(OProcess *, char *buffer, int buflen) {

    QByteArray data(buflen);
    data.fill(*buffer, buflen);

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

void FileTransferLayer::SzRecievedStderr(OProcess *, char *, int) {

    // parse and show data in a progress dialog/widget
}

void FileTransferLayer::recievedStdin(QByteArray &data) {

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

}