Diffstat (limited to 'noncore/net/opietooth/manager/bluebase.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/opietooth/manager/bluebase.cpp | 143 |
1 files changed, 91 insertions, 52 deletions
diff --git a/noncore/net/opietooth/manager/bluebase.cpp b/noncore/net/opietooth/manager/bluebase.cpp index 77eb62b..910bb8c 100644 --- a/noncore/net/opietooth/manager/bluebase.cpp +++ b/noncore/net/opietooth/manager/bluebase.cpp | |||
@@ -59,11 +59,11 @@ namespace OpieTooth { | |||
59 | connect( ListView2, SIGNAL( clicked( QListViewItem* )), | 59 | connect( ListView2, SIGNAL( clicked( QListViewItem* )), |
60 | this, SLOT( startServiceActionClicked( QListViewItem* ) ) ); | 60 | this, SLOT( startServiceActionClicked( QListViewItem* ) ) ); |
61 | connect( ListView2, SIGNAL( rightButtonClicked( QListViewItem *, const QPoint &, int ) ), | 61 | connect( ListView2, SIGNAL( rightButtonClicked( QListViewItem *, const QPoint &, int ) ), |
62 | this, SLOT(startServiceActionHold( QListViewItem *, const QPoint &, int) ) ); | 62 | this, SLOT(startServiceActionHold( BTListItem *, const QPoint &, int) ) ); |
63 | connect( localDevice , SIGNAL( foundServices( const QString& , Services::ValueList ) ), | 63 | connect( localDevice , SIGNAL( foundServices( const QString& , Services::ValueList ) ), |
64 | this, SLOT( addServicesToDevice( const QString& , Services::ValueList ) ) ); | 64 | this, SLOT( addServicesToDevice( const QString& , Services::ValueList ) ) ); |
65 | // connect( localDevice, SIGNAL( available( const QString& device, bool connected ) ), | 65 | connect( localDevice, SIGNAL( available( const QString& device, bool connected ) ), |
66 | // this, SLOT() ); | 66 | this, SLOT( deviceActive( const QString& mac, bool connected ) ) ); |
67 | 67 | ||
68 | //Load all icons needed | 68 | //Load all icons needed |
69 | 69 | ||
@@ -86,11 +86,10 @@ namespace OpieTooth { | |||
86 | //TESTING | 86 | //TESTING |
87 | ListView2->setRootIsDecorated(true); | 87 | ListView2->setRootIsDecorated(true); |
88 | 88 | ||
89 | QListViewItem *topLV2 = new QListViewItem( ListView2, "Siemens S45" , "no" ); | 89 | BTListItem *topLV2 = new BTListItem( ListView2, "Siemens S45", "", "device" ); |
90 | topLV2->setPixmap( 1, onPix ); | 90 | topLV2->setPixmap( 1, onPix ); |
91 | topLV2->setText(4, "device" ); | 91 | (void) new BTListItem( topLV2, "Serial" ,"", "service" ); |
92 | (void) new QListViewItem( topLV2, "Serial" ); | 92 | (void) new BTListItem( topLV2, "BlueNiC" , "", "service" ); |
93 | (void) new QListViewItem( topLV2, "BlueNiC" ); | ||
94 | } | 93 | } |
95 | 94 | ||
96 | 95 | ||
@@ -171,10 +170,11 @@ namespace OpieTooth { | |||
171 | for ( ; it.current(); ++it ) { | 170 | for ( ; it.current(); ++it ) { |
172 | 171 | ||
173 | // seperate config file for each device, to store more information in future. | 172 | // seperate config file for each device, to store more information in future. |
173 | // TO FIX: BTLISTITEM!!! | ||
174 | 174 | ||
175 | Config conf( QDir::homeDirPath() + "/Settings/bluetooth/" + (it.current()->text(3)) + ".conf", Config::File ); | 175 | // Config conf( QDir::homeDirPath() + "/Settings/bluetooth/" + (((BTListItem)it.current())->mac()) + ".conf", Config::File ); |
176 | conf.setGroup( "Info" ); | 176 | // conf.setGroup( "Info" ); |
177 | conf.writeEntry( "name", it.current()->text(0) ); | 177 | // conf.writeEntry( "name", it.current()->name() ); |
178 | } | 178 | } |
179 | } | 179 | } |
180 | 180 | ||
@@ -238,7 +238,7 @@ namespace OpieTooth { | |||
238 | */ | 238 | */ |
239 | void BlueBase::addSearchedDevices( QList<RemoteDevice> &newDevices ) { | 239 | void BlueBase::addSearchedDevices( QList<RemoteDevice> &newDevices ) { |
240 | 240 | ||
241 | QListViewItem * deviceItem; | 241 | BTListItem * deviceItem; |
242 | 242 | ||
243 | QListIterator<RemoteDevice> it( newDevices ); | 243 | QListIterator<RemoteDevice> it( newDevices ); |
244 | 244 | ||
@@ -246,18 +246,16 @@ namespace OpieTooth { | |||
246 | 246 | ||
247 | 247 | ||
248 | RemoteDevice *dev = it.current(); | 248 | RemoteDevice *dev = it.current(); |
249 | deviceItem = new QListViewItem( ListView2 , dev->name() ); | 249 | deviceItem = new BTListItem( ListView2 , dev->name(), dev->mac(), "device" ); |
250 | deviceItem->setExpandable ( true ); | 250 | deviceItem->setExpandable ( true ); |
251 | 251 | ||
252 | if ( deviceActive( dev ) ) { | 252 | // look if device is avail. atm, async |
253 | deviceItem->setPixmap( 1 , onPix ); | 253 | deviceActive( dev ); |
254 | } else { | ||
255 | deviceItem->setPixmap( 1, offPix ); | ||
256 | } | ||
257 | 254 | ||
258 | deviceItem->setText( 3, dev->mac() ); | 255 | // move into the c'tor |
256 | // deviceItem->setMac( dev->mac() ); | ||
259 | // what kind of entry is it. | 257 | // what kind of entry is it. |
260 | deviceItem->setText( 4, "device"); | 258 | //deviceItem->setType( "device"); |
261 | 259 | ||
262 | // ggf auch hier? | 260 | // ggf auch hier? |
263 | addServicesToDevice( deviceItem ); | 261 | addServicesToDevice( deviceItem ); |
@@ -276,53 +274,70 @@ namespace OpieTooth { | |||
276 | /** | 274 | /** |
277 | * Action that are toggled on hold (mostly QPopups i guess) | 275 | * Action that are toggled on hold (mostly QPopups i guess) |
278 | */ | 276 | */ |
279 | void BlueBase::startServiceActionHold( QListViewItem * item, const QPoint & point, int column ) { | 277 | void BlueBase::startServiceActionHold( BTListItem * item, const QPoint & point, int column ) { |
280 | 278 | ||
281 | QPopupMenu *menu = new QPopupMenu(); | 279 | QPopupMenu *menu = new QPopupMenu(); |
282 | QPopupMenu *groups = new QPopupMenu(); | 280 | |
283 | int ret=0; | 281 | int ret=0; |
284 | 282 | ||
285 | //QSize s = menu->sizeHint ( ); | 283 | //QSize s = menu->sizeHint ( ); |
286 | 284 | ||
287 | if ( item->text(4) == "device") { | 285 | if ( item->type() == "device") { |
286 | |||
287 | QPopupMenu *groups = new QPopupMenu(); | ||
288 | |||
288 | menu->insertItem( tr("rescan sevices:"), 0); | 289 | menu->insertItem( tr("rescan sevices:"), 0); |
289 | menu->insertItem( tr("to group"), groups , 1); | 290 | menu->insertItem( tr("to group"), groups , 1); |
290 | menu->insertItem( tr("delete"), 2); | 291 | menu->insertItem( tr("delete"), 2); |
291 | } else if ( item->text(4) == "service") { | 292 | |
293 | |||
294 | ret = menu->exec( point , 0); | ||
295 | |||
296 | switch(ret) { | ||
297 | case 0: | ||
298 | break; | ||
299 | case 1: | ||
300 | break; | ||
301 | case 2: | ||
302 | // delete childs too | ||
303 | delete item; | ||
304 | break; | ||
305 | } | ||
306 | delete groups; | ||
307 | |||
308 | } else if ( item->type() == "service") { | ||
292 | menu->insertItem( tr("Test1:"), 0); | 309 | menu->insertItem( tr("Test1:"), 0); |
293 | menu->insertItem( tr("connect"), 1); | 310 | menu->insertItem( tr("connect"), 1); |
294 | menu->insertItem( tr("delete"), 2); | 311 | menu->insertItem( tr("delete"), 2); |
295 | } | ||
296 | 312 | ||
297 | ret = menu->exec( point , 0); | 313 | ret = menu->exec( point , 0); |
298 | 314 | ||
299 | // noch differenzieren | 315 | switch(ret) { |
300 | switch(ret) { | 316 | case 0: |
301 | case 0: | 317 | break; |
302 | break; | 318 | case 1: |
303 | case 1: | 319 | break; |
304 | break; | 320 | case 2: |
305 | case 2: | 321 | // delete childs too |
306 | // delete childs too | 322 | delete item; |
307 | delete item; | 323 | break; |
308 | break; | 324 | } |
309 | } | 325 | } |
310 | 326 | ||
311 | delete menu; | 327 | delete menu; |
312 | delete groups; | ||
313 | } | 328 | } |
314 | 329 | ||
315 | /** | 330 | /** |
316 | * Search and display avail. services for a device (on expand from device listing) | 331 | * Search and display avail. services for a device (on expand from device listing) |
317 | * | 332 | * |
318 | */ | 333 | */ |
319 | void BlueBase::addServicesToDevice( QListViewItem * item ) { | 334 | void BlueBase::addServicesToDevice( BTListItem * item ) { |
320 | 335 | ||
321 | qDebug("addServicesToDevice"); | 336 | qDebug("addServicesToDevice"); |
322 | // row of mac adress text(3) | 337 | // row of mac adress text(3) |
323 | RemoteDevice *device = new RemoteDevice( item->text(3), item->text(0) ); | 338 | RemoteDevice *device = new RemoteDevice( item->mac(), item->name() ); |
324 | 339 | ||
325 | deviceList.insert( item->text(3) , item ); | 340 | deviceList.insert( item->mac() , item ); |
326 | 341 | ||
327 | // and some time later I get a signal foundServices( const QString& device, Services::ValueList ); back | 342 | // and some time later I get a signal foundServices( const QString& device, Services::ValueList ); back |
328 | localDevice->searchServices( *device ); | 343 | localDevice->searchServices( *device ); |
@@ -340,9 +355,9 @@ namespace OpieTooth { | |||
340 | 355 | ||
341 | qDebug("fill services list"); | 356 | qDebug("fill services list"); |
342 | 357 | ||
343 | QMap<QString,QListViewItem*>::Iterator it; | 358 | QMap<QString,BTListItem*>::Iterator it; |
344 | 359 | ||
345 | QListViewItem* deviceItem; | 360 | BTListItem* deviceItem; |
346 | 361 | ||
347 | // get the right devices which requested the search | 362 | // get the right devices which requested the search |
348 | for( it = deviceList.begin(); it != deviceList.end(); ++it ) { | 363 | for( it = deviceList.begin(); it != deviceList.end(); ++it ) { |
@@ -363,17 +378,17 @@ namespace OpieTooth { | |||
363 | 378 | ||
364 | QValueList<OpieTooth::Services>::Iterator it2; | 379 | QValueList<OpieTooth::Services>::Iterator it2; |
365 | 380 | ||
366 | QListViewItem * serviceItem; | 381 | BTListItem * serviceItem; |
367 | 382 | ||
368 | if (!servicesList.isEmpty() ) { | 383 | if (!servicesList.isEmpty() ) { |
369 | // add services | 384 | // add services |
370 | for( it2 = servicesList.begin(); it2 != servicesList.end(); ++it2 ) { | 385 | for( it2 = servicesList.begin(); it2 != servicesList.end(); ++it2 ) { |
371 | serviceItem = new QListViewItem( deviceItem , (*it2).serviceName() ); | 386 | serviceItem = new BTListItem( deviceItem , (*it2).serviceName() , "" , "service" ); |
372 | serviceItem->setText(4, "service"); | 387 | //serviceItem->setText(4, "service"); |
373 | } | 388 | } |
374 | } else { | 389 | } else { |
375 | serviceItem = new QListViewItem( deviceItem , tr("no services found") ); | 390 | serviceItem = new BTListItem( deviceItem , tr("no services found"), "" , "service" ); |
376 | serviceItem->setText(4, "service"); | 391 | //serviceItem->setText(4, "service"); |
377 | } | 392 | } |
378 | } | 393 | } |
379 | 394 | ||
@@ -392,15 +407,39 @@ namespace OpieTooth { | |||
392 | /** | 407 | /** |
393 | * Find out if a device can currently be reached | 408 | * Find out if a device can currently be reached |
394 | */ | 409 | */ |
395 | bool BlueBase::deviceActive( RemoteDevice *device ) { | 410 | void BlueBase::deviceActive( RemoteDevice *device ) { |
396 | |||
397 | // search by mac | ||
398 | localDevice->isAvailable( device->mac() ); | ||
399 | 411 | ||
400 | return true; | 412 | // search by mac, async, gets a signal back |
413 | localDevice->isAvailable( device->mac() ); | ||
401 | } | 414 | } |
402 | 415 | ||
416 | /** | ||
417 | * The signal catcher. Set the avail. status on device. | ||
418 | * @param device - the mac address | ||
419 | * @param connected - if it is avail. or not | ||
420 | */ | ||
421 | void BlueBase::deviceActive( const QString& device, bool connected ) { | ||
422 | |||
423 | qDebug("deviceActive slot"); | ||
403 | 424 | ||
425 | QMap<QString,BTListItem*>::Iterator it; | ||
426 | |||
427 | BTListItem* deviceItem; | ||
428 | |||
429 | // get the right devices which requested the search | ||
430 | for( it = deviceList.begin(); it != deviceList.end(); ++it ) { | ||
431 | if ( it.key() == device ) { | ||
432 | deviceItem = it.data(); | ||
433 | } | ||
434 | } | ||
435 | |||
436 | if ( connected ) { | ||
437 | deviceItem->setPixmap( 1, onPix ); | ||
438 | } else { | ||
439 | deviceItem->setPixmap( 1, offPix ); | ||
440 | } | ||
441 | |||
442 | } | ||
404 | 443 | ||
405 | 444 | ||
406 | 445 | ||