summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/obex/obexsend.cpp74
1 files changed, 41 insertions, 33 deletions
diff --git a/core/obex/obexsend.cpp b/core/obex/obexsend.cpp
index bca6784..45754e3 100644
--- a/core/obex/obexsend.cpp
+++ b/core/obex/obexsend.cpp
@@ -1,305 +1,313 @@
1// 7-Jul-2005 mbh@sdgsystems.com: replace hand coded form with one 1// 7-Jul-2005 mbh@sdgsystems.com: replace hand coded form with one
2// generated via QT2 Designer. The new form supports 2// generated via QT2 Designer. The new form supports
3// selection of target devices, as opposed to sending to 3// selection of target devices, as opposed to sending to
4// all. 4// all.
5 5
6#include "obex.h" 6#include "obex.h"
7#include "btobex.h" 7#include "btobex.h"
8#include "obexsend.h" 8#include "obexsend.h"
9using namespace OpieObex; 9using namespace OpieObex;
10using namespace OpieTooth; 10using namespace OpieTooth;
11 11
12/* OPIE */ 12/* OPIE */
13#include <opie2/odebug.h> 13#include <opie2/odebug.h>
14#include <qpe/qcopenvelope_qws.h> 14#include <qpe/qcopenvelope_qws.h>
15#include <opie2/oresource.h> 15#include <opie2/oresource.h>
16#include <qpe/version.h> 16#include <qpe/version.h>
17#include <devicehandler.h> 17#include <devicehandler.h>
18#include "remotedevice.h" 18#include "remotedevice.h"
19 19
20using namespace Opie::Core; 20using namespace Opie::Core;
21 21
22/* QT */ 22/* QT */
23#include <qlabel.h> 23#include <qlabel.h>
24#include <qpushbutton.h> 24#include <qpushbutton.h>
25#include <qpixmap.h> 25#include <qpixmap.h>
26#include <qlistview.h> 26#include <qlistview.h>
27 27
28#include <unistd.h> 28#include <unistd.h>
29/* TRANSLATOR OpieObex::SendWidget */ 29/* TRANSLATOR OpieObex::SendWidget */
30 30
31/* Just for backward compatibility */ 31/* Just for backward compatibility */
32#if OPIE_VERSION < 102010 32#if OPIE_VERSION < 102010
33 #define OResource Resource 33 #define OResource Resource
34#endif 34#endif
35 35
36SendWidget::SendWidget( QWidget* parent, const char* name ) 36SendWidget::SendWidget( QWidget* parent, const char* name )
37 : obexSendBase( parent, name ) { 37 : obexSendBase( parent, name ) {
38 initUI(); 38 initUI();
39} 39}
40SendWidget::~SendWidget() { 40SendWidget::~SendWidget() {
41} 41}
42void SendWidget::initUI() { 42void SendWidget::initUI() {
43 m_obex = new Obex(this, "obex"); 43 m_obex = new Obex(this, "obex");
44 connect(m_obex, SIGNAL(error(int) ), 44 connect(m_obex, SIGNAL(error(int) ),
45 this, SLOT(slotIrError(int) ) ); 45 this, SLOT(slotIrError(int) ) );
46 connect(m_obex, SIGNAL(sent(bool) ), 46 connect(m_obex, SIGNAL(sent(bool) ),
47 this, SLOT(slotIrSent(bool) ) ); 47 this, SLOT(slotIrSent(bool) ) );
48 connect(m_obex, SIGNAL(currentTry(unsigned int) ), 48 connect(m_obex, SIGNAL(currentTry(unsigned int) ),
49 this, SLOT(slotIrTry(unsigned int) ) ); 49 this, SLOT(slotIrTry(unsigned int) ) );
50 50
51 QCopChannel* chan = new QCopChannel("QPE/IrDaAppletBack", this ); 51 QCopChannel* chan = new QCopChannel("QPE/IrDaAppletBack", this );
52 connect(chan, SIGNAL(received(const QCString&,const QByteArray&) ), 52 connect(chan, SIGNAL(received(const QCString&,const QByteArray&) ),
53 this, SLOT(dispatchIrda(const QCString&,const QByteArray&) ) ); 53 this, SLOT(dispatchIrda(const QCString&,const QByteArray&) ) );
54 54
55 m_btobex = new BtObex(this, "btobex"); 55 m_btobex = new BtObex(this, "btobex");
56 connect(m_btobex, SIGNAL(error(int) ), 56 connect(m_btobex, SIGNAL(error(int) ),
57 this, SLOT(slotBtError(int) ) ); 57 this, SLOT(slotBtError(int) ) );
58 connect(m_btobex, SIGNAL(sent(bool) ), 58 connect(m_btobex, SIGNAL(sent(bool) ),
59 this, SLOT(slotBtSent(bool) ) ); 59 this, SLOT(slotBtSent(bool) ) );
60 connect(m_btobex, SIGNAL(currentTry(unsigned int) ), 60 connect(m_btobex, SIGNAL(currentTry(unsigned int) ),
61 this, SLOT(slotBtTry(unsigned int) ) ); 61 this, SLOT(slotBtTry(unsigned int) ) );
62 62
63 chan = new QCopChannel("QPE/BluetoothBack", this ); 63 chan = new QCopChannel("QPE/BluetoothBack", this );
64 connect(chan, SIGNAL(received(const QCString&,const QByteArray&) ), 64 connect(chan, SIGNAL(received(const QCString&,const QByteArray&) ),
65 this, SLOT(dispatchBt(const QCString&,const QByteArray&) ) ); 65 this, SLOT(dispatchBt(const QCString&,const QByteArray&) ) );
66 66
67} 67}
68 68
69/* 69/*
70 * in send we'll first set everything up 70 * in send we'll first set everything up
71 * and then wait for a list of devices. 71 * and then wait for a list of devices.
72 */ 72 */
73void SendWidget::send( const QString& file, const QString& desc ) { 73void SendWidget::send( const QString& file, const QString& desc ) {
74 m_file = file; 74 m_file = file;
75 m_irDa.clear(); 75 m_irDa.clear();
76 m_bt.clear();
76 m_start = 0; 77 m_start = 0;
77 78
78 fileToSend->setText(desc.isEmpty() ? file : desc ); 79 fileToSend->setText(desc.isEmpty() ? file : desc );
80
81 if ( !QCopChannel::isRegistered("QPE/IrDaApplet") )
82 {
83 irdaStatus->setText(tr("not enabled."));
84 }
85 else
86 {
87 QCopEnvelope e1("QPE/IrDaApplet", "enableIrda()");
88 irdaStatus->setText(tr("ready"));
89 sendButton->setEnabled( true );
90 }
91 if ( !QCopChannel::isRegistered("QPE/Bluetooth") )
92 {
93 btStatus->setText(tr("not enabled."));
94 }
95 else
96 {
97 QCopEnvelope e1("QPE/Bluetooth", "enableBluetooth()");
98 btStatus->setText(tr("ready."));
99 sendButton->setEnabled( true );
100 }
79 read_receivers(); 101 read_receivers();
80} 102}
81 103
82int SendWidget::addReceiver(const QString& str, const char *icon) 104int SendWidget::addReceiver(const QString& str, const char *icon)
83{ 105{
84 QListViewItem * item = new QListViewItem( receiverList, 0 ); 106 QListViewItem * item = new QListViewItem( receiverList, 0 );
85 item->setText( 0, str ); 107 item->setText( 0, str );
86 item->setPixmap( 1, OResource::loadPixmap( icon ) ); 108 item->setPixmap( 1, OResource::loadPixmap( icon ) );
87 109
88 int id=receivers.count(); 110 int id = receivers.count();
89 receivers[id]=item; 111 receivers[id] = item;
90 return id; 112 return id;
91} 113}
92 114
93bool SendWidget::receiverSelected(int id) 115bool SendWidget::receiverSelected(int id)
94{ 116{
95 return (bool)(receivers[id]->pixmap(2) != NULL); 117 return (bool)(receivers[id]->pixmap(2) != NULL);
96} 118}
97 119
98void SendWidget::setReceiverStatus( int id, const QString& status ) { 120void SendWidget::setReceiverStatus( int id, const QString& status ) {
99 if ( !receivers.contains(id) ) return; 121 if ( !receivers.contains(id) ) return;
100 receivers[id]->setText(3, status ); 122 receivers[id]->setText(3, status );
101} 123}
102 124
103void SendWidget::slotIrDaDevices( const QStringList& list) { 125void SendWidget::slotIrDaDevices( const QStringList& list) {
104 for (QStringList::ConstIterator it = list.begin(); 126 for (QStringList::ConstIterator it = list.begin();
105 it != list.end(); ++it ) { 127 it != list.end(); ++it ) {
106 int id = addReceiver(*it, "obex/irda.png"); 128 int id = addReceiver(*it, "obex/irda.png");
107 m_irDa.insert( id, (*it) ); 129 m_irDa.insert( id, (*it) );
108 } 130 }
109 irdaStatus->setText( tr("ready.")); 131 irdaStatus->setText( tr("ready."));
110 m_irDaIt = m_irDa.begin(); 132 m_irDaIt = m_irDa.begin();
111 133
112} 134}
113 135
114void SendWidget::slotBTDevices( const QMap<QString, QString>& str ) { 136void SendWidget::slotBTDevices( const QMap<QString, QString>& str ) {
115 for(QMap<QString, QString>::ConstIterator it = str.begin(); 137 for(QMap<QString, QString>::ConstIterator it = str.begin();
116 it != str.end(); ++it ) { 138 it != str.end(); ++it ) {
117 int id = addReceiver(it.key(), "obex/bt.png"); 139 int id = addReceiver(it.key(), "obex/bt.png");
118 m_bt.insert( id, Pair( it.key(), it.data() ) ); 140 m_bt.insert( id, Pair( it.key(), it.data() ) );
119 } 141 }
120 btStatus->setText(tr("ready.")); 142 btStatus->setText(tr("ready."));
121 m_btIt = m_bt.begin(); 143 m_btIt = m_bt.begin();
122 144
123} 145}
124void SendWidget::slotSelectedDevice( int, int ) { 146void SendWidget::slotSelectedDevice( int, int ) {
125/* if ( name == m_irDeSearch ) { 147/* if ( name == m_irDeSearch ) {
126 for (QMap<int, QString>::Iterator it= m_irDa.begin(); it != m_irDa.end(); ++it ) 148 for (QMap<int, QString>::Iterator it= m_irDa.begin(); it != m_irDa.end(); ++it )
127 m_devBox->removeDevice( it.key() ); 149 m_devBox->removeDevice( it.key() );
128 150
129 QCopEnvelope e2("QPE/IrDaApplet", "listDevices()"); 151 QCopEnvelope e2("QPE/IrDaApplet", "listDevices()");
130 }*/ 152 }*/
131} 153}
132void SendWidget::dispatchIrda( const QCString& str, const QByteArray& ar ) { 154void SendWidget::dispatchIrda( const QCString& str, const QByteArray& ar ) {
133 if ( str == "devices(QStringList)" ) { 155 if ( str == "devices(QStringList)" ) {
134 QDataStream stream( ar, IO_ReadOnly ); 156 QDataStream stream( ar, IO_ReadOnly );
135 QStringList list; 157 QStringList list;
136 stream >> list; 158 stream >> list;
137 slotIrDaDevices( list ); 159 slotIrDaDevices( list );
138 } 160 }
139} 161}
140void SendWidget::slotIrError( int ) { 162void SendWidget::slotIrError( int ) {
141 irdaStatus->setText(tr("error :(")); 163 irdaStatus->setText(tr("error :("));
142} 164}
143void SendWidget::slotIrSent( bool b) { 165void SendWidget::slotIrSent( bool b) {
144 QString text = b ? tr("Sent") : tr("Failure"); 166 QString text = b ? tr("Sent") : tr("Failure");
145 setReceiverStatus( m_irDaIt.key(), text ); 167 setReceiverStatus( m_irDaIt.key(), text );
146 ++m_irDaIt; 168 ++m_irDaIt;
147 slotStartIrda(); 169 slotStartIrda();
148} 170}
149void SendWidget::slotIrTry(unsigned int trI) { 171void SendWidget::slotIrTry(unsigned int trI) {
150 setReceiverStatus(m_irDaIt.key(), tr("Try %1").arg( QString::number( trI ) )); 172 setReceiverStatus(m_irDaIt.key(), tr("Try %1").arg( QString::number( trI ) ));
151} 173}
152void SendWidget::slotStartIrda() { 174void SendWidget::slotStartIrda() {
153 if ( !m_irDa.count() ) 175 if ( !m_irDa.count() )
154 return; 176 return;
155 if ( m_irDaIt == m_irDa.end() || !receiverSelected(m_irDaIt.key())) { 177 if ( m_irDaIt == m_irDa.end() || !receiverSelected(m_irDaIt.key())) {
156 irdaStatus->setText(tr("complete.")); 178 irdaStatus->setText(tr("complete."));
179 m_irDaIt = m_irDa.begin();
157 return; 180 return;
158 } 181 }
159 setReceiverStatus( m_irDaIt.key(), tr("Start sending") ); 182 setReceiverStatus( m_irDaIt.key(), tr("Start sending") );
183 irdaStatus->setText(tr("sending."));
160 m_obex->send( m_file, tr("noaddress") ); 184 m_obex->send( m_file, tr("noaddress") );
161} 185}
162 186
163void SendWidget::dispatchBt( const QCString& str, const QByteArray& ar ) { 187void SendWidget::dispatchBt( const QCString& str, const QByteArray& ar ) {
164 if ( str == "devices(QStringMap)" ) { 188 if ( str == "devices(QStringMap)" ) {
165 QDataStream stream( ar, IO_ReadOnly ); 189 QDataStream stream( ar, IO_ReadOnly );
166 QMap<QString, QString> btmap; 190 QMap<QString, QString> btmap;
167 stream >> btmap; 191 stream >> btmap;
168 slotBTDevices( btmap ); 192 slotBTDevices( btmap );
169 } 193 }
170} 194}
171void SendWidget::slotBtError( int ) { 195void SendWidget::slotBtError( int ) {
172 btStatus->setText(tr("error :(")); 196 btStatus->setText(tr("error :("));
173} 197}
174void SendWidget::slotBtSent( bool b) { 198void SendWidget::slotBtSent( bool b) {
175 QString text = b ? tr("Sent") : tr("Failure"); 199 QString text = b ? tr("Sent") : tr("Failure");
176 setReceiverStatus( m_btIt.key(), text ); 200 setReceiverStatus( m_btIt.key(), text );
177 ++m_btIt; 201 ++m_btIt;
178 slotStartBt(); 202 slotStartBt();
179} 203}
180void SendWidget::slotBtTry(unsigned int trI) { 204void SendWidget::slotBtTry(unsigned int trI) {
181 setReceiverStatus( m_btIt.key(), tr("Try %1").arg( QString::number( trI ) ) ); 205 setReceiverStatus( m_btIt.key(), tr("Try %1").arg( QString::number( trI ) ) );
182} 206}
183void SendWidget::slotStartBt() { 207void SendWidget::slotStartBt() {
184 // skip past unselected receivers 208 // skip past unselected receivers
209 if ( !m_bt.count() )
210 return;
185 while((m_btIt != m_bt.end()) && !receiverSelected(m_btIt.key())) 211 while((m_btIt != m_bt.end()) && !receiverSelected(m_btIt.key()))
186 ++m_btIt; 212 ++m_btIt;
187 if (m_btIt == m_bt.end() ) { 213 if (m_btIt == m_bt.end() ) {
188 btStatus->setText(tr("complete.")); 214 btStatus->setText(tr("complete."));
215 m_btIt = m_bt.begin();
189 return; 216 return;
190 } 217 }
191 setReceiverStatus( m_btIt.key(), tr("Start sending") ); 218 setReceiverStatus( m_btIt.key(), tr("Start sending") );
219 btStatus->setText(tr("sending."));
192 m_btobex->send( m_file, m_btIt.data().second() ); 220 m_btobex->send( m_file, m_btIt.data().second() );
193} 221}
194 222
195void SendWidget::send_to_receivers() { 223void SendWidget::send_to_receivers() {
196 slotStartIrda();
197 slotStartBt(); 224 slotStartBt();
225 slotStartIrda();
198} 226}
199 227
200/** 228/**
201 * Read receivers saved by bluetooth manager 229 * Read receivers saved by bluetooth manager
202 */ 230 */
203void SendWidget::read_receivers() 231void SendWidget::read_receivers()
204{ 232{
205 QValueList<RemoteDevice> devices; 233 QValueList<RemoteDevice> devices;
206 DeviceHandler handler; 234 DeviceHandler handler;
207 QValueList<RemoteDevice>::ConstIterator it; 235 QValueList<RemoteDevice>::ConstIterator it;
208 236
209 receiverList->clear(); 237 receiverList->clear();
210 receivers.clear(); 238 receivers.clear();
211 sendButton->setDisabled( true ); 239 sendButton->setDisabled( true );
240 btStatus->setText(tr("load."));
241 m_bt.clear();
212 242
213 if ( !QCopChannel::isRegistered("QPE/IrDaApplet") ) 243 if ( QCopChannel::isRegistered("QPE/Bluetooth") )
214 { 244 {
215 irdaStatus->setText(tr("not enabled."));
216 }
217 else
218 {
219 QCopEnvelope e1("QPE/IrDaApplet", "enableIrda()");
220 irdaStatus->setText(tr("ready"));
221 sendButton->setEnabled( true );
222 }
223 if ( !QCopChannel::isRegistered("QPE/Bluetooth") )
224 {
225 btStatus->setText(tr("not enabled."));
226 }
227 else
228 {
229 QCopEnvelope e1("QPE/Bluetooth", "enableBluetooth()");
230
231 devices = handler.load(); 245 devices = handler.load();
232 for( it = devices.begin(); it != devices.end() ; ++it ) 246 for( it = devices.begin(); it != devices.end() ; ++it )
233 { 247 {
234 int id = addReceiver((*it).name(), "obex/bt.png"); 248 int id = addReceiver((*it).name(), "obex/bt.png");
235 m_bt.insert(id, Pair((*it).name(), (*it).mac())); 249 m_bt.insert(id, Pair((*it).name(), (*it).mac()));
236 } 250 }
237 btStatus->setText(tr("ready.")); 251 btStatus->setText(tr("ready."));
238 m_btIt = m_bt.begin(); 252 m_btIt = m_bt.begin();
239 sendButton->setEnabled( true ); 253 sendButton->setEnabled( true );
240 } 254 }
241} 255}
242 256
243 257
244void SendWidget::scan_for_receivers() 258void SendWidget::scan_for_receivers()
245{ 259{
260 sendButton->setDisabled( true );
246 receiverList->clear(); 261 receiverList->clear();
247 receivers.clear(); 262 receivers.clear();
248 sendButton->setDisabled( true ); 263 m_irDa.clear();
264 m_bt.clear();
249 265
250 if ( !QCopChannel::isRegistered("QPE/IrDaApplet") ) 266 if ( QCopChannel::isRegistered("QPE/IrDaApplet") )
251 {
252 irdaStatus->setText(tr("not enabled."));
253 }
254 else
255 { 267 {
256 QCopEnvelope e1("QPE/IrDaApplet", "enableIrda()");
257 irdaStatus->setText(tr("searching...")); 268 irdaStatus->setText(tr("searching..."));
258 sendButton->setEnabled( true ); 269 sendButton->setEnabled( true );
259 QCopEnvelope e2("QPE/IrDaApplet", "listDevices()"); 270 QCopEnvelope e2("QPE/IrDaApplet", "listDevices()");
260 } 271 }
261 272
262 if ( !QCopChannel::isRegistered("QPE/Bluetooth") ) 273 if ( QCopChannel::isRegistered("QPE/Bluetooth") )
263 { 274 {
264 btStatus->setText(tr("not enabled."));
265 }
266 else
267 {
268 QCopEnvelope e1("QPE/Bluetooth", "enableBluetooth()");
269 btStatus->setText(tr("searching...")); 275 btStatus->setText(tr("searching..."));
270 sendButton->setEnabled( true ); 276 sendButton->setEnabled( true );
271 QCopEnvelope e3("QPE/Bluetooth", "listDevices()"); 277 QCopEnvelope e3("QPE/Bluetooth", "listDevices()");
272 } 278 }
273} 279}
274 280
275void SendWidget::toggle_receiver(QListViewItem* item) 281void SendWidget::toggle_receiver(QListViewItem* item)
276{ 282{
283 if (!item)
284 return;
277 // toggle the state of an individual receiver. 285 // toggle the state of an individual receiver.
278 if (item->pixmap(2)) 286 if (item->pixmap(2))
279 item->setPixmap(2, QPixmap()); 287 item->setPixmap(2, QPixmap());
280 else 288 else
281 item->setPixmap(2, OResource::loadPixmap("obex/check.png")); 289 item->setPixmap(2, OResource::loadPixmap("obex/check.png"));
282} 290}
283 291
284 292
285void SendWidget::closeEvent( QCloseEvent* evt) { 293void SendWidget::closeEvent( QCloseEvent* evt) {
286 delete m_obex; 294 delete m_obex;
287 m_obex = NULL; 295 m_obex = NULL;
288 delete m_btobex; 296 delete m_btobex;
289 m_btobex = NULL; 297 m_btobex = NULL;
290 obexSendBase::closeEvent(evt); 298 obexSendBase::closeEvent(evt);
291 { 299 {
292 QCopEnvelope e("QPE/IrDaApplet", "disableIrda()"); 300 QCopEnvelope e("QPE/IrDaApplet", "disableIrda()");
293 } 301 }
294 { 302 {
295 QCopEnvelope e("QPE/Bluetooth", "disableBluetooth()"); 303 QCopEnvelope e("QPE/Bluetooth", "disableBluetooth()");
296 } 304 }
297} 305}
298 306
299void SendWidget::userDone() { 307void SendWidget::userDone() {
300 close(); 308 close();
301} 309}
302 310
303QString SendWidget::file()const { 311QString SendWidget::file()const {
304 return m_file; 312 return m_file;
305} 313}