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