author | zecke <zecke> | 2002-06-28 16:30:08 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-06-28 16:30:08 (UTC) |
commit | e72d93a703f4b38109f8f02ec96a759d93b8f91c (patch) (unidiff) | |
tree | 39d6725fa1061965c64c42dabb663a3cfdc1c976 | |
parent | ce221c2cf5b003f1033e6f0b603670ceb0bff7c7 (diff) | |
download | opie-e72d93a703f4b38109f8f02ec96a759d93b8f91c.zip opie-e72d93a703f4b38109f8f02ec96a759d93b8f91c.tar.gz opie-e72d93a703f4b38109f8f02ec96a759d93b8f91c.tar.bz2 |
Don't leak
-rw-r--r-- | noncore/net/opietooth/manager/bluebase.cpp | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/noncore/net/opietooth/manager/bluebase.cpp b/noncore/net/opietooth/manager/bluebase.cpp index b4b59c3..0385cb1 100644 --- a/noncore/net/opietooth/manager/bluebase.cpp +++ b/noncore/net/opietooth/manager/bluebase.cpp | |||
@@ -1,515 +1,516 @@ | |||
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 | 21 | ||
22 | #include <qframe.h> | 22 | #include <qframe.h> |
23 | #include <qlabel.h> | 23 | #include <qlabel.h> |
24 | #include <qpushbutton.h> | 24 | #include <qpushbutton.h> |
25 | #include <qlayout.h> | 25 | #include <qlayout.h> |
26 | #include <qvariant.h> | 26 | #include <qvariant.h> |
27 | #include <qwhatsthis.h> | 27 | #include <qwhatsthis.h> |
28 | #include <qimage.h> | 28 | #include <qimage.h> |
29 | #include <qpixmap.h> | 29 | #include <qpixmap.h> |
30 | #include <qtabwidget.h> | 30 | #include <qtabwidget.h> |
31 | #include <qscrollview.h> | 31 | #include <qscrollview.h> |
32 | #include <qvbox.h> | 32 | #include <qvbox.h> |
33 | #include <qmessagebox.h> | 33 | #include <qmessagebox.h> |
34 | #include <qcheckbox.h> | 34 | #include <qcheckbox.h> |
35 | #include <qlineedit.h> | 35 | #include <qlineedit.h> |
36 | #include <qlistview.h> | 36 | #include <qlistview.h> |
37 | #include <qdir.h> | 37 | #include <qdir.h> |
38 | #include <qpopupmenu.h> | 38 | #include <qpopupmenu.h> |
39 | 39 | ||
40 | #include <qpe/resource.h> | 40 | #include <qpe/resource.h> |
41 | #include <qpe/config.h> | 41 | #include <qpe/config.h> |
42 | 42 | ||
43 | #include <remotedevice.h> | 43 | #include <remotedevice.h> |
44 | 44 | ||
45 | 45 | ||
46 | namespace OpieTooth { | 46 | namespace OpieTooth { |
47 | 47 | ||
48 | 48 | ||
49 | BlueBase::BlueBase( QWidget* parent, const char* name, WFlags fl ) | 49 | BlueBase::BlueBase( QWidget* parent, const char* name, WFlags fl ) |
50 | : BluetoothBase( parent, name, fl ) { | 50 | : BluetoothBase( parent, name, fl ) { |
51 | 51 | ||
52 | localDevice = new Manager( "hci0" ); | 52 | localDevice = new Manager( "hci0" ); |
53 | 53 | ||
54 | connect( PushButton2, SIGNAL( clicked() ), this, SLOT(startScan() ) ); | 54 | connect( PushButton2, SIGNAL( clicked() ), this, SLOT(startScan() ) ); |
55 | connect( configApplyButton, SIGNAL(clicked() ), this, SLOT(applyConfigChanges() ) ); | 55 | connect( configApplyButton, SIGNAL(clicked() ), this, SLOT(applyConfigChanges() ) ); |
56 | // not good since lib is async | 56 | // not good since lib is async |
57 | // connect( ListView2, SIGNAL( expanded ( QListViewItem* ) ), | 57 | // connect( ListView2, SIGNAL( expanded ( QListViewItem* ) ), |
58 | // this, SLOT( addServicesToDevice( QListViewItem * ) ) ); | 58 | // this, SLOT( addServicesToDevice( QListViewItem * ) ) ); |
59 | connect( ListView2, SIGNAL( clicked( QListViewItem* )), | 59 | connect( ListView2, SIGNAL( clicked( QListViewItem* )), |
60 | this, SLOT( startServiceActionClicked( QListViewItem* ) ) ); | 60 | this, SLOT( startServiceActionClicked( QListViewItem* ) ) ); |
61 | // hehe, cast right later | 61 | // hehe, cast right later |
62 | connect( ListView2, SIGNAL( rightButtonClicked( QListViewItem *, const QPoint &, int ) ), | 62 | connect( ListView2, SIGNAL( rightButtonClicked( QListViewItem *, const QPoint &, int ) ), |
63 | this, SLOT(startServiceActionHold( QListViewItem *, const QPoint &, int) ) ); | 63 | this, SLOT(startServiceActionHold( QListViewItem *, const QPoint &, int) ) ); |
64 | connect( localDevice , SIGNAL( foundServices( const QString& , Services::ValueList ) ), | 64 | connect( localDevice , SIGNAL( foundServices( const QString& , Services::ValueList ) ), |
65 | this, SLOT( addServicesToDevice( const QString& , Services::ValueList ) ) ); | 65 | this, SLOT( addServicesToDevice( const QString& , Services::ValueList ) ) ); |
66 | connect( localDevice, SIGNAL( available( const QString&, bool ) ), | 66 | connect( localDevice, SIGNAL( available( const QString&, bool ) ), |
67 | this, SLOT( deviceActive( const QString& , bool ) ) ); | 67 | this, SLOT( deviceActive( const QString& , bool ) ) ); |
68 | 68 | ||
69 | //Load all icons needed | 69 | //Load all icons needed |
70 | 70 | ||
71 | offPix = Resource::loadPixmap( "editdelete" ); | 71 | offPix = Resource::loadPixmap( "editdelete" ); |
72 | onPix = Resource::loadPixmap( "installed" ); | 72 | onPix = Resource::loadPixmap( "installed" ); |
73 | 73 | ||
74 | QPalette pal = this->palette(); | 74 | QPalette pal = this->palette(); |
75 | QColor col = pal.color( QPalette::Active, QColorGroup::Background ); | 75 | QColor col = pal.color( QPalette::Active, QColorGroup::Background ); |
76 | pal.setColor( QPalette::Active, QColorGroup::Button, col ); | 76 | pal.setColor( QPalette::Active, QColorGroup::Button, col ); |
77 | pal.setColor( QPalette::Inactive, QColorGroup::Button, col ); | 77 | pal.setColor( QPalette::Inactive, QColorGroup::Button, col ); |
78 | pal.setColor( QPalette::Normal, QColorGroup::Button, col ); | 78 | pal.setColor( QPalette::Normal, QColorGroup::Button, col ); |
79 | pal.setColor( QPalette::Disabled, QColorGroup::Button, col ); | 79 | pal.setColor( QPalette::Disabled, QColorGroup::Button, col ); |
80 | this->setPalette( pal ); | 80 | this->setPalette( pal ); |
81 | 81 | ||
82 | setCaption( tr( "Bluetooth Manager" ) ); | 82 | setCaption( tr( "Bluetooth Manager" ) ); |
83 | 83 | ||
84 | readConfig(); | 84 | readConfig(); |
85 | initGui(); | 85 | initGui(); |
86 | 86 | ||
87 | //TESTING | 87 | //TESTING |
88 | ListView2->setRootIsDecorated(true); | 88 | ListView2->setRootIsDecorated(true); |
89 | 89 | ||
90 | BTListItem *topLV2 = new BTListItem( ListView2, "Siemens S45", "", "device" ); | 90 | BTListItem *topLV2 = new BTListItem( ListView2, "Siemens S45", "", "device" ); |
91 | topLV2->setPixmap( 1, onPix ); | 91 | topLV2->setPixmap( 1, onPix ); |
92 | (void) new BTListItem( topLV2, "Serial" ,"", "service" ); | 92 | (void) new BTListItem( topLV2, "Serial" ,"", "service" ); |
93 | (void) new BTListItem( topLV2, "BlueNiC" , "", "service" ); | 93 | (void) new BTListItem( topLV2, "BlueNiC" , "", "service" ); |
94 | writeToHciConfig(); | 94 | writeToHciConfig(); |
95 | } | 95 | } |
96 | 96 | ||
97 | 97 | ||
98 | /** | 98 | /** |
99 | * Reads all options from the config file | 99 | * Reads all options from the config file |
100 | */ | 100 | */ |
101 | void BlueBase::readConfig() { | 101 | void BlueBase::readConfig() { |
102 | 102 | ||
103 | Config cfg( "bluetoothmanager" ); | 103 | Config cfg( "bluetoothmanager" ); |
104 | cfg.setGroup( "bluezsettings" ); | 104 | cfg.setGroup( "bluezsettings" ); |
105 | 105 | ||
106 | 106 | ||
107 | deviceName = cfg.readEntry( "name" , "No name" ); // name the device should identify with | 107 | deviceName = cfg.readEntry( "name" , "No name" ); // name the device should identify with |
108 | defaultPasskey = cfg.readEntryCrypt( "passkey" , "" ); // <- hmm, look up how good the trolls did that, maybe too weak | 108 | defaultPasskey = cfg.readEntryCrypt( "passkey" , "" ); // <- hmm, look up how good the trolls did that, maybe too weak |
109 | useEncryption = cfg.readNumEntry( "useEncryption" , 1 ); | 109 | useEncryption = cfg.readNumEntry( "useEncryption" , 1 ); |
110 | enableAuthentification = cfg.readNumEntry( "enableAuthentification" , 1 ); | 110 | enableAuthentification = cfg.readNumEntry( "enableAuthentification" , 1 ); |
111 | enablePagescan = cfg.readNumEntry( "enablePagescan" , 1 ); | 111 | enablePagescan = cfg.readNumEntry( "enablePagescan" , 1 ); |
112 | enableInquiryscan = cfg.readNumEntry( "enableInquiryscan" , 1 ); | 112 | enableInquiryscan = cfg.readNumEntry( "enableInquiryscan" , 1 ); |
113 | 113 | ||
114 | } | 114 | } |
115 | 115 | ||
116 | /** | 116 | /** |
117 | * Writes all options to the config file | 117 | * Writes all options to the config file |
118 | */ | 118 | */ |
119 | void BlueBase::writeConfig() { | 119 | void BlueBase::writeConfig() { |
120 | 120 | ||
121 | 121 | ||
122 | Config cfg( "bluetoothmanager" ); | 122 | Config cfg( "bluetoothmanager" ); |
123 | cfg.setGroup( "bluezsettings" ); | 123 | cfg.setGroup( "bluezsettings" ); |
124 | 124 | ||
125 | cfg.writeEntry( "name" , deviceName ); | 125 | cfg.writeEntry( "name" , deviceName ); |
126 | cfg.writeEntryCrypt( "passkey" , defaultPasskey ); | 126 | cfg.writeEntryCrypt( "passkey" , defaultPasskey ); |
127 | cfg.writeEntry( "useEncryption" , useEncryption ); | 127 | cfg.writeEntry( "useEncryption" , useEncryption ); |
128 | cfg.writeEntry( "enableAuthentification" , enableAuthentification ); | 128 | cfg.writeEntry( "enableAuthentification" , enableAuthentification ); |
129 | cfg.writeEntry( "enablePagescan" , enablePagescan ); | 129 | cfg.writeEntry( "enablePagescan" , enablePagescan ); |
130 | cfg.writeEntry( "enableInquiryscan" , enableInquiryscan ); | 130 | cfg.writeEntry( "enableInquiryscan" , enableInquiryscan ); |
131 | 131 | ||
132 | writeToHciConfig(); | 132 | writeToHciConfig(); |
133 | } | 133 | } |
134 | 134 | ||
135 | void BlueBase::writeToHciConfig() { | 135 | void BlueBase::writeToHciConfig() { |
136 | 136 | ||
137 | HciConfWrapper *hciconf = new HciConfWrapper( "/tmp/hcid.conf" ); | 137 | HciConfWrapper *hciconf = new HciConfWrapper( "/tmp/hcid.conf" ); |
138 | hciconf->setPinHelper( "/bin/QtPalmtop/bin/blue-pin" ); | 138 | hciconf->setPinHelper( "/bin/QtPalmtop/bin/blue-pin" ); |
139 | 139 | ||
140 | 140 | ||
141 | // hciconf->setPinHelper( "/bin/QtPalmtop/bin/blue-pin" ); | 141 | // hciconf->setPinHelper( "/bin/QtPalmtop/bin/blue-pin" ); |
142 | 142 | ||
143 | hciconf->setName( deviceName ); | 143 | hciconf->setName( deviceName ); |
144 | 144 | ||
145 | if ( useEncryption == 1) { | 145 | if ( useEncryption == 1) { |
146 | hciconf->setEncrypt( true ); | 146 | hciconf->setEncrypt( true ); |
147 | } else { | 147 | } else { |
148 | hciconf->setEncrypt( false ); | 148 | hciconf->setEncrypt( false ); |
149 | } | 149 | } |
150 | 150 | ||
151 | 151 | ||
152 | if ( enableAuthentification == 1) { | 152 | if ( enableAuthentification == 1) { |
153 | hciconf->setAuth( true ); | 153 | hciconf->setAuth( true ); |
154 | } else { | 154 | } else { |
155 | hciconf->setAuth( false ); | 155 | hciconf->setAuth( false ); |
156 | } | 156 | } |
157 | 157 | ||
158 | if ( enablePagescan == 1) { | 158 | if ( enablePagescan == 1) { |
159 | hciconf->setPscan( true ); | 159 | hciconf->setPscan( true ); |
160 | } else { | 160 | } else { |
161 | hciconf->setPscan( false ); | 161 | hciconf->setPscan( false ); |
162 | } | 162 | } |
163 | 163 | ||
164 | if ( enableInquiryscan == 1) { | 164 | if ( enableInquiryscan == 1) { |
165 | hciconf->setIscan( true ); | 165 | hciconf->setIscan( true ); |
166 | } else { | 166 | } else { |
167 | hciconf->setIscan( false ); | 167 | hciconf->setIscan( false ); |
168 | } | 168 | } |
169 | delete hciconf; | ||
169 | } | 170 | } |
170 | 171 | ||
171 | 172 | ||
172 | /** | 173 | /** |
173 | * Read the list of allready known devices | 174 | * Read the list of allready known devices |
174 | * | 175 | * |
175 | */ | 176 | */ |
176 | void BlueBase::readSavedDevices() { | 177 | void BlueBase::readSavedDevices() { |
177 | 178 | ||
178 | QList<RemoteDevice> *loadedDevices = new QList<RemoteDevice>; | 179 | QList<RemoteDevice> *loadedDevices = new QList<RemoteDevice>; |
179 | 180 | ||
180 | QDir deviceListSave( QDir::homeDirPath() + "/Settings/bluetooth/"); | 181 | QDir deviceListSave( QDir::homeDirPath() + "/Settings/bluetooth/"); |
181 | // list of .conf files | 182 | // list of .conf files |
182 | QStringList devicesFileList = deviceListSave.entryList(); | 183 | QStringList devicesFileList = deviceListSave.entryList(); |
183 | 184 | ||
184 | // cut .conf of to get the mac and also read the name entry in it. | 185 | // cut .conf of to get the mac and also read the name entry in it. |
185 | 186 | ||
186 | for ( QStringList::Iterator it = devicesFileList.begin(); it != devicesFileList.end(); ++it ) { | 187 | for ( QStringList::Iterator it = devicesFileList.begin(); it != devicesFileList.end(); ++it ) { |
187 | 188 | ||
188 | QString name; | 189 | QString name; |
189 | QString mac; | 190 | QString mac; |
190 | qDebug((*it).latin1() ); | 191 | qDebug((*it).latin1() ); |
191 | Config conf((*it)); | 192 | Config conf((*it)); |
192 | conf.setGroup("Info"); | 193 | conf.setGroup("Info"); |
193 | name = conf.readEntry("name", "Error"); | 194 | name = conf.readEntry("name", "Error"); |
194 | qDebug("MAC: " + mac); | 195 | qDebug("MAC: " + mac); |
195 | qDebug("NAME: " + name); | 196 | qDebug("NAME: " + name); |
196 | RemoteDevice currentDevice = RemoteDevice( mac , name ); | 197 | RemoteDevice currentDevice = RemoteDevice( mac , name ); |
197 | loadedDevices->append( ¤tDevice ); | 198 | loadedDevices->append( ¤tDevice ); |
198 | } | 199 | } |
199 | addSearchedDevices( *loadedDevices ); | 200 | addSearchedDevices( *loadedDevices ); |
200 | } | 201 | } |
201 | 202 | ||
202 | /** | 203 | /** |
203 | * Write the list of allready known devices | 204 | * Write the list of allready known devices |
204 | * | 205 | * |
205 | */ | 206 | */ |
206 | void BlueBase::writeSavedDevices() { | 207 | void BlueBase::writeSavedDevices() { |
207 | 208 | ||
208 | QListViewItemIterator it( ListView2 ); | 209 | QListViewItemIterator it( ListView2 ); |
209 | 210 | ||
210 | for ( ; it.current(); ++it ) { | 211 | for ( ; it.current(); ++it ) { |
211 | 212 | ||
212 | // seperate config file for each device, to store more information in future. | 213 | // seperate config file for each device, to store more information in future. |
213 | // TO FIX: BTLISTITEM!!! | 214 | // TO FIX: BTLISTITEM!!! |
214 | 215 | ||
215 | // Config conf( QDir::homeDirPath() + "/Settings/bluetooth/" + (((BTListItem)it.current())->mac()) + ".conf", Config::File ); | 216 | // Config conf( QDir::homeDirPath() + "/Settings/bluetooth/" + (((BTListItem)it.current())->mac()) + ".conf", Config::File ); |
216 | // conf.setGroup( "Info" ); | 217 | // conf.setGroup( "Info" ); |
217 | // conf.writeEntry( "name", it.current()->name() ); | 218 | // conf.writeEntry( "name", it.current()->name() ); |
218 | } | 219 | } |
219 | } | 220 | } |
220 | 221 | ||
221 | 222 | ||
222 | /** | 223 | /** |
223 | * Set up the gui | 224 | * Set up the gui |
224 | */ | 225 | */ |
225 | void BlueBase::initGui() { | 226 | void BlueBase::initGui() { |
226 | 227 | ||
227 | StatusLabel->setText( getStatus() ); // maybe move it to getStatus() | 228 | StatusLabel->setText( getStatus() ); // maybe move it to getStatus() |
228 | 229 | ||
229 | cryptCheckBox->setChecked( useEncryption ); | 230 | cryptCheckBox->setChecked( useEncryption ); |
230 | authCheckBox->setChecked( enableAuthentification ); | 231 | authCheckBox->setChecked( enableAuthentification ); |
231 | pagescanCheckBox->setChecked( enablePagescan ); | 232 | pagescanCheckBox->setChecked( enablePagescan ); |
232 | inquiryscanCheckBox->setChecked( enableInquiryscan ); | 233 | inquiryscanCheckBox->setChecked( enableInquiryscan ); |
233 | deviceNameLine->setText( deviceName ); | 234 | deviceNameLine->setText( deviceName ); |
234 | passkeyLine->setText( defaultPasskey ); | 235 | passkeyLine->setText( defaultPasskey ); |
235 | // set info tab | 236 | // set info tab |
236 | setInfo(); | 237 | setInfo(); |
237 | } | 238 | } |
238 | 239 | ||
239 | 240 | ||
240 | /** | 241 | /** |
241 | * Get the status informations and returns it | 242 | * Get the status informations and returns it |
242 | * @return QString the status informations gathered | 243 | * @return QString the status informations gathered |
243 | */ | 244 | */ |
244 | QString BlueBase::getStatus(){ | 245 | QString BlueBase::getStatus(){ |
245 | 246 | ||
246 | QString infoString = tr( "<b>Device name : </b> Ipaq" ); | 247 | QString infoString = tr( "<b>Device name : </b> Ipaq" ); |
247 | infoString += QString( "<br><b>" + tr( "MAC adress: " ) +"</b> No idea" ); | 248 | infoString += QString( "<br><b>" + tr( "MAC adress: " ) +"</b> No idea" ); |
248 | infoString += QString( "<br><b>" + tr( "Class" ) + "</b> PDA" ); | 249 | infoString += QString( "<br><b>" + tr( "Class" ) + "</b> PDA" ); |
249 | 250 | ||
250 | return (infoString); | 251 | return (infoString); |
251 | } | 252 | } |
252 | 253 | ||
253 | 254 | ||
254 | /** | 255 | /** |
255 | * Read the current values from the gui and invoke writeConfig() | 256 | * Read the current values from the gui and invoke writeConfig() |
256 | */ | 257 | */ |
257 | void BlueBase::applyConfigChanges() { | 258 | void BlueBase::applyConfigChanges() { |
258 | 259 | ||
259 | deviceName = deviceNameLine->text(); | 260 | deviceName = deviceNameLine->text(); |
260 | defaultPasskey = passkeyLine->text(); | 261 | defaultPasskey = passkeyLine->text(); |
261 | useEncryption = cryptCheckBox->isChecked(); | 262 | useEncryption = cryptCheckBox->isChecked(); |
262 | enableAuthentification = authCheckBox->isChecked(); | 263 | enableAuthentification = authCheckBox->isChecked(); |
263 | enablePagescan = pagescanCheckBox->isChecked(); | 264 | enablePagescan = pagescanCheckBox->isChecked(); |
264 | enableInquiryscan = inquiryscanCheckBox->isChecked(); | 265 | enableInquiryscan = inquiryscanCheckBox->isChecked(); |
265 | 266 | ||
266 | writeConfig(); | 267 | writeConfig(); |
267 | 268 | ||
268 | 269 | ||
269 | QMessageBox* box = new QMessageBox( this, "Test" ); | 270 | QMessageBox* box = new QMessageBox( this, "Test" ); |
270 | box->setText( tr( "Changes applied" ) ); | 271 | box->setText( tr( "Changes applied" ) ); |
271 | box->show(); | 272 | box->show(); |
272 | // falls nötig hcid killhupen - die funktionalität adden | 273 | // falls nötig hcid killhupen - die funktionalität adden |
273 | } | 274 | } |
274 | 275 | ||
275 | 276 | ||
276 | /** | 277 | /** |
277 | * Add fresh found devices from scan dialog to the listing | 278 | * Add fresh found devices from scan dialog to the listing |
278 | * | 279 | * |
279 | */ | 280 | */ |
280 | void BlueBase::addSearchedDevices( QList<RemoteDevice> &newDevices ) { | 281 | void BlueBase::addSearchedDevices( QList<RemoteDevice> &newDevices ) { |
281 | 282 | ||
282 | BTListItem * deviceItem; | 283 | BTListItem * deviceItem; |
283 | 284 | ||
284 | QListIterator<RemoteDevice> it( newDevices ); | 285 | QListIterator<RemoteDevice> it( newDevices ); |
285 | 286 | ||
286 | for( ; it.current() ; ++it ) { | 287 | for( ; it.current() ; ++it ) { |
287 | 288 | ||
288 | 289 | ||
289 | RemoteDevice *dev = it.current(); | 290 | RemoteDevice *dev = it.current(); |
290 | deviceItem = new BTListItem( ListView2 , dev->name(), dev->mac(), "device" ); | 291 | deviceItem = new BTListItem( ListView2 , dev->name(), dev->mac(), "device" ); |
291 | deviceItem->setExpandable ( true ); | 292 | deviceItem->setExpandable ( true ); |
292 | 293 | ||
293 | // look if device is avail. atm, async | 294 | // look if device is avail. atm, async |
294 | deviceActive( dev ); | 295 | deviceActive( dev ); |
295 | 296 | ||
296 | // move into the c'tor | 297 | // move into the c'tor |
297 | // deviceItem->setMac( dev->mac() ); | 298 | // deviceItem->setMac( dev->mac() ); |
298 | // what kind of entry is it. | 299 | // what kind of entry is it. |
299 | //deviceItem->setType( "device"); | 300 | //deviceItem->setType( "device"); |
300 | 301 | ||
301 | // ggf auch hier? | 302 | // ggf auch hier? |
302 | addServicesToDevice( deviceItem ); | 303 | addServicesToDevice( deviceItem ); |
303 | } | 304 | } |
304 | } | 305 | } |
305 | 306 | ||
306 | 307 | ||
307 | /** | 308 | /** |
308 | * Action that is toggled on entrys on click | 309 | * Action that is toggled on entrys on click |
309 | */ | 310 | */ |
310 | void BlueBase::startServiceActionClicked( QListViewItem *item ) { | 311 | void BlueBase::startServiceActionClicked( QListViewItem *item ) { |
311 | 312 | ||
312 | 313 | ||
313 | } | 314 | } |
314 | 315 | ||
315 | /** | 316 | /** |
316 | * Action that are toggled on hold (mostly QPopups i guess) | 317 | * Action that are toggled on hold (mostly QPopups i guess) |
317 | */ | 318 | */ |
318 | void BlueBase::startServiceActionHold( QListViewItem * item, const QPoint & point, int column ) { | 319 | void BlueBase::startServiceActionHold( QListViewItem * item, const QPoint & point, int column ) { |
319 | 320 | ||
320 | QPopupMenu *menu = new QPopupMenu(); | 321 | QPopupMenu *menu = new QPopupMenu(); |
321 | 322 | ||
322 | int ret=0; | 323 | int ret=0; |
323 | 324 | ||
324 | 325 | ||
325 | //QSize s = menu->sizeHint ( ); | 326 | //QSize s = menu->sizeHint ( ); |
326 | 327 | ||
327 | if ( ((BTListItem*)item)->type() == "device") { | 328 | if ( ((BTListItem*)item)->type() == "device") { |
328 | 329 | ||
329 | QPopupMenu *groups = new QPopupMenu(); | 330 | QPopupMenu *groups = new QPopupMenu(); |
330 | 331 | ||
331 | menu->insertItem( tr("rescan sevices:"), 0); | 332 | menu->insertItem( tr("rescan sevices:"), 0); |
332 | menu->insertItem( tr("to group"), groups , 1); | 333 | menu->insertItem( tr("to group"), groups , 1); |
333 | menu->insertItem( tr("delete"), 2); | 334 | menu->insertItem( tr("delete"), 2); |
334 | 335 | ||
335 | 336 | ||
336 | ret = menu->exec( point , 0); | 337 | ret = menu->exec( point , 0); |
337 | 338 | ||
338 | switch(ret) { | 339 | switch(ret) { |
339 | case 0: | 340 | case 0: |
340 | break; | 341 | break; |
341 | case 1: | 342 | case 1: |
342 | break; | 343 | break; |
343 | case 2: | 344 | case 2: |
344 | // delete childs too | 345 | // delete childs too |
345 | delete item; | 346 | delete item; |
346 | break; | 347 | break; |
347 | } | 348 | } |
348 | delete groups; | 349 | delete groups; |
349 | 350 | ||
350 | } else if ( ((BTListItem*)item)->type() == "service") { | 351 | } else if ( ((BTListItem*)item)->type() == "service") { |
351 | menu->insertItem( tr("Test1:"), 0); | 352 | menu->insertItem( tr("Test1:"), 0); |
352 | menu->insertItem( tr("connect"), 1); | 353 | menu->insertItem( tr("connect"), 1); |
353 | menu->insertItem( tr("delete"), 2); | 354 | menu->insertItem( tr("delete"), 2); |
354 | 355 | ||
355 | ret = menu->exec( point , 0); | 356 | ret = menu->exec( point , 0); |
356 | 357 | ||
357 | switch(ret) { | 358 | switch(ret) { |
358 | case 0: | 359 | case 0: |
359 | break; | 360 | break; |
360 | case 1: | 361 | case 1: |
361 | break; | 362 | break; |
362 | case 2: | 363 | case 2: |
363 | // delete childs too | 364 | // delete childs too |
364 | delete item; | 365 | delete item; |
365 | break; | 366 | break; |
366 | } | 367 | } |
367 | } | 368 | } |
368 | 369 | ||
369 | delete menu; | 370 | delete menu; |
370 | } | 371 | } |
371 | 372 | ||
372 | /** | 373 | /** |
373 | * Search and display avail. services for a device (on expand from device listing) | 374 | * Search and display avail. services for a device (on expand from device listing) |
374 | * | 375 | * |
375 | */ | 376 | */ |
376 | void BlueBase::addServicesToDevice( BTListItem * item ) { | 377 | void BlueBase::addServicesToDevice( BTListItem * item ) { |
377 | 378 | ||
378 | qDebug("addServicesToDevice"); | 379 | qDebug("addServicesToDevice"); |
379 | // row of mac adress text(3) | 380 | // row of mac adress text(3) |
380 | RemoteDevice *device = new RemoteDevice( item->mac(), item->name() ); | 381 | RemoteDevice *device = new RemoteDevice( item->mac(), item->name() ); |
381 | 382 | ||
382 | deviceList.insert( item->mac() , item ); | 383 | deviceList.insert( item->mac() , item ); |
383 | 384 | ||
384 | // and some time later I get a signal foundServices( const QString& device, Services::ValueList ); back | 385 | // and some time later I get a signal foundServices( const QString& device, Services::ValueList ); back |
385 | localDevice->searchServices( *device ); | 386 | localDevice->searchServices( *device ); |
386 | 387 | ||
387 | // delete | 388 | // delete |
388 | } | 389 | } |
389 | 390 | ||
390 | 391 | ||
391 | /** | 392 | /** |
392 | * Overloaded. This one it the one that is connected to the foundServices signal | 393 | * Overloaded. This one it the one that is connected to the foundServices signal |
393 | * @param device the mac address of the remote device | 394 | * @param device the mac address of the remote device |
394 | * @param servicesList the list with the service the device has. | 395 | * @param servicesList the list with the service the device has. |
395 | */ | 396 | */ |
396 | void BlueBase::addServicesToDevice( const QString& device, Services::ValueList servicesList ) { | 397 | void BlueBase::addServicesToDevice( const QString& device, Services::ValueList servicesList ) { |
397 | 398 | ||
398 | qDebug("fill services list"); | 399 | qDebug("fill services list"); |
399 | 400 | ||
400 | QMap<QString,BTListItem*>::Iterator it; | 401 | QMap<QString,BTListItem*>::Iterator it; |
401 | 402 | ||
402 | BTListItem* deviceItem; | 403 | BTListItem* deviceItem; |
403 | 404 | ||
404 | // get the right devices which requested the search | 405 | // get the right devices which requested the search |
405 | for( it = deviceList.begin(); it != deviceList.end(); ++it ) { | 406 | for( it = deviceList.begin(); it != deviceList.end(); ++it ) { |
406 | if ( it.key() == device ) { | 407 | if ( it.key() == device ) { |
407 | deviceItem = it.data(); | 408 | deviceItem = it.data(); |
408 | } | 409 | } |
409 | } | 410 | } |
410 | 411 | ||
411 | 412 | ||
412 | // empty entries | 413 | // empty entries |
413 | // QListViewItem * myChild = deviceItem->firstChild(); | 414 | // QListViewItem * myChild = deviceItem->firstChild(); |
414 | //QList<QListViewItem*> tmpList; | 415 | //QList<QListViewItem*> tmpList; |
415 | //while( myChild ) { | 416 | //while( myChild ) { |
416 | // tmpList.append(myChild); | 417 | // tmpList.append(myChild); |
417 | // myChild = myChild->nextSibling(); | 418 | // myChild = myChild->nextSibling(); |
418 | // } | 419 | // } |
419 | 420 | ||
420 | 421 | ||
421 | QValueList<OpieTooth::Services>::Iterator it2; | 422 | QValueList<OpieTooth::Services>::Iterator it2; |
422 | 423 | ||
423 | BTListItem * serviceItem; | 424 | BTListItem * serviceItem; |
424 | 425 | ||
425 | if (!servicesList.isEmpty() ) { | 426 | if (!servicesList.isEmpty() ) { |
426 | // add services | 427 | // add services |
427 | for( it2 = servicesList.begin(); it2 != servicesList.end(); ++it2 ) { | 428 | for( it2 = servicesList.begin(); it2 != servicesList.end(); ++it2 ) { |
428 | serviceItem = new BTListItem( deviceItem , (*it2).serviceName() , "" , "service" ); | 429 | serviceItem = new BTListItem( deviceItem , (*it2).serviceName() , "" , "service" ); |
429 | //serviceItem->setText(4, "service"); | 430 | //serviceItem->setText(4, "service"); |
430 | } | 431 | } |
431 | } else { | 432 | } else { |
432 | serviceItem = new BTListItem( deviceItem , tr("no services found"), "" , "service" ); | 433 | serviceItem = new BTListItem( deviceItem , tr("no services found"), "" , "service" ); |
433 | //serviceItem->setText(4, "service"); | 434 | //serviceItem->setText(4, "service"); |
434 | } | 435 | } |
435 | } | 436 | } |
436 | 437 | ||
437 | 438 | ||
438 | /** | 439 | /** |
439 | * Add the existing connections (pairs) to the connections tab. | 440 | * Add the existing connections (pairs) to the connections tab. |
440 | * | 441 | * |
441 | */ | 442 | */ |
442 | void BlueBase::addConnectedDevices() { | 443 | void BlueBase::addConnectedDevices() { |
443 | 444 | ||
444 | 445 | ||
445 | //mac address | 446 | //mac address |
446 | 447 | ||
447 | } | 448 | } |
448 | 449 | ||
449 | /** | 450 | /** |
450 | * Find out if a device can currently be reached | 451 | * Find out if a device can currently be reached |
451 | */ | 452 | */ |
452 | void BlueBase::deviceActive( RemoteDevice *device ) { | 453 | void BlueBase::deviceActive( RemoteDevice *device ) { |
453 | 454 | ||
454 | // search by mac, async, gets a signal back | 455 | // search by mac, async, gets a signal back |
455 | localDevice->isAvailable( device->mac() ); | 456 | localDevice->isAvailable( device->mac() ); |
456 | } | 457 | } |
457 | 458 | ||
458 | /** | 459 | /** |
459 | * The signal catcher. Set the avail. status on device. | 460 | * The signal catcher. Set the avail. status on device. |
460 | * @param device - the mac address | 461 | * @param device - the mac address |
461 | * @param connected - if it is avail. or not | 462 | * @param connected - if it is avail. or not |
462 | */ | 463 | */ |
463 | void BlueBase::deviceActive( const QString& device, bool connected ) { | 464 | void BlueBase::deviceActive( const QString& device, bool connected ) { |
464 | 465 | ||
465 | qDebug("deviceActive slot"); | 466 | qDebug("deviceActive slot"); |
466 | 467 | ||
467 | QMap<QString,BTListItem*>::Iterator it; | 468 | QMap<QString,BTListItem*>::Iterator it; |
468 | 469 | ||
469 | BTListItem* deviceItem; | 470 | BTListItem* deviceItem; |
470 | 471 | ||
471 | // get the right devices which requested the search | 472 | // get the right devices which requested the search |
472 | for( it = deviceList.begin(); it != deviceList.end(); ++it ) { | 473 | for( it = deviceList.begin(); it != deviceList.end(); ++it ) { |
473 | if ( it.key() == device ) { | 474 | if ( it.key() == device ) { |
474 | deviceItem = it.data(); | 475 | deviceItem = it.data(); |
475 | } | 476 | } |
476 | } | 477 | } |
477 | 478 | ||
478 | if ( connected ) { | 479 | if ( connected ) { |
479 | deviceItem->setPixmap( 1, onPix ); | 480 | deviceItem->setPixmap( 1, onPix ); |
480 | } else { | 481 | } else { |
481 | deviceItem->setPixmap( 1, offPix ); | 482 | deviceItem->setPixmap( 1, offPix ); |
482 | } | 483 | } |
483 | 484 | ||
484 | } | 485 | } |
485 | 486 | ||
486 | 487 | ||
487 | 488 | ||
488 | /** | 489 | /** |
489 | * Open the "scan for devices" dialog | 490 | * Open the "scan for devices" dialog |
490 | */ | 491 | */ |
491 | void BlueBase::startScan() { | 492 | void BlueBase::startScan() { |
492 | 493 | ||
493 | ScanDialog *scan = new ScanDialog( this, "", true); | 494 | ScanDialog *scan = new ScanDialog( this, "", true); |
494 | QObject::connect( scan, SIGNAL( selectedDevices( QList<RemoteDevice>& ) ), | 495 | QObject::connect( scan, SIGNAL( selectedDevices( QList<RemoteDevice>& ) ), |
495 | this, SLOT( addSearchedDevices( QList<RemoteDevice>& ) ) ); | 496 | this, SLOT( addSearchedDevices( QList<RemoteDevice>& ) ) ); |
496 | 497 | ||
497 | scan->showMaximized(); | 498 | scan->showMaximized(); |
498 | } | 499 | } |
499 | 500 | ||
500 | 501 | ||
501 | /** | 502 | /** |
502 | * Set the informations about the local device in information Tab | 503 | * Set the informations about the local device in information Tab |
503 | */ | 504 | */ |
504 | void BlueBase::setInfo() { | 505 | void BlueBase::setInfo() { |
505 | StatusLabel->setText( getStatus() ); | 506 | StatusLabel->setText( getStatus() ); |
506 | } | 507 | } |
507 | 508 | ||
508 | /** | 509 | /** |
509 | * Decontructor | 510 | * Decontructor |
510 | */ | 511 | */ |
511 | BlueBase::~BlueBase() { | 512 | BlueBase::~BlueBase() { |
512 | writeSavedDevices(); | 513 | writeSavedDevices(); |
513 | } | 514 | } |
514 | } | 515 | } |
515 | 516 | ||