-rw-r--r-- | noncore/apps/opie-console/transferdialog.cpp | 53 | ||||
-rw-r--r-- | noncore/apps/opie-console/transferdialog.h | 3 |
2 files changed, 55 insertions, 1 deletions
diff --git a/noncore/apps/opie-console/transferdialog.cpp b/noncore/apps/opie-console/transferdialog.cpp index 45522a8..d639de6 100644 --- a/noncore/apps/opie-console/transferdialog.cpp +++ b/noncore/apps/opie-console/transferdialog.cpp | |||
@@ -1,128 +1,179 @@ | |||
1 | #include "transferdialog.h" | 1 | #include "transferdialog.h" |
2 | 2 | ||
3 | #include "filetransfer.h" | 3 | #include "filetransfer.h" |
4 | #include "io_serial.h" | 4 | #include "io_serial.h" |
5 | 5 | ||
6 | #include "qlayout.h" | 6 | #include "qlayout.h" |
7 | #include "qcombobox.h" | 7 | #include "qcombobox.h" |
8 | #include "qlabel.h" | 8 | #include "qlabel.h" |
9 | #include "qlineedit.h" | 9 | #include "qlineedit.h" |
10 | #include "qpushbutton.h" | 10 | #include "qpushbutton.h" |
11 | #include "qmessagebox.h" | 11 | #include "qmessagebox.h" |
12 | #include "qprogressbar.h" | 12 | #include "qprogressbar.h" |
13 | 13 | ||
14 | #include "opie/ofiledialog.h" | 14 | #include "opie/ofiledialog.h" |
15 | 15 | ||
16 | TransferDialog::TransferDialog(QWidget *parent, const char *name) | 16 | TransferDialog::TransferDialog(QWidget *parent, const char *name) |
17 | : QDialog(/*parent, name*/NULL, NULL, true) | 17 | : QDialog(/*parent, name*/NULL, NULL, true) |
18 | { | 18 | { |
19 | QVBoxLayout *vbox; | 19 | QVBoxLayout *vbox; |
20 | QHBoxLayout *hbox, *hbox2; | 20 | QHBoxLayout *hbox, *hbox2; |
21 | QLabel *file, *mode, *progress, *status; | 21 | QLabel *file, *mode, *progress, *status; |
22 | QPushButton *selector; | 22 | QPushButton *selector; |
23 | 23 | ||
24 | transfer = NULL; | 24 | transfer = NULL; |
25 | 25 | ||
26 | file = new QLabel(QObject::tr("Send file"), this); | 26 | file = new QLabel(QObject::tr("Send file"), this); |
27 | mode = new QLabel(QObject::tr("Transfer mode"), this); | 27 | mode = new QLabel(QObject::tr("Transfer mode"), this); |
28 | progress = new QLabel(QObject::tr("Progress"), this); | 28 | progress = new QLabel(QObject::tr("Progress"), this); |
29 | status = new QLabel(QObject::tr("Status"), this); | 29 | status = new QLabel(QObject::tr("Status"), this); |
30 | 30 | ||
31 | statusbar = new QLabel(QObject::tr("ready"), this); | 31 | statusbar = new QLabel(QObject::tr("ready"), this); |
32 | statusbar->setFrameStyle(QFrame::Panel | QFrame::Sunken); | 32 | statusbar->setFrameStyle(QFrame::Panel | QFrame::Sunken); |
33 | 33 | ||
34 | protocol = new QComboBox(this); | 34 | protocol = new QComboBox(this); |
35 | protocol->insertItem("XModem"); | 35 | protocol->insertItem("XModem"); |
36 | protocol->insertItem("YModem"); | 36 | protocol->insertItem("YModem"); |
37 | protocol->insertItem("ZModem"); | 37 | protocol->insertItem("ZModem"); |
38 | 38 | ||
39 | filename = new QLineEdit(this); | 39 | filename = new QLineEdit(this); |
40 | 40 | ||
41 | progressbar = new QProgressBar(this); | 41 | progressbar = new QProgressBar(this); |
42 | progressbar->setProgress(0); | 42 | progressbar->setProgress(0); |
43 | 43 | ||
44 | selector = new QPushButton("...", this); | 44 | selector = new QPushButton("...", this); |
45 | ok = new QPushButton(QObject::tr("Start transfer"), this); | 45 | ok = new QPushButton(QObject::tr("Start transfer"), this); |
46 | cancel = new QPushButton(QObject::tr("Cancel"), this); | 46 | cancel = new QPushButton(QObject::tr("Cancel"), this); |
47 | 47 | ||
48 | vbox = new QVBoxLayout(this, 2); | 48 | vbox = new QVBoxLayout(this, 2); |
49 | vbox->add(file); | 49 | vbox->add(file); |
50 | hbox = new QHBoxLayout(vbox, 0); | 50 | hbox = new QHBoxLayout(vbox, 0); |
51 | hbox->add(filename); | 51 | hbox->add(filename); |
52 | hbox->add(selector); | 52 | hbox->add(selector); |
53 | vbox->add(mode); | 53 | vbox->add(mode); |
54 | vbox->add(protocol); | 54 | vbox->add(protocol); |
55 | vbox->add(progress); | 55 | vbox->add(progress); |
56 | vbox->add(progressbar); | 56 | vbox->add(progressbar); |
57 | vbox->add(status); | 57 | vbox->add(status); |
58 | vbox->add(statusbar); | 58 | vbox->add(statusbar); |
59 | vbox->addStretch(1); | 59 | vbox->addStretch(1); |
60 | hbox2 = new QHBoxLayout(vbox, 2); | 60 | hbox2 = new QHBoxLayout(vbox, 2); |
61 | hbox2->add(ok); | 61 | hbox2->add(ok); |
62 | hbox2->add(cancel); | 62 | hbox2->add(cancel); |
63 | 63 | ||
64 | setCaption(QObject::tr("File transfer")); | 64 | setCaption(QObject::tr("File transfer")); |
65 | show(); | 65 | show(); |
66 | 66 | ||
67 | connect(selector, SIGNAL(clicked()), SLOT(slotFilename())); | 67 | connect(selector, SIGNAL(clicked()), SLOT(slotFilename())); |
68 | connect(ok, SIGNAL(clicked()), SLOT(slotTransfer())); | 68 | connect(ok, SIGNAL(clicked()), SLOT(slotTransfer())); |
69 | connect(cancel, SIGNAL(clicked()), SLOT(slotCancel())); | 69 | connect(cancel, SIGNAL(clicked()), SLOT(slotCancel())); |
70 | } | 70 | } |
71 | 71 | ||
72 | TransferDialog::~TransferDialog() | 72 | TransferDialog::~TransferDialog() |
73 | { | 73 | { |
74 | } | 74 | } |
75 | 75 | ||
76 | void TransferDialog::slotFilename() | 76 | void TransferDialog::slotFilename() |
77 | { | 77 | { |
78 | QString f; | 78 | QString f; |
79 | 79 | ||
80 | f = OFileDialog::getOpenFileName(0); | 80 | f = OFileDialog::getOpenFileName(0); |
81 | if(!f.isNull()) filename->setText(f); | 81 | if(!f.isNull()) filename->setText(f); |
82 | } | 82 | } |
83 | 83 | ||
84 | void TransferDialog::slotTransfer() | 84 | void TransferDialog::slotTransfer() |
85 | { | 85 | { |
86 | if(filename->text().isEmpty()) | 86 | if(filename->text().isEmpty()) |
87 | { | 87 | { |
88 | QMessageBox::information(this, | 88 | QMessageBox::information(this, |
89 | QObject::tr("Attention"), | 89 | QObject::tr("Attention"), |
90 | QObject::tr("No file has been specified.")); | 90 | QObject::tr("No file has been specified.")); |
91 | return; | 91 | return; |
92 | } | 92 | } |
93 | 93 | ||
94 | ok->setEnabled(false); | 94 | ok->setEnabled(false); |
95 | 95 | ||
96 | statusbar->setText(QObject::tr("Sending...")); | 96 | statusbar->setText(QObject::tr("Sending...")); |
97 | progressbar->setProgress(1); | ||
98 | 97 | ||
99 | FileTransfer::Type transfermode = FileTransfer::SX; | 98 | FileTransfer::Type transfermode = FileTransfer::SX; |
100 | if(protocol->currentText() == "YModem") transfermode == FileTransfer::SY; | 99 | if(protocol->currentText() == "YModem") transfermode == FileTransfer::SY; |
101 | if(protocol->currentText() == "ZModem") transfermode == FileTransfer::SZ; | 100 | if(protocol->currentText() == "ZModem") transfermode == FileTransfer::SZ; |
102 | 101 | ||
103 | // dummy profile | 102 | // dummy profile |
104 | Profile profile("Dummy", "serial", "vt102", Profile::White, Profile::Black, Profile::VT102); | 103 | Profile profile("Dummy", "serial", "vt102", Profile::White, Profile::Black, Profile::VT102); |
105 | 104 | ||
106 | transfer = new FileTransfer(transfermode, new IOSerial(profile)); | 105 | transfer = new FileTransfer(transfermode, new IOSerial(profile)); |
107 | transfer->sendFile(filename->text()); | 106 | transfer->sendFile(filename->text()); |
107 | connect(transfer, SIGNAL(progress(const QString&, int, int, int, int, int)), SLOT(slotProgress(const QString&, int, int, int, int, int))); | ||
108 | connect(transfer, SIGNAL(error(int, const QString&)), SLOT(slotError(int, const QString&))); | ||
109 | connect(transfer, SIGNAL(sent()), SLOT(slotSent())); | ||
108 | } | 110 | } |
109 | 111 | ||
110 | void TransferDialog::slotCancel() | 112 | void TransferDialog::slotCancel() |
111 | { | 113 | { |
112 | ok->setEnabled(true); | 114 | ok->setEnabled(true); |
113 | 115 | ||
114 | if(transfer) | 116 | if(transfer) |
115 | { | 117 | { |
116 | transfer->cancel(); | 118 | transfer->cancel(); |
117 | delete transfer; | 119 | delete transfer; |
118 | transfer = NULL; | 120 | transfer = NULL; |
119 | QMessageBox::information(this, | 121 | QMessageBox::information(this, |
120 | QObject::tr("Cancelled"), | 122 | QObject::tr("Cancelled"), |
121 | QObject::tr("The file transfer has been cancelled.")); | 123 | QObject::tr("The file transfer has been cancelled.")); |
122 | } | 124 | } |
123 | else | 125 | else |
124 | { | 126 | { |
125 | close(); | 127 | close(); |
126 | } | 128 | } |
127 | } | 129 | } |
128 | 130 | ||
131 | void TransferDialog::slotProgress(const QString& file, int progress, int speed, int hours, int minutes, int seconds) | ||
132 | { | ||
133 | progressbar->setProgress(progress); | ||
134 | } | ||
135 | |||
136 | void TransferDialog::slotError(int error, const QString& message) | ||
137 | { | ||
138 | switch(error) | ||
139 | { | ||
140 | case FileTransferLayer::NotSupported: | ||
141 | QMessageBox::critical(this, | ||
142 | QObject::tr("Error"), | ||
143 | QObject::tr("Operation not supported.")); | ||
144 | break; | ||
145 | case FileTransferLayer::StartError: | ||
146 | QMessageBox::critical(this, | ||
147 | QObject::tr("Error"), | ||
148 | QObject::tr("Operation not supported.")); | ||
149 | break; | ||
150 | case FileTransferLayer::NoError: | ||
151 | QMessageBox::critical(this, | ||
152 | QObject::tr("Error"), | ||
153 | QObject::tr("Operation not supported.")); | ||
154 | break; | ||
155 | case FileTransferLayer::Undefined: | ||
156 | QMessageBox::critical(this, | ||
157 | QObject::tr("Error"), | ||
158 | QObject::tr("Operation not supported.")); | ||
159 | break; | ||
160 | case FileTransferLayer::Incomplete: | ||
161 | QMessageBox::critical(this, | ||
162 | QObject::tr("Error"), | ||
163 | QObject::tr("Operation not supported.")); | ||
164 | break; | ||
165 | case FileTransferLayer::Unknown: | ||
166 | default: | ||
167 | QMessageBox::critical(this, | ||
168 | QObject::tr("Error"), | ||
169 | QObject::tr("Operation not supported.")); | ||
170 | break; | ||
171 | } | ||
172 | } | ||
173 | |||
174 | void TransferDialog::slotSent() | ||
175 | { | ||
176 | QMessageBox::information(this, QObject::tr("Sent"), QObject::tr("File has been sent.")); | ||
177 | ok->setEnabled(true); | ||
178 | } | ||
179 | |||
diff --git a/noncore/apps/opie-console/transferdialog.h b/noncore/apps/opie-console/transferdialog.h index 62ae14d..61f425c 100644 --- a/noncore/apps/opie-console/transferdialog.h +++ b/noncore/apps/opie-console/transferdialog.h | |||
@@ -1,35 +1,38 @@ | |||
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 FileTransfer; | 11 | class FileTransfer; |
12 | 12 | ||
13 | class TransferDialog : public QDialog | 13 | class TransferDialog : public QDialog |
14 | { | 14 | { |
15 | Q_OBJECT | 15 | Q_OBJECT |
16 | public: | 16 | public: |
17 | TransferDialog(QWidget *parent = NULL, const char *name = NULL); | 17 | TransferDialog(QWidget *parent = NULL, const char *name = NULL); |
18 | ~TransferDialog(); | 18 | ~TransferDialog(); |
19 | 19 | ||
20 | public slots: | 20 | public slots: |
21 | void slotFilename(); | 21 | void slotFilename(); |
22 | void slotTransfer(); | 22 | void slotTransfer(); |
23 | void slotCancel(); | 23 | void slotCancel(); |
24 | void slotProgress(const QString&, int, int, int, int, int); | ||
25 | void slotError(int error, const QString& message); | ||
26 | void slotSent(); | ||
24 | 27 | ||
25 | private: | 28 | private: |
26 | QLineEdit *filename; | 29 | QLineEdit *filename; |
27 | QComboBox *protocol; | 30 | QComboBox *protocol; |
28 | QProgressBar *progressbar; | 31 | QProgressBar *progressbar; |
29 | QLabel *statusbar; | 32 | QLabel *statusbar; |
30 | QPushButton *ok, *cancel; | 33 | QPushButton *ok, *cancel; |
31 | FileTransfer *transfer; | 34 | FileTransfer *transfer; |
32 | }; | 35 | }; |
33 | 36 | ||
34 | #endif | 37 | #endif |
35 | 38 | ||