Diffstat (limited to 'noncore/apps/opie-console/filetransfer.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/apps/opie-console/filetransfer.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/noncore/apps/opie-console/filetransfer.cpp b/noncore/apps/opie-console/filetransfer.cpp index 221838c..5144941 100644 --- a/noncore/apps/opie-console/filetransfer.cpp +++ b/noncore/apps/opie-console/filetransfer.cpp | |||
@@ -48,193 +48,193 @@ void FileTransfer::sendFile( const QString& file ) { | |||
48 | m_pid = fork(); | 48 | m_pid = fork(); |
49 | switch( m_pid ) { | 49 | switch( m_pid ) { |
50 | case -1: | 50 | case -1: |
51 | emit error( StartError, tr("Was not able to fork") ); | 51 | emit error( StartError, tr("Was not able to fork") ); |
52 | slotExec(); | 52 | slotExec(); |
53 | break; | 53 | break; |
54 | case 0:{ | 54 | case 0:{ |
55 | setupChild(); | 55 | setupChild(); |
56 | /* exec */ | 56 | /* exec */ |
57 | char* verbose = "-vv"; | 57 | char* verbose = "-vv"; |
58 | char* binray = "-b"; | 58 | char* binray = "-b"; |
59 | 59 | ||
60 | 60 | ||
61 | char* typus; | 61 | char* typus; |
62 | switch(m_type ) { | 62 | switch(m_type ) { |
63 | default: | 63 | default: |
64 | case SZ: | 64 | case SZ: |
65 | typus = ""; | 65 | typus = ""; |
66 | break; | 66 | break; |
67 | case SX: | 67 | case SX: |
68 | typus = "-X"; | 68 | typus = "-X"; |
69 | break; | 69 | break; |
70 | case SY: | 70 | case SY: |
71 | typus = "--ymodem"; | 71 | typus = "--ymodem"; |
72 | break; | 72 | break; |
73 | } | 73 | } |
74 | 74 | ||
75 | /* we should never return from here */ | 75 | /* we should never return from here */ |
76 | execlp("sz", "sz", verbose, binray, file.latin1(), typus, NULL ); | 76 | execlp("sz", "sz", verbose, binray, file.latin1(), typus, NULL ); |
77 | 77 | ||
78 | /* communication for error!*/ | 78 | /* communication for error!*/ |
79 | char resultByte =1; | 79 | char resultByte =1; |
80 | if (m_info[1] ) | 80 | if (m_info[1] ) |
81 | write(m_info[1], &resultByte, 1 ); | 81 | write(m_info[1], &resultByte, 1 ); |
82 | _exit( -1 ); | 82 | _exit( -1 ); |
83 | break; | 83 | break; |
84 | } | 84 | } |
85 | default:{ | 85 | default:{ |
86 | if ( m_info[1] ) | 86 | if ( m_info[1] ) |
87 | close( m_info[1] ); | 87 | close( m_info[1] ); |
88 | if ( m_info[0] ) for (;;) { | 88 | if ( m_info[0] ) for (;;) { |
89 | char resultByte; int len; | 89 | char resultByte; int len; |
90 | len = read(m_info[0], &resultByte, 1 ); | 90 | len = read(m_info[0], &resultByte, 1 ); |
91 | /* len == 1 start up failed */ | 91 | /* len == 1 start up failed */ |
92 | if ( len == 1 ) { | 92 | if ( len == 1 ) { |
93 | emit error( StartError, tr("Could not start") ); | 93 | emit error( StartError, tr("Could not start") ); |
94 | return; | 94 | return; |
95 | } | 95 | } |
96 | if ( len == -1 ) | 96 | if ( len == -1 ) |
97 | if ( (errno == ECHILD ) || (errno == EINTR ) ) | 97 | if ( (errno == ECHILD ) || (errno == EINTR ) ) |
98 | continue; | 98 | continue; |
99 | 99 | ||
100 | // len == 0 or something like this | 100 | // len == 0 or something like this |
101 | break; | 101 | break; |
102 | } | 102 | } |
103 | if ( m_info[0] ) | 103 | if ( m_info[0] ) |
104 | close( m_info[0] ); | 104 | close( m_info[0] ); |
105 | 105 | ||
106 | 106 | ||
107 | 107 | ||
108 | /* replace by QSocketNotifier!!! */ | 108 | /* replace by QSocketNotifier!!! */ |
109 | m_not = new QSocketNotifier(m_comm[0], QSocketNotifier::Read ); | 109 | m_not = new QSocketNotifier(m_comm[0], QSocketNotifier::Read ); |
110 | connect(m_not, SIGNAL(activated(int) ), | 110 | connect(m_not, SIGNAL(activated(int) ), |
111 | this, SLOT(slotRead() ) ); | 111 | this, SLOT(slotRead() ) ); |
112 | if ( pipe(m_term) < 0 ) | 112 | if ( pipe(m_term) < 0 ) |
113 | m_term[0] = m_term[1] = 0; | 113 | m_term[0] = m_term[1] = 0; |
114 | 114 | ||
115 | ProcCtl::self()->add(m_pid, m_term[1] ); | 115 | ProcCtl::self()->add(m_pid, m_term[1] ); |
116 | m_proc = new QSocketNotifier(m_term[0], QSocketNotifier::Read ); | 116 | m_proc = new QSocketNotifier(m_term[0], QSocketNotifier::Read ); |
117 | connect(m_proc, SIGNAL(activated(int) ), | 117 | connect(m_proc, SIGNAL(activated(int) ), |
118 | this, SLOT(slotExec() ) ); | 118 | this, SLOT(slotExec() ) ); |
119 | 119 | ||
120 | } | 120 | } |
121 | break; | 121 | break; |
122 | } | 122 | } |
123 | } | 123 | } |
124 | /* | 124 | /* |
125 | * let's call the one with the filename | 125 | * let's call the one with the filename |
126 | */ | 126 | */ |
127 | void FileTransfer::sendFile( const QFile& file ) { | 127 | void FileTransfer::sendFile( const QFile& file ) { |
128 | sendFile( file.name() ); | 128 | sendFile( file.name() ); |
129 | } | 129 | } |
130 | 130 | ||
131 | /* | 131 | /* |
132 | * setting up communication | 132 | * setting up communication |
133 | * between parent child and ioLayer | 133 | * between parent child and ioLayer |
134 | */ | 134 | */ |
135 | void FileTransfer::setupChild() { | 135 | void FileTransfer::setupChild() { |
136 | /* | 136 | /* |
137 | * we do not want to read from our | 137 | * we do not want to read from our |
138 | * information channel | 138 | * information channel |
139 | */ | 139 | */ |
140 | if (m_info[0] ) | 140 | if (m_info[0] ) |
141 | close(m_info[0] ); | 141 | close(m_info[0] ); |
142 | /* | 142 | /* |
143 | * FD_CLOEXEC will close the | 143 | * FD_CLOEXEC will close the |
144 | * fd on successfull exec | 144 | * fd on successful exec |
145 | */ | 145 | */ |
146 | if (m_info[1] ) | 146 | if (m_info[1] ) |
147 | fcntl(m_info[1], F_SETFD, FD_CLOEXEC ); | 147 | fcntl(m_info[1], F_SETFD, FD_CLOEXEC ); |
148 | 148 | ||
149 | if (m_comm[0] ) | 149 | if (m_comm[0] ) |
150 | close( m_comm[0] ); | 150 | close( m_comm[0] ); |
151 | /* | 151 | /* |
152 | * now set the communication | 152 | * now set the communication |
153 | * m_fd STDIN_FILENO | 153 | * m_fd STDIN_FILENO |
154 | * STDOUT_FILENO | 154 | * STDOUT_FILENO |
155 | * STDERR_FILENO | 155 | * STDERR_FILENO |
156 | */ | 156 | */ |
157 | dup2( m_fd, STDIN_FILENO ); | 157 | dup2( m_fd, STDIN_FILENO ); |
158 | dup2( m_fd, STDOUT_FILENO ); | 158 | dup2( m_fd, STDOUT_FILENO ); |
159 | dup2( m_comm[1], STDERR_FILENO ); | 159 | dup2( m_comm[1], STDERR_FILENO ); |
160 | } | 160 | } |
161 | 161 | ||
162 | /* | 162 | /* |
163 | * read from the stderr of the child | 163 | * read from the stderr of the child |
164 | * process | 164 | * process |
165 | */ | 165 | */ |
166 | void FileTransfer::slotRead() { | 166 | void FileTransfer::slotRead() { |
167 | QByteArray ar(4096); | 167 | QByteArray ar(4096); |
168 | int len = read(m_comm[0], ar.data(), 4096 ); | 168 | int len = read(m_comm[0], ar.data(), 4096 ); |
169 | for (int i = 0; i < len; i++ ) { | 169 | for (int i = 0; i < len; i++ ) { |
170 | // printf("%c", ar[i] ); | 170 | // printf("%c", ar[i] ); |
171 | } | 171 | } |
172 | ar.resize( len ); | 172 | ar.resize( len ); |
173 | QString str( ar ); | 173 | QString str( ar ); |
174 | QStringList lis = QStringList::split(' ', str ); | 174 | QStringList lis = QStringList::split(' ', str ); |
175 | /* | 175 | /* |
176 | * Transfer finished.. either complete or incomplete | 176 | * Transfer finished.. either complete or incomplete |
177 | */ | 177 | */ |
178 | if ( lis[0].simplifyWhiteSpace() == "Transfer" ) { | 178 | if ( lis[0].simplifyWhiteSpace() == "Transfer" ) { |
179 | return; | 179 | return; |
180 | } | 180 | } |
181 | /* | 181 | /* |
182 | * do progress reading | 182 | * do progress reading |
183 | */ | 183 | */ |
184 | slotProgress( lis ); | 184 | slotProgress( lis ); |
185 | 185 | ||
186 | 186 | ||
187 | } | 187 | } |
188 | /* | 188 | /* |
189 | * find the progress | 189 | * find the progress |
190 | */ | 190 | */ |
191 | void FileTransfer::slotProgress( const QStringList& list ) { | 191 | void FileTransfer::slotProgress( const QStringList& list ) { |
192 | if ( m_type != SZ ) | 192 | if ( m_type != SZ ) |
193 | return; | 193 | return; |
194 | bool complete = true; | 194 | bool complete = true; |
195 | int min, sec; | 195 | int min, sec; |
196 | int bps; | 196 | int bps; |
197 | unsigned long sent, total; | 197 | unsigned long sent, total; |
198 | 198 | ||
199 | min = sec = bps = -1; | 199 | min = sec = bps = -1; |
200 | sent = total = 0; | 200 | sent = total = 0; |
201 | 201 | ||
202 | // Data looks like this | 202 | // Data looks like this |
203 | // 0 1 2 3 4 5 | 203 | // 0 1 2 3 4 5 |
204 | // Bytes Sent 65536/11534336 BPS:7784 ETA 24:33 | 204 | // Bytes Sent 65536/11534336 BPS:7784 ETA 24:33 |
205 | QStringList progi = QStringList::split('/', list[2].simplifyWhiteSpace() ); | 205 | QStringList progi = QStringList::split('/', list[2].simplifyWhiteSpace() ); |
206 | sent = progi[0].toULong(&complete ); | 206 | sent = progi[0].toULong(&complete ); |
207 | if (!complete ) return; | 207 | if (!complete ) return; |
208 | 208 | ||
209 | total = progi[1].toULong(&complete ); | 209 | total = progi[1].toULong(&complete ); |
210 | if (!complete || total == 0) { | 210 | if (!complete || total == 0) { |
211 | return; | 211 | return; |
212 | } | 212 | } |
213 | 213 | ||
214 | 214 | ||
215 | double pro = (double)sent/total; | 215 | double pro = (double)sent/total; |
216 | int prog = pro * 100; | 216 | int prog = pro * 100; |
217 | 217 | ||
218 | // speed | 218 | // speed |
219 | progi = QStringList::split(':', list[3].simplifyWhiteSpace() ); | 219 | progi = QStringList::split(':', list[3].simplifyWhiteSpace() ); |
220 | bps = progi[1].toInt(); | 220 | bps = progi[1].toInt(); |
221 | 221 | ||
222 | // time | 222 | // time |
223 | progi = QStringList::split(':', list[5].simplifyWhiteSpace() ); | 223 | progi = QStringList::split(':', list[5].simplifyWhiteSpace() ); |
224 | min = progi[0].toInt(); | 224 | min = progi[0].toInt(); |
225 | sec = progi[1].toInt(); | 225 | sec = progi[1].toInt(); |
226 | 226 | ||
227 | 227 | ||
228 | if ( prog > m_prog ) { | 228 | if ( prog > m_prog ) { |
229 | m_prog = prog; | 229 | m_prog = prog; |
230 | emit progress(m_file, m_prog, bps, -1, min , sec ); | 230 | emit progress(m_file, m_prog, bps, -1, min , sec ); |
231 | } | 231 | } |
232 | 232 | ||
233 | } | 233 | } |
234 | void FileTransfer::cancel() { | 234 | void FileTransfer::cancel() { |
235 | if(m_pid > 0) ::kill(m_pid,9 ); | 235 | if(m_pid > 0) ::kill(m_pid,9 ); |
236 | 236 | ||
237 | } | 237 | } |
238 | void FileTransfer::slotExec() { | 238 | void FileTransfer::slotExec() { |
239 | char buf[2]; | 239 | char buf[2]; |
240 | ::read(m_term[0], buf, 1 ); | 240 | ::read(m_term[0], buf, 1 ); |