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,5 +1,5 @@
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"
4#include "irdaconfigwidget.h" 4#include "irdaconfigwidget.h"
5#include "btconfigwidget.h" 5#include "btconfigwidget.h"
@@ -11,13 +11,13 @@
11extern "C" { 11extern "C" {
12 // FILE Transfer Stuff 12 // FILE Transfer Stuff
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 }
22 22
23 // Layer stuff 23 // Layer stuff
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
@@ -1,6 +1,8 @@
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 <qmap.h>
5
4#include "io_layer.h" 6#include "io_layer.h"
5 7
6class QFile; 8class QFile;
@@ -8,10 +10,17 @@ class QFile;
8 * this is the layer for sending files 10 * this is the layer for sending files
9 */ 11 */
10class FileTransferLayer : public QObject { 12class FileTransferLayer : public QObject {
11
12 Q_OBJECT 13 Q_OBJECT
13 14
14public: 15public:
16 enum Errors{
17 NotSupported,
18 StartError,
19 NoError,
20 Unknown,
21 Undefined,
22 Incomplete
23 };
15 /** 24 /**
16 *the io layer to be used 25 *the io layer to be used
17 */ 26 */
@@ -24,6 +33,7 @@ public slots:
24 */ 33 */
25 virtual void sendFile( const QString& file ) = 0; 34 virtual void sendFile( const QString& file ) = 0;
26 virtual void sendFile( const QFile& ) = 0; 35 virtual void sendFile( const QFile& ) = 0;
36 virtual void cancel() = 0;
27 37
28signals: 38signals:
29 /** 39 /**
@@ -38,10 +48,15 @@ signals:
38 void error( int, const QString& ); 48 void error( int, const QString& );
39 49
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
46protected: 61protected:
47 IOLayer* layer(); 62 IOLayer* layer();
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
@@ -11,12 +11,26 @@
11 11
12#include "filetransfer.h" 12#include "filetransfer.h"
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;
15pid_t FileTransfer::m_pid; 27pid_t FileTransfer::m_pid;
16 28
17FileTransfer::FileTransfer( Type t, IOLayer* lay ) 29FileTransfer::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}
21FileTransfer::~FileTransfer() { 35FileTransfer::~FileTransfer() {
22} 36}
@@ -30,21 +44,26 @@ FileTransfer::~FileTransfer() {
30 * to do direct IO from and to the fd 44 * to do direct IO from and to the fd
31 */ 45 */
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();
34// 49//
35// m_fd = ::open("/dev/ttyS0", O_RDWR); 50// m_fd = ::open("/dev/ttyS0", O_RDWR);
36 51
37 52 m_file = file;
38 if ( pipe( m_comm ) < 0 ) 53 if ( pipe( m_comm ) < 0 )
39 m_comm[0] = m_comm[1] = 0; 54 m_comm[0] = m_comm[1] = 0;
40 if ( pipe( m_info ) < 0 ) 55 if ( pipe( m_info ) < 0 )
41 m_info[0] = m_info[1] = 0; 56 m_info[0] = m_info[1] = 0;
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 */
49 char* verbose = "-vv"; 68 char* verbose = "-vv";
50 char* binray = "-b"; 69 char* binray = "-b";
@@ -67,8 +86,10 @@ void FileTransfer::sendFile( const QString& file ) {
67 char resultByte; int len; 86 char resultByte; int len;
68 len = read(m_info[0], &resultByte, 1 ); 87 len = read(m_info[0], &resultByte, 1 );
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 )
73 if ( (errno == ECHILD ) || (errno == EINTR ) ) 94 if ( (errno == ECHILD ) || (errno == EINTR ) )
74 continue; 95 continue;
@@ -85,35 +106,35 @@ void FileTransfer::sendFile( const QString& file ) {
85 int sel; 106 int sel;
86 107
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 ) {
109 sendFile( file.name() ); 120 sendFile( file.name() );
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;
113 signal( SIGCHLD, signal_handler ); 129 signal( SIGCHLD, signal_handler );
114 waitpid( m_pid, &status, WNOHANG ); 130 waitpid( m_pid, &status, WNOHANG );
115 terminate = true; 131 terminate = true;
116} 132}
133
134/*
135 * setting up communication
136 * between parent child and ioLayer
137 */
117void FileTransfer::setupChild() { 138void FileTransfer::setupChild() {
118 /* 139 /*
119 * we do not want to read from our 140 * we do not want to read from our
@@ -140,3 +161,85 @@ void FileTransfer::setupChild() {
140 dup2( m_fd, STDOUT_FILENO ); 161 dup2( m_fd, STDOUT_FILENO );
141 dup2( m_comm[1], STDERR_FILENO ); 162 dup2( m_comm[1], STDERR_FILENO );
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
@@ -4,13 +4,16 @@
4#include <sys/types.h> 4#include <sys/types.h>
5 5
6#include <qfile.h> 6#include <qfile.h>
7#include <qstringlist.h>
7 8
8#include "file_layer.h" 9#include "file_layer.h"
9 10
10class QSocketNotifier; 11class 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:
15 enum Type { 18 enum Type {
16 SZ = 0, 19 SZ = 0,
@@ -22,15 +25,27 @@ public:
22 25
23 void sendFile( const QString& file ); 26 void sendFile( const QString& file );
24 void sendFile( const QFile& ); 27 void sendFile( const QFile& );
28 void cancel();
25 29
26private slots: 30private 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);
35 static bool terminate; 50 static bool terminate;
36}; 51};
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
@@ -15,3 +15,6 @@ IOLayer::~IOLayer() {
15int IOLayer::rawIO()const{ 15int IOLayer::rawIO()const{
16 return -1; 16 return -1;
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
@@ -54,8 +54,16 @@ public:
54 * a file descriptor which opens 54 * a file descriptor which opens
55 * the device for io but does not 55 * the device for io but does not
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:
60 /** 68 /**
61 * received input as QCString 69 * received input as QCString
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
@@ -27,6 +27,7 @@ void IOSerial::send(const QByteArray &data) {
27} 27}
28 28
29void IOSerial::close() { 29void IOSerial::close() {
30 qWarning("closing!");
30 if (m_fd) { 31 if (m_fd) {
31 delete m_read; 32 delete m_read;
32 delete m_error; 33 delete m_error;
@@ -117,7 +118,7 @@ bool IOSerial::open() {
117 connect(m_error, SIGNAL(activated(int)), this, SLOT(errorOccured())); 118 connect(m_error, SIGNAL(activated(int)), this, SLOT(errorOccured()));
118 return TRUE; 119 return TRUE;
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"));
122 m_fd = 0; 123 m_fd = 0;
123 return FALSE; 124 return FALSE;
@@ -176,7 +177,20 @@ QString IOSerial::name() const {
176 return "RS232 Serial IO Layer"; 177 return "RS232 Serial IO Layer";
177} 178}
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 );
180 186
181 return fd; 187 return fd;
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
@@ -36,6 +36,7 @@ public:
36 QString identifier() const; 36 QString identifier() const;
37 QString name() const; 37 QString name() const;
38 int rawIO()const; 38 int rawIO()const;
39 void closeRawIO(int fd );
39signals: 40signals:
40 void received(const QByteArray &); 41 void received(const QByteArray &);
41 void error(int, const QString &); 42 void error(int, const QString &);
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
@@ -3,7 +3,7 @@ TEMPLATE = app
3 CONFIG = qt debug 3 CONFIG = qt debug
4DESTDIR = $(OPIEDIR)/bin 4DESTDIR = $(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 \
8 session.h \ 8 session.h \
9 mainwindow.h \ 9 mainwindow.h \
@@ -31,7 +31,7 @@ HEADERS = io_layer.h io_serial.h io_irda.h \
31 31
32 32
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 \
36 metafactory.cpp \ 36 metafactory.cpp \
37 session.cpp \ 37 session.cpp \
@@ -59,6 +59,6 @@ SOURCES = io_layer.cpp io_serial.cpp io_irda.cpp \
59INTERFACES = configurebase.ui editbase.ui 59INTERFACES = configurebase.ui editbase.ui
60INCLUDEPATH += $(OPIEDIR)/include 60INCLUDEPATH += $(OPIEDIR)/include
61DEPENDPATH += $(OPIEDIR)/include 61DEPENDPATH += $(OPIEDIR)/include
62LIBS += -lqpe -lopie 62LIBS += -lqpe -lopie
63TARGET = opie-console 63TARGET = opie-console
64 64
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
@@ -2,7 +2,7 @@
2#include "tabwidget.h" 2#include "tabwidget.h"
3 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*) ),
7 this, SLOT( slotCurChanged(QWidget*) ) ); 7 this, SLOT( slotCurChanged(QWidget*) ) );
8} 8}
@@ -14,8 +14,8 @@ void TabWidget::add( Session* ses ) {
14 if ( !ses->widgetStack() ) return; 14 if ( !ses->widgetStack() ) return;
15 qWarning("going to add it"); 15 qWarning("going to add it");
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 );
20} 20}
21 21
@@ -37,7 +37,8 @@ void TabWidget::setCurrent( Session* ses ) {
37 if (!ses ) 37 if (!ses )
38 return; 38 return;
39 39
40 showPage( ses->widgetStack() ); 40 //showPage( ses->widgetStack() );
41 setCurrentTab( ses->widgetStack() );
41} 42}
42 43
43 44
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
@@ -2,14 +2,14 @@
2#define OPIE_TAB_WIDGET_H 2#define OPIE_TAB_WIDGET_H
3 3
4#include <qmap.h> 4#include <qmap.h>
5#include <qtabwidget.h> 5#include <opie/otabwidget.h>
6 6
7#include "session.h" 7#include "session.h"
8/** 8/**
9 * This is our central tab widget 9 * This is our central tab widget
10 * we can add sessions here 10 * we can add sessions here
11 */ 11 */
12class TabWidget : public QTabWidget{ 12class TabWidget : public OTabWidget{
13 Q_OBJECT 13 Q_OBJECT
14public: 14public:
15 TabWidget(QWidget *parent, const char* name ); 15 TabWidget(QWidget *parent, const char* name );