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 | |||
@@ -50,56 +50,55 @@ namespace OpieTooth { | |||
50 | : BluetoothBase( parent, name, fl ) { | 50 | : BluetoothBase( parent, name, fl ) { |
51 | 51 | ||
52 | localDevice = new Manager( "hci0" ); | 52 | localDevice = new Manager( "hci0" ); |
53 | 53 | ||
54 | connect( PushButton2, SIGNAL( clicked() ), this, SLOT(startScan() ) ); | 54 | connect( PushButton2, SIGNAL( clicked() ), this, SLOT(startScan() ) ); |
55 | connect( configApplyButton, SIGNAL(clicked() ), this, SLOT(applyConfigChanges() ) ); | 55 | connect( configApplyButton, SIGNAL(clicked() ), this, SLOT(applyConfigChanges() ) ); |
56 | // not good since lib is async | 56 | // not good since lib is async |
57 | // connect( ListView2, SIGNAL( expanded ( QListViewItem* ) ), | 57 | // connect( ListView2, SIGNAL( expanded ( QListViewItem* ) ), |
58 | // this, SLOT( addServicesToDevice( QListViewItem * ) ) ); | 58 | // this, SLOT( addServicesToDevice( QListViewItem * ) ) ); |
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 | ||
70 | offPix = Resource::loadPixmap( "editdelete" ); | 70 | offPix = Resource::loadPixmap( "editdelete" ); |
71 | onPix = Resource::loadPixmap( "installed" ); | 71 | onPix = Resource::loadPixmap( "installed" ); |
72 | 72 | ||
73 | QPalette pal = this->palette(); | 73 | QPalette pal = this->palette(); |
74 | QColor col = pal.color( QPalette::Active, QColorGroup::Background ); | 74 | QColor col = pal.color( QPalette::Active, QColorGroup::Background ); |
75 | pal.setColor( QPalette::Active, QColorGroup::Button, col ); | 75 | pal.setColor( QPalette::Active, QColorGroup::Button, col ); |
76 | pal.setColor( QPalette::Inactive, QColorGroup::Button, col ); | 76 | pal.setColor( QPalette::Inactive, QColorGroup::Button, col ); |
77 | pal.setColor( QPalette::Normal, QColorGroup::Button, col ); | 77 | pal.setColor( QPalette::Normal, QColorGroup::Button, col ); |
78 | pal.setColor( QPalette::Disabled, QColorGroup::Button, col ); | 78 | pal.setColor( QPalette::Disabled, QColorGroup::Button, col ); |
79 | this->setPalette( pal ); | 79 | this->setPalette( pal ); |
80 | 80 | ||
81 | setCaption( tr( "Bluetooth Manager" ) ); | 81 | setCaption( tr( "Bluetooth Manager" ) ); |
82 | 82 | ||
83 | readConfig(); | 83 | readConfig(); |
84 | initGui(); | 84 | initGui(); |
85 | 85 | ||
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 | ||
97 | /** | 96 | /** |
98 | * Reads all options from the config file | 97 | * Reads all options from the config file |
99 | */ | 98 | */ |
100 | void BlueBase::readConfig() { | 99 | void BlueBase::readConfig() { |
101 | 100 | ||
102 | Config cfg( "bluetoothmanager" ); | 101 | Config cfg( "bluetoothmanager" ); |
103 | cfg.setGroup( "bluezsettings" ); | 102 | cfg.setGroup( "bluezsettings" ); |
104 | 103 | ||
105 | 104 | ||
@@ -162,28 +161,29 @@ namespace OpieTooth { | |||
162 | 161 | ||
163 | /** | 162 | /** |
164 | * Write the list of allready known devices | 163 | * Write the list of allready known devices |
165 | * | 164 | * |
166 | */ | 165 | */ |
167 | void BlueBase::writeSavedDevices() { | 166 | void BlueBase::writeSavedDevices() { |
168 | 167 | ||
169 | QListViewItemIterator it( ListView2 ); | 168 | QListViewItemIterator it( ListView2 ); |
170 | 169 | ||
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 | ||
181 | 181 | ||
182 | /** | 182 | /** |
183 | * Set up the gui | 183 | * Set up the gui |
184 | */ | 184 | */ |
185 | void BlueBase::initGui() { | 185 | void BlueBase::initGui() { |
186 | 186 | ||
187 | StatusLabel->setText( getStatus() ); // maybe move it to getStatus() | 187 | StatusLabel->setText( getStatus() ); // maybe move it to getStatus() |
188 | 188 | ||
189 | cryptCheckBox->setChecked( useEncryption ); | 189 | cryptCheckBox->setChecked( useEncryption ); |
@@ -229,187 +229,226 @@ namespace OpieTooth { | |||
229 | box->setText( tr( "Changes applied" ) ); | 229 | box->setText( tr( "Changes applied" ) ); |
230 | box->show(); | 230 | box->show(); |
231 | // falls nötig hcid killhupen - die funktionalität adden | 231 | // falls nötig hcid killhupen - die funktionalität adden |
232 | } | 232 | } |
233 | 233 | ||
234 | 234 | ||
235 | /** | 235 | /** |
236 | * Add fresh found devices from scan dialog to the listing | 236 | * Add fresh found devices from scan dialog to the listing |
237 | * | 237 | * |
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 | ||
245 | for( ; it.current() ; ++it ) { | 245 | for( ; it.current() ; ++it ) { |
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 ); |
264 | } | 262 | } |
265 | } | 263 | } |
266 | 264 | ||
267 | 265 | ||
268 | /** | 266 | /** |
269 | * Action that is toggled on entrys on click | 267 | * Action that is toggled on entrys on click |
270 | */ | 268 | */ |
271 | void BlueBase::startServiceActionClicked( QListViewItem *item ) { | 269 | void BlueBase::startServiceActionClicked( QListViewItem *item ) { |
272 | 270 | ||
273 | 271 | ||
274 | } | 272 | } |
275 | 273 | ||
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 ); |
329 | 344 | ||
330 | // delete | 345 | // delete |
331 | } | 346 | } |
332 | 347 | ||
333 | 348 | ||
334 | /** | 349 | /** |
335 | * Overloaded. This one it the one that is connected to the foundServices signal | 350 | * Overloaded. This one it the one that is connected to the foundServices signal |
336 | * @param device the mac address of the remote device | 351 | * @param device the mac address of the remote device |
337 | * @param servicesList the list with the service the device has. | 352 | * @param servicesList the list with the service the device has. |
338 | */ | 353 | */ |
339 | void BlueBase::addServicesToDevice( const QString& device, Services::ValueList servicesList ) { | 354 | void BlueBase::addServicesToDevice( const QString& device, Services::ValueList servicesList ) { |
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 ) { |
349 | if ( it.key() == device ) { | 364 | if ( it.key() == device ) { |
350 | deviceItem = it.data(); | 365 | deviceItem = it.data(); |
351 | } | 366 | } |
352 | } | 367 | } |
353 | 368 | ||
354 | 369 | ||
355 | // empty entries | 370 | // empty entries |
356 | // QListViewItem * myChild = deviceItem->firstChild(); | 371 | // QListViewItem * myChild = deviceItem->firstChild(); |
357 | //QList<QListViewItem*> tmpList; | 372 | //QList<QListViewItem*> tmpList; |
358 | //while( myChild ) { | 373 | //while( myChild ) { |
359 | // tmpList.append(myChild); | 374 | // tmpList.append(myChild); |
360 | // myChild = myChild->nextSibling(); | 375 | // myChild = myChild->nextSibling(); |
361 | // } | 376 | // } |
362 | 377 | ||
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 | ||
380 | 395 | ||
381 | /** | 396 | /** |
382 | * Add the existing connections (pairs) to the connections tab. | 397 | * Add the existing connections (pairs) to the connections tab. |
383 | * | 398 | * |
384 | */ | 399 | */ |
385 | void BlueBase::addConnectedDevices() { | 400 | void BlueBase::addConnectedDevices() { |
386 | 401 | ||
387 | 402 | ||
388 | //mac address | 403 | //mac address |
389 | 404 | ||
390 | } | 405 | } |
391 | 406 | ||
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 | ||
407 | /** | 446 | /** |
408 | * Open the "scan for devices" dialog | 447 | * Open the "scan for devices" dialog |
409 | */ | 448 | */ |
410 | void BlueBase::startScan() { | 449 | void BlueBase::startScan() { |
411 | 450 | ||
412 | ScanDialog *scan = new ScanDialog( this, "", true); | 451 | ScanDialog *scan = new ScanDialog( this, "", true); |
413 | QObject::connect( scan, SIGNAL( selectedDevices( QList<RemoteDevice>& ) ), | 452 | QObject::connect( scan, SIGNAL( selectedDevices( QList<RemoteDevice>& ) ), |
414 | this, SLOT( addSearchedDevices( QList<RemoteDevice>& ) ) ); | 453 | this, SLOT( addSearchedDevices( QList<RemoteDevice>& ) ) ); |
415 | 454 | ||