-rw-r--r-- | noncore/apps/opie-console/file_layer.cpp | 53 | ||||
-rw-r--r-- | noncore/apps/opie-console/file_layer.h | 11 |
2 files changed, 60 insertions, 4 deletions
diff --git a/noncore/apps/opie-console/file_layer.cpp b/noncore/apps/opie-console/file_layer.cpp index 3ff85af..4830f3b 100644 --- a/noncore/apps/opie-console/file_layer.cpp +++ b/noncore/apps/opie-console/file_layer.cpp | |||
@@ -1,13 +1,66 @@ | |||
1 | /* | ||
2 | * <zecke> what you would simply do is connect stdout of the sz process | ||
3 | * <zecke> to the send slot of the IOLayer | ||
4 | * <zecke> and stdin to the receive signal of IOlayer | ||
5 | * <zecke> on stderr you can see the progress | ||
6 | */ | ||
7 | |||
1 | #include "file_layer.h" | 8 | #include "file_layer.h" |
9 | #include <qfile.h> | ||
10 | #include <opie/oprocess.h> | ||
2 | 11 | ||
3 | FileTransferLayer::FileTransferLayer(IOLayer *layer) | 12 | FileTransferLayer::FileTransferLayer(IOLayer *layer) |
4 | : QObject(), m_layer( layer ) | 13 | : QObject(), m_layer( layer ) |
5 | { | 14 | { |
6 | } | 15 | } |
7 | 16 | ||
8 | FileTransferLayer::~FileTransferLayer() { | 17 | FileTransferLayer::~FileTransferLayer() { |
9 | } | 18 | } |
19 | |||
20 | void FileTransferLayer::sendFile(const QFile& file) { | ||
21 | |||
22 | sendFile(file.name()); | ||
23 | } | ||
24 | |||
25 | void FileTransferLayer::sendFile(const QString& file) { | ||
26 | |||
27 | proc = new OProcess; | ||
28 | *proc << "sz"; | ||
29 | *proc << "-vv" << file; | ||
30 | connect(proc, SIGNAL(processExited(OProcess *)), | ||
31 | this, SLOT(sent())); | ||
32 | connect(proc, SIGNAL(processRecievedStdout(OProcess *, char *, int)), | ||
33 | this, SLOT(SzRecievedStdout(OProcess *, char *, int))); | ||
34 | connect(proc, SIGNAL(processRecievedStderr(OProcess *, char *, int)), | ||
35 | this, SLOT(SzRecievedStderr(OProcess *, char *, int))); | ||
36 | connect(m_layer, SIGNAL(received(QByteArray &)), | ||
37 | this, SLOT(recievedStdin(QByteArray &))); | ||
38 | proc->start(OProcess::NotifyOnExit, OProcess::All); | ||
39 | |||
40 | } | ||
41 | |||
10 | IOLayer* FileTransferLayer::layer() { | 42 | IOLayer* FileTransferLayer::layer() { |
11 | return m_layer; | 43 | return m_layer; |
12 | } | 44 | } |
13 | 45 | ||
46 | |||
47 | void FileTransferLayer::SzRecievedStdout(OProcess *, char *buffer, int buflen) { | ||
48 | |||
49 | QByteArray data(buflen); | ||
50 | data.fill(*buffer, buflen); | ||
51 | |||
52 | // send out through the io layer | ||
53 | m_layer->send(data); | ||
54 | } | ||
55 | |||
56 | void FileTransferLayer::SzRecievedStderr(OProcess *, char *, int) { | ||
57 | |||
58 | // parse and show data in a progress dialog/widget | ||
59 | } | ||
60 | |||
61 | void FileTransferLayer::recievedStdin(QByteArray &data) { | ||
62 | |||
63 | // recieved data from the io layer goes to sz | ||
64 | proc->writeStdin(data.data(), data.size()); | ||
65 | |||
66 | } | ||
diff --git a/noncore/apps/opie-console/file_layer.h b/noncore/apps/opie-console/file_layer.h index 035e125..71a0c82 100644 --- a/noncore/apps/opie-console/file_layer.h +++ b/noncore/apps/opie-console/file_layer.h | |||
@@ -1,56 +1,59 @@ | |||
1 | #ifndef OPIE_FILE_LAYER_H | 1 | #ifndef OPIE_FILE_LAYER_H |
2 | #define OPIE_FILE_LAYER_H | 2 | #define OPIE_FILE_LAYER_H |
3 | 3 | ||
4 | #include "io_layer.h" | 4 | #include "io_layer.h" |
5 | #include <opie/oprocess.h> | ||
5 | 6 | ||
6 | class QFile; | 7 | class QFile; |
7 | /** | 8 | /** |
8 | * this is the layer for sending files | 9 | * this is the layer for sending files |
9 | */ | 10 | */ |
10 | class FileTransferLayer : public QObject { | 11 | class FileTransferLayer : public QObject { |
11 | Q_OBJECT | 12 | Q_OBJECT |
12 | public: | 13 | public: |
13 | /** | 14 | /** |
14 | *the io layer to be used | 15 | *the io layer to be used |
15 | */ | 16 | */ |
16 | FileTransferLayer( IOLayer* ); | 17 | FileTransferLayer( IOLayer* ); |
17 | virtual ~FileTransferLayer(); | 18 | virtual ~FileTransferLayer(); |
18 | 19 | ||
19 | public slots: | 20 | public slots: |
20 | /** | 21 | /** |
21 | * send a file over the layer | 22 | * send a file over the layer |
22 | */ | 23 | */ |
23 | virtual void sendFile( const QString& file ) = 0; | 24 | virtual void sendFile( const QString& file ) = 0; |
24 | |||
25 | /** | ||
26 | * convience method | ||
27 | */ | ||
28 | virtual void sendFile( const QFile& ) = 0; | 25 | virtual void sendFile( const QFile& ) = 0; |
29 | 26 | ||
27 | private slots: | ||
28 | void SzRecievedStdout(OProcess *, char *, int); | ||
29 | void SzRecievedStderr(OProcess *, char *, int); | ||
30 | void recievedStdin(QByteArray &); | ||
31 | |||
30 | signals: | 32 | signals: |
31 | /** | 33 | /** |
32 | * sent the file | 34 | * sent the file |
33 | */ | 35 | */ |
34 | void sent(); | 36 | void sent(); |
35 | 37 | ||
36 | /** | 38 | /** |
37 | * an error occured | 39 | * an error occured |
38 | */ | 40 | */ |
39 | 41 | ||
40 | void error( int, const QString& ); | 42 | void error( int, const QString& ); |
41 | 43 | ||
42 | /* | 44 | /* |
43 | * 100 == done | 45 | * 100 == done |
44 | * | 46 | * |
45 | */ | 47 | */ |
46 | void progress( const QString& file, int progress ); | 48 | void progress( const QString& file, int progress ); |
47 | 49 | ||
48 | protected: | 50 | protected: |
49 | IOLayer* layer(); | 51 | IOLayer* layer(); |
50 | 52 | ||
51 | private: | 53 | private: |
52 | IOLayer* m_layer; | 54 | IOLayer* m_layer; |
55 | OProcess *proc; | ||
53 | 56 | ||
54 | }; | 57 | }; |
55 | 58 | ||
56 | #endif | 59 | #endif |