author | zecke <zecke> | 2002-10-11 22:31:15 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-10-11 22:31:15 (UTC) |
commit | c8c961b4106f49f544195733cef17af5f15f6bb8 (patch) (unidiff) | |
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 | 143 | ||||
-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 | 6 | ||||
-rw-r--r-- | noncore/apps/opie-console/tabwidget.cpp | 9 | ||||
-rw-r--r-- | noncore/apps/opie-console/tabwidget.h | 4 |
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,68 +1,68 @@ | |||
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" |
6 | #include "terminalwidget.h" | 6 | #include "terminalwidget.h" |
7 | #include "vt102emulation.h" | 7 | #include "vt102emulation.h" |
8 | 8 | ||
9 | #include "default.h" | 9 | #include "default.h" |
10 | 10 | ||
11 | extern "C" { | 11 | extern "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 |
24 | IOLayer* newSerialLayer( const Profile& prof) { | 24 | IOLayer* newSerialLayer( const Profile& prof) { |
25 | return new IOSerial( prof ); | 25 | return new IOSerial( prof ); |
26 | } | 26 | } |
27 | IOLayer* newBTLayer( const Profile& ) { | 27 | IOLayer* newBTLayer( const Profile& ) { |
28 | return 0l; | 28 | return 0l; |
29 | } | 29 | } |
30 | IOLayer* newIrDaLayer( const Profile& ) { | 30 | IOLayer* newIrDaLayer( const Profile& ) { |
31 | return 0l; | 31 | return 0l; |
32 | } | 32 | } |
33 | 33 | ||
34 | // Connection Widgets | 34 | // Connection Widgets |
35 | ProfileDialogWidget* newSerialWidget( const QString& str, QWidget* wid ) { | 35 | ProfileDialogWidget* newSerialWidget( const QString& str, QWidget* wid ) { |
36 | return new SerialConfigWidget( str, wid ); | 36 | return new SerialConfigWidget( str, wid ); |
37 | } | 37 | } |
38 | ProfileDialogWidget* newIrDaWidget( const QString& str, QWidget* wid ) { | 38 | ProfileDialogWidget* newIrDaWidget( const QString& str, QWidget* wid ) { |
39 | return new IrdaConfigWidget( str, wid ); | 39 | return new IrdaConfigWidget( str, wid ); |
40 | } | 40 | } |
41 | ProfileDialogWidget* newBTWidget( const QString& str, QWidget* wid ) { | 41 | ProfileDialogWidget* newBTWidget( const QString& str, QWidget* wid ) { |
42 | return new BTConfigWidget(str, wid ); | 42 | return new BTConfigWidget(str, wid ); |
43 | } | 43 | } |
44 | 44 | ||
45 | // Terminal Widget(s) | 45 | // Terminal Widget(s) |
46 | ProfileDialogWidget* newTerminalWidget(const QString& na, QWidget* wid) { | 46 | ProfileDialogWidget* newTerminalWidget(const QString& na, QWidget* wid) { |
47 | return new TerminalWidget(na, wid,0 ); | 47 | return new TerminalWidget(na, wid,0 ); |
48 | } | 48 | } |
49 | 49 | ||
50 | // VT Emulations | 50 | // VT Emulations |
51 | EmulationLayer* newVT102( WidgetLayer* wid ) { | 51 | EmulationLayer* newVT102( WidgetLayer* wid ) { |
52 | return new Vt102Emulation( wid ); | 52 | return new Vt102Emulation( wid ); |
53 | } | 53 | } |
54 | 54 | ||
55 | }; | 55 | }; |
56 | 56 | ||
57 | Default::Default( MetaFactory* fact ) { | 57 | Default::Default( MetaFactory* fact ) { |
58 | fact->addFileTransferLayer( "SZ", QObject::tr("Z-Modem"), newSZTransfer ); | 58 | fact->addFileTransferLayer( "SZ", QObject::tr("Z-Modem"), newSZTransfer ); |
59 | fact->addFileTransferLayer( "SY", QObject::tr("Y-Modem"), newSYTransfer ); | 59 | fact->addFileTransferLayer( "SY", QObject::tr("Y-Modem"), newSYTransfer ); |
60 | fact->addFileTransferLayer( "SX", QObject::tr("X-Modem"), newSXTransfer ); | 60 | fact->addFileTransferLayer( "SX", QObject::tr("X-Modem"), newSXTransfer ); |
61 | 61 | ||
62 | fact->addIOLayerFactory( "serial", QObject::tr("Serial"), newSerialLayer ); | 62 | fact->addIOLayerFactory( "serial", QObject::tr("Serial"), newSerialLayer ); |
63 | fact->addIOLayerFactory( "irda", QObject::tr("Infrared"), newIrDaLayer ); | 63 | fact->addIOLayerFactory( "irda", QObject::tr("Infrared"), newIrDaLayer ); |
64 | fact->addIOLayerFactory( "bt", QObject::tr("Bluetooth"), newBTLayer ); | 64 | fact->addIOLayerFactory( "bt", QObject::tr("Bluetooth"), newBTLayer ); |
65 | 65 | ||
66 | fact->addConnectionWidgetFactory( "serial", QObject::tr("Serial"), newSerialWidget ); | 66 | fact->addConnectionWidgetFactory( "serial", QObject::tr("Serial"), newSerialWidget ); |
67 | fact->addConnectionWidgetFactory( "irda", QObject::tr("Infrared"), newIrDaWidget ); | 67 | fact->addConnectionWidgetFactory( "irda", QObject::tr("Infrared"), newIrDaWidget ); |
68 | fact->addConnectionWidgetFactory( "bt", QObject::tr("Bluetooth"), newBTWidget ); | 68 | fact->addConnectionWidgetFactory( "bt", QObject::tr("Bluetooth"), newBTWidget ); |
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,54 +1,69 @@ | |||
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 | ||
6 | class QFile; | 8 | class QFile; |
7 | /** | 9 | /** |
8 | * this is the layer for sending files | 10 | * this is the layer for sending files |
9 | */ | 11 | */ |
10 | class FileTransferLayer : public QObject { | 12 | class FileTransferLayer : public QObject { |
11 | |||
12 | Q_OBJECT | 13 | Q_OBJECT |
13 | 14 | ||
14 | public: | 15 | public: |
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 | */ |
18 | FileTransferLayer( IOLayer* ); | 27 | FileTransferLayer( IOLayer* ); |
19 | virtual ~FileTransferLayer(); | 28 | virtual ~FileTransferLayer(); |
20 | 29 | ||
21 | public slots: | 30 | public slots: |
22 | /** | 31 | /** |
23 | * send a file over the layer | 32 | * send a file over the layer |
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 | ||
28 | signals: | 38 | signals: |
29 | /** | 39 | /** |
30 | * sent the file | 40 | * sent the file |
31 | */ | 41 | */ |
32 | void sent(); | 42 | void sent(); |
33 | 43 | ||
34 | /** | 44 | /** |
35 | * an error occured | 45 | * an error occured |
36 | */ | 46 | */ |
37 | 47 | ||
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 | ||
46 | protected: | 61 | protected: |
47 | IOLayer* layer(); | 62 | IOLayer* layer(); |
48 | 63 | ||
49 | private: | 64 | private: |
50 | IOLayer* m_layer; | 65 | IOLayer* m_layer; |
51 | 66 | ||
52 | }; | 67 | }; |
53 | 68 | ||
54 | #endif | 69 | #endif |
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 | |||
@@ -1,142 +1,245 @@ | |||
1 | #include <stdio.h> | 1 | #include <stdio.h> |
2 | #include <stdlib.h> | 2 | #include <stdlib.h> |
3 | #include <errno.h> | 3 | #include <errno.h> |
4 | #include <fcntl.h> | 4 | #include <fcntl.h> |
5 | #include <unistd.h> | 5 | #include <unistd.h> |
6 | 6 | ||
7 | #include <qcstring.h> | 7 | #include <qcstring.h> |
8 | #include <qsocketnotifier.h> | 8 | #include <qsocketnotifier.h> |
9 | 9 | ||
10 | #include <opie/oprocess.h> | 10 | #include <opie/oprocess.h> |
11 | 11 | ||
12 | #include "filetransfer.h" | 12 | #include "filetransfer.h" |
13 | 13 | ||
14 | /** | ||
15 | * | ||
16 | * | ||
17 | class FileTransferControl { | ||
18 | public: | ||
19 | FileTransferControl(); | ||
20 | ~FileTransferControl(); | ||
21 | |||
22 | |||
23 | }; | ||
24 | */ | ||
25 | |||
14 | bool FileTransfer::terminate = false; | 26 | bool FileTransfer::terminate = false; |
15 | pid_t FileTransfer::m_pid; | 27 | pid_t FileTransfer::m_pid; |
16 | 28 | ||
17 | FileTransfer::FileTransfer( Type t, IOLayer* lay ) | 29 | 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 | } |
21 | FileTransfer::~FileTransfer() { | 35 | FileTransfer::~FileTransfer() { |
22 | } | 36 | } |
23 | 37 | ||
24 | /** | 38 | /** |
25 | * now we will send the file. | 39 | * now we will send the file. |
26 | * | 40 | * |
27 | * we request an fd. The IOLayer should be closed | 41 | * we request an fd. The IOLayer should be closed |
28 | * then we will setup a pipe for progress communication | 42 | * then we will setup a pipe for progress communication |
29 | * then we will dup2 the m_fd in the forked process | 43 | * then we will dup2 the m_fd in the forked process |
30 | * to do direct IO from and to the fd | 44 | * to do direct IO from and to the fd |
31 | */ | 45 | */ |
32 | void FileTransfer::sendFile( const QString& file ) { | 46 | void 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"; |
51 | 70 | ||
52 | 71 | ||
53 | /* we should never return from here */ | 72 | /* we should never return from here */ |
54 | execlp("sz", "sz", verbose, binray, file.latin1(), NULL ); | 73 | execlp("sz", "sz", verbose, binray, file.latin1(), NULL ); |
55 | 74 | ||
56 | /* communication for error!*/ | 75 | /* communication for error!*/ |
57 | char resultByte =1; | 76 | char resultByte =1; |
58 | if (m_info[1] ) | 77 | if (m_info[1] ) |
59 | write(m_info[1], &resultByte, 1 ); | 78 | write(m_info[1], &resultByte, 1 ); |
60 | _exit( -1 ); | 79 | _exit( -1 ); |
61 | break; | 80 | break; |
62 | } | 81 | } |
63 | default:{ | 82 | default:{ |
64 | if ( m_info[1] ) | 83 | if ( m_info[1] ) |
65 | close( m_info[1] ); | 84 | close( m_info[1] ); |
66 | if ( m_info[0] ) for (;;) { | 85 | if ( m_info[0] ) for (;;) { |
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; |
75 | 96 | ||
76 | // len == 0 or something like this | 97 | // len == 0 or something like this |
77 | break; | 98 | break; |
78 | } | 99 | } |
79 | if ( m_info[0] ) | 100 | if ( m_info[0] ) |
80 | close( m_info[0] ); | 101 | close( m_info[0] ); |
81 | 102 | ||
82 | terminate = false; | 103 | terminate = false; |
83 | fd_set fds; | 104 | fd_set fds; |
84 | struct timeval timeout; | 105 | struct timeval timeout; |
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 | */ | ||
108 | void FileTransfer::sendFile( const QFile& file ) { | 119 | void 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 | */ | ||
111 | void FileTransfer::signal_handler(int ) { | 126 | void 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 | */ | ||
117 | void FileTransfer::setupChild() { | 138 | void FileTransfer::setupChild() { |
118 | /* | 139 | /* |
119 | * we do not want to read from our | 140 | * we do not want to read from our |
120 | * information channel | 141 | * information channel |
121 | */ | 142 | */ |
122 | if (m_info[0] ) | 143 | if (m_info[0] ) |
123 | close(m_info[0] ); | 144 | close(m_info[0] ); |
124 | /* | 145 | /* |
125 | * FD_CLOEXEC will close the | 146 | * FD_CLOEXEC will close the |
126 | * fd on successfull exec | 147 | * fd on successfull exec |
127 | */ | 148 | */ |
128 | if (m_info[1] ) | 149 | if (m_info[1] ) |
129 | fcntl(m_info[1], F_SETFD, FD_CLOEXEC ); | 150 | fcntl(m_info[1], F_SETFD, FD_CLOEXEC ); |
130 | 151 | ||
131 | if (m_comm[0] ) | 152 | if (m_comm[0] ) |
132 | close( m_comm[0] ); | 153 | close( m_comm[0] ); |
133 | /* | 154 | /* |
134 | * now set the communication | 155 | * now set the communication |
135 | * m_fd STDIN_FILENO | 156 | * m_fd STDIN_FILENO |
136 | * STDOUT_FILENO | 157 | * STDOUT_FILENO |
137 | * STDERR_FILENO | 158 | * STDERR_FILENO |
138 | */ | 159 | */ |
139 | dup2( m_fd, STDIN_FILENO ); | 160 | dup2( m_fd, STDIN_FILENO ); |
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 | */ | ||
169 | void 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 | */ | ||
197 | void 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 | } | ||
242 | void 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 | |||
@@ -1,38 +1,53 @@ | |||
1 | #ifndef OPIE_FILE_TRANSFER_H | 1 | #ifndef OPIE_FILE_TRANSFER_H |
2 | #define OPIE_FILE_TRANSFER_H | 2 | #define OPIE_FILE_TRANSFER_H |
3 | 3 | ||
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 | ||
10 | class QSocketNotifier; | 11 | class QSocketNotifier; |
11 | class OProcess; | 12 | class OProcess; |
13 | class FileTransferControl; | ||
12 | class FileTransfer : public FileTransferLayer{ | 14 | class FileTransfer : public FileTransferLayer{ |
13 | Q_OBJECT | 15 | Q_OBJECT |
16 | friend class FileTransferControl; | ||
14 | public: | 17 | public: |
15 | enum Type { | 18 | enum Type { |
16 | SZ = 0, | 19 | SZ = 0, |
17 | SX, | 20 | SX, |
18 | SY | 21 | SY |
19 | }; | 22 | }; |
20 | FileTransfer( Type t, IOLayer* ); | 23 | FileTransfer( Type t, IOLayer* ); |
21 | ~FileTransfer(); | 24 | ~FileTransfer(); |
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 | ||
26 | private slots: | 30 | private slots: |
27 | void setupChild(); | 31 | void setupChild(); |
32 | void slotRead(); | ||
33 | void slotProgress( const QStringList& ); | ||
28 | private: | 34 | private: |
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 | }; |
37 | 52 | ||
38 | #endif | 53 | #endif |
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 | |||
@@ -1,17 +1,20 @@ | |||
1 | #include "io_layer.h" | 1 | #include "io_layer.h" |
2 | 2 | ||
3 | IOLayer::IOLayer() | 3 | IOLayer::IOLayer() |
4 | : QObject() | 4 | : QObject() |
5 | { | 5 | { |
6 | } | 6 | } |
7 | 7 | ||
8 | IOLayer::IOLayer(const Profile &) | 8 | IOLayer::IOLayer(const Profile &) |
9 | : QObject() | 9 | : QObject() |
10 | { | 10 | { |
11 | } | 11 | } |
12 | 12 | ||
13 | IOLayer::~IOLayer() { | 13 | IOLayer::~IOLayer() { |
14 | } | 14 | } |
15 | int IOLayer::rawIO()const{ | 15 | int IOLayer::rawIO()const{ |
16 | return -1; | 16 | return -1; |
17 | } | 17 | } |
18 | void 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 | |||
@@ -9,86 +9,94 @@ | |||
9 | /** | 9 | /** |
10 | * This is the base class for IO Layers | 10 | * This is the base class for IO Layers |
11 | * It will used to sent and recv data( QByteArray ) | 11 | * It will used to sent and recv data( QByteArray ) |
12 | * it | 12 | * it |
13 | */ | 13 | */ |
14 | class IOLayer : public QObject { | 14 | class IOLayer : public QObject { |
15 | Q_OBJECT | 15 | Q_OBJECT |
16 | public: | 16 | public: |
17 | enum Error { | 17 | enum Error { |
18 | NoError = -1, | 18 | NoError = -1, |
19 | Refuse = 0, | 19 | Refuse = 0, |
20 | CouldNotOpen =1, | 20 | CouldNotOpen =1, |
21 | ClosedUnexpected =2, | 21 | ClosedUnexpected =2, |
22 | ClosedError =3, | 22 | ClosedError =3, |
23 | Terminate = 4 | 23 | Terminate = 4 |
24 | /* add more errors here */ | 24 | /* add more errors here */ |
25 | }; | 25 | }; |
26 | /** | 26 | /** |
27 | * a small c'tor | 27 | * a small c'tor |
28 | */ | 28 | */ |
29 | IOLayer(); | 29 | IOLayer(); |
30 | 30 | ||
31 | /** | 31 | /** |
32 | * create an IOLayer instance from a config file | 32 | * create an IOLayer instance from a config file |
33 | * the currently set group stores the profile/session | 33 | * the currently set group stores the profile/session |
34 | * information | 34 | * information |
35 | */ | 35 | */ |
36 | IOLayer( const Profile& ); | 36 | IOLayer( const Profile& ); |
37 | 37 | ||
38 | /** | 38 | /** |
39 | * destructor | 39 | * destructor |
40 | */ | 40 | */ |
41 | virtual ~IOLayer(); | 41 | virtual ~IOLayer(); |
42 | 42 | ||
43 | /** | 43 | /** |
44 | * a small internal identifier | 44 | * a small internal identifier |
45 | */ | 45 | */ |
46 | virtual QString identifier() const = 0; | 46 | virtual QString identifier() const = 0; |
47 | 47 | ||
48 | /** | 48 | /** |
49 | * a short name | 49 | * a short name |
50 | */ | 50 | */ |
51 | virtual QString name() const = 0; | 51 | virtual QString name() const = 0; |
52 | 52 | ||
53 | /** | 53 | /** |
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); | ||
59 | signals: | 67 | signals: |
60 | /** | 68 | /** |
61 | * received input as QCString | 69 | * received input as QCString |
62 | */ | 70 | */ |
63 | virtual void received( const QByteArray& ) = 0; | 71 | virtual void received( const QByteArray& ) = 0; |
64 | 72 | ||
65 | /** | 73 | /** |
66 | * an error occured | 74 | * an error occured |
67 | * int for the error number | 75 | * int for the error number |
68 | * and QString for a text | 76 | * and QString for a text |
69 | */ | 77 | */ |
70 | virtual void error( int, const QString& ) = 0; | 78 | virtual void error( int, const QString& ) = 0; |
71 | 79 | ||
72 | public slots: | 80 | public slots: |
73 | /** | 81 | /** |
74 | * send a QCString to the device | 82 | * send a QCString to the device |
75 | */ | 83 | */ |
76 | virtual void send( const QByteArray& ) = 0; | 84 | virtual void send( const QByteArray& ) = 0; |
77 | 85 | ||
78 | /** | 86 | /** |
79 | * bool open | 87 | * bool open |
80 | */ | 88 | */ |
81 | virtual bool open() = 0; | 89 | virtual bool open() = 0; |
82 | 90 | ||
83 | /** | 91 | /** |
84 | * close the io | 92 | * close the io |
85 | */ | 93 | */ |
86 | virtual void close() = 0; | 94 | virtual void close() = 0; |
87 | 95 | ||
88 | /** | 96 | /** |
89 | * closes and reloads the settings | 97 | * closes and reloads the settings |
90 | */ | 98 | */ |
91 | virtual void reload( const Profile& ) = 0; | 99 | virtual void reload( const Profile& ) = 0; |
92 | }; | 100 | }; |
93 | 101 | ||
94 | #endif | 102 | #endif |
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 | |||
@@ -1,182 +1,196 @@ | |||
1 | #include <fcntl.h> | 1 | #include <fcntl.h> |
2 | #include <termios.h> | 2 | #include <termios.h> |
3 | #include <errno.h> | 3 | #include <errno.h> |
4 | #include <unistd.h> | 4 | #include <unistd.h> |
5 | #include "io_serial.h" | 5 | #include "io_serial.h" |
6 | 6 | ||
7 | IOSerial::IOSerial(const Profile &config) : IOLayer(config) { | 7 | IOSerial::IOSerial(const Profile &config) : IOLayer(config) { |
8 | m_read = 0l; | 8 | m_read = 0l; |
9 | m_error = 0l; | 9 | m_error = 0l; |
10 | m_fd = 0; | 10 | m_fd = 0; |
11 | reload(config); | 11 | reload(config); |
12 | } | 12 | } |
13 | 13 | ||
14 | 14 | ||
15 | IOSerial::~IOSerial() { | 15 | IOSerial::~IOSerial() { |
16 | if (m_fd) { | 16 | if (m_fd) { |
17 | close(); | 17 | close(); |
18 | } | 18 | } |
19 | } | 19 | } |
20 | 20 | ||
21 | void IOSerial::send(const QByteArray &data) { | 21 | void IOSerial::send(const QByteArray &data) { |
22 | if (m_fd) { | 22 | if (m_fd) { |
23 | write(m_fd, data.data(), data.size()); | 23 | write(m_fd, data.data(), data.size()); |
24 | } else { | 24 | } else { |
25 | emit error(Refuse, tr("Not connected")); | 25 | emit error(Refuse, tr("Not connected")); |
26 | } | 26 | } |
27 | } | 27 | } |
28 | 28 | ||
29 | void IOSerial::close() { | 29 | void 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; |
33 | ::close(m_fd); | 34 | ::close(m_fd); |
34 | m_fd = 0; | 35 | m_fd = 0; |
35 | } else { | 36 | } else { |
36 | emit error(Refuse, tr("Not connected")); | 37 | emit error(Refuse, tr("Not connected")); |
37 | } | 38 | } |
38 | } | 39 | } |
39 | 40 | ||
40 | bool IOSerial::open() { | 41 | bool IOSerial::open() { |
41 | qWarning("open"); | 42 | qWarning("open"); |
42 | if (!m_fd) { | 43 | if (!m_fd) { |
43 | qWarning("going to open %s", m_device.latin1()); | 44 | qWarning("going to open %s", m_device.latin1()); |
44 | struct termios tty; | 45 | struct termios tty; |
45 | m_fd = ::open(m_device, O_RDWR | O_NOCTTY | O_NONBLOCK); | 46 | m_fd = ::open(m_device, O_RDWR | O_NOCTTY | O_NONBLOCK); |
46 | if (m_fd < 0) { | 47 | if (m_fd < 0) { |
47 | qWarning(" fd < 0 "); | 48 | qWarning(" fd < 0 "); |
48 | emit error(CouldNotOpen, strerror(errno)); | 49 | emit error(CouldNotOpen, strerror(errno)); |
49 | return FALSE; | 50 | return FALSE; |
50 | } | 51 | } |
51 | tcgetattr(m_fd, &tty); | 52 | tcgetattr(m_fd, &tty); |
52 | 53 | ||
53 | /* Baud rate */ | 54 | /* Baud rate */ |
54 | int speed = baud(m_baud); | 55 | int speed = baud(m_baud); |
55 | if (speed == -1) { | 56 | if (speed == -1) { |
56 | qWarning("speed -1"); | 57 | qWarning("speed -1"); |
57 | emit error(Refuse, tr("Invalid baud rate")); | 58 | emit error(Refuse, tr("Invalid baud rate")); |
58 | } | 59 | } |
59 | cfsetospeed(&tty, speed); | 60 | cfsetospeed(&tty, speed); |
60 | cfsetispeed(&tty, speed); | 61 | cfsetispeed(&tty, speed); |
61 | 62 | ||
62 | /* Take care of Space / Mark parity */ | 63 | /* Take care of Space / Mark parity */ |
63 | if (m_dbits == 7 && (m_parity == ParitySpace || m_parity == ParityMark)) { | 64 | if (m_dbits == 7 && (m_parity == ParitySpace || m_parity == ParityMark)) { |
64 | m_dbits = 8; | 65 | m_dbits = 8; |
65 | } | 66 | } |
66 | 67 | ||
67 | /* Data bits */ | 68 | /* Data bits */ |
68 | switch (m_dbits) { | 69 | switch (m_dbits) { |
69 | case 5: tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS5; break; | 70 | case 5: tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS5; break; |
70 | case 6: tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS6; break; | 71 | case 6: tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS6; break; |
71 | case 7: tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS7; break; | 72 | case 7: tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS7; break; |
72 | case 8: tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS8; break; | 73 | case 8: tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS8; break; |
73 | default: break; | 74 | default: break; |
74 | } | 75 | } |
75 | 76 | ||
76 | /* Raw, no echo mode */ | 77 | /* Raw, no echo mode */ |
77 | tty.c_iflag = IGNBRK; | 78 | tty.c_iflag = IGNBRK; |
78 | tty.c_lflag = 0; | 79 | tty.c_lflag = 0; |
79 | tty.c_oflag = 0; | 80 | tty.c_oflag = 0; |
80 | tty.c_cflag |= CLOCAL | CREAD; | 81 | tty.c_cflag |= CLOCAL | CREAD; |
81 | 82 | ||
82 | /* Stop bits */ | 83 | /* Stop bits */ |
83 | if (m_sbits == 2) { | 84 | if (m_sbits == 2) { |
84 | tty.c_cflag |= CSTOPB; | 85 | tty.c_cflag |= CSTOPB; |
85 | } else { | 86 | } else { |
86 | tty.c_cflag &= ~CSTOPB; | 87 | tty.c_cflag &= ~CSTOPB; |
87 | } | 88 | } |
88 | 89 | ||
89 | tty.c_cc[VMIN] = 1; | 90 | tty.c_cc[VMIN] = 1; |
90 | tty.c_cc[VTIME] = 5; | 91 | tty.c_cc[VTIME] = 5; |
91 | 92 | ||
92 | /* Flow control */ | 93 | /* Flow control */ |
93 | if (m_flow & FlowSW) | 94 | if (m_flow & FlowSW) |
94 | tty.c_iflag |= IXON | IXOFF; | 95 | tty.c_iflag |= IXON | IXOFF; |
95 | else | 96 | else |
96 | tty.c_iflag &= ~(IXON|IXOFF|IXANY); | 97 | tty.c_iflag &= ~(IXON|IXOFF|IXANY); |
97 | 98 | ||
98 | if (m_flow & FlowHW) | 99 | if (m_flow & FlowHW) |
99 | tty.c_cflag |= CRTSCTS; | 100 | tty.c_cflag |= CRTSCTS; |
100 | else | 101 | else |
101 | tty.c_cflag &= ~CRTSCTS; | 102 | tty.c_cflag &= ~CRTSCTS; |
102 | 103 | ||
103 | /* Parity */ | 104 | /* Parity */ |
104 | tty.c_cflag &= ~(PARENB | PARODD); | 105 | tty.c_cflag &= ~(PARENB | PARODD); |
105 | if (m_parity & ParityEven) | 106 | if (m_parity & ParityEven) |
106 | tty.c_cflag |= PARENB; | 107 | tty.c_cflag |= PARENB; |
107 | else if (m_parity & ParityOdd) | 108 | else if (m_parity & ParityOdd) |
108 | tty.c_cflag |= (PARENB | PARODD); | 109 | tty.c_cflag |= (PARENB | PARODD); |
109 | 110 | ||
110 | /* Set the changes */ | 111 | /* Set the changes */ |
111 | tcsetattr(m_fd, TCSANOW, &tty); | 112 | tcsetattr(m_fd, TCSANOW, &tty); |
112 | 113 | ||
113 | /* Notifications on read & errors */ | 114 | /* Notifications on read & errors */ |
114 | m_read = new QSocketNotifier(m_fd, QSocketNotifier::Read, this); | 115 | m_read = new QSocketNotifier(m_fd, QSocketNotifier::Read, this); |
115 | m_error = new QSocketNotifier(m_fd, QSocketNotifier::Exception, this); | 116 | m_error = new QSocketNotifier(m_fd, QSocketNotifier::Exception, this); |
116 | connect(m_read, SIGNAL(activated(int)), this, SLOT(dataArrived())); | 117 | connect(m_read, SIGNAL(activated(int)), this, SLOT(dataArrived())); |
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; |
124 | } | 125 | } |
125 | } | 126 | } |
126 | 127 | ||
127 | void IOSerial::reload(const Profile &config) { | 128 | void IOSerial::reload(const Profile &config) { |
128 | m_device = config.readEntry("Device", SERIAL_DEFAULT_DEVICE); | 129 | m_device = config.readEntry("Device", SERIAL_DEFAULT_DEVICE); |
129 | qWarning( "Dev" +m_device ); | 130 | qWarning( "Dev" +m_device ); |
130 | qWarning( "Conf:" +config.readEntry("Device") ); | 131 | qWarning( "Conf:" +config.readEntry("Device") ); |
131 | m_baud = config.readNumEntry("Baud", SERIAL_DEFAULT_BAUD); | 132 | m_baud = config.readNumEntry("Baud", SERIAL_DEFAULT_BAUD); |
132 | m_parity = config.readNumEntry("Parity", SERIAL_DEFAULT_PARITY); | 133 | m_parity = config.readNumEntry("Parity", SERIAL_DEFAULT_PARITY); |
133 | m_dbits = config.readNumEntry("DataBits", SERIAL_DEFAULT_DBITS); | 134 | m_dbits = config.readNumEntry("DataBits", SERIAL_DEFAULT_DBITS); |
134 | m_sbits = config.readNumEntry("StopBits", SERIAL_DEFAULT_SBITS); | 135 | m_sbits = config.readNumEntry("StopBits", SERIAL_DEFAULT_SBITS); |
135 | m_flow = config.readNumEntry("Flow", SERIAL_DEFAULT_FLOW); | 136 | m_flow = config.readNumEntry("Flow", SERIAL_DEFAULT_FLOW); |
136 | } | 137 | } |
137 | 138 | ||
138 | int IOSerial::baud(int baud) const { | 139 | int IOSerial::baud(int baud) const { |
139 | switch (baud) { | 140 | switch (baud) { |
140 | case 300: return B300; break; | 141 | case 300: return B300; break; |
141 | case 600: return B600; break; | 142 | case 600: return B600; break; |
142 | case 1200: return B1200; break; | 143 | case 1200: return B1200; break; |
143 | case 2400: return B2400; break; | 144 | case 2400: return B2400; break; |
144 | case 4800: return B4800; break; | 145 | case 4800: return B4800; break; |
145 | case 9600: return B9600; break; | 146 | case 9600: return B9600; break; |
146 | case 19200: return B19200; break; | 147 | case 19200: return B19200; break; |
147 | case 38400: return B38400; break; | 148 | case 38400: return B38400; break; |
148 | case 57600: return B57600; break; | 149 | case 57600: return B57600; break; |
149 | case 115200: return B115200; break; | 150 | case 115200: return B115200; break; |
150 | } | 151 | } |
151 | return -1; | 152 | return -1; |
152 | } | 153 | } |
153 | 154 | ||
154 | void IOSerial::errorOccured() { | 155 | void IOSerial::errorOccured() { |
155 | emit error(ClosedUnexpected, strerror(errno)); | 156 | emit error(ClosedUnexpected, strerror(errno)); |
156 | close(); | 157 | close(); |
157 | } | 158 | } |
158 | 159 | ||
159 | void IOSerial::dataArrived() { | 160 | void IOSerial::dataArrived() { |
160 | QByteArray array(4097); | 161 | QByteArray array(4097); |
161 | 162 | ||
162 | int len = read(m_fd, array.data(), 4096); | 163 | int len = read(m_fd, array.data(), 4096); |
163 | if (len == 0) | 164 | if (len == 0) |
164 | close(); | 165 | close(); |
165 | if (len < 0) | 166 | if (len < 0) |
166 | return; | 167 | return; |
167 | array.resize( len ); | 168 | array.resize( len ); |
168 | emit received(array); | 169 | emit received(array); |
169 | } | 170 | } |
170 | 171 | ||
171 | QString IOSerial::identifier() const { | 172 | QString IOSerial::identifier() const { |
172 | return "serial"; | 173 | return "serial"; |
173 | } | 174 | } |
174 | 175 | ||
175 | QString IOSerial::name() const { | 176 | QString IOSerial::name() const { |
176 | return "RS232 Serial IO Layer"; | 177 | return "RS232 Serial IO Layer"; |
177 | } | 178 | } |
178 | int IOSerial::rawIO()const { | 179 | int 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 | }; |
189 | void 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 | |||
@@ -1,64 +1,65 @@ | |||
1 | #ifndef OPIE_IO_SERIAL | 1 | #ifndef OPIE_IO_SERIAL |
2 | #define OPIE_IO_SERIAL | 2 | #define OPIE_IO_SERIAL |
3 | 3 | ||
4 | #include <qsocketnotifier.h> | 4 | #include <qsocketnotifier.h> |
5 | #include "io_layer.h" | 5 | #include "io_layer.h" |
6 | 6 | ||
7 | /* Default values to be used if the profile information is incomplete */ | 7 | /* Default values to be used if the profile information is incomplete */ |
8 | #define SERIAL_DEFAULT_DEVICE "/dev/ttyS0" | 8 | #define SERIAL_DEFAULT_DEVICE "/dev/ttyS0" |
9 | #define SERIAL_DEFAULT_BAUD 9600 | 9 | #define SERIAL_DEFAULT_BAUD 9600 |
10 | #define SERIAL_DEFAULT_PARITY 0 | 10 | #define SERIAL_DEFAULT_PARITY 0 |
11 | #define SERIAL_DEFAULT_DBITS 8 | 11 | #define SERIAL_DEFAULT_DBITS 8 |
12 | #define SERIAL_DEFAULT_SBITS 1 | 12 | #define SERIAL_DEFAULT_SBITS 1 |
13 | #define SERIAL_DEFAULT_FLOW 0 | 13 | #define SERIAL_DEFAULT_FLOW 0 |
14 | 14 | ||
15 | /* IOSerial implements a RS232 IO Layer */ | 15 | /* IOSerial implements a RS232 IO Layer */ |
16 | 16 | ||
17 | class IOSerial : public IOLayer { | 17 | class IOSerial : public IOLayer { |
18 | Q_OBJECT | 18 | Q_OBJECT |
19 | public: | 19 | public: |
20 | enum Parity { | 20 | enum Parity { |
21 | ParityNone = 0, | 21 | ParityNone = 0, |
22 | ParityEven, | 22 | ParityEven, |
23 | ParityOdd, | 23 | ParityOdd, |
24 | ParitySpace, | 24 | ParitySpace, |
25 | ParityMark | 25 | ParityMark |
26 | }; | 26 | }; |
27 | 27 | ||
28 | enum Flow { | 28 | enum Flow { |
29 | FlowHW = 0x01, | 29 | FlowHW = 0x01, |
30 | FlowSW = 0x02 | 30 | FlowSW = 0x02 |
31 | }; | 31 | }; |
32 | 32 | ||
33 | IOSerial(const Profile &); | 33 | IOSerial(const Profile &); |
34 | ~IOSerial(); | 34 | ~IOSerial(); |
35 | 35 | ||
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 ); | ||
39 | signals: | 40 | signals: |
40 | void received(const QByteArray &); | 41 | void received(const QByteArray &); |
41 | void error(int, const QString &); | 42 | void error(int, const QString &); |
42 | public slots: | 43 | public slots: |
43 | void send(const QByteArray &); | 44 | void send(const QByteArray &); |
44 | bool open(); | 45 | bool open(); |
45 | void close(); | 46 | void close(); |
46 | void reload(const Profile &); | 47 | void reload(const Profile &); |
47 | protected: | 48 | protected: |
48 | int baud(int baud) const; | 49 | int baud(int baud) const; |
49 | protected slots: | 50 | protected slots: |
50 | void dataArrived(); | 51 | void dataArrived(); |
51 | void errorOccured(); | 52 | void errorOccured(); |
52 | protected: | 53 | protected: |
53 | QSocketNotifier *m_read; | 54 | QSocketNotifier *m_read; |
54 | QSocketNotifier *m_error; | 55 | QSocketNotifier *m_error; |
55 | QString m_device; | 56 | QString m_device; |
56 | int m_baud; | 57 | int m_baud; |
57 | int m_parity; | 58 | int m_parity; |
58 | int m_dbits; | 59 | int m_dbits; |
59 | int m_sbits; | 60 | int m_sbits; |
60 | int m_flow; | 61 | int m_flow; |
61 | int m_fd; | 62 | int m_fd; |
62 | }; | 63 | }; |
63 | 64 | ||
64 | #endif /* OPIE_IO_SERIAL */ | 65 | #endif /* OPIE_IO_SERIAL */ |
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 | |||
@@ -1,64 +1,64 @@ | |||
1 | TEMPLATE = app | 1 | TEMPLATE = app |
2 | #CONFIG = qt warn_on release | 2 | #CONFIG = qt warn_on release |
3 | CONFIG = qt debug | 3 | CONFIG = qt debug |
4 | DESTDIR = $(OPIEDIR)/bin | 4 | DESTDIR = $(OPIEDIR)/bin |
5 | HEADERS = io_layer.h io_serial.h io_irda.h \ | 5 | HEADERS = 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 \ |
10 | profile.h \ | 10 | profile.h \ |
11 | profileconfig.h \ | 11 | profileconfig.h \ |
12 | profilemanager.h \ | 12 | profilemanager.h \ |
13 | configwidget.h \ | 13 | configwidget.h \ |
14 | tabwidget.h \ | 14 | tabwidget.h \ |
15 | configdialog.h \ | 15 | configdialog.h \ |
16 | emulation_layer.h \ | 16 | emulation_layer.h \ |
17 | vt102emulation.h \ | 17 | vt102emulation.h \ |
18 | common.h \ | 18 | common.h \ |
19 | history.h \ | 19 | history.h \ |
20 | screen.h \ | 20 | screen.h \ |
21 | keytrans.h \ | 21 | keytrans.h \ |
22 | widget_layer.h \ | 22 | widget_layer.h \ |
23 | transferdialog.h \ | 23 | transferdialog.h \ |
24 | profiledialogwidget.h \ | 24 | profiledialogwidget.h \ |
25 | profileeditordialog.h \ | 25 | profileeditordialog.h \ |
26 | default.h \ | 26 | default.h \ |
27 | terminalwidget.h \ | 27 | terminalwidget.h \ |
28 | iolayerbase.h \ | 28 | iolayerbase.h \ |
29 | serialconfigwidget.h irdaconfigwidget.h btconfigwidget.h \ | 29 | serialconfigwidget.h irdaconfigwidget.h btconfigwidget.h \ |
30 | emulation_widget.h | 30 | emulation_widget.h |
31 | 31 | ||
32 | 32 | ||
33 | SOURCES = io_layer.cpp io_serial.cpp io_irda.cpp \ | 33 | SOURCES = 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 \ |
38 | mainwindow.cpp \ | 38 | mainwindow.cpp \ |
39 | profile.cpp \ | 39 | profile.cpp \ |
40 | profileconfig.cpp \ | 40 | profileconfig.cpp \ |
41 | profilemanager.cpp \ | 41 | profilemanager.cpp \ |
42 | tabwidget.cpp \ | 42 | tabwidget.cpp \ |
43 | configdialog.cpp \ | 43 | configdialog.cpp \ |
44 | emulation_layer.cpp \ | 44 | emulation_layer.cpp \ |
45 | vt102emulation.cpp \ | 45 | vt102emulation.cpp \ |
46 | history.cpp \ | 46 | history.cpp \ |
47 | screen.cpp \ | 47 | screen.cpp \ |
48 | keytrans.cpp \ | 48 | keytrans.cpp \ |
49 | widget_layer.cpp \ | 49 | widget_layer.cpp \ |
50 | transferdialog.cpp \ | 50 | transferdialog.cpp \ |
51 | profiledialogwidget.cpp \ | 51 | profiledialogwidget.cpp \ |
52 | profileeditordialog.cpp \ | 52 | profileeditordialog.cpp \ |
53 | default.cpp \ | 53 | default.cpp \ |
54 | terminalwidget.cpp \ | 54 | terminalwidget.cpp \ |
55 | iolayerbase.cpp \ | 55 | iolayerbase.cpp \ |
56 | serialconfigwidget.cpp irdaconfigwidget.cpp btconfigwidget.cpp \ | 56 | serialconfigwidget.cpp irdaconfigwidget.cpp btconfigwidget.cpp \ |
57 | emulation_widget.cpp | 57 | emulation_widget.cpp |
58 | 58 | ||
59 | INTERFACES = configurebase.ui editbase.ui | 59 | INTERFACES = configurebase.ui editbase.ui |
60 | INCLUDEPATH += $(OPIEDIR)/include | 60 | INCLUDEPATH += $(OPIEDIR)/include |
61 | DEPENDPATH += $(OPIEDIR)/include | 61 | DEPENDPATH += $(OPIEDIR)/include |
62 | LIBS += -lqpe -lopie | 62 | LIBS += -lqpe -lopie |
63 | TARGET = opie-console | 63 | TARGET = 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 | |||
@@ -1,43 +1,44 @@ | |||
1 | 1 | ||
2 | #include "tabwidget.h" | 2 | #include "tabwidget.h" |
3 | 3 | ||
4 | TabWidget::TabWidget( QWidget* parent, const char* name ) | 4 | TabWidget::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 | } |
9 | 9 | ||
10 | TabWidget::~TabWidget() { | 10 | TabWidget::~TabWidget() { |
11 | } | 11 | } |
12 | 12 | ||
13 | void TabWidget::add( Session* ses ) { | 13 | 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 | ||
22 | void TabWidget::remove( Session* ses ) { | 22 | void TabWidget::remove( Session* ses ) { |
23 | m_map.remove( ses->widgetStack() ); | 23 | m_map.remove( ses->widgetStack() ); |
24 | removePage( ses->widgetStack() ); | 24 | removePage( ses->widgetStack() ); |
25 | } | 25 | } |
26 | 26 | ||
27 | void TabWidget::slotCurChanged( QWidget* wid ) { | 27 | void TabWidget::slotCurChanged( QWidget* wid ) { |
28 | QMap<QWidget*, Session*>::Iterator it; | 28 | QMap<QWidget*, Session*>::Iterator it; |
29 | it = m_map.find( wid ); | 29 | it = m_map.find( wid ); |
30 | if ( it == m_map.end() ) { | 30 | if ( it == m_map.end() ) { |
31 | return; | 31 | return; |
32 | } | 32 | } |
33 | 33 | ||
34 | emit activated( it.data() ); | 34 | emit activated( it.data() ); |
35 | } | 35 | } |
36 | void TabWidget::setCurrent( Session* ses ) { | 36 | 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 | |||
@@ -1,29 +1,29 @@ | |||
1 | #ifndef OPIE_TAB_WIDGET_H | 1 | #ifndef OPIE_TAB_WIDGET_H |
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 | */ |
12 | class TabWidget : public QTabWidget{ | 12 | class TabWidget : public OTabWidget{ |
13 | Q_OBJECT | 13 | Q_OBJECT |
14 | public: | 14 | public: |
15 | TabWidget(QWidget *parent, const char* name ); | 15 | TabWidget(QWidget *parent, const char* name ); |
16 | ~TabWidget(); | 16 | ~TabWidget(); |
17 | void add( Session* ); | 17 | void add( Session* ); |
18 | void remove( Session* ); | 18 | void remove( Session* ); |
19 | void setCurrent( Session* ); | 19 | void setCurrent( Session* ); |
20 | 20 | ||
21 | signals: | 21 | signals: |
22 | void activated(Session* ses ); | 22 | void activated(Session* ses ); |
23 | private slots: | 23 | private slots: |
24 | void slotCurChanged( QWidget* wid ); | 24 | void slotCurChanged( QWidget* wid ); |
25 | private: | 25 | private: |
26 | QMap<QWidget*, Session*> m_map; | 26 | QMap<QWidget*, Session*> m_map; |
27 | }; | 27 | }; |
28 | 28 | ||
29 | #endif | 29 | #endif |