summaryrefslogtreecommitdiff
authorkorovkin <korovkin>2006-11-14 21:31:46 (UTC)
committer korovkin <korovkin>2006-11-14 21:31:46 (UTC)
commit9813113f0024205e09af9e54328287dd859fa2e8 (patch) (unidiff)
tree399134d6f3f601c9112df009bd4102751df24d1d
parent663a33f463ac184b10cb3adc354f62a6a5c3e2b0 (diff)
downloadopie-9813113f0024205e09af9e54328287dd859fa2e8.zip
opie-9813113f0024205e09af9e54328287dd859fa2e8.tar.gz
opie-9813113f0024205e09af9e54328287dd859fa2e8.tar.bz2
Clear both IRDA and BT lists at startup.
Enable IRDA and bluetooth at startup only. Move index to the beginning after send. Added status line change. Added checks for NULL pointers and empty list of bluetooth devices.
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
@@ -60,46 +60,68 @@ void SendWidget::initUI() {
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 ) {
@@ -141,152 +163,138 @@ void 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()");