summaryrefslogtreecommitdiff
path: root/core/obex/obexsend.cpp
authormickeyl <mickeyl>2005-08-22 09:36:38 (UTC)
committer mickeyl <mickeyl>2005-08-22 09:36:38 (UTC)
commit7202ac536ac98e7e433984d98cb9236330b25cc8 (patch) (unidiff)
treec8b5d4e57dd4b9b302999d1f88a89c28e4ee0e5e /core/obex/obexsend.cpp
parent140e4dc44a29678de1ae8b2cef5b1d081993223e (diff)
downloadopie-7202ac536ac98e7e433984d98cb9236330b25cc8.zip
opie-7202ac536ac98e7e433984d98cb9236330b25cc8.tar.gz
opie-7202ac536ac98e7e433984d98cb9236330b25cc8.tar.bz2
Replace the existing, apparently non-working, OBEX Send form with a
completely new implementation. The new implementation supports selective send over both IrDA and Bluetooth, to selected receivers (which are discovered as the form pops up). The form also indicates transfer status as the transfers progress. There is a new QT Designer UI form file, integrated into the build. There are also two new source files for the form to supply the abstract methods (typical of QT2). Patch courtesy Michael Haynie - thanks!
Diffstat (limited to 'core/obex/obexsend.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/obex/obexsend.cpp289
1 files changed, 0 insertions, 289 deletions
diff --git a/core/obex/obexsend.cpp b/core/obex/obexsend.cpp
deleted file mode 100644
index 675c5e4..0000000
--- a/core/obex/obexsend.cpp
+++ b/dev/null
@@ -1,289 +0,0 @@
1#include "obex.h"
2#include "obexsend.h"
3using namespace OpieObex;
4
5/* OPIE */
6#include <opie2/odebug.h>
7#include <qpe/qcopenvelope_qws.h>
8using namespace Opie::Core;
9
10/* QT */
11#include <qpushbutton.h>
12#include <qlabel.h>
13#include <qlayout.h>
14#include <qtimer.h>
15
16/* TRANSLATOR OpieObex::SendWidget */
17
18SendWidget::SendWidget( QWidget* parent, const char* name )
19 : QWidget( parent, name ) {
20 initUI();
21}
22SendWidget::~SendWidget() {
23}
24void SendWidget::initUI() {
25 m_obex = new Obex(this, "obex");
26 connect(m_obex, SIGNAL(error(int) ),
27 this, SLOT(slotIrError(int) ) );
28 connect(m_obex, SIGNAL(sent(bool) ),
29 this, SLOT(slotIrSent(bool) ) );
30 connect(m_obex, SIGNAL(currentTry(unsigned int) ),
31 this, SLOT(slotIrTry(unsigned int) ) );
32
33 QCopChannel* chan = new QCopChannel("QPE/IrDaAppletBack", this );
34 connect(chan, SIGNAL(received(const QCString&,const QByteArray&) ),
35 this, SLOT(dispatchIrda(const QCString&,const QByteArray&) ) );
36
37 chan = new QCopChannel("QPE/BluetoothBack", this );
38 connect(chan, SIGNAL(received(const QCString&,const QByteArray&) ),
39 this, SLOT(dispatchBt(const QCString&,const QByteArray&) ) );
40
41 QVBoxLayout* lay = new QVBoxLayout(this);
42
43 QHBox* nameBox = new QHBox(this);
44 QLabel* name = new QLabel(nameBox);
45 name->setText( tr("<qt><h1>Sending:</h1></qt>") );
46 name->setAlignment( AlignLeft | AlignTop );
47 m_lblFile = new QLabel(nameBox);
48 lay->addWidget(nameBox, 0);
49
50 QFrame* frame = new QFrame(this);
51 frame->setFrameShape( QFrame::HLine );
52 frame->setFrameShadow( QFrame::Sunken );
53 lay->addWidget(frame, 10);
54
55 QLabel* devices = new QLabel(this);
56 devices->setText("<qt><b>Devices:</b></qt>");
57 devices->setAlignment( AlignLeft | AlignTop );
58 lay->addWidget( devices,10 );
59
60 m_devBox = new DeviceBox(this);
61 lay->addWidget( m_devBox, 50 );
62 connect(m_devBox, SIGNAL(selectedDevice(int,int) ),
63 this, SLOT(slotSelectedDevice(int,int) ) );
64
65 QPushButton *but = new QPushButton(this);
66 but->setText(tr("Done") );
67 connect(but, SIGNAL(clicked() ),
68 this, SLOT(slotDone() ) );
69
70 lay->addWidget( but );
71 m_lay = lay;
72
73 // QT does not like if you add items to an layout which already exits....
74 // and was layouted invalidate() does not help too
75 // so we use RichText....
76}
77
78/*
79 * in send we'll first set everything up
80 * and then wait for a list of devices.
81 */
82void SendWidget::send( const QString& file, const QString& desc ) {
83 m_file = file;
84 m_irDa.clear();
85 m_start = 0;
86 m_lblFile->setText(desc.isEmpty() ? file : desc );
87
88 if ( !QCopChannel::isRegistered("QPE/IrDaApplet") ) {
89 m_irDeSearch = m_devBox->addDevice( tr("IrDa is not enabled!"), DeviceBox::Error );
90 m_start++;
91 }else
92 m_irDeSearch = m_devBox->addDevice( tr("Searching for IrDa Devices."), DeviceBox::Search );
93
94 if ( !QCopChannel::isRegistered("QPE/Bluetooth") ) {
95 m_btDeSearch = m_devBox->addDevice( tr("Bluetooth is not available"), DeviceBox::Error );
96 m_start++;
97 }else
98 m_btDeSearch = m_devBox->addDevice( tr("Searching for bluetooth Devices."), DeviceBox::Search );
99
100 if (m_start != 2 ) {
101 QCopEnvelope e0("QPE/IrDaApplet", "enableIrda()");
102 QCopEnvelope e1("QPE/Bluetooth", "enableBluetooth()");
103 QCopEnvelope e2("QPE/IrDaApplet", "listDevices()");
104 QCopEnvelope e3("QPE/Bluetooth", "listDevices()");
105 }
106}
107void SendWidget::slotIrDaDevices( const QStringList& list) {
108 for (QStringList::ConstIterator it = list.begin(); it != list.end(); ++it ) {
109 int id = m_devBox->addDevice( (*it), DeviceBox::IrDa, tr("Scheduling for beam.") );
110 m_irDa.insert( id, (*it) );
111 }
112 m_devBox->removeDevice( m_irDeSearch );
113 m_irDaIt = m_irDa.begin();
114
115 slotStartIrda();
116}
117
118void SendWidget::slotBTDevices( const QMap<QString, QString>& str ) {
119 for(QMap<QString, QString>::ConstIterator it = str.begin(); it != str.end(); ++it ) {
120 int id = m_devBox->addDevice( it.key(), DeviceBox::BT, tr("Click to beam") );
121 m_bt.insert( id, Pair( it.key(), it.data() ) );
122 }
123 m_devBox->removeDevice( m_btDeSearch );
124}
125void SendWidget::slotSelectedDevice( int name, int ) {
126 if ( name == m_irDeSearch ) {
127 for (QMap<int, QString>::Iterator it= m_irDa.begin(); it != m_irDa.end(); ++it )
128 m_devBox->removeDevice( it.key() );
129
130 QCopEnvelope e2("QPE/IrDaApplet", "listDevices()");
131 }
132}
133void SendWidget::dispatchIrda( const QCString& str, const QByteArray& ar ) {
134 if ( str == "devices(QStringList)" ) {
135 QDataStream stream( ar, IO_ReadOnly );
136 QStringList list;
137 stream >> list;
138 slotIrDaDevices( list );
139 }
140}
141void SendWidget::dispatchBt( const QCString&, const QByteArray& ) {
142
143}
144void SendWidget::slotIrError( int ) {
145
146}
147void SendWidget::slotIrSent( bool b) {
148 QString text = b ? tr("Sent") : tr("Failure");
149 m_devBox->setStatus( m_irDaIt.key(), text );
150 ++m_irDaIt;
151 slotStartIrda();
152}
153void SendWidget::slotIrTry(unsigned int trI) {
154 m_devBox->setStatus( m_irDaIt.key(), tr("Try %1").arg( QString::number( trI ) ) );
155}
156void SendWidget::slotStartIrda() {
157 if (m_irDaIt == m_irDa.end() ) {
158 m_irDeSearch = m_devBox->addDevice(tr("Search again for IrDa."), DeviceBox::Search );
159 return;
160 }
161 m_devBox->setStatus( m_irDaIt.key(), tr("Start sending") );
162 m_obex->send( m_file );
163}
164void SendWidget::closeEvent( QCloseEvent* e) {
165 e->accept(); // make sure
166 QTimer::singleShot(0, this, SLOT(slotDone() ) );
167}
168void SendWidget::slotDone() {
169 QCopEnvelope e0("QPE/IrDaApplet", "disableIrda()");
170 QCopEnvelope e1("QPE/Bluetooth", "disableBluetooth()");
171 emit done();
172}
173QString SendWidget::file()const {
174 return m_file;
175}
176DeviceBox::DeviceBox( QWidget* parent )
177 : QTextBrowser( parent ) {
178
179}
180DeviceBox::~DeviceBox() {
181
182}
183int DeviceBox::addDevice( const QString& name, int dev, const QString& status ) {
184 /* return a id for a range of devices */
185 int id = idFor ( dev );
186 DeviceItem item( name, status, dev,id );
187 m_dev.insert( id, item );
188 setText( allText() );
189
190 return id;
191}
192void DeviceBox::removeDevice( int id ) {
193 if (!m_dev.contains(id) ) return;
194
195 m_dev.remove( id );
196 setText( allText() );
197}
198void DeviceBox::setStatus( int id, const QString& status ) {
199 if ( !m_dev.contains(id) ) return;
200 m_dev[id].setStatus(status );
201 setText( allText() );
202}
203void DeviceBox::setSource( const QString& str ) {
204 int id = str.toInt();
205 emit selectedDevice( id, m_dev[id].device() );
206}
207int DeviceBox::idFor ( int id ) {
208 static int irId = 1501;
209 static int irBT = 1001;
210 static int irSr = 501;
211 static int irEr = 0;
212
213 int ret = -1;
214 switch(id ) {
215 case IrDa:
216 ret = irId;
217 irId++;
218 break;
219 case BT:
220 ret = irBT;
221 irBT++;
222 break;
223 case Search:
224 ret = irSr;
225 irSr++;
226 break;
227 case Error:
228 ret = irEr;
229 irEr++;
230 break;
231 }
232 return ret;
233}
234QString DeviceBox::allText() {
235 QString str;
236 typedef QMap<int, DeviceItem> DeviceMap;
237
238 for (QMap<int, DeviceItem>::Iterator it = m_dev.begin(); it != m_dev.end(); ++it ) {
239 str += it.data().toString() + "<br>";
240 }
241 return str;
242}
243
244DeviceItem::DeviceItem( const QString& name,
245 const QString& status, int dev, int id)
246{
247 m_name = name;
248 m_status = status;
249 m_dev = dev;
250 m_id = id;
251}
252int DeviceItem::id()const {
253 return m_id;
254}
255QString DeviceItem::name()const {
256 return m_name;
257}
258QString DeviceItem::status()const {
259 return m_status;
260}
261int DeviceItem::device()const {
262 return m_dev;
263}
264QString DeviceItem::pixmap()const{
265 QString str;
266 switch(m_dev) {
267 case DeviceBox::IrDa:
268 str ="obex/irda";
269 break;
270 case DeviceBox::BT:
271 str ="obex/bt";
272 break;
273 case DeviceBox::Search:
274 str = "mag";
275 break;
276 case DeviceBox::Error:
277 str = "editdelete";
278 break;
279 };
280 return str;
281}
282DeviceItem::~DeviceItem() {
283}
284void DeviceItem::setStatus(const QString& status ) {
285 m_status = status;
286}
287QString DeviceItem::toString()const {
288 return "<p><a href=\""+QString::number(m_id) +"\" ><img src=\""+pixmap()+"\" >"+m_name+" "+m_status+" </a></p>" ;
289}