summaryrefslogtreecommitdiff
authorharlekin <harlekin>2003-03-06 23:17:10 (UTC)
committer harlekin <harlekin>2003-03-06 23:17:10 (UTC)
commit78a2773ef477a4ab7327350e5f1f6c07428ad8a4 (patch) (unidiff)
treed93e516530f66c0b15260c283d21481e92cfeb18
parent94a385f5f6868e930361dc8d25d3e87eacd20feb (diff)
downloadopie-78a2773ef477a4ab7327350e5f1f6c07428ad8a4.zip
opie-78a2773ef477a4ab7327350e5f1f6c07428ad8a4.tar.gz
opie-78a2773ef477a4ab7327350e5f1f6c07428ad8a4.tar.bz2
remove previous found services on rescan
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/opietooth/manager/bluebase.cpp20
1 files changed, 16 insertions, 4 deletions
diff --git a/noncore/net/opietooth/manager/bluebase.cpp b/noncore/net/opietooth/manager/bluebase.cpp
index 5c5f069..8b15c4f 100644
--- a/noncore/net/opietooth/manager/bluebase.cpp
+++ b/noncore/net/opietooth/manager/bluebase.cpp
@@ -1,540 +1,552 @@
1/* 1/*
2 * bluebase.cpp * 2 * bluebase.cpp *
3 * --------------------- 3 * ---------------------
4 * 4 *
5 * copyright : (c) 2002 by Maximilian Reiß 5 * copyright : (c) 2002 by Maximilian Reiß
6 * email : max.reiss@gmx.de 6 * email : max.reiss@gmx.de
7 * 7 *
8 */ 8 */
9/*************************************************************************** 9/***************************************************************************
10 * * 10 * *
11 * This program is free software; you can redistribute it and/or modify * 11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by * 12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or * 13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. * 14 * (at your option) any later version. *
15 * * 15 * *
16 ***************************************************************************/ 16 ***************************************************************************/
17 17
18#include "bluebase.h" 18#include "bluebase.h"
19#include "scandialog.h" 19#include "scandialog.h"
20#include "hciconfwrapper.h" 20#include "hciconfwrapper.h"
21#include "devicehandler.h" 21#include "devicehandler.h"
22#include "btconnectionitem.h" 22#include "btconnectionitem.h"
23 23
24#include <remotedevice.h> 24#include <remotedevice.h>
25#include <services.h> 25#include <services.h>
26 26
27#include <stdlib.h> 27#include <stdlib.h>
28 28
29#include <qframe.h> 29#include <qframe.h>
30#include <qlabel.h> 30#include <qlabel.h>
31#include <qpushbutton.h> 31#include <qpushbutton.h>
32#include <qlayout.h> 32#include <qlayout.h>
33#include <qvariant.h> 33#include <qvariant.h>
34#include <qimage.h> 34#include <qimage.h>
35#include <qpixmap.h> 35#include <qpixmap.h>
36#include <qtabwidget.h> 36#include <qtabwidget.h>
37#include <qscrollview.h> 37#include <qscrollview.h>
38#include <qvbox.h> 38#include <qvbox.h>
39#include <qmessagebox.h> 39#include <qmessagebox.h>
40#include <qcheckbox.h> 40#include <qcheckbox.h>
41#include <qlineedit.h> 41#include <qlineedit.h>
42#include <qlistview.h> 42#include <qlistview.h>
43#include <qdir.h> 43#include <qdir.h>
44#include <qpopupmenu.h> 44#include <qpopupmenu.h>
45#include <qtimer.h> 45#include <qtimer.h>
46#include <qlist.h>
46 47
47#include <qpe/qpeapplication.h> 48#include <qpe/qpeapplication.h>
48#include <qpe/resource.h> 49#include <qpe/resource.h>
49#include <qpe/config.h> 50#include <qpe/config.h>
50 51
51 52
52using namespace OpieTooth; 53using namespace OpieTooth;
53 54
54BlueBase::BlueBase( QWidget* parent, const char* name, WFlags fl ) 55BlueBase::BlueBase( QWidget* parent, const char* name, WFlags fl )
55 : BluetoothBase( parent, name, fl ) { 56 : BluetoothBase( parent, name, fl ) {
56 57
57 m_localDevice = new Manager( "hci0" ); 58 m_localDevice = new Manager( "hci0" );
58 59
59 connect( PushButton2, SIGNAL( clicked() ), this, SLOT(startScan() ) ); 60 connect( PushButton2, SIGNAL( clicked() ), this, SLOT(startScan() ) );
60 connect( configApplyButton, SIGNAL(clicked() ), this, SLOT(applyConfigChanges() ) ); 61 connect( configApplyButton, SIGNAL(clicked() ), this, SLOT(applyConfigChanges() ) );
61 // not good since lib is async 62 // not good since lib is async
62 // connect( ListView2, SIGNAL( expanded ( QListViewItem* ) ), 63 // connect( ListView2, SIGNAL( expanded ( QListViewItem* ) ),
63 // this, SLOT( addServicesToDevice( QListViewItem * ) ) ); 64 // this, SLOT( addServicesToDevice( QListViewItem * ) ) );
64 connect( ListView2, SIGNAL( clicked( QListViewItem* )), 65 connect( ListView2, SIGNAL( clicked( QListViewItem* )),
65 this, SLOT( startServiceActionClicked( QListViewItem* ) ) ); 66 this, SLOT( startServiceActionClicked( QListViewItem* ) ) );
66 connect( ListView2, SIGNAL( rightButtonClicked( QListViewItem *, const QPoint &, int ) ), 67 connect( ListView2, SIGNAL( rightButtonClicked( QListViewItem *, const QPoint &, int ) ),
67 this, SLOT(startServiceActionHold( QListViewItem *, const QPoint &, int) ) ); 68 this, SLOT(startServiceActionHold( QListViewItem *, const QPoint &, int) ) );
68 connect( m_localDevice , SIGNAL( foundServices( const QString& , Services::ValueList ) ), 69 connect( m_localDevice , SIGNAL( foundServices( const QString& , Services::ValueList ) ),
69 this, SLOT( addServicesToDevice( const QString& , Services::ValueList ) ) ); 70 this, SLOT( addServicesToDevice( const QString& , Services::ValueList ) ) );
70 connect( m_localDevice, SIGNAL( available( const QString&, bool ) ), 71 connect( m_localDevice, SIGNAL( available( const QString&, bool ) ),
71 this, SLOT( deviceActive( const QString& , bool ) ) ); 72 this, SLOT( deviceActive( const QString& , bool ) ) );
72 connect( m_localDevice, SIGNAL( connections( ConnectionState::ValueList ) ), 73 connect( m_localDevice, SIGNAL( connections( ConnectionState::ValueList ) ),
73 this, SLOT( addConnectedDevices( ConnectionState::ValueList ) ) ); 74 this, SLOT( addConnectedDevices( ConnectionState::ValueList ) ) );
74 75
75 76
76 // let hold be rightButtonClicked() 77 // let hold be rightButtonClicked()
77 QPEApplication::setStylusOperation( ListView2->viewport(), QPEApplication::RightOnHold); 78 QPEApplication::setStylusOperation( ListView2->viewport(), QPEApplication::RightOnHold);
78 QPEApplication::setStylusOperation( ListView4->viewport(), QPEApplication::RightOnHold); 79 QPEApplication::setStylusOperation( ListView4->viewport(), QPEApplication::RightOnHold);
79 80
80 //Load all icons needed 81 //Load all icons needed
81 m_offPix = Resource::loadPixmap( "opietooth/notconnected" ); 82 m_offPix = Resource::loadPixmap( "opietooth/notconnected" );
82 m_onPix = Resource::loadPixmap( "opietooth/connected" ); 83 m_onPix = Resource::loadPixmap( "opietooth/connected" );
83 m_findPix = Resource::loadPixmap( "opietooth/find" ); 84 m_findPix = Resource::loadPixmap( "opietooth/find" );
84 85
85 QPalette pal = this->palette(); 86 QPalette pal = this->palette();
86 QColor col = pal.color( QPalette::Active, QColorGroup::Background ); 87 QColor col = pal.color( QPalette::Active, QColorGroup::Background );
87 pal.setColor( QPalette::Active, QColorGroup::Button, col ); 88 pal.setColor( QPalette::Active, QColorGroup::Button, col );
88 pal.setColor( QPalette::Inactive, QColorGroup::Button, col ); 89 pal.setColor( QPalette::Inactive, QColorGroup::Button, col );
89 pal.setColor( QPalette::Normal, QColorGroup::Button, col ); 90 pal.setColor( QPalette::Normal, QColorGroup::Button, col );
90 pal.setColor( QPalette::Disabled, QColorGroup::Button, col ); 91 pal.setColor( QPalette::Disabled, QColorGroup::Button, col );
91 this->setPalette( pal ); 92 this->setPalette( pal );
92 93
93 setCaption( tr( "Bluetooth Manager" ) ); 94 setCaption( tr( "Bluetooth Manager" ) );
94 95
95 readConfig(); 96 readConfig();
96 initGui(); 97 initGui();
97 98
98 ListView2->setRootIsDecorated(true); 99 ListView2->setRootIsDecorated(true);
99 100
100 writeToHciConfig(); 101 writeToHciConfig();
101 // search conncetions 102 // search conncetions
102 addConnectedDevices(); 103 addConnectedDevices();
103 m_iconLoader = new BTIconLoader(); 104 m_iconLoader = new BTIconLoader();
104 readSavedDevices(); 105 readSavedDevices();
105} 106}
106 107
107/** 108/**
108 * Reads all options from the config file 109 * Reads all options from the config file
109 */ 110 */
110void BlueBase::readConfig() { 111void BlueBase::readConfig() {
111 112
112 Config cfg( "bluetoothmanager" ); 113 Config cfg( "bluetoothmanager" );
113 cfg.setGroup( "bluezsettings" ); 114 cfg.setGroup( "bluezsettings" );
114 115
115 m_deviceName = cfg.readEntry( "name" , "No name" ); // name the device should identify with 116 m_deviceName = cfg.readEntry( "name" , "No name" ); // name the device should identify with
116 m_defaultPasskey = cfg.readEntryCrypt( "passkey" , "" ); // <- hmm, look up how good the trolls did that, maybe too weak 117 m_defaultPasskey = cfg.readEntryCrypt( "passkey" , "" ); // <- hmm, look up how good the trolls did that, maybe too weak
117 m_useEncryption = cfg.readBoolEntry( "useEncryption" , TRUE ); 118 m_useEncryption = cfg.readBoolEntry( "useEncryption" , TRUE );
118 m_enableAuthentification = cfg.readBoolEntry( "enableAuthentification" , TRUE ); 119 m_enableAuthentification = cfg.readBoolEntry( "enableAuthentification" , TRUE );
119 m_enablePagescan = cfg.readBoolEntry( "enablePagescan" , TRUE ); 120 m_enablePagescan = cfg.readBoolEntry( "enablePagescan" , TRUE );
120 m_enableInquiryscan = cfg.readBoolEntry( "enableInquiryscan" , TRUE ); 121 m_enableInquiryscan = cfg.readBoolEntry( "enableInquiryscan" , TRUE );
121} 122}
122 123
123/** 124/**
124 * Writes all options to the config file 125 * Writes all options to the config file
125 */ 126 */
126void BlueBase::writeConfig() { 127void BlueBase::writeConfig() {
127 128
128 Config cfg( "bluetoothmanager" ); 129 Config cfg( "bluetoothmanager" );
129 cfg.setGroup( "bluezsettings" ); 130 cfg.setGroup( "bluezsettings" );
130 131
131 cfg.writeEntry( "name" , m_deviceName ); 132 cfg.writeEntry( "name" , m_deviceName );
132 cfg.writeEntryCrypt( "passkey" , m_defaultPasskey ); 133 cfg.writeEntryCrypt( "passkey" , m_defaultPasskey );
133 cfg.writeEntry( "useEncryption" , m_useEncryption ); 134 cfg.writeEntry( "useEncryption" , m_useEncryption );
134 cfg.writeEntry( "enableAuthentification" , m_enableAuthentification ); 135 cfg.writeEntry( "enableAuthentification" , m_enableAuthentification );
135 cfg.writeEntry( "enablePagescan" , m_enablePagescan ); 136 cfg.writeEntry( "enablePagescan" , m_enablePagescan );
136 cfg.writeEntry( "enableInquiryscan" , m_enableInquiryscan ); 137 cfg.writeEntry( "enableInquiryscan" , m_enableInquiryscan );
137 138
138 writeToHciConfig(); 139 writeToHciConfig();
139} 140}
140 141
141/** 142/**
142 * Modify the hcid.conf file to our needs 143 * Modify the hcid.conf file to our needs
143 */ 144 */
144void BlueBase::writeToHciConfig() { 145void BlueBase::writeToHciConfig() {
145 qWarning("writeToHciConfig"); 146 qWarning("writeToHciConfig");
146 HciConfWrapper hciconf ( "/etc/bluetooth/hcid.conf" ); 147 HciConfWrapper hciconf ( "/etc/bluetooth/hcid.conf" );
147 hciconf.load(); 148 hciconf.load();
148 hciconf.setPinHelper( "/bin/QtPalmtop/bin/blue-pin" ); 149 hciconf.setPinHelper( "/bin/QtPalmtop/bin/blue-pin" );
149 hciconf.setName( m_deviceName ); 150 hciconf.setName( m_deviceName );
150 hciconf.setEncrypt( m_useEncryption ); 151 hciconf.setEncrypt( m_useEncryption );
151 hciconf.setAuth( m_enableAuthentification ); 152 hciconf.setAuth( m_enableAuthentification );
152 hciconf.setPscan( m_enablePagescan ); 153 hciconf.setPscan( m_enablePagescan );
153 hciconf.setIscan( m_enableInquiryscan ); 154 hciconf.setIscan( m_enableInquiryscan );
154 hciconf.save(); 155 hciconf.save();
155} 156}
156 157
157 158
158/** 159/**
159 * Read the list of allready known devices 160 * Read the list of allready known devices
160 */ 161 */
161void BlueBase::readSavedDevices() { 162void BlueBase::readSavedDevices() {
162 163
163 QValueList<RemoteDevice> loadedDevices; 164 QValueList<RemoteDevice> loadedDevices;
164 DeviceHandler handler; 165 DeviceHandler handler;
165 loadedDevices = handler.load(); 166 loadedDevices = handler.load();
166 167
167 addSearchedDevices( loadedDevices ); 168 addSearchedDevices( loadedDevices );
168} 169}
169 170
170 171
171/** 172/**
172 * Write the list of allready known devices 173 * Write the list of allready known devices
173 */ 174 */
174void BlueBase::writeSavedDevices() { 175void BlueBase::writeSavedDevices() {
175 QListViewItemIterator it( ListView2 ); 176 QListViewItemIterator it( ListView2 );
176 BTListItem* item; 177 BTListItem* item;
177 BTDeviceItem* device; 178 BTDeviceItem* device;
178 RemoteDevice::ValueList list; 179 RemoteDevice::ValueList list;
179 for ( ; it.current(); ++it ) { 180 for ( ; it.current(); ++it ) {
180 item = (BTListItem*)it.current(); 181 item = (BTListItem*)it.current();
181 if(item->typeId() != BTListItem::Device ) 182 if(item->typeId() != BTListItem::Device )
182 continue; 183 continue;
183 device = (BTDeviceItem*)item; 184 device = (BTDeviceItem*)item;
184 185
185 list.append( device->remoteDevice() ); 186 list.append( device->remoteDevice() );
186 } 187 }
187 /* 188 /*
188 * if not empty save the List through DeviceHandler 189 * if not empty save the List through DeviceHandler
189 */ 190 */
190 if ( list.isEmpty() ) 191 if ( list.isEmpty() )
191 return; 192 return;
192 DeviceHandler handler; 193 DeviceHandler handler;
193 handler.save( list ); 194 handler.save( list );
194} 195}
195 196
196 197
197/** 198/**
198 * Set up the gui 199 * Set up the gui
199 */ 200 */
200void BlueBase::initGui() { 201void BlueBase::initGui() {
201 StatusLabel->setText( status() ); // maybe move it to getStatus() 202 StatusLabel->setText( status() ); // maybe move it to getStatus()
202 cryptCheckBox->setChecked( m_useEncryption ); 203 cryptCheckBox->setChecked( m_useEncryption );
203 authCheckBox->setChecked( m_enableAuthentification ); 204 authCheckBox->setChecked( m_enableAuthentification );
204 pagescanCheckBox->setChecked( m_enablePagescan ); 205 pagescanCheckBox->setChecked( m_enablePagescan );
205 inquiryscanCheckBox->setChecked( m_enableInquiryscan ); 206 inquiryscanCheckBox->setChecked( m_enableInquiryscan );
206 deviceNameLine->setText( m_deviceName ); 207 deviceNameLine->setText( m_deviceName );
207 passkeyLine->setText( m_defaultPasskey ); 208 passkeyLine->setText( m_defaultPasskey );
208 // set info tab 209 // set info tab
209 setInfo(); 210 setInfo();
210} 211}
211 212
212 213
213/** 214/**
214 * Get the status informations and returns it 215 * Get the status informations and returns it
215 * @return QString the status informations gathered 216 * @return QString the status informations gathered
216 */ 217 */
217QString BlueBase::status()const{ 218QString BlueBase::status()const{
218 QString infoString = tr( "<b>Device name : </b> Ipaq" ); 219 QString infoString = tr( "<b>Device name : </b> Ipaq" );
219 infoString += QString( "<br><b>" + tr( "MAC adress: " ) +"</b> No idea" ); 220 infoString += QString( "<br><b>" + tr( "MAC adress: " ) +"</b> No idea" );
220 infoString += QString( "<br><b>" + tr( "Class" ) + "</b> PDA" ); 221 infoString += QString( "<br><b>" + tr( "Class" ) + "</b> PDA" );
221 222
222 return (infoString); 223 return (infoString);
223} 224}
224 225
225 226
226/** 227/**
227 * Read the current values from the gui and invoke writeConfig() 228 * Read the current values from the gui and invoke writeConfig()
228 */ 229 */
229void BlueBase::applyConfigChanges() { 230void BlueBase::applyConfigChanges() {
230 m_deviceName = deviceNameLine->text(); 231 m_deviceName = deviceNameLine->text();
231 m_defaultPasskey = passkeyLine->text(); 232 m_defaultPasskey = passkeyLine->text();
232 m_useEncryption = cryptCheckBox->isChecked(); 233 m_useEncryption = cryptCheckBox->isChecked();
233 m_enableAuthentification = authCheckBox->isChecked(); 234 m_enableAuthentification = authCheckBox->isChecked();
234 m_enablePagescan = pagescanCheckBox->isChecked(); 235 m_enablePagescan = pagescanCheckBox->isChecked();
235 m_enableInquiryscan = inquiryscanCheckBox->isChecked(); 236 m_enableInquiryscan = inquiryscanCheckBox->isChecked();
236 237
237 writeConfig(); 238 writeConfig();
238 239
239 QMessageBox::information( this, tr("Test") , tr("Changes were applied.") ); 240 QMessageBox::information( this, tr("Test") , tr("Changes were applied.") );
240} 241}
241 242
242/** 243/**
243 * Add fresh found devices from scan dialog to the listing 244 * Add fresh found devices from scan dialog to the listing
244 * 245 *
245 */ 246 */
246void BlueBase::addSearchedDevices( const QValueList<RemoteDevice> &newDevices ) { 247void BlueBase::addSearchedDevices( const QValueList<RemoteDevice> &newDevices ) {
247 BTDeviceItem * deviceItem; 248 BTDeviceItem * deviceItem;
248 QValueList<RemoteDevice>::ConstIterator it; 249 QValueList<RemoteDevice>::ConstIterator it;
249 250
250 for( it = newDevices.begin(); it != newDevices.end() ; ++it ) { 251 for( it = newDevices.begin(); it != newDevices.end() ; ++it ) {
251 252
252 if (find( (*it) )) // is already inserted 253 if (find( (*it) )) // is already inserted
253 continue; 254 continue;
254 255
255 deviceItem = new BTDeviceItem( ListView2 , (*it) ); 256 deviceItem = new BTDeviceItem( ListView2 , (*it) );
256 deviceItem->setPixmap( 1, m_findPix ); 257 deviceItem->setPixmap( 1, m_findPix );
257 deviceItem->setExpandable ( true ); 258 deviceItem->setExpandable ( true );
258 259
259 // look if device is avail. atm, async 260 // look if device is avail. atm, async
260 deviceActive( (*it) ); 261 deviceActive( (*it) );
261 262
262 // ggf auch hier? 263 // ggf auch hier?
263 addServicesToDevice( deviceItem ); 264 addServicesToDevice( deviceItem );
264 } 265 }
265} 266}
266 267
267 268
268/** 269/**
269 * Action that is toggled on entrys on click 270 * Action that is toggled on entrys on click
270 */ 271 */
271void BlueBase::startServiceActionClicked( QListViewItem */*item*/ ) { 272void BlueBase::startServiceActionClicked( QListViewItem */*item*/ ) {
272} 273}
273 274
274 275
275/** 276/**
276 * Action that are toggled on hold (mostly QPopups i guess) 277 * Action that are toggled on hold (mostly QPopups i guess)
277 */ 278 */
278void BlueBase::startServiceActionHold( QListViewItem * item, const QPoint & point, int /*column*/ ) { 279void BlueBase::startServiceActionHold( QListViewItem * item, const QPoint & point, int /*column*/ ) {
279 if (!item ) 280 if (!item )
280 return; 281 return;
281 282
282 QPopupMenu *menu = new QPopupMenu(); 283 QPopupMenu *menu = new QPopupMenu();
283 int ret=0; 284 int ret=0;
284 285
285 if ( ((BTListItem*)item)->type() == "device") { 286 if ( ((BTListItem*)item)->type() == "device") {
286 287
287 QPopupMenu *groups = new QPopupMenu(); 288 QPopupMenu *groups = new QPopupMenu();
288 289
289 menu->insertItem( ((BTDeviceItem*)item)->name(),0 ); 290 menu->insertItem( ((BTDeviceItem*)item)->name(),0 );
290 menu->insertSeparator(1); 291 menu->insertSeparator(1);
291 menu->insertItem( tr("rescan sevices"), 2); 292 menu->insertItem( tr("rescan sevices"), 2);
292 menu->insertItem( tr("to group"), groups , 3); 293 menu->insertItem( tr("to group"), groups , 3);
293 menu->insertItem( tr("delete"), 4); 294 menu->insertItem( tr("delete"), 4);
294 295
295 ret = menu->exec( point , 0); 296 ret = menu->exec( point , 0);
296 297
297 switch(ret) { 298 switch(ret) {
298 case -1: 299 case -1:
299 break; 300 break;
300 case 2: 301 case 2:
301 addServicesToDevice( (BTDeviceItem*)item ); 302 addServicesToDevice( (BTDeviceItem*)item );
302 break; 303 break;
303 304
304 case 4: 305 case 4:
305 // deletes childs too 306 // deletes childs too
306 delete item; 307 delete item;
307 break; 308 break;
308 } 309 }
309 delete groups; 310 delete groups;
310 311
311 } 312 }
312 313
313 /* 314 /*
314 * We got service sensitive PopupMenus in our factory 315 * We got service sensitive PopupMenus in our factory
315 * We will create one through the factory and will insert 316 * We will create one through the factory and will insert
316 * our Separator + ShowInfo into the menu or create a new 317 * our Separator + ShowInfo into the menu or create a new
317 * one if the factory returns 0 318 * one if the factory returns 0
318 * PopupMenu deletion is kind of weird. 319 * PopupMenu deletion is kind of weird.
319 * If escaped( -1 ) or any of our items were chosen we'll 320 * If escaped( -1 ) or any of our items were chosen we'll
320 * delete the PopupMenu otherwise it's the responsibility of 321 * delete the PopupMenu otherwise it's the responsibility of
321 * the PopupMenu to delete itself 322 * the PopupMenu to delete itself
322 * 323 *
323 */ 324 */
324 else if ( ((BTListItem*)item)->type() == "service") { 325 else if ( ((BTListItem*)item)->type() == "service") {
325 BTServiceItem* service = (BTServiceItem*)item; 326 BTServiceItem* service = (BTServiceItem*)item;
326 QMap<int, QString> list = service->services().classIdList(); 327 QMap<int, QString> list = service->services().classIdList();
327 QMap<int, QString>::Iterator it = list.begin(); 328 QMap<int, QString>::Iterator it = list.begin();
328 QPopupMenu *popup =0l; 329 QPopupMenu *popup =0l;
329 if ( it != list.end() ) { 330 if ( it != list.end() ) {
330 qWarning("Searching id %d %s", it.key(), it.data().latin1() ); 331 qWarning("Searching id %d %s", it.key(), it.data().latin1() );
331 popup = m_popHelper.find( it.key() /*1*/, 332 popup = m_popHelper.find( it.key() /*1*/,
332 service->services(), 333 service->services(),
333 (BTDeviceItem*)service->parent() ); 334 (BTDeviceItem*)service->parent() );
334 }else { 335 }else {
335 qWarning("Empty"); 336 qWarning("Empty");
336 } 337 }
337 338
338 if ( popup == 0l ) { 339 if ( popup == 0l ) {
339 qWarning("factory returned 0l"); 340 qWarning("factory returned 0l");
340 popup = new QPopupMenu(); 341 popup = new QPopupMenu();
341 } 342 }
342 int test1 = popup->insertItem( tr("Test1:"), 2); 343 int test1 = popup->insertItem( tr("Test1:"), 2);
343 344
344 ret = popup->exec( point ); 345 ret = popup->exec( point );
345 qWarning("returned from exec() "); 346 qWarning("returned from exec() ");
346 if ( ret == -1 ) { 347 if ( ret == -1 ) {
347 ; 348 ;
348 } else if ( ret == test1 ) { 349 } else if ( ret == test1 ) {
349 ; 350 ;
350 } 351 }
351 delete popup; 352 delete popup;
352 } 353 }
353 delete menu; 354 delete menu;
354} 355}
355 356
356 357
357/** 358/**
358 * Search and display avail. services for a device (on expand from device listing) 359 * Search and display avail. services for a device (on expand from device listing)
359 * @param item the service item returned 360 * @param item the service item returned
360 */ 361 */
361void BlueBase::addServicesToDevice( BTDeviceItem * item ) { 362void BlueBase::addServicesToDevice( BTDeviceItem * item ) {
362 qDebug("addServicesToDevice"); 363 qDebug("addServicesToDevice");
363 // row of mac adress text(3) 364 // row of mac adress text(3)
364 RemoteDevice device = item->remoteDevice(); 365 RemoteDevice device = item->remoteDevice();
365 m_deviceList.insert( item->mac() , item ); 366 m_deviceList.insert( item->mac() , item );
366 // and some time later I get a signal foundServices( const QString& device, Services::ValueList ); back 367 // and some time later I get a signal foundServices( const QString& device, Services::ValueList ); back
367 m_localDevice->searchServices( device ); 368 m_localDevice->searchServices( device );
368} 369}
369 370
370 371
371/** 372/**
372 * Overloaded. This one it the one that is connected to the foundServices signal 373 * Overloaded. This one it the one that is connected to the foundServices signal
373 * @param device the mac address of the remote device 374 * @param device the mac address of the remote device
374 * @param servicesList the list with the service the device has. 375 * @param servicesList the list with the service the device has.
375 */ 376 */
376void BlueBase::addServicesToDevice( const QString& device, Services::ValueList servicesList ) { 377void BlueBase::addServicesToDevice( const QString& device, Services::ValueList servicesList ) {
377 qDebug("fill services list"); 378 qDebug("fill services list");
378 379
379 QMap<QString,BTDeviceItem*>::Iterator it; 380 QMap<QString,BTDeviceItem*>::Iterator it;
380 BTDeviceItem* deviceItem = 0; 381 BTDeviceItem* deviceItem = 0;
381 382
382 // get the right devices which requested the search 383 // get the right devices which requested the search
383 it = m_deviceList.find( device ); 384 it = m_deviceList.find( device );
384 if( it == m_deviceList.end() ) 385 if( it == m_deviceList.end() )
385 return; 386 return;
386 deviceItem = it.data(); 387 deviceItem = it.data();
387 388
389 // remove previous entries
390 QList<QListViewItem> tempList;
391 tempList.setAutoDelete( true );
392 QListViewItem * child = deviceItem->firstChild();
393 while( child ) {
394 tempList.append( child );
395 child = child->nextSibling();
396 }
397 tempList.clear();
398
388 QValueList<OpieTooth::Services>::Iterator it2; 399 QValueList<OpieTooth::Services>::Iterator it2;
389 BTServiceItem * serviceItem; 400 BTServiceItem* serviceItem;
401
390 402
391 if (!servicesList.isEmpty() ) { 403 if (!servicesList.isEmpty() ) {
392 // add services 404 // add services
393 QMap<int, QString> list; 405 QMap<int, QString> list;
394 QMap<int, QString>::Iterator classIt; 406 QMap<int, QString>::Iterator classIt;
395 for( it2 = servicesList.begin(); it2 != servicesList.end(); ++it2 ) { 407 for( it2 = servicesList.begin(); it2 != servicesList.end(); ++it2 ) {
396 serviceItem = new BTServiceItem( deviceItem , (*it2) ); 408 serviceItem = new BTServiceItem( deviceItem, (*it2) );
397 list = (*it2).classIdList(); 409 list = (*it2).classIdList();
398 classIt = list.begin(); 410 classIt = list.begin();
399 int classId=0; 411 int classId=0;
400 if ( classIt != list.end() ) { 412 if ( classIt != list.end() ) {
401 classId = classIt.key(); 413 classId = classIt.key();
402 } 414 }
403 415
404 serviceItem->setPixmap( 0, m_iconLoader->serviceIcon( classId ) ); 416 serviceItem->setPixmap( 0, m_iconLoader->serviceIcon( classId ) );
405 } 417 }
406 } else { 418 } else {
407 Services s1; 419 Services s1;
408 s1.setServiceName( tr("no serives found") ); 420 s1.setServiceName( tr("no services found") );
409 serviceItem = new BTServiceItem( deviceItem, s1 ); 421 serviceItem = new BTServiceItem( deviceItem, s1 );
410 } 422 }
411 // now remove them from the list 423 // now remove them from the list
412 m_deviceList.remove( it ); 424 m_deviceList.remove( it );
413} 425}
414 426
415 427
416/** 428/**
417 * Add the existing connections (pairs) to the connections tab. 429 * Add the existing connections (pairs) to the connections tab.
418 * This one triggers the search 430 * This one triggers the search
419 */ 431 */
420void BlueBase::addConnectedDevices() { 432void BlueBase::addConnectedDevices() {
421 m_localDevice->searchConnections(); 433 m_localDevice->searchConnections();
422} 434}
423 435
424 436
425/** 437/**
426 * This adds the found connections to the connection tab. 438 * This adds the found connections to the connection tab.
427 * @param connectionList the ValueList with all current connections 439 * @param connectionList the ValueList with all current connections
428 */ 440 */
429void BlueBase::addConnectedDevices( ConnectionState::ValueList connectionList ) { 441void BlueBase::addConnectedDevices( ConnectionState::ValueList connectionList ) {
430 442
431 // clear the ListView first 443 // clear the ListView first
432 ListView4->clear(); 444 ListView4->clear();
433 445
434 QValueList<OpieTooth::ConnectionState>::Iterator it; 446 QValueList<OpieTooth::ConnectionState>::Iterator it;
435 BTConnectionItem * connectionItem; 447 BTConnectionItem * connectionItem;
436 448
437 if ( !connectionList.isEmpty() ) { 449 if ( !connectionList.isEmpty() ) {
438 450
439 for (it = connectionList.begin(); it != connectionList.end(); ++it) { 451 for (it = connectionList.begin(); it != connectionList.end(); ++it) {
440 connectionItem = new BTConnectionItem( ListView4 , (*it) ); 452 connectionItem = new BTConnectionItem( ListView4 , (*it) );
441 } 453 }
442 } else { 454 } else {
443 ConnectionState con; 455 ConnectionState con;
444 con.setMac( tr("No connections found") ); 456 con.setMac( tr("No connections found") );
445 connectionItem = new BTConnectionItem( ListView4 , con ); 457 connectionItem = new BTConnectionItem( ListView4 , con );
446 } 458 }
447 459
448 // recall connection search after some time 460 // recall connection search after some time
449 QTimer::singleShot( 20000, this, SLOT( addConnectedDevices() ) ); 461 QTimer::singleShot( 15000, this, SLOT( addConnectedDevices() ) );
450} 462}
451 463
452 464
453/** 465/**
454 * Find out if a device can currently be reached 466 * Find out if a device can currently be reached
455 * @param device 467 * @param device
456 */ 468 */
457void BlueBase::deviceActive( const RemoteDevice &device ) { 469void BlueBase::deviceActive( const RemoteDevice &device ) {
458 // search by mac, async, gets a signal back 470 // search by mac, async, gets a signal back
459 // We should have a BTDeviceItem there or where does it get added to the map -zecke 471 // We should have a BTDeviceItem there or where does it get added to the map -zecke
460 m_localDevice->isAvailable( device.mac() ); 472 m_localDevice->isAvailable( device.mac() );
461} 473}
462 474
463 475
464/** 476/**
465 * The signal catcher. Set the avail. status on device. 477 * The signal catcher. Set the avail. status on device.
466 * @param device - the mac address 478 * @param device - the mac address
467 * @param connected - if it is avail. or not 479 * @param connected - if it is avail. or not
468 */ 480 */
469void BlueBase::deviceActive( const QString& device, bool connected ) { 481void BlueBase::deviceActive( const QString& device, bool connected ) {
470 qDebug("deviceActive slot"); 482 qDebug("deviceActive slot");
471 483
472 QMap<QString,BTDeviceItem*>::Iterator it; 484 QMap<QString,BTDeviceItem*>::Iterator it;
473 485
474 it = m_deviceList.find( device ); 486 it = m_deviceList.find( device );
475 if( it == m_deviceList.end() ) 487 if( it == m_deviceList.end() )
476 return; 488 return;
477 489
478 BTDeviceItem* deviceItem = it.data(); 490 BTDeviceItem* deviceItem = it.data();
479 491
480 492
481 if ( connected ) { 493 if ( connected ) {
482 deviceItem->setPixmap( 1, m_onPix ); 494 deviceItem->setPixmap( 1, m_onPix );
483 } else { 495 } else {
484 deviceItem->setPixmap( 1, m_offPix ); 496 deviceItem->setPixmap( 1, m_offPix );
485 } 497 }
486 m_deviceList.remove( it ); 498 m_deviceList.remove( it );
487} 499}
488 500
489 501
490/** 502/**
491 * Open the "scan for devices" dialog 503 * Open the "scan for devices" dialog
492 */ 504 */
493void BlueBase::startScan() { 505void BlueBase::startScan() {
494 ScanDialog *scan = new ScanDialog( this, "ScanDialog", 506 ScanDialog *scan = new ScanDialog( this, "ScanDialog",
495 true, WDestructiveClose ); 507 true, WDestructiveClose );
496 QObject::connect( scan, SIGNAL( selectedDevices( const QValueList<RemoteDevice>& ) ), 508 QObject::connect( scan, SIGNAL( selectedDevices( const QValueList<RemoteDevice>& ) ),
497 this, SLOT( addSearchedDevices( const QValueList<RemoteDevice>& ) ) ); 509 this, SLOT( addSearchedDevices( const QValueList<RemoteDevice>& ) ) );
498 510
499 scan->showMaximized(); 511 scan->showMaximized();
500} 512}
501 513
502 514
503/** 515/**
504 * Set the informations about the local device in information Tab 516 * Set the informations about the local device in information Tab
505 */ 517 */
506void BlueBase::setInfo() { 518void BlueBase::setInfo() {
507 StatusLabel->setText( status() ); 519 StatusLabel->setText( status() );
508} 520}
509 521
510 522
511/** 523/**
512 * Decontructor 524 * Decontructor
513 */ 525 */
514BlueBase::~BlueBase() { 526BlueBase::~BlueBase() {
515 writeSavedDevices(); 527 writeSavedDevices();
516 delete m_iconLoader; 528 delete m_iconLoader;
517} 529}
518 530
519 531
520/** 532/**
521 * find searches the ListView for a BTDeviceItem containig 533 * find searches the ListView for a BTDeviceItem containig
522 * the same Device if found return true else false 534 * the same Device if found return true else false
523 * @param dev RemoteDevice to find 535 * @param dev RemoteDevice to find
524 * @return returns true if found 536 * @return returns true if found
525 */ 537 */
526bool BlueBase::find( const RemoteDevice& rem ) { 538bool BlueBase::find( const RemoteDevice& rem ) {
527 QListViewItemIterator it( ListView2 ); 539 QListViewItemIterator it( ListView2 );
528 BTListItem* item; 540 BTListItem* item;
529 BTDeviceItem* device; 541 BTDeviceItem* device;
530 for (; it.current(); ++it ) { 542 for (; it.current(); ++it ) {
531 item = (BTListItem*) it.current(); 543 item = (BTListItem*) it.current();
532 if ( item->typeId() != BTListItem::Device ) 544 if ( item->typeId() != BTListItem::Device )
533 continue; 545 continue;
534 546
535 device = (BTDeviceItem*)item; 547 device = (BTDeviceItem*)item;
536 if ( rem.equals( device->remoteDevice() ) ) 548 if ( rem.equals( device->remoteDevice() ) )
537 return true; 549 return true;
538 } 550 }
539 return false; // not found 551 return false; // not found
540} 552}