author | korovkin <korovkin> | 2006-11-14 21:31:46 (UTC) |
---|---|---|
committer | korovkin <korovkin> | 2006-11-14 21:31:46 (UTC) |
commit | 9813113f0024205e09af9e54328287dd859fa2e8 (patch) (side-by-side diff) | |
tree | 399134d6f3f601c9112df009bd4102751df24d1d /core | |
parent | 663a33f463ac184b10cb3adc354f62a6a5c3e2b0 (diff) | |
download | opie-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.
-rw-r--r-- | core/obex/obexsend.cpp | 74 |
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 @@ -64,38 +64,60 @@ void SendWidget::initUI() { connect(chan, SIGNAL(received(const QCString&,const QByteArray&) ), this, SLOT(dispatchBt(const QCString&,const QByteArray&) ) ); } /* * in send we'll first set everything up * and then wait for a list of devices. */ void SendWidget::send( const QString& file, const QString& desc ) { m_file = file; m_irDa.clear(); + m_bt.clear(); m_start = 0; fileToSend->setText(desc.isEmpty() ? file : desc ); + + if ( !QCopChannel::isRegistered("QPE/IrDaApplet") ) + { + irdaStatus->setText(tr("not enabled.")); + } + else + { + QCopEnvelope e1("QPE/IrDaApplet", "enableIrda()"); + irdaStatus->setText(tr("ready")); + sendButton->setEnabled( true ); + } + if ( !QCopChannel::isRegistered("QPE/Bluetooth") ) + { + btStatus->setText(tr("not enabled.")); + } + else + { + QCopEnvelope e1("QPE/Bluetooth", "enableBluetooth()"); + btStatus->setText(tr("ready.")); + sendButton->setEnabled( true ); + } read_receivers(); } int SendWidget::addReceiver(const QString& str, const char *icon) { QListViewItem * item = new QListViewItem( receiverList, 0 ); item->setText( 0, str ); item->setPixmap( 1, OResource::loadPixmap( icon ) ); - int id=receivers.count(); - receivers[id]=item; + int id = receivers.count(); + receivers[id] = item; return id; } bool SendWidget::receiverSelected(int id) { return (bool)(receivers[id]->pixmap(2) != NULL); } void SendWidget::setReceiverStatus( int id, const QString& status ) { if ( !receivers.contains(id) ) return; receivers[id]->setText(3, status ); } @@ -145,27 +167,29 @@ void SendWidget::slotIrSent( bool b) { setReceiverStatus( m_irDaIt.key(), text ); ++m_irDaIt; slotStartIrda(); } void SendWidget::slotIrTry(unsigned int trI) { setReceiverStatus(m_irDaIt.key(), tr("Try %1").arg( QString::number( trI ) )); } void SendWidget::slotStartIrda() { if ( !m_irDa.count() ) return; if ( m_irDaIt == m_irDa.end() || !receiverSelected(m_irDaIt.key())) { irdaStatus->setText(tr("complete.")); + m_irDaIt = m_irDa.begin(); return; } setReceiverStatus( m_irDaIt.key(), tr("Start sending") ); + irdaStatus->setText(tr("sending.")); m_obex->send( m_file, tr("noaddress") ); } void SendWidget::dispatchBt( const QCString& str, const QByteArray& ar ) { if ( str == "devices(QStringMap)" ) { QDataStream stream( ar, IO_ReadOnly ); QMap<QString, QString> btmap; stream >> btmap; slotBTDevices( btmap ); } } void SendWidget::slotBtError( int ) { @@ -173,116 +197,100 @@ void SendWidget::slotBtError( int ) { } void SendWidget::slotBtSent( bool b) { QString text = b ? tr("Sent") : tr("Failure"); setReceiverStatus( m_btIt.key(), text ); ++m_btIt; slotStartBt(); } void SendWidget::slotBtTry(unsigned int trI) { setReceiverStatus( m_btIt.key(), tr("Try %1").arg( QString::number( trI ) ) ); } void SendWidget::slotStartBt() { // skip past unselected receivers + if ( !m_bt.count() ) + return; while((m_btIt != m_bt.end()) && !receiverSelected(m_btIt.key())) ++m_btIt; if (m_btIt == m_bt.end() ) { btStatus->setText(tr("complete.")); + m_btIt = m_bt.begin(); return; } setReceiverStatus( m_btIt.key(), tr("Start sending") ); + btStatus->setText(tr("sending.")); m_btobex->send( m_file, m_btIt.data().second() ); } void SendWidget::send_to_receivers() { - slotStartIrda(); slotStartBt(); + slotStartIrda(); } /** * Read receivers saved by bluetooth manager */ void SendWidget::read_receivers() { QValueList<RemoteDevice> devices; DeviceHandler handler; QValueList<RemoteDevice>::ConstIterator it; receiverList->clear(); receivers.clear(); sendButton->setDisabled( true ); + btStatus->setText(tr("load.")); + m_bt.clear(); - if ( !QCopChannel::isRegistered("QPE/IrDaApplet") ) + if ( QCopChannel::isRegistered("QPE/Bluetooth") ) { - irdaStatus->setText(tr("not enabled.")); - } - else - { - QCopEnvelope e1("QPE/IrDaApplet", "enableIrda()"); - irdaStatus->setText(tr("ready")); - sendButton->setEnabled( true ); - } - if ( !QCopChannel::isRegistered("QPE/Bluetooth") ) - { - btStatus->setText(tr("not enabled.")); - } - else - { - QCopEnvelope e1("QPE/Bluetooth", "enableBluetooth()"); - devices = handler.load(); for( it = devices.begin(); it != devices.end() ; ++it ) { int id = addReceiver((*it).name(), "obex/bt.png"); m_bt.insert(id, Pair((*it).name(), (*it).mac())); } btStatus->setText(tr("ready.")); m_btIt = m_bt.begin(); sendButton->setEnabled( true ); } } void SendWidget::scan_for_receivers() { + sendButton->setDisabled( true ); receiverList->clear(); receivers.clear(); - sendButton->setDisabled( true ); + m_irDa.clear(); + m_bt.clear(); - if ( !QCopChannel::isRegistered("QPE/IrDaApplet") ) - { - irdaStatus->setText(tr("not enabled.")); - } - else + if ( QCopChannel::isRegistered("QPE/IrDaApplet") ) { - QCopEnvelope e1("QPE/IrDaApplet", "enableIrda()"); irdaStatus->setText(tr("searching...")); sendButton->setEnabled( true ); QCopEnvelope e2("QPE/IrDaApplet", "listDevices()"); } - if ( !QCopChannel::isRegistered("QPE/Bluetooth") ) + if ( QCopChannel::isRegistered("QPE/Bluetooth") ) { - btStatus->setText(tr("not enabled.")); - } - else - { - QCopEnvelope e1("QPE/Bluetooth", "enableBluetooth()"); btStatus->setText(tr("searching...")); sendButton->setEnabled( true ); QCopEnvelope e3("QPE/Bluetooth", "listDevices()"); } } void SendWidget::toggle_receiver(QListViewItem* item) { + if (!item) + return; // toggle the state of an individual receiver. if (item->pixmap(2)) item->setPixmap(2, QPixmap()); else item->setPixmap(2, OResource::loadPixmap("obex/check.png")); } void SendWidget::closeEvent( QCloseEvent* evt) { delete m_obex; m_obex = NULL; delete m_btobex; |