summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-console/transferdialog.cpp
Unidiff
Diffstat (limited to 'noncore/apps/opie-console/transferdialog.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-console/transferdialog.cpp99
1 files changed, 65 insertions, 34 deletions
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
@@ -2,66 +2,71 @@
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
24TransferDialog::TransferDialog(MainWindow *parent, const char *name) 20TransferDialog::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);
@@ -77,12 +82,13 @@ TransferDialog::TransferDialog(MainWindow *parent, const char *name)
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
85TransferDialog::~TransferDialog() 91TransferDialog::~TransferDialog()
86{ 92{
87} 93}
88 94
@@ -93,41 +99,48 @@ void TransferDialog::slotFilename()
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
97void TransferDialog::slotTransfer() 103void 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
120void TransferDialog::slotCancel() 132void 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
@@ -140,48 +153,66 @@ void TransferDialog::slotProgress(const QString& file, int progress, int speed,
140{ 153{
141 progressbar->setProgress(progress); 154 progressbar->setProgress(progress);
142} 155}
143 156
144void TransferDialog::slotError(int error, const QString& message) 157void 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
182void TransferDialog::slotSent() 197void 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
204void 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