author | josef <josef> | 2002-10-13 12:11:15 (UTC) |
---|---|---|
committer | josef <josef> | 2002-10-13 12:11:15 (UTC) |
commit | 0e6d241e26211a8ffff07ba8e23f4a3cec9065be (patch) (unidiff) | |
tree | 1cecafc71b4261943250cf7f83013e749c5c3a1e | |
parent | 5f9fb52583eb399c79a108b8e79c1a558a730422 (diff) | |
download | opie-0e6d241e26211a8ffff07ba8e23f4a3cec9065be.zip opie-0e6d241e26211a8ffff07ba8e23f4a3cec9065be.tar.gz opie-0e6d241e26211a8ffff07ba8e23f4a3cec9065be.tar.bz2 |
- extend file transfer dialog so it can receive too (without filename argument)
- fix error messages so they match the error code
- don't show dialog maximized. It's still modal but we're coming near...
- reset status to "ready" after interrupting or finishing operation
- bugfix in filetransfer.cpp: don't kill process if pid is not set
=> before the fix, cancel() killed random processes!
-rw-r--r-- | noncore/apps/opie-console/filetransfer.cpp | 4 | ||||
-rw-r--r-- | noncore/apps/opie-console/mainwindow.cpp | 2 | ||||
-rw-r--r-- | noncore/apps/opie-console/transferdialog.cpp | 99 | ||||
-rw-r--r-- | noncore/apps/opie-console/transferdialog.h | 14 |
4 files changed, 79 insertions, 40 deletions
diff --git a/noncore/apps/opie-console/filetransfer.cpp b/noncore/apps/opie-console/filetransfer.cpp index 8e86ebb..14787f6 100644 --- a/noncore/apps/opie-console/filetransfer.cpp +++ b/noncore/apps/opie-console/filetransfer.cpp | |||
@@ -1,81 +1,81 @@ | |||
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 "procctl.h" | 12 | #include "procctl.h" |
13 | #include "filetransfer.h" | 13 | #include "filetransfer.h" |
14 | 14 | ||
15 | 15 | ||
16 | FileTransfer::FileTransfer( Type t, IOLayer* lay ) | 16 | FileTransfer::FileTransfer( Type t, IOLayer* lay ) |
17 | : FileTransferLayer( lay ), m_type( t ) { | 17 | : FileTransferLayer( lay ), m_type( t ), m_pid ( 0 ) { |
18 | signal(SIGPIPE, SIG_IGN ); | 18 | signal(SIGPIPE, SIG_IGN ); |
19 | 19 | ||
20 | m_not = 0l; | 20 | m_not = 0l; |
21 | m_proc = 0l; | 21 | m_proc = 0l; |
22 | } | 22 | } |
23 | FileTransfer::~FileTransfer() { | 23 | FileTransfer::~FileTransfer() { |
24 | } | 24 | } |
25 | 25 | ||
26 | /** | 26 | /** |
27 | * now we will send the file. | 27 | * now we will send the file. |
28 | * | 28 | * |
29 | * we request an fd. The IOLayer should be closed | 29 | * we request an fd. The IOLayer should be closed |
30 | * then we will setup a pipe for progress communication | 30 | * then we will setup a pipe for progress communication |
31 | * then we will dup2 the m_fd in the forked process | 31 | * then we will dup2 the m_fd in the forked process |
32 | * to do direct IO from and to the fd | 32 | * to do direct IO from and to the fd |
33 | */ | 33 | */ |
34 | void FileTransfer::sendFile( const QString& file ) { | 34 | void FileTransfer::sendFile( const QString& file ) { |
35 | m_prog =-1; | 35 | m_prog =-1; |
36 | m_fd = layer()->rawIO(); | 36 | m_fd = layer()->rawIO(); |
37 | // | 37 | // |
38 | // m_fd = ::open("/dev/ttyS0", O_RDWR); | 38 | // m_fd = ::open("/dev/ttyS0", O_RDWR); |
39 | 39 | ||
40 | m_file = file; | 40 | m_file = file; |
41 | if ( pipe( m_comm ) < 0 ) | 41 | if ( pipe( m_comm ) < 0 ) |
42 | m_comm[0] = m_comm[1] = 0; | 42 | m_comm[0] = m_comm[1] = 0; |
43 | if ( pipe( m_info ) < 0 ) | 43 | if ( pipe( m_info ) < 0 ) |
44 | m_info[0] = m_info[1] = 0; | 44 | m_info[0] = m_info[1] = 0; |
45 | 45 | ||
46 | 46 | ||
47 | m_pid = fork(); | 47 | m_pid = fork(); |
48 | switch( m_pid ) { | 48 | switch( m_pid ) { |
49 | case -1: | 49 | case -1: |
50 | emit error( StartError, tr("Was not able to fork") ); | 50 | emit error( StartError, tr("Was not able to fork") ); |
51 | break; | 51 | break; |
52 | case 0:{ | 52 | case 0:{ |
53 | setupChild(); | 53 | setupChild(); |
54 | qWarning("output:"+file ); | 54 | qWarning("output:"+file ); |
55 | /* exec */ | 55 | /* exec */ |
56 | char* verbose = "-vv"; | 56 | char* verbose = "-vv"; |
57 | char* binray = "-b"; | 57 | char* binray = "-b"; |
58 | 58 | ||
59 | 59 | ||
60 | char* typus; | 60 | char* typus; |
61 | switch(m_type ) { | 61 | switch(m_type ) { |
62 | case SZ: | 62 | case SZ: |
63 | typus = ""; | 63 | typus = ""; |
64 | break; | 64 | break; |
65 | case SX: | 65 | case SX: |
66 | typus = "-X"; | 66 | typus = "-X"; |
67 | break; | 67 | break; |
68 | case SY: | 68 | case SY: |
69 | typus = "--ymodem"; | 69 | typus = "--ymodem"; |
70 | break; | 70 | break; |
71 | } | 71 | } |
72 | 72 | ||
73 | /* we should never return from here */ | 73 | /* we should never return from here */ |
74 | execlp("sz", "sz", verbose, binray, file.latin1(), typus, NULL ); | 74 | execlp("sz", "sz", verbose, binray, file.latin1(), typus, NULL ); |
75 | 75 | ||
76 | /* communication for error!*/ | 76 | /* communication for error!*/ |
77 | char resultByte =1; | 77 | char resultByte =1; |
78 | if (m_info[1] ) | 78 | if (m_info[1] ) |
79 | write(m_info[1], &resultByte, 1 ); | 79 | write(m_info[1], &resultByte, 1 ); |
80 | _exit( -1 ); | 80 | _exit( -1 ); |
81 | break; | 81 | break; |
@@ -174,80 +174,80 @@ void FileTransfer::slotRead() { | |||
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 | qWarning("sent!!!!"); | 179 | qWarning("sent!!!!"); |
180 | emit sent(); | 180 | emit sent(); |
181 | return; | 181 | return; |
182 | } | 182 | } |
183 | /* | 183 | /* |
184 | * do progress reading | 184 | * do progress reading |
185 | */ | 185 | */ |
186 | slotProgress( lis ); | 186 | slotProgress( lis ); |
187 | 187 | ||
188 | 188 | ||
189 | } | 189 | } |
190 | /* | 190 | /* |
191 | * find the progress | 191 | * find the progress |
192 | */ | 192 | */ |
193 | void FileTransfer::slotProgress( const QStringList& list ) { | 193 | void FileTransfer::slotProgress( const QStringList& list ) { |
194 | if ( m_type != SZ ) | 194 | if ( m_type != SZ ) |
195 | return; | 195 | return; |
196 | bool complete = true; | 196 | bool complete = true; |
197 | int min, sec; | 197 | int min, sec; |
198 | int bps; | 198 | int bps; |
199 | unsigned long sent, total; | 199 | unsigned long sent, total; |
200 | 200 | ||
201 | min = sec = bps = -1; | 201 | min = sec = bps = -1; |
202 | sent = total = 0; | 202 | sent = total = 0; |
203 | 203 | ||
204 | // Data looks like this | 204 | // Data looks like this |
205 | // 0 1 2 3 4 5 | 205 | // 0 1 2 3 4 5 |
206 | // Bytes Sent 65536/11534336 BPS:7784 ETA 24:33 | 206 | // Bytes Sent 65536/11534336 BPS:7784 ETA 24:33 |
207 | QStringList progi = QStringList::split('/', list[2].simplifyWhiteSpace() ); | 207 | QStringList progi = QStringList::split('/', list[2].simplifyWhiteSpace() ); |
208 | sent = progi[0].toULong(&complete ); | 208 | sent = progi[0].toULong(&complete ); |
209 | if (!complete ) return; | 209 | if (!complete ) return; |
210 | 210 | ||
211 | total = progi[1].toULong(&complete ); | 211 | total = progi[1].toULong(&complete ); |
212 | if (!complete || total == 0) { | 212 | if (!complete || total == 0) { |
213 | return; | 213 | return; |
214 | } | 214 | } |
215 | 215 | ||
216 | qWarning("%s, %d, %d", progi.join("/").latin1(), sent, total ); | 216 | qWarning("%s, %d, %d", progi.join("/").latin1(), sent, total ); |
217 | 217 | ||
218 | double pro = (double)sent/total; | 218 | double pro = (double)sent/total; |
219 | int prog = pro * 100; | 219 | int prog = pro * 100; |
220 | 220 | ||
221 | // speed | 221 | // speed |
222 | progi = QStringList::split(':', list[3].simplifyWhiteSpace() ); | 222 | progi = QStringList::split(':', list[3].simplifyWhiteSpace() ); |
223 | bps = progi[1].toInt(); | 223 | bps = progi[1].toInt(); |
224 | 224 | ||
225 | // time | 225 | // time |
226 | progi = QStringList::split(':', list[5].simplifyWhiteSpace() ); | 226 | progi = QStringList::split(':', list[5].simplifyWhiteSpace() ); |
227 | min = progi[0].toInt(); | 227 | min = progi[0].toInt(); |
228 | sec = progi[1].toInt(); | 228 | sec = progi[1].toInt(); |
229 | 229 | ||
230 | 230 | ||
231 | if ( prog > m_prog ) { | 231 | if ( prog > m_prog ) { |
232 | m_prog = prog; | 232 | m_prog = prog; |
233 | emit progress(m_file, m_prog, bps, -1, min , sec ); | 233 | emit progress(m_file, m_prog, bps, -1, min , sec ); |
234 | } | 234 | } |
235 | 235 | ||
236 | } | 236 | } |
237 | void FileTransfer::cancel() { | 237 | void FileTransfer::cancel() { |
238 | ::kill(m_pid,9 ); | 238 | if(m_pid > 0) ::kill(m_pid,9 ); |
239 | delete m_not; | 239 | delete m_not; |
240 | } | 240 | } |
241 | void FileTransfer::slotExec() { | 241 | void FileTransfer::slotExec() { |
242 | qWarning("exited!"); | 242 | qWarning("exited!"); |
243 | char buf[2]; | 243 | char buf[2]; |
244 | ::read(m_term[0], buf, 1 ); | 244 | ::read(m_term[0], buf, 1 ); |
245 | delete m_proc; | 245 | delete m_proc; |
246 | delete m_not; | 246 | delete m_not; |
247 | m_proc = m_not = 0l; | 247 | m_proc = m_not = 0l; |
248 | close( m_term[0] ); | 248 | close( m_term[0] ); |
249 | close( m_term[1] ); | 249 | close( m_term[1] ); |
250 | close( m_comm[0] ); | 250 | close( m_comm[0] ); |
251 | close( m_comm[1] ); | 251 | close( m_comm[1] ); |
252 | emit sent(); | 252 | emit sent(); |
253 | } | 253 | } |
diff --git a/noncore/apps/opie-console/mainwindow.cpp b/noncore/apps/opie-console/mainwindow.cpp index 3af0cba..8f5d56b 100644 --- a/noncore/apps/opie-console/mainwindow.cpp +++ b/noncore/apps/opie-console/mainwindow.cpp | |||
@@ -200,76 +200,76 @@ void MainWindow::slotDisconnect() { | |||
200 | } | 200 | } |
201 | 201 | ||
202 | void MainWindow::slotTerminate() { | 202 | void MainWindow::slotTerminate() { |
203 | if ( currentSession() ) | 203 | if ( currentSession() ) |
204 | currentSession()->layer()->close(); | 204 | currentSession()->layer()->close(); |
205 | 205 | ||
206 | slotClose(); | 206 | slotClose(); |
207 | /* FIXME move to the next session */ | 207 | /* FIXME move to the next session */ |
208 | } | 208 | } |
209 | 209 | ||
210 | void MainWindow::slotConfigure() { | 210 | void MainWindow::slotConfigure() { |
211 | qWarning("configure"); | 211 | qWarning("configure"); |
212 | ConfigDialog conf( manager()->all(), factory() ); | 212 | ConfigDialog conf( manager()->all(), factory() ); |
213 | conf.showMaximized(); | 213 | conf.showMaximized(); |
214 | 214 | ||
215 | int ret = conf.exec(); | 215 | int ret = conf.exec(); |
216 | 216 | ||
217 | if ( QDialog::Accepted == ret ) { | 217 | if ( QDialog::Accepted == ret ) { |
218 | qWarning("conf %d", conf.list().count() ); | 218 | qWarning("conf %d", conf.list().count() ); |
219 | manager()->setProfiles( conf.list() ); | 219 | manager()->setProfiles( conf.list() ); |
220 | populateProfiles(); | 220 | populateProfiles(); |
221 | } | 221 | } |
222 | } | 222 | } |
223 | /* | 223 | /* |
224 | * we will remove | 224 | * we will remove |
225 | * this window from the tabwidget | 225 | * this window from the tabwidget |
226 | * remove it from the list | 226 | * remove it from the list |
227 | * delete it | 227 | * delete it |
228 | * and set the currentSession() | 228 | * and set the currentSession() |
229 | */ | 229 | */ |
230 | void MainWindow::slotClose() { | 230 | void MainWindow::slotClose() { |
231 | qWarning("close"); | 231 | qWarning("close"); |
232 | if (!currentSession() ) | 232 | if (!currentSession() ) |
233 | return; | 233 | return; |
234 | 234 | ||
235 | tabWidget()->remove( currentSession() ); | 235 | tabWidget()->remove( currentSession() ); |
236 | /*it's autodelete */ | 236 | /*it's autodelete */ |
237 | m_sessions.remove( m_curSession ); | 237 | m_sessions.remove( m_curSession ); |
238 | m_curSession = m_sessions.first(); | 238 | m_curSession = m_sessions.first(); |
239 | tabWidget()->setCurrent( m_curSession ); | 239 | tabWidget()->setCurrent( m_curSession ); |
240 | } | 240 | } |
241 | 241 | ||
242 | /* | 242 | /* |
243 | * We will get the name | 243 | * We will get the name |
244 | * Then the profile | 244 | * Then the profile |
245 | * and then we will make a profile | 245 | * and then we will make a profile |
246 | */ | 246 | */ |
247 | void MainWindow::slotProfile( int id) { | 247 | void MainWindow::slotProfile( int id) { |
248 | Profile prof = manager()->profile( m_sessionsPop->text( id) ); | 248 | Profile prof = manager()->profile( m_sessionsPop->text( id) ); |
249 | create( prof ); | 249 | create( prof ); |
250 | } | 250 | } |
251 | void MainWindow::create( const Profile& prof ) { | 251 | void MainWindow::create( const Profile& prof ) { |
252 | Session *ses = manager()->fromProfile( prof, tabWidget() ); | 252 | Session *ses = manager()->fromProfile( prof, tabWidget() ); |
253 | 253 | ||
254 | m_sessions.append( ses ); | 254 | m_sessions.append( ses ); |
255 | tabWidget()->add( ses ); | 255 | tabWidget()->add( ses ); |
256 | m_curSession = ses; | 256 | m_curSession = ses; |
257 | 257 | ||
258 | } | 258 | } |
259 | 259 | ||
260 | void MainWindow::slotTransfer() | 260 | void MainWindow::slotTransfer() |
261 | { | 261 | { |
262 | if ( currentSession() ) { | 262 | if ( currentSession() ) { |
263 | TransferDialog dlg(this); | 263 | TransferDialog dlg(this); |
264 | dlg.showMaximized(); | 264 | //dlg.showMaximized(); |
265 | dlg.exec(); | 265 | dlg.exec(); |
266 | } | 266 | } |
267 | } | 267 | } |
268 | 268 | ||
269 | 269 | ||
270 | void MainWindow::slotOpenKeb(bool state) { | 270 | void MainWindow::slotOpenKeb(bool state) { |
271 | 271 | ||
272 | if (state) m_keyBar->show(); | 272 | if (state) m_keyBar->show(); |
273 | else m_keyBar->hide(); | 273 | else m_keyBar->hide(); |
274 | 274 | ||
275 | } | 275 | } |
diff --git a/noncore/apps/opie-console/transferdialog.cpp b/noncore/apps/opie-console/transferdialog.cpp index ba06199..d3b9c0a 100644 --- a/noncore/apps/opie-console/transferdialog.cpp +++ b/noncore/apps/opie-console/transferdialog.cpp | |||
@@ -1,187 +1,218 @@ | |||
1 | #include <qlayout.h> | 1 | #include <qlayout.h> |
2 | #include <qcombobox.h> | 2 | #include <qcombobox.h> |
3 | #include <qlabel.h> | 3 | #include <qlabel.h> |
4 | #include <qlineedit.h> | 4 | #include <qlineedit.h> |
5 | #include <qpushbutton.h> | 5 | #include <qpushbutton.h> |
6 | #include <qmessagebox.h> | 6 | #include <qmessagebox.h> |
7 | #include <qprogressbar.h> | 7 | #include <qprogressbar.h> |
8 | #include <qradiobutton.h> | ||
9 | #include <qbuttongroup.h> | ||
8 | 10 | ||
9 | #include <opie/ofiledialog.h> | 11 | #include <opie/ofiledialog.h> |
10 | 12 | ||
11 | #include "filetransfer.h" | 13 | #include "filetransfer.h" |
12 | #include "io_serial.h" | 14 | #include "io_serial.h" |
13 | #include "metafactory.h" | 15 | #include "metafactory.h" |
14 | #include "mainwindow.h" | 16 | #include "mainwindow.h" |
15 | 17 | ||
16 | #include "transferdialog.h" | 18 | #include "transferdialog.h" |
17 | 19 | ||
18 | |||
19 | |||
20 | |||
21 | |||
22 | |||
23 | |||
24 | TransferDialog::TransferDialog(MainWindow *parent, const char *name) | 20 | TransferDialog::TransferDialog(MainWindow *parent, const char *name) |
25 | : QDialog(/*parent, name*/0l, 0l, true), m_win(parent) | 21 | : QDialog(0l, 0l, true), m_win(parent) |
26 | { | 22 | { |
27 | m_lay = 0l; | 23 | m_lay = 0l; |
28 | QVBoxLayout *vbox; | 24 | QVBoxLayout *vbox, *vbox2; |
29 | QHBoxLayout *hbox, *hbox2; | 25 | QHBoxLayout *hbox, *hbox2, *hbox3; |
30 | QLabel *file, *mode, *progress, *status; | 26 | QLabel *file, *mode, *progress, *status; |
31 | QPushButton *selector; | 27 | QButtonGroup *group; |
32 | 28 | QRadioButton *mode_send, *mode_receive; | |
29 | |||
30 | group = new QButtonGroup(QObject::tr("Transfer mode"), this); | ||
31 | mode_send = new QRadioButton(QObject::tr("Send"), group); | ||
32 | mode_receive = new QRadioButton(QObject::tr("Receive"), group); | ||
33 | group->insert(mode_send, id_send); | ||
34 | group->insert(mode_receive, id_receive); | ||
35 | vbox2 = new QVBoxLayout(group, 2); | ||
36 | vbox2->addSpacing(10); | ||
37 | hbox3 = new QHBoxLayout(vbox2, 2); | ||
38 | hbox3->add(mode_send); | ||
39 | hbox3->add(mode_receive); | ||
40 | mode_send->setChecked(true); | ||
41 | m_transfermode = id_send; | ||
33 | 42 | ||
34 | file = new QLabel(QObject::tr("Send file"), this); | 43 | file = new QLabel(QObject::tr("Send file"), this); |
35 | mode = new QLabel(QObject::tr("Transfer mode"), this); | 44 | mode = new QLabel(QObject::tr("Transfer protocol"), this); |
36 | progress = new QLabel(QObject::tr("Progress"), this); | 45 | progress = new QLabel(QObject::tr("Progress"), this); |
37 | status = new QLabel(QObject::tr("Status"), this); | 46 | status = new QLabel(QObject::tr("Status"), this); |
38 | 47 | ||
39 | statusbar = new QLabel(QObject::tr("ready"), this); | 48 | statusbar = new QLabel(QObject::tr("Ready"), this); |
40 | statusbar->setFrameStyle(QFrame::Panel | QFrame::Sunken); | 49 | statusbar->setFrameStyle(QFrame::Panel | QFrame::Sunken); |
41 | 50 | ||
42 | protocol = new QComboBox(this); | 51 | protocol = new QComboBox(this); |
43 | /* use the fscking MetaFactory | 52 | QStringList list = m_win->factory()->fileTransferLayers(); |
44 | * because we invented it for that fscking reason | 53 | for (QStringList::Iterator it = list.begin(); it != list.end(); ++it) |
45 | * I'm really getting UPSET!!!! | 54 | protocol->insertItem((*it)); |
46 | */ | ||
47 | QStringList list = m_win->factory()->fileTransferLayers(); | ||
48 | for (QStringList::Iterator it =list.begin(); it != list.end(); ++it ) { | ||
49 | protocol->insertItem( (*it) ); | ||
50 | } | ||
51 | 55 | ||
52 | filename = new QLineEdit(this); | 56 | filename = new QLineEdit(this); |
53 | 57 | ||
54 | progressbar = new QProgressBar(this); | 58 | progressbar = new QProgressBar(this); |
55 | progressbar->setProgress(0); | 59 | progressbar->setProgress(0); |
56 | 60 | ||
57 | selector = new QPushButton("...", this); | 61 | selector = new QPushButton("...", this); |
58 | ok = new QPushButton(QObject::tr("Start transfer"), this); | 62 | ok = new QPushButton(QObject::tr("Start transfer"), this); |
59 | cancel = new QPushButton(QObject::tr("Cancel"), this); | 63 | cancel = new QPushButton(QObject::tr("Cancel"), this); |
60 | 64 | ||
61 | vbox = new QVBoxLayout(this, 2); | 65 | vbox = new QVBoxLayout(this, 2); |
66 | vbox->add(group); | ||
62 | vbox->add(file); | 67 | vbox->add(file); |
63 | hbox = new QHBoxLayout(vbox, 0); | 68 | hbox = new QHBoxLayout(vbox, 0); |
64 | hbox->add(filename); | 69 | hbox->add(filename); |
65 | hbox->add(selector); | 70 | hbox->add(selector); |
66 | vbox->add(mode); | 71 | vbox->add(mode); |
67 | vbox->add(protocol); | 72 | vbox->add(protocol); |
68 | vbox->add(progress); | 73 | vbox->add(progress); |
69 | vbox->add(progressbar); | 74 | vbox->add(progressbar); |
70 | vbox->add(status); | 75 | vbox->add(status); |
71 | vbox->add(statusbar); | 76 | vbox->add(statusbar); |
72 | vbox->addStretch(1); | 77 | vbox->addStretch(1); |
73 | hbox2 = new QHBoxLayout(vbox, 2); | 78 | hbox2 = new QHBoxLayout(vbox, 2); |
74 | hbox2->add(ok); | 79 | hbox2->add(ok); |
75 | hbox2->add(cancel); | 80 | hbox2->add(cancel); |
76 | 81 | ||
77 | setCaption(QObject::tr("File transfer")); | 82 | setCaption(QObject::tr("File transfer")); |
78 | show(); | 83 | show(); |
79 | 84 | ||
80 | connect(selector, SIGNAL(clicked()), SLOT(slotFilename())); | 85 | connect(selector, SIGNAL(clicked()), SLOT(slotFilename())); |
81 | connect(ok, SIGNAL(clicked()), SLOT(slotTransfer())); | 86 | connect(ok, SIGNAL(clicked()), SLOT(slotTransfer())); |
82 | connect(cancel, SIGNAL(clicked()), SLOT(slotCancel())); | 87 | connect(cancel, SIGNAL(clicked()), SLOT(slotCancel())); |
88 | connect(group, SIGNAL(clicked(int)), SLOT(slotMode(int))); | ||
83 | } | 89 | } |
84 | 90 | ||
85 | TransferDialog::~TransferDialog() | 91 | TransferDialog::~TransferDialog() |
86 | { | 92 | { |
87 | } | 93 | } |
88 | 94 | ||
89 | void TransferDialog::slotFilename() | 95 | void TransferDialog::slotFilename() |
90 | { | 96 | { |
91 | QString f; | 97 | QString f; |
92 | 98 | ||
93 | f = OFileDialog::getOpenFileName(0); | 99 | f = OFileDialog::getOpenFileName(0); |
94 | if(!f.isNull()) filename->setText(f); | 100 | if(!f.isNull()) filename->setText(f); |
95 | } | 101 | } |
96 | 102 | ||
97 | void TransferDialog::slotTransfer() | 103 | void TransferDialog::slotTransfer() |
98 | { | 104 | { |
99 | if(filename->text().isEmpty()) | 105 | if((m_transfermode == id_send) && (filename->text().isEmpty())) |
100 | { | 106 | { |
101 | QMessageBox::information(this, | 107 | QMessageBox::information(this, |
102 | QObject::tr("Attention"), | 108 | QObject::tr("Attention"), |
103 | QObject::tr("No file has been specified.")); | 109 | QObject::tr("No file has been specified.")); |
104 | return; | 110 | return; |
105 | } | 111 | } |
106 | 112 | ||
107 | ok->setEnabled(false); | 113 | ok->setEnabled(false); |
108 | 114 | ||
109 | statusbar->setText(QObject::tr("Sending...")); | 115 | if(m_transfermode == id_send) statusbar->setText(QObject::tr("Sending...")); |
116 | else statusbar->setText(QObject::tr("Receiving...")); | ||
110 | 117 | ||
111 | m_lay = m_win->factory()->newFileTransfer( protocol->currentText(), | 118 | m_lay = m_win->factory()->newFileTransfer(protocol->currentText(), m_win->currentSession()->layer()); |
112 | m_win->currentSession()->layer() ); | 119 | if(m_transfermode == id_send) |
113 | m_lay->sendFile(filename->text()); | 120 | { |
121 | m_lay->sendFile(filename->text()); | ||
122 | } | ||
123 | else | ||
124 | { | ||
125 | } | ||
114 | 126 | ||
115 | connect(m_lay, SIGNAL(progress(const QString&, int, int, int, int, int)), SLOT(slotProgress(const QString&, int, int, int, int, int))); | 127 | connect(m_lay, SIGNAL(progress(const QString&, int, int, int, int, int)), SLOT(slotProgress(const QString&, int, int, int, int, int))); |
116 | connect(m_lay, SIGNAL(error(int, const QString&)), SLOT(slotError(int, const QString&))); | 128 | connect(m_lay, SIGNAL(error(int, const QString&)), SLOT(slotError(int, const QString&))); |
117 | connect(m_lay, SIGNAL(sent()), SLOT(slotSent())); | 129 | connect(m_lay, SIGNAL(sent()), SLOT(slotSent())); |
118 | } | 130 | } |
119 | 131 | ||
120 | void TransferDialog::slotCancel() | 132 | void TransferDialog::slotCancel() |
121 | { | 133 | { |
122 | ok->setEnabled(true); | 134 | ok->setEnabled(true); |
135 | statusbar->setText(QObject::tr("Ready")); | ||
123 | 136 | ||
124 | if(m_lay) | 137 | if(m_lay) |
125 | { | 138 | { |
126 | m_lay->cancel(); | 139 | m_lay->cancel(); |
127 | delete m_lay; | 140 | delete m_lay; |
128 | m_lay = 0l; | 141 | m_lay = 0l; |
129 | QMessageBox::information(this, | 142 | QMessageBox::information(this, |
130 | QObject::tr("Cancelled"), | 143 | QObject::tr("Cancelled"), |
131 | QObject::tr("The file transfer has been cancelled.")); | 144 | QObject::tr("The file transfer has been cancelled.")); |
132 | } | 145 | } |
133 | else | 146 | else |
134 | { | 147 | { |
135 | close(); | 148 | close(); |
136 | } | 149 | } |
137 | } | 150 | } |
138 | 151 | ||
139 | void TransferDialog::slotProgress(const QString& file, int progress, int speed, int hours, int minutes, int seconds) | 152 | void TransferDialog::slotProgress(const QString& file, int progress, int speed, int hours, int minutes, int seconds) |
140 | { | 153 | { |
141 | progressbar->setProgress(progress); | 154 | progressbar->setProgress(progress); |
142 | } | 155 | } |
143 | 156 | ||
144 | void TransferDialog::slotError(int error, const QString& message) | 157 | void TransferDialog::slotError(int error, const QString& message) |
145 | { | 158 | { |
159 | statusbar->setText(QObject::tr("Ready")); | ||
160 | |||
146 | switch(error) | 161 | switch(error) |
147 | { | 162 | { |
148 | case FileTransferLayer::NotSupported: | 163 | case FileTransferLayer::NotSupported: |
149 | QMessageBox::critical(this, | 164 | QMessageBox::critical(this, |
150 | QObject::tr("Error"), | 165 | QObject::tr("Error"), |
151 | QObject::tr("Operation not supported.")); | 166 | QObject::tr("Operation not supported.")); |
152 | break; | 167 | break; |
153 | case FileTransferLayer::StartError: | 168 | case FileTransferLayer::StartError: |
154 | QMessageBox::critical(this, | 169 | QMessageBox::critical(this, |
155 | QObject::tr("Error"), | 170 | QObject::tr("Error"), |
156 | QObject::tr("Operation not supported.")); | 171 | QObject::tr("Transfer could not be started.")); |
157 | break; | 172 | break; |
158 | case FileTransferLayer::NoError: | 173 | case FileTransferLayer::NoError: |
159 | QMessageBox::critical(this, | 174 | QMessageBox::critical(this, |
160 | QObject::tr("Error"), | 175 | QObject::tr("Error"), |
161 | QObject::tr("Operation not supported.")); | 176 | QObject::tr("No error.")); |
162 | break; | 177 | break; |
163 | case FileTransferLayer::Undefined: | 178 | case FileTransferLayer::Undefined: |
164 | QMessageBox::critical(this, | 179 | QMessageBox::critical(this, |
165 | QObject::tr("Error"), | 180 | QObject::tr("Error"), |
166 | QObject::tr("Operation not supported.")); | 181 | QObject::tr("Undefined error occured.")); |
167 | break; | 182 | break; |
168 | case FileTransferLayer::Incomplete: | 183 | case FileTransferLayer::Incomplete: |
169 | QMessageBox::critical(this, | 184 | QMessageBox::critical(this, |
170 | QObject::tr("Error"), | 185 | QObject::tr("Error"), |
171 | QObject::tr("Operation not supported.")); | 186 | QObject::tr("Incomplete transfer.")); |
172 | break; | 187 | break; |
173 | case FileTransferLayer::Unknown: | 188 | case FileTransferLayer::Unknown: |
174 | default: | 189 | default: |
175 | QMessageBox::critical(this, | 190 | QMessageBox::critical(this, |
176 | QObject::tr("Error"), | 191 | QObject::tr("Error"), |
177 | QObject::tr("Operation not supported.")); | 192 | QObject::tr("Unknown error occured.")); |
178 | break; | 193 | break; |
179 | } | 194 | } |
180 | } | 195 | } |
181 | 196 | ||
182 | void TransferDialog::slotSent() | 197 | void TransferDialog::slotSent() |
183 | { | 198 | { |
184 | QMessageBox::information(this, QObject::tr("Sent"), QObject::tr("File has been sent.")); | 199 | QMessageBox::information(this, QObject::tr("Sent"), QObject::tr("File has been sent.")); |
185 | ok->setEnabled(true); | 200 | ok->setEnabled(true); |
201 | statusbar->setText(QObject::tr("Ready")); | ||
202 | } | ||
203 | |||
204 | void TransferDialog::slotMode(int id) | ||
205 | { | ||
206 | if(id == id_send) | ||
207 | { | ||
208 | selector->setEnabled(true); | ||
209 | filename->setEnabled(true); | ||
210 | } | ||
211 | else | ||
212 | { | ||
213 | selector->setEnabled(false); | ||
214 | filename->setEnabled(false); | ||
215 | } | ||
216 | m_transfermode = id; | ||
186 | } | 217 | } |
187 | 218 | ||
diff --git a/noncore/apps/opie-console/transferdialog.h b/noncore/apps/opie-console/transferdialog.h index b0c1a76..a567161 100644 --- a/noncore/apps/opie-console/transferdialog.h +++ b/noncore/apps/opie-console/transferdialog.h | |||
@@ -1,40 +1,48 @@ | |||
1 | #ifndef TRANSFER_DIALOG_H | 1 | #ifndef TRANSFER_DIALOG_H |
2 | #define TRANSFER_DIALOG_H | 2 | #define TRANSFER_DIALOG_H |
3 | 3 | ||
4 | #include "qdialog.h" | 4 | #include "qdialog.h" |
5 | 5 | ||
6 | class QLineEdit; | 6 | class QLineEdit; |
7 | class QComboBox; | 7 | class QComboBox; |
8 | class QProgressBar; | 8 | class QProgressBar; |
9 | class QLabel; | 9 | class QLabel; |
10 | class QPushButton; | 10 | class QPushButton; |
11 | class MainWindow; | 11 | class MainWindow; |
12 | class FileTransferLayer; | 12 | class FileTransferLayer; |
13 | 13 | ||
14 | class TransferDialog : public QDialog | 14 | class TransferDialog : public QDialog |
15 | { | 15 | { |
16 | Q_OBJECT | 16 | Q_OBJECT |
17 | public: | 17 | public: |
18 | TransferDialog(MainWindow *parent = 0l, const char *name = 0l); | 18 | TransferDialog(MainWindow *parent = 0l, const char *name = 0l); |
19 | ~TransferDialog(); | 19 | ~TransferDialog(); |
20 | 20 | ||
21 | public slots: | 21 | public slots: |
22 | void slotFilename(); | 22 | void slotFilename(); |
23 | void slotTransfer(); | 23 | void slotTransfer(); |
24 | void slotCancel(); | 24 | void slotCancel(); |
25 | void slotProgress(const QString&, int, int, int, int, int); | 25 | void slotProgress(const QString&, int, int, int, int, int); |
26 | void slotError(int error, const QString& message); | 26 | void slotError(int error, const QString& message); |
27 | void slotSent(); | 27 | void slotSent(); |
28 | void slotMode(int id); | ||
28 | 29 | ||
29 | private: | 30 | private: |
31 | enum Modes | ||
32 | { | ||
33 | id_send, | ||
34 | id_receive | ||
35 | }; | ||
36 | |||
30 | QLineEdit *filename; | 37 | QLineEdit *filename; |
31 | QComboBox *protocol; | 38 | QComboBox *protocol; |
32 | QProgressBar *progressbar; | 39 | QProgressBar *progressbar; |
33 | QLabel *statusbar; | 40 | QLabel *statusbar; |
34 | QPushButton *ok, *cancel; | 41 | QPushButton *ok, *cancel, *selector; |
35 | MainWindow* m_win; | 42 | MainWindow* m_win; |
36 | FileTransferLayer* m_lay; | 43 | FileTransferLayer* m_lay; |
44 | int m_transfermode; | ||
37 | }; | 45 | }; |
38 | 46 | ||
39 | #endif | 47 | #endif |
40 | 48 | ||