Diffstat (limited to 'noncore/net/opietooth/manager/bluebase.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/opietooth/manager/bluebase.cpp | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/noncore/net/opietooth/manager/bluebase.cpp b/noncore/net/opietooth/manager/bluebase.cpp index 0ea45d2..29030ab 100644 --- a/noncore/net/opietooth/manager/bluebase.cpp +++ b/noncore/net/opietooth/manager/bluebase.cpp | |||
@@ -1,273 +1,273 @@ | |||
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 | #include "rfcommassigndialogimpl.h" | 23 | #include "rfcommassigndialogimpl.h" |
24 | 24 | ||
25 | /* OPIE */ | 25 | /* OPIE */ |
26 | #include <qpe/qpeapplication.h> | 26 | #include <qpe/qpeapplication.h> |
27 | #include <qpe/resource.h> | 27 | #include <qpe/resource.h> |
28 | #include <qpe/config.h> | 28 | #include <qpe/config.h> |
29 | 29 | ||
30 | /* QT */ | 30 | /* QT */ |
31 | #include <qframe.h> | 31 | #include <qframe.h> |
32 | #include <qlabel.h> | 32 | #include <qlabel.h> |
33 | #include <qpushbutton.h> | 33 | #include <qpushbutton.h> |
34 | #include <qlayout.h> | 34 | #include <qlayout.h> |
35 | #include <qvariant.h> | 35 | #include <qvariant.h> |
36 | #include <qimage.h> | 36 | #include <qimage.h> |
37 | #include <qpixmap.h> | 37 | #include <qpixmap.h> |
38 | #include <qtabwidget.h> | 38 | #include <qtabwidget.h> |
39 | #include <qscrollview.h> | 39 | #include <qscrollview.h> |
40 | #include <qvbox.h> | 40 | #include <qvbox.h> |
41 | #include <qmessagebox.h> | 41 | #include <qmessagebox.h> |
42 | #include <qcheckbox.h> | 42 | #include <qcheckbox.h> |
43 | #include <qlineedit.h> | 43 | #include <qlineedit.h> |
44 | #include <qlistview.h> | 44 | #include <qlistview.h> |
45 | #include <qdir.h> | 45 | #include <qdir.h> |
46 | #include <qpopupmenu.h> | 46 | #include <qpopupmenu.h> |
47 | #include <qtimer.h> | 47 | #include <qtimer.h> |
48 | #include <qlist.h> | 48 | #include <qlist.h> |
49 | 49 | ||
50 | /* STD */ | 50 | /* STD */ |
51 | #include <remotedevice.h> | 51 | #include <remotedevice.h> |
52 | #include <services.h> | 52 | #include <services.h> |
53 | #include <stdlib.h> | 53 | #include <stdlib.h> |
54 | 54 | ||
55 | using namespace OpieTooth; | 55 | using namespace OpieTooth; |
56 | 56 | ||
57 | BlueBase::BlueBase( QWidget* parent, const char* name, WFlags fl ) | 57 | BlueBase::BlueBase( QWidget* parent, const char* name, WFlags fl ) |
58 | : BluetoothBase( parent, name, fl ) | 58 | : BluetoothBase( parent, name, fl ) |
59 | { | 59 | { |
60 | 60 | ||
61 | m_localDevice = new Manager( "hci0" ); | 61 | m_localDevice = new Manager( "hci0" ); |
62 | 62 | ||
63 | connect( PushButton2, SIGNAL( clicked() ), this, SLOT(startScan() ) ); | 63 | connect( PushButton2, SIGNAL( clicked() ), this, SLOT(startScan() ) ); |
64 | connect( configApplyButton, SIGNAL(clicked() ), this, SLOT(applyConfigChanges() ) ); | 64 | connect( configApplyButton, SIGNAL(clicked() ), this, SLOT(applyConfigChanges() ) ); |
65 | 65 | ||
66 | connect( rfcommBindButton, SIGNAL( clicked() ), this, SLOT( rfcommDialog() ) ); | 66 | connect( rfcommBindButton, SIGNAL( clicked() ), this, SLOT( rfcommDialog() ) ); |
67 | // not good since lib is async | 67 | // not good since lib is async |
68 | // connect( ListView2, SIGNAL( expanded ( QListViewItem* ) ), | 68 | // connect( ListView2, SIGNAL( expanded(QListViewItem*) ), |
69 | // this, SLOT( addServicesToDevice( QListViewItem * ) ) ); | 69 | // this, SLOT( addServicesToDevice(QListViewItem*) ) ); |
70 | connect( ListView2, SIGNAL( clicked( QListViewItem* )), | 70 | connect( ListView2, SIGNAL( clicked(QListViewItem*)), |
71 | this, SLOT( startServiceActionClicked( QListViewItem* ) ) ); | 71 | this, SLOT( startServiceActionClicked(QListViewItem*) ) ); |
72 | connect( ListView2, SIGNAL( rightButtonClicked( QListViewItem *, const QPoint &, int ) ), | 72 | connect( ListView2, SIGNAL( rightButtonClicked(QListViewItem*,const QPoint&,int) ), |
73 | this, SLOT(startServiceActionHold( QListViewItem *, const QPoint &, int) ) ); | 73 | this, SLOT(startServiceActionHold(QListViewItem*,const QPoint&,int) ) ); |
74 | connect( m_localDevice , SIGNAL( foundServices( const QString& , Services::ValueList ) ), | 74 | connect( m_localDevice , SIGNAL( foundServices(const QString&,Services::ValueList) ), |
75 | this, SLOT( addServicesToDevice( const QString& , Services::ValueList ) ) ); | 75 | this, SLOT( addServicesToDevice(const QString&,Services::ValueList) ) ); |
76 | connect( m_localDevice, SIGNAL( available( const QString&, bool ) ), | 76 | connect( m_localDevice, SIGNAL( available(const QString&,bool) ), |
77 | this, SLOT( deviceActive( const QString& , bool ) ) ); | 77 | this, SLOT( deviceActive(const QString&,bool) ) ); |
78 | connect( m_localDevice, SIGNAL( connections( ConnectionState::ValueList ) ), | 78 | connect( m_localDevice, SIGNAL( connections(ConnectionState::ValueList) ), |
79 | this, SLOT( addConnectedDevices( ConnectionState::ValueList ) ) ); | 79 | this, SLOT( addConnectedDevices(ConnectionState::ValueList) ) ); |
80 | connect( m_localDevice, SIGNAL( signalStrength( const QString&, const QString& ) ), | 80 | connect( m_localDevice, SIGNAL( signalStrength(const QString&,const QString&) ), |
81 | this, SLOT( addSignalStrength( const QString&, const QString& ) ) ); | 81 | this, SLOT( addSignalStrength(const QString&,const QString&) ) ); |
82 | 82 | ||
83 | 83 | ||
84 | // let hold be rightButtonClicked() | 84 | // let hold be rightButtonClicked() |
85 | QPEApplication::setStylusOperation( ListView2->viewport(), QPEApplication::RightOnHold); | 85 | QPEApplication::setStylusOperation( ListView2->viewport(), QPEApplication::RightOnHold); |
86 | QPEApplication::setStylusOperation( ListView4->viewport(), QPEApplication::RightOnHold); | 86 | QPEApplication::setStylusOperation( ListView4->viewport(), QPEApplication::RightOnHold); |
87 | 87 | ||
88 | //Load all icons needed | 88 | //Load all icons needed |
89 | m_offPix = Resource::loadPixmap( "opietooth/notconnected" ); | 89 | m_offPix = Resource::loadPixmap( "opietooth/notconnected" ); |
90 | m_onPix = Resource::loadPixmap( "opietooth/connected" ); | 90 | m_onPix = Resource::loadPixmap( "opietooth/connected" ); |
91 | m_findPix = Resource::loadPixmap( "opietooth/find" ); | 91 | m_findPix = Resource::loadPixmap( "opietooth/find" ); |
92 | 92 | ||
93 | QPalette pal = this->palette(); | 93 | QPalette pal = this->palette(); |
94 | QColor col = pal.color( QPalette::Active, QColorGroup::Background ); | 94 | QColor col = pal.color( QPalette::Active, QColorGroup::Background ); |
95 | pal.setColor( QPalette::Active, QColorGroup::Button, col ); | 95 | pal.setColor( QPalette::Active, QColorGroup::Button, col ); |
96 | pal.setColor( QPalette::Inactive, QColorGroup::Button, col ); | 96 | pal.setColor( QPalette::Inactive, QColorGroup::Button, col ); |
97 | pal.setColor( QPalette::Normal, QColorGroup::Button, col ); | 97 | pal.setColor( QPalette::Normal, QColorGroup::Button, col ); |
98 | pal.setColor( QPalette::Disabled, QColorGroup::Button, col ); | 98 | pal.setColor( QPalette::Disabled, QColorGroup::Button, col ); |
99 | this->setPalette( pal ); | 99 | this->setPalette( pal ); |
100 | 100 | ||
101 | setCaption( tr( "Bluetooth Manager" ) ); | 101 | setCaption( tr( "Bluetooth Manager" ) ); |
102 | 102 | ||
103 | readConfig(); | 103 | readConfig(); |
104 | initGui(); | 104 | initGui(); |
105 | 105 | ||
106 | ListView2->setRootIsDecorated(true); | 106 | ListView2->setRootIsDecorated(true); |
107 | 107 | ||
108 | 108 | ||
109 | writeToHciConfig(); | 109 | writeToHciConfig(); |
110 | // search conncetions | 110 | // search conncetions |
111 | addConnectedDevices(); | 111 | addConnectedDevices(); |
112 | addSignalStrength(); | 112 | addSignalStrength(); |
113 | m_iconLoader = new BTIconLoader(); | 113 | m_iconLoader = new BTIconLoader(); |
114 | readSavedDevices(); | 114 | readSavedDevices(); |
115 | } | 115 | } |
116 | 116 | ||
117 | /** | 117 | /** |
118 | * Reads all options from the config file | 118 | * Reads all options from the config file |
119 | */ | 119 | */ |
120 | void BlueBase::readConfig() | 120 | void BlueBase::readConfig() |
121 | { | 121 | { |
122 | 122 | ||
123 | Config cfg( "bluetoothmanager" ); | 123 | Config cfg( "bluetoothmanager" ); |
124 | cfg.setGroup( "bluezsettings" ); | 124 | cfg.setGroup( "bluezsettings" ); |
125 | 125 | ||
126 | m_deviceName = cfg.readEntry( "name" , "No name" ); // name the device should identify with | 126 | m_deviceName = cfg.readEntry( "name" , "No name" ); // name the device should identify with |
127 | m_defaultPasskey = cfg.readEntryCrypt( "passkey" , "" ); // <- hmm, look up how good the trolls did that, maybe too weak | 127 | m_defaultPasskey = cfg.readEntryCrypt( "passkey" , "" ); // <- hmm, look up how good the trolls did that, maybe too weak |
128 | m_useEncryption = cfg.readBoolEntry( "useEncryption" , TRUE ); | 128 | m_useEncryption = cfg.readBoolEntry( "useEncryption" , TRUE ); |
129 | m_enableAuthentification = cfg.readBoolEntry( "enableAuthentification" , TRUE ); | 129 | m_enableAuthentification = cfg.readBoolEntry( "enableAuthentification" , TRUE ); |
130 | m_enablePagescan = cfg.readBoolEntry( "enablePagescan" , TRUE ); | 130 | m_enablePagescan = cfg.readBoolEntry( "enablePagescan" , TRUE ); |
131 | m_enableInquiryscan = cfg.readBoolEntry( "enableInquiryscan" , TRUE ); | 131 | m_enableInquiryscan = cfg.readBoolEntry( "enableInquiryscan" , TRUE ); |
132 | } | 132 | } |
133 | 133 | ||
134 | /** | 134 | /** |
135 | * Writes all options to the config file | 135 | * Writes all options to the config file |
136 | */ | 136 | */ |
137 | void BlueBase::writeConfig() | 137 | void BlueBase::writeConfig() |
138 | { | 138 | { |
139 | 139 | ||
140 | Config cfg( "bluetoothmanager" ); | 140 | Config cfg( "bluetoothmanager" ); |
141 | cfg.setGroup( "bluezsettings" ); | 141 | cfg.setGroup( "bluezsettings" ); |
142 | 142 | ||
143 | cfg.writeEntry( "name" , m_deviceName ); | 143 | cfg.writeEntry( "name" , m_deviceName ); |
144 | cfg.writeEntryCrypt( "passkey" , m_defaultPasskey ); | 144 | cfg.writeEntryCrypt( "passkey" , m_defaultPasskey ); |
145 | cfg.writeEntry( "useEncryption" , m_useEncryption ); | 145 | cfg.writeEntry( "useEncryption" , m_useEncryption ); |
146 | cfg.writeEntry( "enableAuthentification" , m_enableAuthentification ); | 146 | cfg.writeEntry( "enableAuthentification" , m_enableAuthentification ); |
147 | cfg.writeEntry( "enablePagescan" , m_enablePagescan ); | 147 | cfg.writeEntry( "enablePagescan" , m_enablePagescan ); |
148 | cfg.writeEntry( "enableInquiryscan" , m_enableInquiryscan ); | 148 | cfg.writeEntry( "enableInquiryscan" , m_enableInquiryscan ); |
149 | 149 | ||
150 | writeToHciConfig(); | 150 | writeToHciConfig(); |
151 | } | 151 | } |
152 | 152 | ||
153 | /** | 153 | /** |
154 | * Modify the hcid.conf file to our needs | 154 | * Modify the hcid.conf file to our needs |
155 | */ | 155 | */ |
156 | void BlueBase::writeToHciConfig() | 156 | void BlueBase::writeToHciConfig() |
157 | { | 157 | { |
158 | qWarning("writeToHciConfig"); | 158 | qWarning("writeToHciConfig"); |
159 | HciConfWrapper hciconf ( "/etc/bluetooth/hcid.conf" ); | 159 | HciConfWrapper hciconf ( "/etc/bluetooth/hcid.conf" ); |
160 | hciconf.load(); | 160 | hciconf.load(); |
161 | hciconf.setPinHelper( "/opt/QtPalmtop/bin/bluepin" ); | 161 | hciconf.setPinHelper( "/opt/QtPalmtop/bin/bluepin" ); |
162 | hciconf.setName( m_deviceName ); | 162 | hciconf.setName( m_deviceName ); |
163 | hciconf.setEncrypt( m_useEncryption ); | 163 | hciconf.setEncrypt( m_useEncryption ); |
164 | hciconf.setAuth( m_enableAuthentification ); | 164 | hciconf.setAuth( m_enableAuthentification ); |
165 | hciconf.setPscan( m_enablePagescan ); | 165 | hciconf.setPscan( m_enablePagescan ); |
166 | hciconf.setIscan( m_enableInquiryscan ); | 166 | hciconf.setIscan( m_enableInquiryscan ); |
167 | hciconf.save(); | 167 | hciconf.save(); |
168 | } | 168 | } |
169 | 169 | ||
170 | 170 | ||
171 | /** | 171 | /** |
172 | * Read the list of allready known devices | 172 | * Read the list of allready known devices |
173 | */ | 173 | */ |
174 | void BlueBase::readSavedDevices() | 174 | void BlueBase::readSavedDevices() |
175 | { | 175 | { |
176 | 176 | ||
177 | QValueList<RemoteDevice> loadedDevices; | 177 | QValueList<RemoteDevice> loadedDevices; |
178 | DeviceHandler handler; | 178 | DeviceHandler handler; |
179 | loadedDevices = handler.load(); | 179 | loadedDevices = handler.load(); |
180 | 180 | ||
181 | addSearchedDevices( loadedDevices ); | 181 | addSearchedDevices( loadedDevices ); |
182 | } | 182 | } |
183 | 183 | ||
184 | 184 | ||
185 | /** | 185 | /** |
186 | * Write the list of allready known devices | 186 | * Write the list of allready known devices |
187 | */ | 187 | */ |
188 | void BlueBase::writeSavedDevices() | 188 | void BlueBase::writeSavedDevices() |
189 | { | 189 | { |
190 | QListViewItemIterator it( ListView2 ); | 190 | QListViewItemIterator it( ListView2 ); |
191 | BTListItem* item; | 191 | BTListItem* item; |
192 | BTDeviceItem* device; | 192 | BTDeviceItem* device; |
193 | RemoteDevice::ValueList list; | 193 | RemoteDevice::ValueList list; |
194 | for ( ; it.current(); ++it ) | 194 | for ( ; it.current(); ++it ) |
195 | { | 195 | { |
196 | item = (BTListItem*)it.current(); | 196 | item = (BTListItem*)it.current(); |
197 | if(item->typeId() != BTListItem::Device ) | 197 | if(item->typeId() != BTListItem::Device ) |
198 | continue; | 198 | continue; |
199 | device = (BTDeviceItem*)item; | 199 | device = (BTDeviceItem*)item; |
200 | 200 | ||
201 | list.append( device->remoteDevice() ); | 201 | list.append( device->remoteDevice() ); |
202 | } | 202 | } |
203 | /* | 203 | /* |
204 | * if not empty save the List through DeviceHandler | 204 | * if not empty save the List through DeviceHandler |
205 | */ | 205 | */ |
206 | if ( list.isEmpty() ) | 206 | if ( list.isEmpty() ) |
207 | return; | 207 | return; |
208 | DeviceHandler handler; | 208 | DeviceHandler handler; |
209 | handler.save( list ); | 209 | handler.save( list ); |
210 | } | 210 | } |
211 | 211 | ||
212 | 212 | ||
213 | /** | 213 | /** |
214 | * Set up the gui | 214 | * Set up the gui |
215 | */ | 215 | */ |
216 | void BlueBase::initGui() | 216 | void BlueBase::initGui() |
217 | { | 217 | { |
218 | StatusLabel->setText( status() ); // maybe move it to getStatus() | 218 | StatusLabel->setText( status() ); // maybe move it to getStatus() |
219 | cryptCheckBox->setChecked( m_useEncryption ); | 219 | cryptCheckBox->setChecked( m_useEncryption ); |
220 | authCheckBox->setChecked( m_enableAuthentification ); | 220 | authCheckBox->setChecked( m_enableAuthentification ); |
221 | pagescanCheckBox->setChecked( m_enablePagescan ); | 221 | pagescanCheckBox->setChecked( m_enablePagescan ); |
222 | inquiryscanCheckBox->setChecked( m_enableInquiryscan ); | 222 | inquiryscanCheckBox->setChecked( m_enableInquiryscan ); |
223 | deviceNameLine->setText( m_deviceName ); | 223 | deviceNameLine->setText( m_deviceName ); |
224 | passkeyLine->setText( m_defaultPasskey ); | 224 | passkeyLine->setText( m_defaultPasskey ); |
225 | // set info tab | 225 | // set info tab |
226 | setInfo(); | 226 | setInfo(); |
227 | } | 227 | } |
228 | 228 | ||
229 | 229 | ||
230 | /** | 230 | /** |
231 | * Get the status informations and returns it | 231 | * Get the status informations and returns it |
232 | * @return QString the status informations gathered | 232 | * @return QString the status informations gathered |
233 | */ | 233 | */ |
234 | QString BlueBase::status()const | 234 | QString BlueBase::status()const |
235 | { | 235 | { |
236 | QString infoString = tr( "<b>Device name : </b> Ipaq" ); | 236 | QString infoString = tr( "<b>Device name : </b> Ipaq" ); |
237 | infoString += QString( "<br><b>" + tr( "MAC adress: " ) +"</b> No idea" ); | 237 | infoString += QString( "<br><b>" + tr( "MAC adress: " ) +"</b> No idea" ); |
238 | infoString += QString( "<br><b>" + tr( "Class" ) + "</b> PDA" ); | 238 | infoString += QString( "<br><b>" + tr( "Class" ) + "</b> PDA" ); |
239 | 239 | ||
240 | return (infoString); | 240 | return (infoString); |
241 | } | 241 | } |
242 | 242 | ||
243 | 243 | ||
244 | /** | 244 | /** |
245 | * Read the current values from the gui and invoke writeConfig() | 245 | * Read the current values from the gui and invoke writeConfig() |
246 | */ | 246 | */ |
247 | void BlueBase::applyConfigChanges() | 247 | void BlueBase::applyConfigChanges() |
248 | { | 248 | { |
249 | m_deviceName = deviceNameLine->text(); | 249 | m_deviceName = deviceNameLine->text(); |
250 | m_defaultPasskey = passkeyLine->text(); | 250 | m_defaultPasskey = passkeyLine->text(); |
251 | m_useEncryption = cryptCheckBox->isChecked(); | 251 | m_useEncryption = cryptCheckBox->isChecked(); |
252 | m_enableAuthentification = authCheckBox->isChecked(); | 252 | m_enableAuthentification = authCheckBox->isChecked(); |
253 | m_enablePagescan = pagescanCheckBox->isChecked(); | 253 | m_enablePagescan = pagescanCheckBox->isChecked(); |
254 | m_enableInquiryscan = inquiryscanCheckBox->isChecked(); | 254 | m_enableInquiryscan = inquiryscanCheckBox->isChecked(); |
255 | 255 | ||
256 | writeConfig(); | 256 | writeConfig(); |
257 | 257 | ||
258 | QMessageBox::information( this, tr("Test") , tr("Changes were applied.") ); | 258 | QMessageBox::information( this, tr("Test") , tr("Changes were applied.") ); |
259 | } | 259 | } |
260 | 260 | ||
261 | /** | 261 | /** |
262 | * Launch Rfcomm Bind dialog | 262 | * Launch Rfcomm Bind dialog |
263 | * | 263 | * |
264 | */ | 264 | */ |
265 | void BlueBase::rfcommDialog() | 265 | void BlueBase::rfcommDialog() |
266 | { | 266 | { |
267 | RfcommAssignDialog rfcommAssign ( this, "RfcommAssignDialog", true, WStyle_ContextHelp ); | 267 | RfcommAssignDialog rfcommAssign ( this, "RfcommAssignDialog", true, WStyle_ContextHelp ); |
268 | 268 | ||
269 | if ( QPEApplication::execDialog( &rfcommAssign ) == QDialog::Accepted ) | 269 | if ( QPEApplication::execDialog( &rfcommAssign ) == QDialog::Accepted ) |
270 | { | 270 | { |
271 | rfcommAssign.saveConfig(); | 271 | rfcommAssign.saveConfig(); |
272 | } | 272 | } |
273 | } | 273 | } |
@@ -448,241 +448,241 @@ void BlueBase::addServicesToDevice( const QString& device, Services::ValueList s | |||
448 | QValueList<OpieTooth::Services>::Iterator it2; | 448 | QValueList<OpieTooth::Services>::Iterator it2; |
449 | BTServiceItem* serviceItem; | 449 | BTServiceItem* serviceItem; |
450 | 450 | ||
451 | 451 | ||
452 | if (!servicesList.isEmpty() ) | 452 | if (!servicesList.isEmpty() ) |
453 | { | 453 | { |
454 | // add services | 454 | // add services |
455 | QMap<int, QString> list; | 455 | QMap<int, QString> list; |
456 | QMap<int, QString>::Iterator classIt; | 456 | QMap<int, QString>::Iterator classIt; |
457 | for( it2 = servicesList.begin(); it2 != servicesList.end(); ++it2 ) | 457 | for( it2 = servicesList.begin(); it2 != servicesList.end(); ++it2 ) |
458 | { | 458 | { |
459 | serviceItem = new BTServiceItem( deviceItem, (*it2) ); | 459 | serviceItem = new BTServiceItem( deviceItem, (*it2) ); |
460 | list = (*it2).classIdList(); | 460 | list = (*it2).classIdList(); |
461 | classIt = list.begin(); | 461 | classIt = list.begin(); |
462 | int classId=0; | 462 | int classId=0; |
463 | if ( classIt != list.end() ) | 463 | if ( classIt != list.end() ) |
464 | { | 464 | { |
465 | classId = classIt.key(); | 465 | classId = classIt.key(); |
466 | } | 466 | } |
467 | 467 | ||
468 | serviceItem->setPixmap( 0, m_iconLoader->serviceIcon( classId ) ); | 468 | serviceItem->setPixmap( 0, m_iconLoader->serviceIcon( classId ) ); |
469 | } | 469 | } |
470 | } | 470 | } |
471 | else | 471 | else |
472 | { | 472 | { |
473 | Services s1; | 473 | Services s1; |
474 | s1.setServiceName( tr("no services found") ); | 474 | s1.setServiceName( tr("no services found") ); |
475 | serviceItem = new BTServiceItem( deviceItem, s1 ); | 475 | serviceItem = new BTServiceItem( deviceItem, s1 ); |
476 | } | 476 | } |
477 | // now remove them from the list | 477 | // now remove them from the list |
478 | m_deviceList.remove( it ); | 478 | m_deviceList.remove( it ); |
479 | } | 479 | } |
480 | 480 | ||
481 | 481 | ||
482 | 482 | ||
483 | 483 | ||
484 | 484 | ||
485 | void BlueBase::addSignalStrength() | 485 | void BlueBase::addSignalStrength() |
486 | { | 486 | { |
487 | 487 | ||
488 | QListViewItemIterator it( ListView4 ); | 488 | QListViewItemIterator it( ListView4 ); |
489 | for ( ; it.current(); ++it ) | 489 | for ( ; it.current(); ++it ) |
490 | { | 490 | { |
491 | m_localDevice->signalStrength( ((BTConnectionItem*)it.current() )->connection().mac() ); | 491 | m_localDevice->signalStrength( ((BTConnectionItem*)it.current() )->connection().mac() ); |
492 | } | 492 | } |
493 | 493 | ||
494 | QTimer::singleShot( 5000, this, SLOT( addSignalStrength() ) ); | 494 | QTimer::singleShot( 5000, this, SLOT( addSignalStrength() ) ); |
495 | } | 495 | } |
496 | 496 | ||
497 | void BlueBase::addSignalStrength( const QString& mac, const QString& strength ) | 497 | void BlueBase::addSignalStrength( const QString& mac, const QString& strength ) |
498 | { | 498 | { |
499 | 499 | ||
500 | QListViewItemIterator it( ListView4 ); | 500 | QListViewItemIterator it( ListView4 ); |
501 | for ( ; it.current(); ++it ) | 501 | for ( ; it.current(); ++it ) |
502 | { | 502 | { |
503 | if( ((BTConnectionItem*)it.current())->connection().mac() == mac ) | 503 | if( ((BTConnectionItem*)it.current())->connection().mac() == mac ) |
504 | { | 504 | { |
505 | ((BTConnectionItem*)it.current() )->setSignalStrength( strength ); | 505 | ((BTConnectionItem*)it.current() )->setSignalStrength( strength ); |
506 | } | 506 | } |
507 | } | 507 | } |
508 | } | 508 | } |
509 | 509 | ||
510 | /** | 510 | /** |
511 | * Add the existing connections (pairs) to the connections tab. | 511 | * Add the existing connections (pairs) to the connections tab. |
512 | * This one triggers the search | 512 | * This one triggers the search |
513 | */ | 513 | */ |
514 | void BlueBase::addConnectedDevices() | 514 | void BlueBase::addConnectedDevices() |
515 | { | 515 | { |
516 | m_localDevice->searchConnections(); | 516 | m_localDevice->searchConnections(); |
517 | } | 517 | } |
518 | 518 | ||
519 | /** | 519 | /** |
520 | * This adds the found connections to the connection tab. | 520 | * This adds the found connections to the connection tab. |
521 | * @param connectionList the ValueList with all current connections | 521 | * @param connectionList the ValueList with all current connections |
522 | */ | 522 | */ |
523 | void BlueBase::addConnectedDevices( ConnectionState::ValueList connectionList ) | 523 | void BlueBase::addConnectedDevices( ConnectionState::ValueList connectionList ) |
524 | { | 524 | { |
525 | 525 | ||
526 | QValueList<OpieTooth::ConnectionState>::Iterator it; | 526 | QValueList<OpieTooth::ConnectionState>::Iterator it; |
527 | BTConnectionItem * connectionItem; | 527 | BTConnectionItem * connectionItem; |
528 | 528 | ||
529 | if ( !connectionList.isEmpty() ) | 529 | if ( !connectionList.isEmpty() ) |
530 | { | 530 | { |
531 | 531 | ||
532 | for (it = connectionList.begin(); it != connectionList.end(); ++it) | 532 | for (it = connectionList.begin(); it != connectionList.end(); ++it) |
533 | { | 533 | { |
534 | 534 | ||
535 | QListViewItemIterator it2( ListView4 ); | 535 | QListViewItemIterator it2( ListView4 ); |
536 | bool found = false; | 536 | bool found = false; |
537 | for ( ; it2.current(); ++it2 ) | 537 | for ( ; it2.current(); ++it2 ) |
538 | { | 538 | { |
539 | if( ( (BTConnectionItem*)it2.current())->connection().mac() == (*it).mac() ) | 539 | if( ( (BTConnectionItem*)it2.current())->connection().mac() == (*it).mac() ) |
540 | { | 540 | { |
541 | found = true; | 541 | found = true; |
542 | } | 542 | } |
543 | } | 543 | } |
544 | 544 | ||
545 | if ( found == false ) | 545 | if ( found == false ) |
546 | { | 546 | { |
547 | connectionItem = new BTConnectionItem( ListView4, (*it) ); | 547 | connectionItem = new BTConnectionItem( ListView4, (*it) ); |
548 | 548 | ||
549 | if( m_deviceList.find((*it).mac()).data() ) | 549 | if( m_deviceList.find((*it).mac()).data() ) |
550 | { | 550 | { |
551 | connectionItem->setName( m_deviceList.find( (*it).mac()).data()->name() ); | 551 | connectionItem->setName( m_deviceList.find( (*it).mac()).data()->name() ); |
552 | } | 552 | } |
553 | } | 553 | } |
554 | 554 | ||
555 | } | 555 | } |
556 | 556 | ||
557 | QListViewItemIterator it2( ListView4 ); | 557 | QListViewItemIterator it2( ListView4 ); |
558 | for ( ; it2.current(); ++it2 ) | 558 | for ( ; it2.current(); ++it2 ) |
559 | { | 559 | { |
560 | bool found = false; | 560 | bool found = false; |
561 | for (it = connectionList.begin(); it != connectionList.end(); ++it) | 561 | for (it = connectionList.begin(); it != connectionList.end(); ++it) |
562 | { | 562 | { |
563 | if( ( ((BTConnectionItem*)it2.current())->connection().mac() ) == (*it).mac() ) | 563 | if( ( ((BTConnectionItem*)it2.current())->connection().mac() ) == (*it).mac() ) |
564 | { | 564 | { |
565 | found = true; | 565 | found = true; |
566 | } | 566 | } |
567 | } | 567 | } |
568 | 568 | ||
569 | if ( !found ) | 569 | if ( !found ) |
570 | { | 570 | { |
571 | delete it2.current(); | 571 | delete it2.current(); |
572 | } | 572 | } |
573 | 573 | ||
574 | } | 574 | } |
575 | 575 | ||
576 | 576 | ||
577 | } | 577 | } |
578 | else | 578 | else |
579 | { | 579 | { |
580 | ListView4->clear(); | 580 | ListView4->clear(); |
581 | ConnectionState con; | 581 | ConnectionState con; |
582 | con.setMac( tr("No connections found") ); | 582 | con.setMac( tr("No connections found") ); |
583 | connectionItem = new BTConnectionItem( ListView4 , con ); | 583 | connectionItem = new BTConnectionItem( ListView4 , con ); |
584 | } | 584 | } |
585 | 585 | ||
586 | // recall connection search after some time | 586 | // recall connection search after some time |
587 | QTimer::singleShot( 15000, this, SLOT( addConnectedDevices() ) ); | 587 | QTimer::singleShot( 15000, this, SLOT( addConnectedDevices() ) ); |
588 | } | 588 | } |
589 | 589 | ||
590 | 590 | ||
591 | /** | 591 | /** |
592 | * Find out if a device can currently be reached | 592 | * Find out if a device can currently be reached |
593 | * @param device | 593 | * @param device |
594 | */ | 594 | */ |
595 | void BlueBase::deviceActive( const RemoteDevice &device ) | 595 | void BlueBase::deviceActive( const RemoteDevice &device ) |
596 | { | 596 | { |
597 | // search by mac, async, gets a signal back | 597 | // search by mac, async, gets a signal back |
598 | // We should have a BTDeviceItem there or where does it get added to the map -zecke | 598 | // We should have a BTDeviceItem there or where does it get added to the map -zecke |
599 | m_localDevice->isAvailable( device.mac() ); | 599 | m_localDevice->isAvailable( device.mac() ); |
600 | } | 600 | } |
601 | 601 | ||
602 | 602 | ||
603 | /** | 603 | /** |
604 | * The signal catcher. Set the avail. status on device. | 604 | * The signal catcher. Set the avail. status on device. |
605 | * @param device - the mac address | 605 | * @param device - the mac address |
606 | * @param connected - if it is avail. or not | 606 | * @param connected - if it is avail. or not |
607 | */ | 607 | */ |
608 | void BlueBase::deviceActive( const QString& device, bool connected ) | 608 | void BlueBase::deviceActive( const QString& device, bool connected ) |
609 | { | 609 | { |
610 | qDebug("deviceActive slot"); | 610 | qDebug("deviceActive slot"); |
611 | 611 | ||
612 | QMap<QString,BTDeviceItem*>::Iterator it; | 612 | QMap<QString,BTDeviceItem*>::Iterator it; |
613 | 613 | ||
614 | it = m_deviceList.find( device ); | 614 | it = m_deviceList.find( device ); |
615 | if( it == m_deviceList.end() ) | 615 | if( it == m_deviceList.end() ) |
616 | return; | 616 | return; |
617 | 617 | ||
618 | BTDeviceItem* deviceItem = it.data(); | 618 | BTDeviceItem* deviceItem = it.data(); |
619 | 619 | ||
620 | 620 | ||
621 | if ( connected ) | 621 | if ( connected ) |
622 | { | 622 | { |
623 | deviceItem->setPixmap( 1, m_onPix ); | 623 | deviceItem->setPixmap( 1, m_onPix ); |
624 | } | 624 | } |
625 | else | 625 | else |
626 | { | 626 | { |
627 | deviceItem->setPixmap( 1, m_offPix ); | 627 | deviceItem->setPixmap( 1, m_offPix ); |
628 | } | 628 | } |
629 | m_deviceList.remove( it ); | 629 | m_deviceList.remove( it ); |
630 | } | 630 | } |
631 | 631 | ||
632 | 632 | ||
633 | /** | 633 | /** |
634 | * Open the "scan for devices" dialog | 634 | * Open the "scan for devices" dialog |
635 | */ | 635 | */ |
636 | void BlueBase::startScan() | 636 | void BlueBase::startScan() |
637 | { | 637 | { |
638 | ScanDialog *scan = new ScanDialog( this, "ScanDialog", | 638 | ScanDialog *scan = new ScanDialog( this, "ScanDialog", |
639 | true, WDestructiveClose ); | 639 | true, WDestructiveClose ); |
640 | QObject::connect( scan, SIGNAL( selectedDevices( const QValueList<RemoteDevice>& ) ), | 640 | QObject::connect( scan, SIGNAL( selectedDevices(const QValueList<RemoteDevice>&) ), |
641 | this, SLOT( addSearchedDevices( const QValueList<RemoteDevice>& ) ) ); | 641 | this, SLOT( addSearchedDevices(const QValueList<RemoteDevice>&) ) ); |
642 | 642 | ||
643 | QPEApplication::showDialog( scan ); | 643 | QPEApplication::showDialog( scan ); |
644 | } | 644 | } |
645 | 645 | ||
646 | 646 | ||
647 | /** | 647 | /** |
648 | * Set the informations about the local device in information Tab | 648 | * Set the informations about the local device in information Tab |
649 | */ | 649 | */ |
650 | void BlueBase::setInfo() | 650 | void BlueBase::setInfo() |
651 | { | 651 | { |
652 | StatusLabel->setText( status() ); | 652 | StatusLabel->setText( status() ); |
653 | } | 653 | } |
654 | 654 | ||
655 | 655 | ||
656 | /** | 656 | /** |
657 | * Decontructor | 657 | * Decontructor |
658 | */ | 658 | */ |
659 | BlueBase::~BlueBase() | 659 | BlueBase::~BlueBase() |
660 | { | 660 | { |
661 | writeSavedDevices(); | 661 | writeSavedDevices(); |
662 | delete m_iconLoader; | 662 | delete m_iconLoader; |
663 | } | 663 | } |
664 | 664 | ||
665 | 665 | ||
666 | /** | 666 | /** |
667 | * find searches the ListView for a BTDeviceItem containig | 667 | * find searches the ListView for a BTDeviceItem containig |
668 | * the same Device if found return true else false | 668 | * the same Device if found return true else false |
669 | * @param dev RemoteDevice to find | 669 | * @param dev RemoteDevice to find |
670 | * @return returns true if found | 670 | * @return returns true if found |
671 | */ | 671 | */ |
672 | bool BlueBase::find( const RemoteDevice& rem ) | 672 | bool BlueBase::find( const RemoteDevice& rem ) |
673 | { | 673 | { |
674 | QListViewItemIterator it( ListView2 ); | 674 | QListViewItemIterator it( ListView2 ); |
675 | BTListItem* item; | 675 | BTListItem* item; |
676 | BTDeviceItem* device; | 676 | BTDeviceItem* device; |
677 | for (; it.current(); ++it ) | 677 | for (; it.current(); ++it ) |
678 | { | 678 | { |
679 | item = (BTListItem*) it.current(); | 679 | item = (BTListItem*) it.current(); |
680 | if ( item->typeId() != BTListItem::Device ) | 680 | if ( item->typeId() != BTListItem::Device ) |
681 | continue; | 681 | continue; |
682 | 682 | ||
683 | device = (BTDeviceItem*)item; | 683 | device = (BTDeviceItem*)item; |
684 | if ( rem.equals( device->remoteDevice() ) ) | 684 | if ( rem.equals( device->remoteDevice() ) ) |
685 | return true; | 685 | return true; |
686 | } | 686 | } |
687 | return false; // not found | 687 | return false; // not found |
688 | } | 688 | } |