author | zecke <zecke> | 2002-10-11 22:31:15 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-10-11 22:31:15 (UTC) |
commit | c8c961b4106f49f544195733cef17af5f15f6bb8 (patch) (side-by-side diff) | |
tree | 3db3cad73021d14c417de2166249ec9e7a5f1aa4 | |
parent | 597cda9456f8ef883d486b6ed7d7c09339919da9 (diff) | |
download | opie-c8c961b4106f49f544195733cef17af5f15f6bb8.zip opie-c8c961b4106f49f544195733cef17af5f15f6bb8.tar.gz opie-c8c961b4106f49f544195733cef17af5f15f6bb8.tar.bz2 |
suspending connections in rawMode... closeRawIO afterwards please
Progress for FileTransfer
FileTransferLayer updates. ErrorCodes + Better methods cancel and better progress
default switch to FileTransfer
TabWidget is a OTabWidget again
-rw-r--r-- | noncore/apps/opie-console/default.cpp | 8 | ||||
-rw-r--r-- | noncore/apps/opie-console/file_layer.h | 21 | ||||
-rw-r--r-- | noncore/apps/opie-console/filetransfer.cpp | 141 | ||||
-rw-r--r-- | noncore/apps/opie-console/filetransfer.h | 15 | ||||
-rw-r--r-- | noncore/apps/opie-console/io_layer.cpp | 3 | ||||
-rw-r--r-- | noncore/apps/opie-console/io_layer.h | 8 | ||||
-rw-r--r-- | noncore/apps/opie-console/io_serial.cpp | 16 | ||||
-rw-r--r-- | noncore/apps/opie-console/io_serial.h | 1 | ||||
-rw-r--r-- | noncore/apps/opie-console/opie-console.pro | 4 | ||||
-rw-r--r-- | noncore/apps/opie-console/tabwidget.cpp | 9 | ||||
-rw-r--r-- | noncore/apps/opie-console/tabwidget.h | 4 |
11 files changed, 195 insertions, 35 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 @@ #include "io_serial.h" -#include "sz_transfer.h" +#include "filetransfer.h" #include "serialconfigwidget.h" @@ -13,9 +13,9 @@ extern "C" { FileTransferLayer* newSZTransfer(IOLayer* lay) { - return new SzTransfer( SzTransfer::SZ, lay ); + return new FileTransfer( FileTransfer::SZ, lay ); } FileTransferLayer* newSYTransfer(IOLayer* lay) { - return new SzTransfer( SzTransfer::SY, lay ); + return new FileTransfer( FileTransfer::SY, lay ); } FileTransferLayer* newSXTransfer(IOLayer* lay) { - return new SzTransfer( SzTransfer::SX, lay ); + return new FileTransfer(FileTransfer ::SX, lay ); } 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 @@ +#include <qmap.h> + #include "io_layer.h" @@ -10,3 +12,2 @@ class QFile; class FileTransferLayer : public QObject { - Q_OBJECT @@ -14,2 +15,10 @@ class FileTransferLayer : public QObject { public: + enum Errors{ + NotSupported, + StartError, + NoError, + Unknown, + Undefined, + Incomplete + }; /** @@ -26,2 +35,3 @@ public slots: virtual void sendFile( const QFile& ) = 0; + virtual void cancel() = 0; @@ -40,6 +50,11 @@ signals: /* - * 100 == done + * @param file The file to send + * @param progress the progress made from 0-100 + * @param speed Speed in bps + * @param hours The hours it take to finish + * @param minutes The minutes it takes to finish + * @param send The seconds... * */ - void progress( const QString& file, int progress ); + void progress( const QString& file, int progress, int speed, int hours, int minutes, int seconds ); 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 @@ +/** + * + * +class FileTransferControl { +public: + FileTransferControl(); + ~FileTransferControl(); + + +}; +*/ + bool FileTransfer::terminate = false; @@ -18,3 +30,5 @@ FileTransfer::FileTransfer( Type t, IOLayer* lay ) : FileTransferLayer( lay ), m_type( t ) { + signal(SIGPIPE, SIG_IGN ); signal( SIGCHLD, signal_handler ); + m_not = 0l; } @@ -32,2 +46,3 @@ FileTransfer::~FileTransfer() { void FileTransfer::sendFile( const QString& file ) { + m_prog =-1; m_fd = layer()->rawIO(); @@ -36,3 +51,3 @@ void FileTransfer::sendFile( const QString& file ) { - + m_file = file; if ( pipe( m_comm ) < 0 ) @@ -42,7 +57,11 @@ void FileTransfer::sendFile( const QString& file ) { - qWarning("output:"+file ); + m_pid = fork(); switch( m_pid ) { + case -1: + emit error( StartError, tr("Was not able to fork") ); + break; case 0:{ setupChild(); + qWarning("output:"+file ); /* exec */ @@ -69,4 +88,6 @@ void FileTransfer::sendFile( const QString& file ) { /* len == 1 start up failed */ - if ( len == 1 ) + if ( len == 1 ) { + emit error( StartError, tr("Could not start") ); return; + } if ( len == -1 ) @@ -87,17 +108,5 @@ void FileTransfer::sendFile( const QString& file ) { /* replace by QSocketNotifier!!! */ - while (!terminate) { - FD_ZERO( &fds ); - FD_SET( m_comm[0], &fds ); - sel = select( m_comm[0]+1, &fds, NULL, NULL, &timeout ); - if (sel ) { - if ( FD_ISSET(m_comm[0], &fds ) ) { - printf("out:"); - QByteArray ar(4096); - int len = read(m_comm[0], ar.data(), 4096 ); - for (int i = 0; i < len; i++ ) { - // printf("%c", ar[i] ); - } - printf("\n"); - } - } + m_not = new QSocketNotifier(m_comm[0], QSocketNotifier::Read ); + connect(m_not, SIGNAL(activated(int) ), + this, SLOT(slotRead() ) ); } @@ -106,3 +115,5 @@ void FileTransfer::sendFile( const QString& file ) { } -} +/* + * let's call the one with the filename + */ void FileTransfer::sendFile( const QFile& file ) { @@ -110,3 +121,8 @@ void FileTransfer::sendFile( const QFile& file ) { } +/* + * our signal handler to be replaced by + * a procctl thingie + */ void FileTransfer::signal_handler(int ) { + qWarning("Terminated"); int status; @@ -116,2 +132,7 @@ void FileTransfer::signal_handler(int ) { } + +/* + * setting up communication + * between parent child and ioLayer + */ void FileTransfer::setupChild() { @@ -142 +163,83 @@ void FileTransfer::setupChild() { } + +/* + * read from the stderr of the child + * process + */ +void FileTransfer::slotRead() { + QByteArray ar(4096); + int len = read(m_comm[0], ar.data(), 4096 ); + qWarning("slot read %d", len); + for (int i = 0; i < len; i++ ) { + // printf("%c", ar[i] ); + } + ar.resize( len ); + QString str( ar ); + QStringList lis = QStringList::split(' ', str ); + /* + * Transfer finished.. either complete or incomplete + */ + if ( lis[0].simplifyWhiteSpace() == "Transfer" ) { + qWarning("sent!!!!"); + emit sent(); + return; + } + /* + * do progress reading + */ + slotProgress( lis ); + + +} +/* + * find the progress + */ +void FileTransfer::slotProgress( const QStringList& list ) { + bool complete = true; + int min, sec; + int bps; + unsigned long sent, total; + + min = sec = bps = -1; + sent = total = 0; + + // Data looks like this + // 0 1 2 3 4 5 + // Bytes Sent 65536/11534336 BPS:7784 ETA 24:33 + QStringList progi = QStringList::split('/', list[2].simplifyWhiteSpace() ); + sent = progi[0].toULong(&complete ); + if (!complete ) return; + + total = progi[1].toULong(&complete ); + if (!complete || total == 0) { + qWarning("returning!!"); + return; + } + + qWarning("%s, %d, %d", progi.join("/").latin1(), sent, total ); + + double pro = (double)sent/total; + int prog = pro * 100; + + // speed + progi = QStringList::split(':', list[3].simplifyWhiteSpace() ); + bps = progi[1].toInt(); + + // time + progi = QStringList::split(':', list[5].simplifyWhiteSpace() ); + min = progi[0].toInt(); + sec = progi[1].toInt(); + + + qWarning("Prog!:%d", prog ); + if ( prog > m_prog ) { + m_prog = prog; + emit progress(m_file, m_prog, bps, -1, min , sec ); + qWarning("Progress: %s, %d\%, %d, %d:%d", m_file.latin1(), m_prog, bps, min, sec ); + } + +} +void FileTransfer::cancel() { + ::kill(m_pid,9 ); + delete m_not; +} 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 @@ #include <qfile.h> +#include <qstringlist.h> @@ -11,4 +12,6 @@ class QSocketNotifier; class OProcess; +class FileTransferControl; class FileTransfer : public FileTransferLayer{ Q_OBJECT + friend class FileTransferControl; public: @@ -24,2 +27,3 @@ public: void sendFile( const QFile& ); + void cancel(); @@ -27,8 +31,19 @@ private slots: void setupChild(); + void slotRead(); + void slotProgress( const QStringList& ); private: + /* + * FIXME? What does happen if we've + * two FileTransfers at a time? + * Have a procctl which does listen + * for termination and then send a signal + */ static pid_t m_pid; int m_fd; + int m_prog; int m_info[2]; int m_comm[2]; + QString m_file; Type m_type; + QSocketNotifier *m_not; 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{ } +void IOLayer::closeRawIO(int) { + +} 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: * do any ioctling on it... + * and it'll stop listening to the before opened + * device */ virtual int rawIO()const; + + /** + * will close the rawIO stuff + * and will listen to it's data again... + */ + virtual void closeRawIO(int); signals: 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) { void IOSerial::close() { + qWarning("closing!"); if (m_fd) { @@ -119,3 +120,3 @@ bool IOSerial::open() { } else { - qWarning("opened"); + qWarning(" already opened"); emit error(Refuse, tr("Device is already connected")); @@ -178,2 +179,7 @@ QString IOSerial::name() const { int IOSerial::rawIO()const { + if (m_read ) + disconnect(m_read, SIGNAL(activated(int)), this, SLOT(dataArrived())); + if (m_error ) + disconnect(m_error, SIGNAL(activated(int)), this, SLOT(errorOccured())); + int fd = ::open(m_device, O_RDWR ); @@ -182 +188,9 @@ int IOSerial::rawIO()const { }; +void IOSerial::closeRawIO(int fd) { + if (m_read ) + connect(m_read, SIGNAL(activated(int)), this, SLOT(dataArrived())); + if (m_error ) + connect(m_error, SIGNAL(activated(int)), this, SLOT(errorOccured())); + + ::close( fd ); +} 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: int rawIO()const; + void closeRawIO(int fd ); signals: 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 HEADERS = io_layer.h io_serial.h io_irda.h \ - file_layer.h sz_transfer.h \ + file_layer.h filetransfer.h \ metafactory.h \ @@ -33,3 +33,3 @@ HEADERS = io_layer.h io_serial.h io_irda.h \ SOURCES = io_layer.cpp io_serial.cpp io_irda.cpp \ - file_layer.cpp sz_transfer.cpp \ + file_layer.cpp filetransfer.cpp \ main.cpp \ 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 @@ TabWidget::TabWidget( QWidget* parent, const char* name ) - : QTabWidget( parent, name ) { + : OTabWidget( parent, name ) { connect(this, SIGNAL( currentChanged(QWidget*) ), @@ -16,4 +16,4 @@ void TabWidget::add( Session* ses ) { //reparent( ses->widgetStack(), QPoint() ); - //addTab( ses->widgetStack(), "console/konsole", ses->name() ); - addTab( ses->widgetStack(), ses->name() ); + addTab( ses->widgetStack(), "console/konsole", ses->name() ); + //addTab( ses->widgetStack(), ses->name() ); m_map.insert( ses->widgetStack(), ses ); @@ -39,3 +39,4 @@ void TabWidget::setCurrent( Session* ses ) { - showPage( ses->widgetStack() ); + //showPage( ses->widgetStack() ); + setCurrentTab( ses->widgetStack() ); } 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 @@ #include <qmap.h> -#include <qtabwidget.h> +#include <opie/otabwidget.h> @@ -11,3 +11,3 @@ */ -class TabWidget : public QTabWidget{ +class TabWidget : public OTabWidget{ Q_OBJECT |