summaryrefslogtreecommitdiff
path: root/core/obex/obexsend.cpp
authorzecke <zecke>2003-02-18 20:42:05 (UTC)
committer zecke <zecke>2003-02-18 20:42:05 (UTC)
commitd3f15e100af8a91504ac9e5fb95dce0cadfe4837 (patch) (unidiff)
tree04ddeda0f690aa1d51ba486b114251250eef2ef9 /core/obex/obexsend.cpp
parent9f5098a6da637e81f6525482456394a68524dc61 (diff)
downloadopie-d3f15e100af8a91504ac9e5fb95dce0cadfe4837.zip
opie-d3f15e100af8a91504ac9e5fb95dce0cadfe4837.tar.gz
opie-d3f15e100af8a91504ac9e5fb95dce0cadfe4837.tar.bz2
Convert the way of storing the devices in the QTextBrowser
we assign ids by now it looks soo nice... but it counts up tries and then say there was a failure but it is working though
Diffstat (limited to 'core/obex/obexsend.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/obex/obexsend.cpp141
1 files changed, 89 insertions, 52 deletions
diff --git a/core/obex/obexsend.cpp b/core/obex/obexsend.cpp
index d5ebd81..0da57ca 100644
--- a/core/obex/obexsend.cpp
+++ b/core/obex/obexsend.cpp
@@ -3,6 +3,7 @@
3#include <qhbox.h> 3#include <qhbox.h>
4#include <qlayout.h> 4#include <qlayout.h>
5#include <qtimer.h> 5#include <qtimer.h>
6#include <qtl.h>
6 7
7#include <qcopchannel_qws.h> 8#include <qcopchannel_qws.h>
8 9
@@ -59,8 +60,8 @@ void SendWidget::initUI() {
59 60
60 m_devBox = new DeviceBox(this); 61 m_devBox = new DeviceBox(this);
61 lay->addWidget( m_devBox, 50 ); 62 lay->addWidget( m_devBox, 50 );
62 connect(m_devBox, SIGNAL(selectedDevice(const QString&, int ) ), 63 connect(m_devBox, SIGNAL(selectedDevice(int, int ) ),
63 this, SLOT(slotSelectedDevice(const QString&, int) ) ); 64 this, SLOT(slotSelectedDevice(int, int) ) );
64 65
65 QPushButton *but = new QPushButton(this); 66 QPushButton *but = new QPushButton(this);
66 but->setText(tr("Done") ); 67 but->setText(tr("Done") );
@@ -86,16 +87,16 @@ void SendWidget::send( const QString& file, const QString& desc ) {
86 m_lblFile->setText(desc.isEmpty() ? file : desc ); 87 m_lblFile->setText(desc.isEmpty() ? file : desc );
87 88
88 if ( !QCopChannel::isRegistered("QPE/IrDaApplet") ) { 89 if ( !QCopChannel::isRegistered("QPE/IrDaApplet") ) {
89 m_devBox->addDevice( tr("IrDa is not enabled!"), DeviceBox::Error ); 90 m_irDeSearch = m_devBox->addDevice( tr("IrDa is not enabled!"), DeviceBox::Error );
90 m_start++; 91 m_start++;
91 }else 92 }else
92 m_devBox->addDevice( tr("Searching for IrDa Devices."), DeviceBox::Search ); 93 m_irDeSearch = m_devBox->addDevice( tr("Searching for IrDa Devices."), DeviceBox::Search );
93 94
94 if ( !QCopChannel::isRegistered("QPE/Bluetooth") ) { 95 if ( !QCopChannel::isRegistered("QPE/Bluetooth") ) {
95 m_devBox->addDevice( tr("Bluetooth is not available"), DeviceBox::Error ); 96 m_btDeSearch = m_devBox->addDevice( tr("Bluetooth is not available"), DeviceBox::Error );
96 m_start++; 97 m_start++;
97 }else 98 }else
98 m_devBox->addDevice( tr("Searching for bluetooth Devices."), DeviceBox::Search ); 99 m_btDeSearch = m_devBox->addDevice( tr("Searching for bluetooth Devices."), DeviceBox::Search );
99 100
100 if (m_start != 2 ) { 101 if (m_start != 2 ) {
101 QCopEnvelope e0("QPE/IrDaApplet", "enableIrda()"); 102 QCopEnvelope e0("QPE/IrDaApplet", "enableIrda()");
@@ -106,27 +107,28 @@ void SendWidget::send( const QString& file, const QString& desc ) {
106} 107}
107void SendWidget::slotIrDaDevices( const QStringList& list) { 108void SendWidget::slotIrDaDevices( const QStringList& list) {
108 qWarning("slot it irda devices "); 109 qWarning("slot it irda devices ");
109 m_irDa = list; 110 for (QStringList::ConstIterator it = list.begin(); it != list.end(); ++it ) {
110 m_start = 0; 111 int id = m_devBox->addDevice( (*it), DeviceBox::IrDa, tr("Scheduling for beam.") );
111 for (QStringList::ConstIterator it = list.begin(); it != list.end(); ++it ) 112 m_irDa.insert( id, (*it) );
112 m_devBox->addDevice( (*it), DeviceBox::IrDa, tr("Scheduling for beam.") ); 113 }
113 114 m_devBox->removeDevice( m_irDeSearch );
114 m_devBox->removeDevice( tr("Searching for IrDa Devices.") ); 115 m_irDaIt = m_irDa.begin();
115 116
116 slotStartIrda(); 117 slotStartIrda();
117} 118}
119
118void SendWidget::slotBTDevices( const QMap<QString, QString>& str ) { 120void SendWidget::slotBTDevices( const QMap<QString, QString>& str ) {
119 m_bt = str;
120 for(QMap<QString, QString>::ConstIterator it = str.begin(); it != str.end(); ++it ) { 121 for(QMap<QString, QString>::ConstIterator it = str.begin(); it != str.end(); ++it ) {
121 m_devBox->addDevice( it.key(), DeviceBox::BT, tr("Click to beam") ); 122 int id = m_devBox->addDevice( it.key(), DeviceBox::BT, tr("Click to beam") );
123 m_bt.insert( id, Pair( it.key(), it.data() ) );
122 } 124 }
123 m_devBox->removeDevice( tr("Searching for bluetooth Devices.") ); 125 m_devBox->removeDevice( m_btDeSearch );
124} 126}
125void SendWidget::slotSelectedDevice( const QString& name, int dev ) { 127void SendWidget::slotSelectedDevice( int name, int dev ) {
126 qWarning("Start beam? %s %d", name.latin1(), dev ); 128 qWarning("Start beam? %d %d", name, dev );
127 if ( name == tr("Search again for IrDa.") ) { 129 if ( name == m_irDeSearch ) {
128 for (QStringList::Iterator it= m_irDa.begin(); it != m_irDa.end(); ++it ) 130 for (QMap<int, QString>::Iterator it= m_irDa.begin(); it != m_irDa.end(); ++it )
129 m_devBox->removeDevice( (*it) ); 131 m_devBox->removeDevice( it.key() );
130 132
131 QCopEnvelope e2("QPE/IrDaApplet", "listDevices()"); 133 QCopEnvelope e2("QPE/IrDaApplet", "listDevices()");
132 } 134 }
@@ -140,7 +142,7 @@ void SendWidget::dispatchIrda( const QCString& str, const QByteArray& ar ) {
140 slotIrDaDevices( list ); 142 slotIrDaDevices( list );
141 } 143 }
142} 144}
143void SendWidget::dispatchBt( const QCString& str, const QByteArray& ar ) { 145void SendWidget::dispatchBt( const QCString&, const QByteArray& ) {
144 146
145} 147}
146void SendWidget::slotIrError( int ) { 148void SendWidget::slotIrError( int ) {
@@ -149,19 +151,19 @@ void SendWidget::slotIrError( int ) {
149void SendWidget::slotIrSent( bool b) { 151void SendWidget::slotIrSent( bool b) {
150 qWarning("irda sent!!"); 152 qWarning("irda sent!!");
151 QString text = b ? tr("Sent") : tr("Failure"); 153 QString text = b ? tr("Sent") : tr("Failure");
152// m_devBox->setStatus( m_irDa[m_start], text ); 154 m_devBox->setStatus( m_irDaIt.key(), text );
153 m_start++; 155 ++m_irDaIt;
154 slotStartIrda(); 156 slotStartIrda();
155} 157}
156void SendWidget::slotIrTry(unsigned int trI) { 158void SendWidget::slotIrTry(unsigned int trI) {
157// m_devBox->setStatus( m_irDa[m_start], tr("Try %1").arg( QString::number( trI ) ) ); 159 m_devBox->setStatus( m_irDaIt.key(), tr("Try %1").arg( QString::number( trI ) ) );
158} 160}
159void SendWidget::slotStartIrda() { 161void SendWidget::slotStartIrda() {
160 if (m_start >= m_irDa.count() ) { 162 if (m_irDaIt == m_irDa.end() ) {
161 m_devBox->addDevice(tr("Search again for IrDa."), DeviceBox::Search ); 163 m_irDeSearch = m_devBox->addDevice(tr("Search again for IrDa."), DeviceBox::Search );
162 return; 164 return;
163 } 165 }
164// m_devBox->setStatus( m_irDa[m_start], tr("Start sending") ); 166 m_devBox->setStatus( m_irDaIt.key(), tr("Start sending") );
165 m_obex->send( m_file ); 167 m_obex->send( m_file );
166} 168}
167void SendWidget::slotDone() { 169void SendWidget::slotDone() {
@@ -179,43 +181,78 @@ DeviceBox::DeviceBox( QWidget* parent )
179DeviceBox::~DeviceBox() { 181DeviceBox::~DeviceBox() {
180 182
181} 183}
182void DeviceBox::addDevice( const QString& name, int dev, const QString& status ) { 184int DeviceBox::addDevice( const QString& name, int dev, const QString& status ) {
183 QString tex; 185 /* return a id for a range of devices */
184 DeviceItem item( name, status, dev ); 186 int id = idFor ( dev );
185 m_dev.insert( name, item ); 187 DeviceItem item( name, status, dev,id );
186 tex = item.toString(); 188 m_dev.insert( id, item );
187 m_devices.prepend(tex); 189 setText( allText() );
188 setText( text()+ "<br>"+tex );
189}
190void DeviceBox::removeDevice( const QString& name ) {
191 if (!m_dev.contains(name) ) return;
192 m_devices.remove( m_dev[name].toString() );
193 190
194 m_dev.remove(name); 191 return id;
195 setText( m_devices.join("<br>") ); 192}
193void DeviceBox::removeDevice( int id ) {
194 if (!m_dev.contains(id) ) return;
196 195
196 m_dev.remove( id );
197 setText( allText() );
197} 198}
198void DeviceBox::setStatus( const QString& name, const QString& status ) { 199void DeviceBox::setStatus( int id, const QString& status ) {
199 if ( !m_dev.contains(name) ) return; 200 if ( !m_dev.contains(id) ) return;
200 DeviceItem dev = m_dev[name]; 201 m_dev[id].setStatus(status );
201 QString ole = dev.toString(); 202 setText( allText() );
202 dev.setStatus( status );
203 int index = m_devices.findIndex( ole );
204 m_devices[index] = dev.toString();
205 setText( m_devices.join("<br>") );
206} 203}
207void DeviceBox::setSource( const QString& str ) { 204void DeviceBox::setSource( const QString& str ) {
208 qWarning("SetSource:%s", str.latin1() ); 205 qWarning("SetSource:%d", str.toInt() );
209 emit selectedDevice( str, m_dev[str].device() ); 206 int id = str.toInt();
207 emit selectedDevice( id, m_dev[id].device() );
208}
209int DeviceBox::idFor ( int id ) {
210 static int irId = 1501;
211 static int irBT = 1001;
212 static int irSr = 501;
213 static int irEr = 0;
214
215 int ret = -1;
216 switch(id ) {
217 case IrDa:
218 ret = irId;
219 irId++;
220 break;
221 case BT:
222 ret = irBT;
223 irBT++;
224 break;
225 case Search:
226 ret = irSr;
227 irSr++;
228 break;
229 case Error:
230 ret = irEr;
231 irEr++;
232 break;
233 }
234 return ret;
210} 235}
236QString DeviceBox::allText() {
237 QString str;
238 typedef QMap<int, DeviceItem> DeviceMap;
211 239
240 for (QMap<int, DeviceItem>::Iterator it = m_dev.begin(); it != m_dev.end(); ++it ) {
241 str += it.data().toString() + "<br>";
242 }
243 return str;
244}
212 245
213DeviceItem::DeviceItem( const QString& name, 246DeviceItem::DeviceItem( const QString& name,
214 const QString& status, int dev) 247 const QString& status, int dev, int id)
215{ 248{
216 m_name = name; 249 m_name = name;
217 m_status = status; 250 m_status = status;
218 m_dev = dev; 251 m_dev = dev;
252 m_id = id;
253}
254int DeviceItem::id()const {
255 return m_id;
219} 256}
220QString DeviceItem::name()const { 257QString DeviceItem::name()const {
221 return m_name; 258 return m_name;
@@ -250,5 +287,5 @@ void DeviceItem::setStatus(const QString& status ) {
250 m_status = status; 287 m_status = status;
251} 288}
252QString DeviceItem::toString()const { 289QString DeviceItem::toString()const {
253 return "<p><a href=\""+m_name +"\" ><img src=\""+pixmap()+"\" >"+m_name+" "+m_status+" </a></p>" ; 290 return "<p><a href=\""+QString::number(m_id) +"\" ><img src=\""+pixmap()+"\" >"+m_name+" "+m_status+" </a></p>" ;
254} 291}