author | zecke <zecke> | 2002-07-12 17:14:58 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-07-12 17:14:58 (UTC) |
commit | 89dce758480cc90502ad14b6c4cf80774e6c1845 (patch) (unidiff) | |
tree | 2ff4e635c8aa86385dfd896084f5cd419efd0840 /noncore/net/opietooth/manager/bluebase.cpp | |
parent | 716211b5e06bb25145cfbcf62a11a7c52c79dde5 (diff) | |
download | opie-89dce758480cc90502ad14b6c4cf80774e6c1845.zip opie-89dce758480cc90502ad14b6c4cf80774e6c1845.tar.gz opie-89dce758480cc90502ad14b6c4cf80774e6c1845.tar.bz2 |
- Connection -> ConnectionState
- Factory adjustments
- Factory function
- Refactoring the QListViewItem derived class
BTListItem
|
- BTDeviceItem for RemoteDevices
|
- BTServiceItem for Services
|
- BTConnectionItem for ConnectionState
- misc bug fixes
Diffstat (limited to 'noncore/net/opietooth/manager/bluebase.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/opietooth/manager/bluebase.cpp | 84 |
1 files changed, 51 insertions, 33 deletions
diff --git a/noncore/net/opietooth/manager/bluebase.cpp b/noncore/net/opietooth/manager/bluebase.cpp index 85c6717..9cfeaa2 100644 --- a/noncore/net/opietooth/manager/bluebase.cpp +++ b/noncore/net/opietooth/manager/bluebase.cpp | |||
@@ -23,95 +23,100 @@ | |||
23 | #include <qlabel.h> | 23 | #include <qlabel.h> |
24 | #include <qpushbutton.h> | 24 | #include <qpushbutton.h> |
25 | #include <qlayout.h> | 25 | #include <qlayout.h> |
26 | #include <qvariant.h> | 26 | #include <qvariant.h> |
27 | #include <qwhatsthis.h> | 27 | #include <qwhatsthis.h> |
28 | #include <qimage.h> | 28 | #include <qimage.h> |
29 | #include <qpixmap.h> | 29 | #include <qpixmap.h> |
30 | #include <qtabwidget.h> | 30 | #include <qtabwidget.h> |
31 | #include <qscrollview.h> | 31 | #include <qscrollview.h> |
32 | #include <qvbox.h> | 32 | #include <qvbox.h> |
33 | #include <qmessagebox.h> | 33 | #include <qmessagebox.h> |
34 | #include <qcheckbox.h> | 34 | #include <qcheckbox.h> |
35 | #include <qlineedit.h> | 35 | #include <qlineedit.h> |
36 | #include <qlistview.h> | 36 | #include <qlistview.h> |
37 | #include <qdir.h> | 37 | #include <qdir.h> |
38 | #include <qpopupmenu.h> | 38 | #include <qpopupmenu.h> |
39 | #include <qtimer.h> | 39 | #include <qtimer.h> |
40 | 40 | ||
41 | #include <qpe/resource.h> | 41 | #include <qpe/resource.h> |
42 | #include <qpe/config.h> | 42 | #include <qpe/config.h> |
43 | 43 | ||
44 | #include <remotedevice.h> | 44 | #include <remotedevice.h> |
45 | #include <services.h> | 45 | #include <services.h> |
46 | 46 | ||
47 | #include "btconnectionitem.h" | ||
48 | |||
47 | using namespace OpieTooth; | 49 | using namespace OpieTooth; |
48 | 50 | ||
49 | BlueBase::BlueBase( QWidget* parent, const char* name, WFlags fl ) | 51 | BlueBase::BlueBase( QWidget* parent, const char* name, WFlags fl ) |
50 | : BluetoothBase( parent, name, fl ) { | 52 | : BluetoothBase( parent, name, fl ) { |
51 | 53 | ||
52 | m_localDevice = new Manager( "hci0" ); | 54 | m_localDevice = new Manager( "hci0" ); |
53 | 55 | ||
54 | connect( PushButton2, SIGNAL( clicked() ), this, SLOT(startScan() ) ); | 56 | connect( PushButton2, SIGNAL( clicked() ), this, SLOT(startScan() ) ); |
55 | connect( configApplyButton, SIGNAL(clicked() ), this, SLOT(applyConfigChanges() ) ); | 57 | connect( configApplyButton, SIGNAL(clicked() ), this, SLOT(applyConfigChanges() ) ); |
56 | // not good since lib is async | 58 | // not good since lib is async |
57 | // connect( ListView2, SIGNAL( expanded ( QListViewItem* ) ), | 59 | // connect( ListView2, SIGNAL( expanded ( QListViewItem* ) ), |
58 | // this, SLOT( addServicesToDevice( QListViewItem * ) ) ); | 60 | // this, SLOT( addServicesToDevice( QListViewItem * ) ) ); |
59 | connect( ListView2, SIGNAL( clicked( QListViewItem* )), | 61 | connect( ListView2, SIGNAL( clicked( QListViewItem* )), |
60 | this, SLOT( startServiceActionClicked( QListViewItem* ) ) ); | 62 | this, SLOT( startServiceActionClicked( QListViewItem* ) ) ); |
61 | connect( ListView2, SIGNAL( rightButtonClicked( QListViewItem *, const QPoint &, int ) ), | 63 | connect( ListView2, SIGNAL( rightButtonClicked( QListViewItem *, const QPoint &, int ) ), |
62 | this, SLOT(startServiceActionHold( QListViewItem *, const QPoint &, int) ) ); | 64 | this, SLOT(startServiceActionHold( QListViewItem *, const QPoint &, int) ) ); |
63 | connect( m_localDevice , SIGNAL( foundServices( const QString& , Services::ValueList ) ), | 65 | connect( m_localDevice , SIGNAL( foundServices( const QString& , Services::ValueList ) ), |
64 | this, SLOT( addServicesToDevice( const QString& , Services::ValueList ) ) ); | 66 | this, SLOT( addServicesToDevice( const QString& , Services::ValueList ) ) ); |
65 | connect( m_localDevice, SIGNAL( available( const QString&, bool ) ), | 67 | connect( m_localDevice, SIGNAL( available( const QString&, bool ) ), |
66 | this, SLOT( deviceActive( const QString& , bool ) ) ); | 68 | this, SLOT( deviceActive( const QString& , bool ) ) ); |
67 | connect( m_localDevice, SIGNAL( connections( Connection::ValueList ) ), | 69 | connect( m_localDevice, SIGNAL( connections( Connection::ValueList ) ), |
68 | this, SLOT( addConnectedDevices( Connection::ValueList ) ) ); | 70 | this, SLOT( addConnectedDevices( Connection::ValueList ) ) ); |
69 | 71 | ||
70 | //Load all icons needed | 72 | //Load all icons needed |
71 | m_offPix = Resource::loadPixmap( "editdelete" ); | 73 | m_offPix = Resource::loadPixmap( "editdelete" ); |
72 | m_onPix = Resource::loadPixmap( "installed" ); | 74 | m_onPix = Resource::loadPixmap( "installed" ); |
73 | 75 | ||
74 | QPalette pal = this->palette(); | 76 | QPalette pal = this->palette(); |
75 | QColor col = pal.color( QPalette::Active, QColorGroup::Background ); | 77 | QColor col = pal.color( QPalette::Active, QColorGroup::Background ); |
76 | pal.setColor( QPalette::Active, QColorGroup::Button, col ); | 78 | pal.setColor( QPalette::Active, QColorGroup::Button, col ); |
77 | pal.setColor( QPalette::Inactive, QColorGroup::Button, col ); | 79 | pal.setColor( QPalette::Inactive, QColorGroup::Button, col ); |
78 | pal.setColor( QPalette::Normal, QColorGroup::Button, col ); | 80 | pal.setColor( QPalette::Normal, QColorGroup::Button, col ); |
79 | pal.setColor( QPalette::Disabled, QColorGroup::Button, col ); | 81 | pal.setColor( QPalette::Disabled, QColorGroup::Button, col ); |
80 | this->setPalette( pal ); | 82 | this->setPalette( pal ); |
81 | 83 | ||
82 | setCaption( tr( "Bluetooth Manager" ) ); | 84 | setCaption( tr( "Bluetooth Manager" ) ); |
83 | 85 | ||
84 | readConfig(); | 86 | readConfig(); |
85 | initGui(); | 87 | initGui(); |
86 | 88 | ||
87 | //TESTING | 89 | //TESTING |
88 | ListView2->setRootIsDecorated(true); | 90 | ListView2->setRootIsDecorated(true); |
89 | 91 | ||
90 | BTListItem *topLV2 = new BTListItem( ListView2, "Siemens S45", "", "device" ); | 92 | BTDeviceItem *topLV2 = new BTDeviceItem( ListView2, RemoteDevice("xx:", "Siemens S45" ) ); |
91 | topLV2->setPixmap( 1, m_onPix ); | 93 | topLV2->setPixmap( 1, m_onPix ); |
92 | (void) new BTListItem( topLV2, "Serial" ,"", "service" ); | 94 | Services s1; |
93 | (void) new BTListItem( topLV2, "BlueNiC" , "", "service" ); | 95 | s1.setServiceName( "Serial" ); |
96 | (void) new BTServiceItem( topLV2, s1 ); | ||
97 | s1.setServiceName( "BlueNic" ); | ||
98 | (void) new BTServiceItem( topLV2, s1 ); | ||
94 | 99 | ||
95 | writeToHciConfig(); | 100 | writeToHciConfig(); |
96 | // search conncetions | 101 | // search conncetions |
97 | addConnectedDevices(); | 102 | addConnectedDevices(); |
98 | m_iconLoader = new BTIconLoader(); | 103 | m_iconLoader = new BTIconLoader(); |
99 | } | 104 | } |
100 | 105 | ||
101 | /** | 106 | /** |
102 | * Reads all options from the config file | 107 | * Reads all options from the config file |
103 | */ | 108 | */ |
104 | void BlueBase::readConfig() { | 109 | void BlueBase::readConfig() { |
105 | 110 | ||
106 | Config cfg( "bluetoothmanager" ); | 111 | Config cfg( "bluetoothmanager" ); |
107 | cfg.setGroup( "bluezsettings" ); | 112 | cfg.setGroup( "bluezsettings" ); |
108 | 113 | ||
109 | m_deviceName = cfg.readEntry( "name" , "No name" ); // name the device should identify with | 114 | m_deviceName = cfg.readEntry( "name" , "No name" ); // name the device should identify with |
110 | m_defaultPasskey = cfg.readEntryCrypt( "passkey" , "" ); // <- hmm, look up how good the trolls did that, maybe too weak | 115 | m_defaultPasskey = cfg.readEntryCrypt( "passkey" , "" ); // <- hmm, look up how good the trolls did that, maybe too weak |
111 | m_useEncryption = cfg.readBoolEntry( "useEncryption" , TRUE ); | 116 | m_useEncryption = cfg.readBoolEntry( "useEncryption" , TRUE ); |
112 | m_enableAuthentification = cfg.readBoolEntry( "enableAuthentification" , TRUE ); | 117 | m_enableAuthentification = cfg.readBoolEntry( "enableAuthentification" , TRUE ); |
113 | m_enablePagescan = cfg.readBoolEntry( "enablePagescan" , TRUE ); | 118 | m_enablePagescan = cfg.readBoolEntry( "enablePagescan" , TRUE ); |
114 | m_enableInquiryscan = cfg.readBoolEntry( "enableInquiryscan" , TRUE ); | 119 | m_enableInquiryscan = cfg.readBoolEntry( "enableInquiryscan" , TRUE ); |
115 | } | 120 | } |
116 | 121 | ||
117 | /** | 122 | /** |
@@ -163,55 +168,61 @@ using namespace OpieTooth; | |||
163 | // cut .conf of to get the mac and also read the name entry in it. | 168 | // cut .conf of to get the mac and also read the name entry in it. |
164 | 169 | ||
165 | for ( QStringList::Iterator it = devicesFileList.begin(); it != devicesFileList.end(); ++it ) { | 170 | for ( QStringList::Iterator it = devicesFileList.begin(); it != devicesFileList.end(); ++it ) { |
166 | 171 | ||
167 | QString name; | 172 | QString name; |
168 | QString mac; | 173 | QString mac; |
169 | qDebug((*it).latin1() ); | 174 | qDebug((*it).latin1() ); |
170 | Config conf((*it)); | 175 | Config conf((*it)); |
171 | conf.setGroup("Info"); | 176 | conf.setGroup("Info"); |
172 | name = conf.readEntry("name", "Error"); | 177 | name = conf.readEntry("name", "Error"); |
173 | qDebug("MAC: " + mac); | 178 | qDebug("MAC: " + mac); |
174 | qDebug("NAME: " + name); | 179 | qDebug("NAME: " + name); |
175 | RemoteDevice currentDevice( mac , name ); | 180 | RemoteDevice currentDevice( mac , name ); |
176 | loadedDevices.append( currentDevice ); | 181 | loadedDevices.append( currentDevice ); |
177 | } | 182 | } |
178 | addSearchedDevices( loadedDevices ); | 183 | addSearchedDevices( loadedDevices ); |
179 | } | 184 | } |
180 | 185 | ||
181 | /** | 186 | /** |
182 | * Write the list of allready known devices | 187 | * Write the list of allready known devices |
183 | * | 188 | * |
184 | */ | 189 | */ |
185 | void BlueBase::writeSavedDevices() { | 190 | void BlueBase::writeSavedDevices() { |
186 | QListViewItemIterator it( ListView2 ); | 191 | QListViewItemIterator it( ListView2 ); |
192 | BTListItem* item; | ||
193 | BTDeviceItem* device; | ||
187 | 194 | ||
188 | for ( ; it.current(); ++it ) { | 195 | for ( ; it.current(); ++it ) { |
196 | item = (BTListItem*)it.current(); | ||
197 | if(item->typeId() != BTListItem::Device ) | ||
198 | continue; | ||
199 | device = (BTDeviceItem*)item; | ||
189 | // seperate config file for each device, to store more information in future. | 200 | // seperate config file for each device, to store more information in future. |
190 | qDebug( "/Settings/bluetooth/" + (((BTListItem*)it.current())->mac()) + ".conf"); | 201 | qDebug( "/Settings/bluetooth/" + device->mac() + ".conf"); |
191 | Config conf( QDir::homeDirPath() + "/Settings/bluetooth/" + (((BTListItem*)it.current())->mac()) + ".conf", Config::File ); | 202 | Config conf( QDir::homeDirPath() + "/Settings/bluetooth/" + device->mac() + ".conf", Config::File ); |
192 | conf.setGroup( "Info" ); | 203 | conf.setGroup( "Info" ); |
193 | conf.writeEntry( "name", ((BTListItem*)it.current())->name() ); | 204 | conf.writeEntry( "name", device->name() ); |
194 | } | 205 | } |
195 | } | 206 | } |
196 | 207 | ||
197 | 208 | ||
198 | /** | 209 | /** |
199 | * Set up the gui | 210 | * Set up the gui |
200 | */ | 211 | */ |
201 | void BlueBase::initGui() { | 212 | void BlueBase::initGui() { |
202 | StatusLabel->setText( status() ); // maybe move it to getStatus() | 213 | StatusLabel->setText( status() ); // maybe move it to getStatus() |
203 | cryptCheckBox->setChecked( m_useEncryption ); | 214 | cryptCheckBox->setChecked( m_useEncryption ); |
204 | authCheckBox->setChecked( m_enableAuthentification ); | 215 | authCheckBox->setChecked( m_enableAuthentification ); |
205 | pagescanCheckBox->setChecked( m_enablePagescan ); | 216 | pagescanCheckBox->setChecked( m_enablePagescan ); |
206 | inquiryscanCheckBox->setChecked( m_enableInquiryscan ); | 217 | inquiryscanCheckBox->setChecked( m_enableInquiryscan ); |
207 | deviceNameLine->setText( m_deviceName ); | 218 | deviceNameLine->setText( m_deviceName ); |
208 | passkeyLine->setText( m_defaultPasskey ); | 219 | passkeyLine->setText( m_defaultPasskey ); |
209 | // set info tab | 220 | // set info tab |
210 | setInfo(); | 221 | setInfo(); |
211 | } | 222 | } |
212 | 223 | ||
213 | 224 | ||
214 | /** | 225 | /** |
215 | * Get the status informations and returns it | 226 | * Get the status informations and returns it |
216 | * @return QString the status informations gathered | 227 | * @return QString the status informations gathered |
217 | */ | 228 | */ |
@@ -224,53 +235,54 @@ using namespace OpieTooth; | |||
224 | } | 235 | } |
225 | 236 | ||
226 | 237 | ||
227 | /** | 238 | /** |
228 | * Read the current values from the gui and invoke writeConfig() | 239 | * Read the current values from the gui and invoke writeConfig() |
229 | */ | 240 | */ |
230 | void BlueBase::applyConfigChanges() { | 241 | void BlueBase::applyConfigChanges() { |
231 | m_deviceName = deviceNameLine->text(); | 242 | m_deviceName = deviceNameLine->text(); |
232 | m_defaultPasskey = passkeyLine->text(); | 243 | m_defaultPasskey = passkeyLine->text(); |
233 | m_useEncryption = cryptCheckBox->isChecked(); | 244 | m_useEncryption = cryptCheckBox->isChecked(); |
234 | m_enableAuthentification = authCheckBox->isChecked(); | 245 | m_enableAuthentification = authCheckBox->isChecked(); |
235 | m_enablePagescan = pagescanCheckBox->isChecked(); | 246 | m_enablePagescan = pagescanCheckBox->isChecked(); |
236 | m_enableInquiryscan = inquiryscanCheckBox->isChecked(); | 247 | m_enableInquiryscan = inquiryscanCheckBox->isChecked(); |
237 | 248 | ||
238 | writeConfig(); | 249 | writeConfig(); |
239 | 250 | ||
240 | QMessageBox::information( this, tr("Test") , tr("Changes were applied.") ); | 251 | QMessageBox::information( this, tr("Test") , tr("Changes were applied.") ); |
241 | } | 252 | } |
242 | 253 | ||
243 | /** | 254 | /** |
244 | * Add fresh found devices from scan dialog to the listing | 255 | * Add fresh found devices from scan dialog to the listing |
245 | * | 256 | * |
246 | */ | 257 | */ |
247 | void BlueBase::addSearchedDevices( const QValueList<RemoteDevice> &newDevices ) { | 258 | void BlueBase::addSearchedDevices( const QValueList<RemoteDevice> &newDevices ) { |
248 | BTListItem * deviceItem; | 259 | BTDeviceItem * deviceItem; |
249 | QValueList<RemoteDevice>::ConstIterator it; | 260 | QValueList<RemoteDevice>::ConstIterator it; |
250 | 261 | ||
251 | for( it = newDevices.begin(); it != newDevices.end() ; ++it ) { | 262 | for( it = newDevices.begin(); it != newDevices.end() ; ++it ) { |
252 | deviceItem = new BTListItem( ListView2 , (*it).name(), (*it).mac(), "device" ); | 263 | |
264 | deviceItem = new BTDeviceItem( ListView2 , (*it) ); | ||
253 | deviceItem->setExpandable ( true ); | 265 | deviceItem->setExpandable ( true ); |
254 | 266 | ||
255 | // look if device is avail. atm, async | 267 | // look if device is avail. atm, async |
256 | deviceActive( (*it) ); | 268 | deviceActive( (*it) ); |
257 | 269 | ||
258 | // ggf auch hier? | 270 | // ggf auch hier? |
259 | addServicesToDevice( deviceItem ); | 271 | addServicesToDevice( deviceItem ); |
260 | } | 272 | } |
261 | } | 273 | } |
262 | 274 | ||
263 | 275 | ||
264 | /** | 276 | /** |
265 | * Action that is toggled on entrys on click | 277 | * Action that is toggled on entrys on click |
266 | */ | 278 | */ |
267 | void BlueBase::startServiceActionClicked( QListViewItem */*item*/ ) { | 279 | void BlueBase::startServiceActionClicked( QListViewItem */*item*/ ) { |
268 | } | 280 | } |
269 | 281 | ||
270 | /** | 282 | /** |
271 | * Action that are toggled on hold (mostly QPopups i guess) | 283 | * Action that are toggled on hold (mostly QPopups i guess) |
272 | */ | 284 | */ |
273 | void BlueBase::startServiceActionHold( QListViewItem * item, const QPoint & point, int /*column*/ ) { | 285 | void BlueBase::startServiceActionHold( QListViewItem * item, const QPoint & point, int /*column*/ ) { |
274 | 286 | ||
275 | QPopupMenu *menu = new QPopupMenu(); | 287 | QPopupMenu *menu = new QPopupMenu(); |
276 | int ret=0; | 288 | int ret=0; |
@@ -305,148 +317,154 @@ void BlueBase::startServiceActionHold( QListViewItem * item, const QPoint & poin | |||
305 | menu->insertItem( tr("Test1:"), 0); | 317 | menu->insertItem( tr("Test1:"), 0); |
306 | menu->insertItem( tr("connect"), 1); | 318 | menu->insertItem( tr("connect"), 1); |
307 | menu->insertItem( tr("delete"), 2); | 319 | menu->insertItem( tr("delete"), 2); |
308 | 320 | ||
309 | ret = menu->exec( point , 0); | 321 | ret = menu->exec( point , 0); |
310 | 322 | ||
311 | switch(ret) { | 323 | switch(ret) { |
312 | case 0: | 324 | case 0: |
313 | break; | 325 | break; |
314 | case 1: | 326 | case 1: |
315 | break; | 327 | break; |
316 | case 2: | 328 | case 2: |
317 | // delete childs too | 329 | // delete childs too |
318 | delete item; | 330 | delete item; |
319 | break; | 331 | break; |
320 | } | 332 | } |
321 | } | 333 | } |
322 | delete menu; | 334 | delete menu; |
323 | } | 335 | } |
324 | 336 | ||
325 | /** | 337 | /** |
326 | * Search and display avail. services for a device (on expand from device listing) | 338 | * Search and display avail. services for a device (on expand from device listing) |
327 | * | 339 | * |
328 | */ | 340 | */ |
329 | void BlueBase::addServicesToDevice( BTListItem * item ) { | 341 | void BlueBase::addServicesToDevice( BTDeviceItem * item ) { |
330 | qDebug("addServicesToDevice"); | 342 | qDebug("addServicesToDevice"); |
331 | // row of mac adress text(3) | 343 | // row of mac adress text(3) |
332 | RemoteDevice device( item->mac(), item->name() ); | 344 | RemoteDevice device = item->remoteDevice(); |
333 | m_deviceList.insert( item->mac() , item ); | 345 | m_deviceList.insert( item->mac() , item ); |
334 | // and some time later I get a signal foundServices( const QString& device, Services::ValueList ); back | 346 | // and some time later I get a signal foundServices( const QString& device, Services::ValueList ); back |
335 | m_localDevice->searchServices( device ); | 347 | m_localDevice->searchServices( device ); |
336 | } | 348 | } |
337 | 349 | ||
338 | 350 | ||
339 | /** | 351 | /** |
340 | * Overloaded. This one it the one that is connected to the foundServices signal | 352 | * Overloaded. This one it the one that is connected to the foundServices signal |
341 | * @param device the mac address of the remote device | 353 | * @param device the mac address of the remote device |
342 | * @param servicesList the list with the service the device has. | 354 | * @param servicesList the list with the service the device has. |
343 | */ | 355 | */ |
344 | void BlueBase::addServicesToDevice( const QString& device, Services::ValueList servicesList ) { | 356 | void BlueBase::addServicesToDevice( const QString& device, Services::ValueList servicesList ) { |
345 | qDebug("fill services list"); | 357 | qDebug("fill services list"); |
346 | 358 | ||
347 | QMap<QString,BTListItem*>::Iterator it; | 359 | QMap<QString,BTDeviceItem*>::Iterator it; |
348 | BTListItem* deviceItem = 0; | 360 | BTDeviceItem* deviceItem = 0; |
349 | 361 | ||
350 | // get the right devices which requested the search | 362 | // get the right devices which requested the search |
351 | for( it = m_deviceList.begin(); it != m_deviceList.end(); ++it ) { | 363 | it = m_deviceList.find( device ); |
352 | if ( it.key() == device ) { | 364 | if( it == m_deviceList.end() ) |
353 | deviceItem = it.data(); | 365 | return; |
354 | } | 366 | deviceItem = it.data(); |
355 | } | ||
356 | 367 | ||
357 | QValueList<OpieTooth::Services>::Iterator it2; | 368 | QValueList<OpieTooth::Services>::Iterator it2; |
358 | BTListItem * serviceItem; | 369 | BTServiceItem * serviceItem; |
359 | 370 | ||
360 | if (!servicesList.isEmpty() ) { | 371 | if (!servicesList.isEmpty() ) { |
361 | // add services | 372 | // add services |
362 | for( it2 = servicesList.begin(); it2 != servicesList.end(); ++it2 ) { | 373 | for( it2 = servicesList.begin(); it2 != servicesList.end(); ++it2 ) { |
363 | serviceItem = new BTListItem( deviceItem , (*it2).serviceName() , "" , "service" ); | 374 | serviceItem = new BTServiceItem( deviceItem , (*it2) ); |
364 | serviceItem->setPixmap( 0, m_iconLoader->serviceIcon( (*it2).classIdList() ) ); | 375 | serviceItem->setPixmap( 0, m_iconLoader->serviceIcon( (*it2).classIdList() ) ); |
365 | } | 376 | } |
366 | } else { | 377 | } else { |
367 | serviceItem = new BTListItem( deviceItem , tr("no services found"), "" , "service" ); | 378 | Services s1; |
379 | s1.setServiceName( tr("no serives found") ); | ||
380 | serviceItem = new BTServiceItem( deviceItem, s1 ); | ||
368 | } | 381 | } |
382 | // now remove them from the list | ||
383 | m_deviceList.remove( it ); | ||
369 | } | 384 | } |
370 | 385 | ||
371 | 386 | ||
372 | /** | 387 | /** |
373 | * Add the existing connections (pairs) to the connections tab. | 388 | * Add the existing connections (pairs) to the connections tab. |
374 | * This one triggers the search | 389 | * This one triggers the search |
375 | */ | 390 | */ |
376 | void BlueBase::addConnectedDevices() { | 391 | void BlueBase::addConnectedDevices() { |
377 | m_localDevice->searchConnections(); | 392 | m_localDevice->searchConnections(); |
378 | } | 393 | } |
379 | 394 | ||
380 | 395 | ||
381 | void BlueBase::addConnectedDevices( Connection::ValueList connectionList ) { | 396 | void BlueBase::addConnectedDevices( ConnectionState::ValueList connectionList ) { |
382 | QValueList<OpieTooth::Connection>::Iterator it; | 397 | QValueList<OpieTooth::ConnectionState>::Iterator it; |
383 | BTListItem * connectionItem; | 398 | BTConnectionItem * connectionItem; |
384 | 399 | ||
385 | if ( !connectionList.isEmpty() ) { | 400 | if ( !connectionList.isEmpty() ) { |
386 | 401 | ||
387 | for (it = connectionList.begin(); it != connectionList.end(); ++it) { | 402 | for (it = connectionList.begin(); it != connectionList.end(); ++it) { |
388 | connectionItem = new BTListItem( ListView4 , (*it).mac() , (*it).mac() , "connection" ); | 403 | connectionItem = new BTConnectionItem( ListView4 , (*it) ); |
389 | } | 404 | } |
390 | } else { | 405 | } else { |
391 | connectionItem = new BTListItem( ListView4 , tr("No connections found"), "", "connection" ); | 406 | ConnectionState con; |
407 | con.setMac( tr("No connections found") ); | ||
408 | connectionItem = new BTConnectionItem( ListView4 , con ); | ||
392 | } | 409 | } |
393 | 410 | ||
394 | // recall connection search after some time | 411 | // recall connection search after some time |
395 | QTimer::singleShot( 20000, this, SLOT( addConnectedDevices() ) ); | 412 | QTimer::singleShot( 20000, this, SLOT( addConnectedDevices() ) ); |
396 | } | 413 | } |
397 | 414 | ||
398 | /** | 415 | /** |
399 | * Find out if a device can currently be reached | 416 | * Find out if a device can currently be reached |
400 | */ | 417 | */ |
401 | void BlueBase::deviceActive( const RemoteDevice &device ) { | 418 | void BlueBase::deviceActive( const RemoteDevice &device ) { |
402 | // search by mac, async, gets a signal back | 419 | // search by mac, async, gets a signal back |
420 | // We should have a BTDeviceItem there or where does it get added to the map -zecke | ||
403 | m_localDevice->isAvailable( device.mac() ); | 421 | m_localDevice->isAvailable( device.mac() ); |
404 | } | 422 | } |
405 | 423 | ||
406 | /** | 424 | /** |
407 | * The signal catcher. Set the avail. status on device. | 425 | * The signal catcher. Set the avail. status on device. |
408 | * @param device - the mac address | 426 | * @param device - the mac address |
409 | * @param connected - if it is avail. or not | 427 | * @param connected - if it is avail. or not |
410 | */ | 428 | */ |
411 | void BlueBase::deviceActive( const QString& device, bool connected ) { | 429 | void BlueBase::deviceActive( const QString& device, bool connected ) { |
412 | qDebug("deviceActive slot"); | 430 | qDebug("deviceActive slot"); |
413 | 431 | ||
414 | QMap<QString,BTListItem*>::Iterator it; | 432 | QMap<QString,BTDeviceItem*>::Iterator it; |
415 | BTListItem* deviceItem = 0; | 433 | |
434 | it = m_deviceList.find( device ); | ||
435 | if( it == m_deviceList.end() ) | ||
436 | return; | ||
437 | |||
438 | BTDeviceItem* deviceItem = it.data(); | ||
416 | 439 | ||
417 | // get the right devices which requested the search | ||
418 | for( it = m_deviceList.begin(); it != m_deviceList.end(); ++it ) { | ||
419 | if ( it.key() == device ) { | ||
420 | deviceItem = it.data(); | ||
421 | } | ||
422 | } | ||
423 | 440 | ||
424 | if ( connected ) { | 441 | if ( connected ) { |
425 | deviceItem->setPixmap( 1, m_onPix ); | 442 | deviceItem->setPixmap( 1, m_onPix ); |
426 | } else { | 443 | } else { |
427 | deviceItem->setPixmap( 1, m_offPix ); | 444 | deviceItem->setPixmap( 1, m_offPix ); |
428 | } | 445 | } |
446 | m_deviceList.remove( it ); | ||
429 | } | 447 | } |
430 | 448 | ||
431 | /** | 449 | /** |
432 | * Open the "scan for devices" dialog | 450 | * Open the "scan for devices" dialog |
433 | */ | 451 | */ |
434 | void BlueBase::startScan() { | 452 | void BlueBase::startScan() { |
435 | ScanDialog *scan = new ScanDialog( this, "ScanDialog", | 453 | ScanDialog *scan = new ScanDialog( this, "ScanDialog", |
436 | true, WDestructiveClose ); | 454 | true, WDestructiveClose ); |
437 | QObject::connect( scan, SIGNAL( selectedDevices( const QValueList<RemoteDevice>& ) ), | 455 | QObject::connect( scan, SIGNAL( selectedDevices( const QValueList<RemoteDevice>& ) ), |
438 | this, SLOT( addSearchedDevices( const QValueList<RemoteDevice>& ) ) ); | 456 | this, SLOT( addSearchedDevices( const QValueList<RemoteDevice>& ) ) ); |
439 | 457 | ||
440 | scan->showMaximized(); | 458 | scan->showMaximized(); |
441 | } | 459 | } |
442 | 460 | ||
443 | 461 | ||
444 | /** | 462 | /** |
445 | * Set the informations about the local device in information Tab | 463 | * Set the informations about the local device in information Tab |
446 | */ | 464 | */ |
447 | void BlueBase::setInfo() { | 465 | void BlueBase::setInfo() { |
448 | StatusLabel->setText( status() ); | 466 | StatusLabel->setText( status() ); |
449 | } | 467 | } |
450 | 468 | ||
451 | /** | 469 | /** |
452 | * Decontructor | 470 | * Decontructor |