summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-console/default.cpp8
-rw-r--r--noncore/apps/opie-console/file_layer.h21
-rw-r--r--noncore/apps/opie-console/filetransfer.cpp143
-rw-r--r--noncore/apps/opie-console/filetransfer.h15
-rw-r--r--noncore/apps/opie-console/io_layer.cpp3
-rw-r--r--noncore/apps/opie-console/io_layer.h8
-rw-r--r--noncore/apps/opie-console/io_serial.cpp16
-rw-r--r--noncore/apps/opie-console/io_serial.h1
-rw-r--r--noncore/apps/opie-console/opie-console.pro6
-rw-r--r--noncore/apps/opie-console/tabwidget.cpp9
-rw-r--r--noncore/apps/opie-console/tabwidget.h4
11 files changed, 197 insertions, 37 deletions
diff --git a/noncore/apps/opie-console/default.cpp b/noncore/apps/opie-console/default.cpp
index a6c3bc4..b092273 100644
--- a/noncore/apps/opie-console/default.cpp
+++ b/noncore/apps/opie-console/default.cpp
@@ -1,3 +1,3 @@
1#include "io_serial.h" 1#include "io_serial.h"
2#include "sz_transfer.h" 2#include "filetransfer.h"
3#include "serialconfigwidget.h" 3#include "serialconfigwidget.h"
@@ -13,9 +13,9 @@ extern "C" {
13 FileTransferLayer* newSZTransfer(IOLayer* lay) { 13 FileTransferLayer* newSZTransfer(IOLayer* lay) {
14 return new SzTransfer( SzTransfer::SZ, lay ); 14 return new FileTransfer( FileTransfer::SZ, lay );
15 } 15 }
16 FileTransferLayer* newSYTransfer(IOLayer* lay) { 16 FileTransferLayer* newSYTransfer(IOLayer* lay) {
17 return new SzTransfer( SzTransfer::SY, lay ); 17 return new FileTransfer( FileTransfer::SY, lay );
18 } 18 }
19 FileTransferLayer* newSXTransfer(IOLayer* lay) { 19 FileTransferLayer* newSXTransfer(IOLayer* lay) {
20 return new SzTransfer( SzTransfer::SX, lay ); 20 return new FileTransfer(FileTransfer ::SX, lay );
21 } 21 }
diff --git a/noncore/apps/opie-console/file_layer.h b/noncore/apps/opie-console/file_layer.h
index 0bd0fd1..bf31540 100644
--- a/noncore/apps/opie-console/file_layer.h
+++ b/noncore/apps/opie-console/file_layer.h
@@ -3,2 +3,4 @@
3 3
4#include <qmap.h>
5
4#include "io_layer.h" 6#include "io_layer.h"
@@ -10,3 +12,2 @@ class QFile;
10class FileTransferLayer : public QObject { 12class FileTransferLayer : public QObject {
11
12 Q_OBJECT 13 Q_OBJECT
@@ -14,2 +15,10 @@ class FileTransferLayer : public QObject {
14public: 15public:
16 enum Errors{
17 NotSupported,
18 StartError,
19 NoError,
20 Unknown,
21 Undefined,
22 Incomplete
23 };
15 /** 24 /**
@@ -26,2 +35,3 @@ public slots:
26 virtual void sendFile( const QFile& ) = 0; 35 virtual void sendFile( const QFile& ) = 0;
36 virtual void cancel() = 0;
27 37
@@ -40,6 +50,11 @@ signals:
40 /* 50 /*
41 * 100 == done 51 * @param file The file to send
52 * @param progress the progress made from 0-100
53 * @param speed Speed in bps
54 * @param hours The hours it take to finish
55 * @param minutes The minutes it takes to finish
56 * @param send The seconds...
42 * 57 *
43 */ 58 */
44 void progress( const QString& file, int progress ); 59 void progress( const QString& file, int progress, int speed, int hours, int minutes, int seconds );
45 60
diff --git a/noncore/apps/opie-console/filetransfer.cpp b/noncore/apps/opie-console/filetransfer.cpp
index 78982bd..7b75d35 100644
--- a/noncore/apps/opie-console/filetransfer.cpp
+++ b/noncore/apps/opie-console/filetransfer.cpp
@@ -13,2 +13,14 @@
13 13
14/**
15 *
16 *
17class FileTransferControl {
18public:
19 FileTransferControl();
20 ~FileTransferControl();
21
22
23};
24*/
25
14bool FileTransfer::terminate = false; 26bool FileTransfer::terminate = false;
@@ -18,3 +30,5 @@ FileTransfer::FileTransfer( Type t, IOLayer* lay )
18 : FileTransferLayer( lay ), m_type( t ) { 30 : FileTransferLayer( lay ), m_type( t ) {
31 signal(SIGPIPE, SIG_IGN );
19 signal( SIGCHLD, signal_handler ); 32 signal( SIGCHLD, signal_handler );
33 m_not = 0l;
20} 34}
@@ -32,2 +46,3 @@ FileTransfer::~FileTransfer() {
32void FileTransfer::sendFile( const QString& file ) { 46void FileTransfer::sendFile( const QString& file ) {
47 m_prog =-1;
33 m_fd = layer()->rawIO(); 48 m_fd = layer()->rawIO();
@@ -36,3 +51,3 @@ void FileTransfer::sendFile( const QString& file ) {
36 51
37 52 m_file = file;
38 if ( pipe( m_comm ) < 0 ) 53 if ( pipe( m_comm ) < 0 )
@@ -42,7 +57,11 @@ void FileTransfer::sendFile( const QString& file ) {
42 57
43 qWarning("output:"+file ); 58
44 m_pid = fork(); 59 m_pid = fork();
45 switch( m_pid ) { 60 switch( m_pid ) {
61 case -1:
62 emit error( StartError, tr("Was not able to fork") );
63 break;
46 case 0:{ 64 case 0:{
47 setupChild(); 65 setupChild();
66 qWarning("output:"+file );
48 /* exec */ 67 /* exec */
@@ -69,4 +88,6 @@ void FileTransfer::sendFile( const QString& file ) {
69 /* len == 1 start up failed */ 88 /* len == 1 start up failed */
70 if ( len == 1 ) 89 if ( len == 1 ) {
90 emit error( StartError, tr("Could not start") );
71 return; 91 return;
92 }
72 if ( len == -1 ) 93 if ( len == -1 )
@@ -87,22 +108,12 @@ void FileTransfer::sendFile( const QString& file ) {
87 /* replace by QSocketNotifier!!! */ 108 /* replace by QSocketNotifier!!! */
88 while (!terminate) { 109 m_not = new QSocketNotifier(m_comm[0], QSocketNotifier::Read );
89 FD_ZERO( &fds ); 110 connect(m_not, SIGNAL(activated(int) ),
90 FD_SET( m_comm[0], &fds ); 111 this, SLOT(slotRead() ) );
91 sel = select( m_comm[0]+1, &fds, NULL, NULL, &timeout );
92 if (sel ) {
93 if ( FD_ISSET(m_comm[0], &fds ) ) {
94 printf("out:");
95 QByteArray ar(4096);
96 int len = read(m_comm[0], ar.data(), 4096 );
97 for (int i = 0; i < len; i++ ) {
98 // printf("%c", ar[i] );
99 }
100 printf("\n");
101 }
102 }
103 }
104 break;
105 } 112 }
113 break;
106 } 114 }
107} 115}
116/*
117 * let's call the one with the filename
118 */
108void FileTransfer::sendFile( const QFile& file ) { 119void FileTransfer::sendFile( const QFile& file ) {
@@ -110,3 +121,8 @@ void FileTransfer::sendFile( const QFile& file ) {
110} 121}
122/*
123 * our signal handler to be replaced by
124 * a procctl thingie
125 */
111void FileTransfer::signal_handler(int ) { 126void FileTransfer::signal_handler(int ) {
127 qWarning("Terminated");
112 int status; 128 int status;
@@ -116,2 +132,7 @@ void FileTransfer::signal_handler(int ) {
116} 132}
133
134/*
135 * setting up communication
136 * between parent child and ioLayer
137 */
117void FileTransfer::setupChild() { 138void FileTransfer::setupChild() {
@@ -142 +163,83 @@ void FileTransfer::setupChild() {
142} 163}
164
165/*
166 * read from the stderr of the child
167 * process
168 */
169void FileTransfer::slotRead() {
170 QByteArray ar(4096);
171 int len = read(m_comm[0], ar.data(), 4096 );
172 qWarning("slot read %d", len);
173 for (int i = 0; i < len; i++ ) {
174 // printf("%c", ar[i] );
175 }
176 ar.resize( len );
177 QString str( ar );
178 QStringList lis = QStringList::split(' ', str );
179 /*
180 * Transfer finished.. either complete or incomplete
181 */
182 if ( lis[0].simplifyWhiteSpace() == "Transfer" ) {
183 qWarning("sent!!!!");
184 emit sent();
185 return;
186 }
187 /*
188 * do progress reading
189 */
190 slotProgress( lis );
191
192
193}
194/*
195 * find the progress
196 */
197void FileTransfer::slotProgress( const QStringList& list ) {
198 bool complete = true;
199 int min, sec;
200 int bps;
201 unsigned long sent, total;
202
203 min = sec = bps = -1;
204 sent = total = 0;
205
206 // Data looks like this
207 // 0 1 2 3 4 5
208 // Bytes Sent 65536/11534336 BPS:7784 ETA 24:33
209 QStringList progi = QStringList::split('/', list[2].simplifyWhiteSpace() );
210 sent = progi[0].toULong(&complete );
211 if (!complete ) return;
212
213 total = progi[1].toULong(&complete );
214 if (!complete || total == 0) {
215 qWarning("returning!!");
216 return;
217 }
218
219 qWarning("%s, %d, %d", progi.join("/").latin1(), sent, total );
220
221 double pro = (double)sent/total;
222 int prog = pro * 100;
223
224 // speed
225 progi = QStringList::split(':', list[3].simplifyWhiteSpace() );
226 bps = progi[1].toInt();
227
228 // time
229 progi = QStringList::split(':', list[5].simplifyWhiteSpace() );
230 min = progi[0].toInt();
231 sec = progi[1].toInt();
232
233
234 qWarning("Prog!:%d", prog );
235 if ( prog > m_prog ) {
236 m_prog = prog;
237 emit progress(m_file, m_prog, bps, -1, min , sec );
238 qWarning("Progress: %s, %d\%, %d, %d:%d", m_file.latin1(), m_prog, bps, min, sec );
239 }
240
241}
242void FileTransfer::cancel() {
243 ::kill(m_pid,9 );
244 delete m_not;
245}
diff --git a/noncore/apps/opie-console/filetransfer.h b/noncore/apps/opie-console/filetransfer.h
index 06c6d12..0829f16 100644
--- a/noncore/apps/opie-console/filetransfer.h
+++ b/noncore/apps/opie-console/filetransfer.h
@@ -6,2 +6,3 @@
6#include <qfile.h> 6#include <qfile.h>
7#include <qstringlist.h>
7 8
@@ -11,4 +12,6 @@ class QSocketNotifier;
11class OProcess; 12class OProcess;
13class FileTransferControl;
12class FileTransfer : public FileTransferLayer{ 14class FileTransfer : public FileTransferLayer{
13 Q_OBJECT 15 Q_OBJECT
16 friend class FileTransferControl;
14public: 17public:
@@ -24,2 +27,3 @@ public:
24 void sendFile( const QFile& ); 27 void sendFile( const QFile& );
28 void cancel();
25 29
@@ -27,8 +31,19 @@ private slots:
27 void setupChild(); 31 void setupChild();
32 void slotRead();
33 void slotProgress( const QStringList& );
28private: 34private:
35 /*
36 * FIXME? What does happen if we've
37 * two FileTransfers at a time?
38 * Have a procctl which does listen
39 * for termination and then send a signal
40 */
29 static pid_t m_pid; 41 static pid_t m_pid;
30 int m_fd; 42 int m_fd;
43 int m_prog;
31 int m_info[2]; 44 int m_info[2];
32 int m_comm[2]; 45 int m_comm[2];
46 QString m_file;
33 Type m_type; 47 Type m_type;
48 QSocketNotifier *m_not;
34 static void signal_handler(int); 49 static void signal_handler(int);
diff --git a/noncore/apps/opie-console/io_layer.cpp b/noncore/apps/opie-console/io_layer.cpp
index 79d47f5..9ba2f70 100644
--- a/noncore/apps/opie-console/io_layer.cpp
+++ b/noncore/apps/opie-console/io_layer.cpp
@@ -17 +17,4 @@ int IOLayer::rawIO()const{
17} 17}
18void IOLayer::closeRawIO(int) {
19
20}
diff --git a/noncore/apps/opie-console/io_layer.h b/noncore/apps/opie-console/io_layer.h
index 7745021..bf5a893 100644
--- a/noncore/apps/opie-console/io_layer.h
+++ b/noncore/apps/opie-console/io_layer.h
@@ -56,4 +56,12 @@ public:
56 * do any ioctling on it... 56 * do any ioctling on it...
57 * and it'll stop listening to the before opened
58 * device
57 */ 59 */
58 virtual int rawIO()const; 60 virtual int rawIO()const;
61
62 /**
63 * will close the rawIO stuff
64 * and will listen to it's data again...
65 */
66 virtual void closeRawIO(int);
59signals: 67signals:
diff --git a/noncore/apps/opie-console/io_serial.cpp b/noncore/apps/opie-console/io_serial.cpp
index 845f4be..4129d64 100644
--- a/noncore/apps/opie-console/io_serial.cpp
+++ b/noncore/apps/opie-console/io_serial.cpp
@@ -29,2 +29,3 @@ void IOSerial::send(const QByteArray &data) {
29void IOSerial::close() { 29void IOSerial::close() {
30 qWarning("closing!");
30 if (m_fd) { 31 if (m_fd) {
@@ -119,3 +120,3 @@ bool IOSerial::open() {
119 } else { 120 } else {
120 qWarning("opened"); 121 qWarning(" already opened");
121 emit error(Refuse, tr("Device is already connected")); 122 emit error(Refuse, tr("Device is already connected"));
@@ -178,2 +179,7 @@ QString IOSerial::name() const {
178int IOSerial::rawIO()const { 179int IOSerial::rawIO()const {
180 if (m_read )
181 disconnect(m_read, SIGNAL(activated(int)), this, SLOT(dataArrived()));
182 if (m_error )
183 disconnect(m_error, SIGNAL(activated(int)), this, SLOT(errorOccured()));
184
179 int fd = ::open(m_device, O_RDWR ); 185 int fd = ::open(m_device, O_RDWR );
@@ -182 +188,9 @@ int IOSerial::rawIO()const {
182}; 188};
189void IOSerial::closeRawIO(int fd) {
190 if (m_read )
191 connect(m_read, SIGNAL(activated(int)), this, SLOT(dataArrived()));
192 if (m_error )
193 connect(m_error, SIGNAL(activated(int)), this, SLOT(errorOccured()));
194
195 ::close( fd );
196}
diff --git a/noncore/apps/opie-console/io_serial.h b/noncore/apps/opie-console/io_serial.h
index 00a6d2c..facbbc1 100644
--- a/noncore/apps/opie-console/io_serial.h
+++ b/noncore/apps/opie-console/io_serial.h
@@ -38,2 +38,3 @@ public:
38 int rawIO()const; 38 int rawIO()const;
39 void closeRawIO(int fd );
39signals: 40signals:
diff --git a/noncore/apps/opie-console/opie-console.pro b/noncore/apps/opie-console/opie-console.pro
index 996eb84..37cef92 100644
--- a/noncore/apps/opie-console/opie-console.pro
+++ b/noncore/apps/opie-console/opie-console.pro
@@ -5,3 +5,3 @@ DESTDIR = $(OPIEDIR)/bin
5HEADERS = io_layer.h io_serial.h io_irda.h \ 5HEADERS = io_layer.h io_serial.h io_irda.h \
6 file_layer.h sz_transfer.h \ 6 file_layer.h filetransfer.h \
7 metafactory.h \ 7 metafactory.h \
@@ -33,3 +33,3 @@ HEADERS = io_layer.h io_serial.h io_irda.h \
33SOURCES = io_layer.cpp io_serial.cpp io_irda.cpp \ 33SOURCES = io_layer.cpp io_serial.cpp io_irda.cpp \
34 file_layer.cpp sz_transfer.cpp \ 34 file_layer.cpp filetransfer.cpp \
35 main.cpp \ 35 main.cpp \
@@ -61,3 +61,3 @@ INCLUDEPATH += $(OPIEDIR)/include
61DEPENDPATH += $(OPIEDIR)/include 61DEPENDPATH += $(OPIEDIR)/include
62LIBS += -lqpe -lopie 62LIBS += -lqpe -lopie
63TARGET = opie-console 63TARGET = opie-console
diff --git a/noncore/apps/opie-console/tabwidget.cpp b/noncore/apps/opie-console/tabwidget.cpp
index cfaef91..466b536 100644
--- a/noncore/apps/opie-console/tabwidget.cpp
+++ b/noncore/apps/opie-console/tabwidget.cpp
@@ -4,3 +4,3 @@
4TabWidget::TabWidget( QWidget* parent, const char* name ) 4TabWidget::TabWidget( QWidget* parent, const char* name )
5 : QTabWidget( parent, name ) { 5 : OTabWidget( parent, name ) {
6 connect(this, SIGNAL( currentChanged(QWidget*) ), 6 connect(this, SIGNAL( currentChanged(QWidget*) ),
@@ -16,4 +16,4 @@ void TabWidget::add( Session* ses ) {
16 //reparent( ses->widgetStack(), QPoint() ); 16 //reparent( ses->widgetStack(), QPoint() );
17 //addTab( ses->widgetStack(), "console/konsole", ses->name() ); 17 addTab( ses->widgetStack(), "console/konsole", ses->name() );
18 addTab( ses->widgetStack(), ses->name() ); 18 //addTab( ses->widgetStack(), ses->name() );
19 m_map.insert( ses->widgetStack(), ses ); 19 m_map.insert( ses->widgetStack(), ses );
@@ -39,3 +39,4 @@ void TabWidget::setCurrent( Session* ses ) {
39 39
40 showPage( ses->widgetStack() ); 40 //showPage( ses->widgetStack() );
41 setCurrentTab( ses->widgetStack() );
41} 42}
diff --git a/noncore/apps/opie-console/tabwidget.h b/noncore/apps/opie-console/tabwidget.h
index 42a00ec..cbaa0f1 100644
--- a/noncore/apps/opie-console/tabwidget.h
+++ b/noncore/apps/opie-console/tabwidget.h
@@ -4,3 +4,3 @@
4#include <qmap.h> 4#include <qmap.h>
5#include <qtabwidget.h> 5#include <opie/otabwidget.h>
6 6
@@ -11,3 +11,3 @@
11 */ 11 */
12class TabWidget : public QTabWidget{ 12class TabWidget : public OTabWidget{
13 Q_OBJECT 13 Q_OBJECT