author | zecke <zecke> | 2002-07-08 17:58:50 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-07-08 17:58:50 (UTC) |
commit | 35d0ca5cc59b82af7b7ddb343ec092c3171b11ef (patch) (unidiff) | |
tree | 8a7dac4bef44014c262c4b5549697229cbecc084 | |
parent | 078242aa3182fa98582a4881767f3aa1ff22b165 (diff) | |
download | opie-35d0ca5cc59b82af7b7ddb343ec092c3171b11ef.zip opie-35d0ca5cc59b82af7b7ddb343ec092c3171b11ef.tar.gz opie-35d0ca5cc59b82af7b7ddb343ec092c3171b11ef.tar.bz2 |
fix memleaks
fix possible crashes
clean up
-rw-r--r-- | noncore/net/opietooth/manager/bluebase.cpp | 262 | ||||
-rw-r--r-- | noncore/net/opietooth/manager/bluebase.h | 30 |
2 files changed, 132 insertions, 160 deletions
diff --git a/noncore/net/opietooth/manager/bluebase.cpp b/noncore/net/opietooth/manager/bluebase.cpp index 2001db1..ff6981b 100644 --- a/noncore/net/opietooth/manager/bluebase.cpp +++ b/noncore/net/opietooth/manager/bluebase.cpp | |||
@@ -1,485 +1,457 @@ | |||
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 | #include <qtimer.h> | 39 | #include <qtimer.h> |
40 | 40 | ||
41 | #include <qpe/resource.h> | 41 | #include <qpe/resource.h> |
42 | #include <qpe/config.h> | 42 | #include <qpe/config.h> |
43 | 43 | ||
44 | #include <remotedevice.h> | 44 | #include <remotedevice.h> |
45 | #include <services.h> | 45 | #include <services.h> |
46 | 46 | ||
47 | namespace OpieTooth { | 47 | using namespace OpieTooth; |
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 | m_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 | connect( ListView2, SIGNAL( rightButtonClicked( QListViewItem *, const QPoint &, int ) ), | 61 | connect( ListView2, SIGNAL( rightButtonClicked( QListViewItem *, const QPoint &, int ) ), |
62 | this, SLOT(startServiceActionHold( QListViewItem *, const QPoint &, int) ) ); | 62 | this, SLOT(startServiceActionHold( QListViewItem *, const QPoint &, int) ) ); |
63 | connect( localDevice , SIGNAL( foundServices( const QString& , Services::ValueList ) ), | 63 | connect( m_localDevice , SIGNAL( foundServices( const QString& , Services::ValueList ) ), |
64 | this, SLOT( addServicesToDevice( const QString& , Services::ValueList ) ) ); | 64 | this, SLOT( addServicesToDevice( const QString& , Services::ValueList ) ) ); |
65 | connect( localDevice, SIGNAL( available( const QString&, bool ) ), | 65 | connect( m_localDevice, SIGNAL( available( const QString&, bool ) ), |
66 | this, SLOT( deviceActive( const QString& , bool ) ) ); | 66 | this, SLOT( deviceActive( const QString& , bool ) ) ); |
67 | connect( localDevice, SIGNAL( connections( Connection::ValueList ) ), | 67 | connect( m_localDevice, SIGNAL( connections( Connection::ValueList ) ), |
68 | this, SLOT( addConnectedDevices( Connection::ValueList ) ) ); | 68 | this, SLOT( addConnectedDevices( Connection::ValueList ) ) ); |
69 | 69 | ||
70 | //Load all icons needed | 70 | //Load all icons needed |
71 | offPix = Resource::loadPixmap( "editdelete" ); | 71 | m_offPix = Resource::loadPixmap( "editdelete" ); |
72 | onPix = Resource::loadPixmap( "installed" ); | 72 | m_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, m_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 | 94 | ||
95 | writeToHciConfig(); | 95 | writeToHciConfig(); |
96 | // search conncetions | 96 | // search conncetions |
97 | addConnectedDevices(); | 97 | addConnectedDevices(); |
98 | iconLoader = new BTIconLoader(); | 98 | m_iconLoader = new BTIconLoader(); |
99 | } | 99 | } |
100 | 100 | ||
101 | /** | 101 | /** |
102 | * Reads all options from the config file | 102 | * Reads all options from the config file |
103 | */ | 103 | */ |
104 | void BlueBase::readConfig() { | 104 | void BlueBase::readConfig() { |
105 | 105 | ||
106 | Config cfg( "bluetoothmanager" ); | 106 | Config cfg( "bluetoothmanager" ); |
107 | cfg.setGroup( "bluezsettings" ); | 107 | cfg.setGroup( "bluezsettings" ); |
108 | 108 | ||
109 | deviceName = cfg.readEntry( "name" , "No name" ); // name the device should identify with | 109 | m_deviceName = cfg.readEntry( "name" , "No name" ); // name the device should identify with |
110 | defaultPasskey = cfg.readEntryCrypt( "passkey" , "" ); // <- hmm, look up how good the trolls did that, maybe too weak | 110 | m_defaultPasskey = cfg.readEntryCrypt( "passkey" , "" ); // <- hmm, look up how good the trolls did that, maybe too weak |
111 | useEncryption = cfg.readNumEntry( "useEncryption" , 1 ); | 111 | m_useEncryption = cfg.readBoolEntry( "useEncryption" , TRUE ); |
112 | enableAuthentification = cfg.readNumEntry( "enableAuthentification" , 1 ); | 112 | m_enableAuthentification = cfg.readBoolEntry( "enableAuthentification" , TRUE ); |
113 | enablePagescan = cfg.readNumEntry( "enablePagescan" , 1 ); | 113 | m_enablePagescan = cfg.readBoolEntry( "enablePagescan" , TRUE ); |
114 | enableInquiryscan = cfg.readNumEntry( "enableInquiryscan" , 1 ); | 114 | m_enableInquiryscan = cfg.readBoolEntry( "enableInquiryscan" , TRUE ); |
115 | } | 115 | } |
116 | 116 | ||
117 | /** | 117 | /** |
118 | * Writes all options to the config file | 118 | * Writes all options to the config file |
119 | */ | 119 | */ |
120 | void BlueBase::writeConfig() { | 120 | void BlueBase::writeConfig() { |
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" , m_deviceName ); |
126 | cfg.writeEntryCrypt( "passkey" , defaultPasskey ); | 126 | cfg.writeEntryCrypt( "passkey" , m_defaultPasskey ); |
127 | cfg.writeEntry( "useEncryption" , useEncryption ); | 127 | cfg.writeEntry( "useEncryption" , m_useEncryption ); |
128 | cfg.writeEntry( "enableAuthentification" , enableAuthentification ); | 128 | cfg.writeEntry( "enableAuthentification" , m_enableAuthentification ); |
129 | cfg.writeEntry( "enablePagescan" , enablePagescan ); | 129 | cfg.writeEntry( "enablePagescan" , m_enablePagescan ); |
130 | cfg.writeEntry( "enableInquiryscan" , enableInquiryscan ); | 130 | cfg.writeEntry( "enableInquiryscan" , m_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 ( "/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( m_deviceName ); |
144 | 144 | hciconf.setEncrypt( m_useEncryption ); | |
145 | if ( useEncryption == 1) { | 145 | hciconf.setAuth( m_enableAuthentification ); |
146 | hciconf->setEncrypt( true ); | 146 | hciconf.setPscan( m_enablePagescan ); |
147 | } else { | 147 | hciconf.setIscan( m_enableInquiryscan ); |
148 | hciconf->setEncrypt( false ); | ||
149 | } | ||
150 | |||
151 | |||
152 | if ( enableAuthentification == 1) { | ||
153 | hciconf->setAuth( true ); | ||
154 | } else { | ||
155 | hciconf->setAuth( false ); | ||
156 | } | ||
157 | |||
158 | if ( enablePagescan == 1) { | ||
159 | hciconf->setPscan( true ); | ||
160 | } else { | ||
161 | hciconf->setPscan( false ); | ||
162 | } | ||
163 | |||
164 | if ( enableInquiryscan == 1) { | ||
165 | hciconf->setIscan( true ); | ||
166 | } else { | ||
167 | hciconf->setIscan( false ); | ||
168 | } | ||
169 | delete hciconf; | ||
170 | } | 148 | } |
171 | 149 | ||
172 | 150 | ||
173 | /** | 151 | /** |
174 | * Read the list of allready known devices | 152 | * Read the list of allready known devices |
175 | * | 153 | * |
176 | */ | 154 | */ |
177 | void BlueBase::readSavedDevices() { | 155 | void BlueBase::readSavedDevices() { |
178 | 156 | ||
179 | QList<RemoteDevice> *loadedDevices = new QList<RemoteDevice>; | 157 | QValueList<RemoteDevice> loadedDevices; |
180 | 158 | ||
181 | QDir deviceListSave( QDir::homeDirPath() + "/Settings/bluetooth/"); | 159 | QDir deviceListSave( QDir::homeDirPath() + "/Settings/bluetooth/"); |
182 | // list of .conf files | 160 | // list of .conf files |
183 | QStringList devicesFileList = deviceListSave.entryList(); | 161 | QStringList devicesFileList = deviceListSave.entryList(); |
184 | 162 | ||
185 | // cut .conf of to get the mac and also read the name entry in it. | 163 | // cut .conf of to get the mac and also read the name entry in it. |
186 | 164 | ||
187 | for ( QStringList::Iterator it = devicesFileList.begin(); it != devicesFileList.end(); ++it ) { | 165 | for ( QStringList::Iterator it = devicesFileList.begin(); it != devicesFileList.end(); ++it ) { |
188 | 166 | ||
189 | QString name; | 167 | QString name; |
190 | QString mac; | 168 | QString mac; |
191 | qDebug((*it).latin1() ); | 169 | qDebug((*it).latin1() ); |
192 | Config conf((*it)); | 170 | Config conf((*it)); |
193 | conf.setGroup("Info"); | 171 | conf.setGroup("Info"); |
194 | name = conf.readEntry("name", "Error"); | 172 | name = conf.readEntry("name", "Error"); |
195 | qDebug("MAC: " + mac); | 173 | qDebug("MAC: " + mac); |
196 | qDebug("NAME: " + name); | 174 | qDebug("NAME: " + name); |
197 | RemoteDevice currentDevice = RemoteDevice( mac , name ); | 175 | RemoteDevice currentDevice( mac , name ); |
198 | loadedDevices->append( ¤tDevice ); | 176 | loadedDevices.append( currentDevice ); |
199 | } | 177 | } |
200 | addSearchedDevices( *loadedDevices ); | 178 | addSearchedDevices( loadedDevices ); |
201 | } | 179 | } |
202 | 180 | ||
203 | /** | 181 | /** |
204 | * Write the list of allready known devices | 182 | * Write the list of allready known devices |
205 | * | 183 | * |
206 | */ | 184 | */ |
207 | void BlueBase::writeSavedDevices() { | 185 | void BlueBase::writeSavedDevices() { |
208 | QListViewItemIterator it( ListView2 ); | 186 | QListViewItemIterator it( ListView2 ); |
209 | 187 | ||
210 | for ( ; it.current(); ++it ) { | 188 | for ( ; it.current(); ++it ) { |
211 | // seperate config file for each device, to store more information in future. | 189 | // seperate config file for each device, to store more information in future. |
212 | qDebug( "/Settings/bluetooth/" + (((BTListItem*)it.current())->mac()) + ".conf"); | 190 | qDebug( "/Settings/bluetooth/" + (((BTListItem*)it.current())->mac()) + ".conf"); |
213 | Config conf( QDir::homeDirPath() + "/Settings/bluetooth/" + (((BTListItem*)it.current())->mac()) + ".conf", Config::File ); | 191 | Config conf( QDir::homeDirPath() + "/Settings/bluetooth/" + (((BTListItem*)it.current())->mac()) + ".conf", Config::File ); |
214 | conf.setGroup( "Info" ); | 192 | conf.setGroup( "Info" ); |
215 | conf.writeEntry( "name", ((BTListItem*)it.current())->name() ); | 193 | conf.writeEntry( "name", ((BTListItem*)it.current())->name() ); |
216 | } | 194 | } |
217 | } | 195 | } |
218 | 196 | ||
219 | 197 | ||
220 | /** | 198 | /** |
221 | * Set up the gui | 199 | * Set up the gui |
222 | */ | 200 | */ |
223 | void BlueBase::initGui() { | 201 | void BlueBase::initGui() { |
224 | StatusLabel->setText( getStatus() ); // maybe move it to getStatus() | 202 | StatusLabel->setText( status() ); // maybe move it to getStatus() |
225 | cryptCheckBox->setChecked( useEncryption ); | 203 | cryptCheckBox->setChecked( m_useEncryption ); |
226 | authCheckBox->setChecked( enableAuthentification ); | 204 | authCheckBox->setChecked( m_enableAuthentification ); |
227 | pagescanCheckBox->setChecked( enablePagescan ); | 205 | pagescanCheckBox->setChecked( m_enablePagescan ); |
228 | inquiryscanCheckBox->setChecked( enableInquiryscan ); | 206 | inquiryscanCheckBox->setChecked( m_enableInquiryscan ); |
229 | deviceNameLine->setText( deviceName ); | 207 | deviceNameLine->setText( m_deviceName ); |
230 | passkeyLine->setText( defaultPasskey ); | 208 | passkeyLine->setText( m_defaultPasskey ); |
231 | // set info tab | 209 | // set info tab |
232 | setInfo(); | 210 | setInfo(); |
233 | } | 211 | } |
234 | 212 | ||
235 | 213 | ||
236 | /** | 214 | /** |
237 | * Get the status informations and returns it | 215 | * Get the status informations and returns it |
238 | * @return QString the status informations gathered | 216 | * @return QString the status informations gathered |
239 | */ | 217 | */ |
240 | QString BlueBase::getStatus(){ | 218 | QString BlueBase::status()const{ |
241 | QString infoString = tr( "<b>Device name : </b> Ipaq" ); | 219 | QString infoString = tr( "<b>Device name : </b> Ipaq" ); |
242 | infoString += QString( "<br><b>" + tr( "MAC adress: " ) +"</b> No idea" ); | 220 | infoString += QString( "<br><b>" + tr( "MAC adress: " ) +"</b> No idea" ); |
243 | infoString += QString( "<br><b>" + tr( "Class" ) + "</b> PDA" ); | 221 | infoString += QString( "<br><b>" + tr( "Class" ) + "</b> PDA" ); |
244 | 222 | ||
245 | return (infoString); | 223 | return (infoString); |
246 | } | 224 | } |
247 | 225 | ||
248 | 226 | ||
249 | /** | 227 | /** |
250 | * Read the current values from the gui and invoke writeConfig() | 228 | * Read the current values from the gui and invoke writeConfig() |
251 | */ | 229 | */ |
252 | void BlueBase::applyConfigChanges() { | 230 | void BlueBase::applyConfigChanges() { |
253 | deviceName = deviceNameLine->text(); | 231 | m_deviceName = deviceNameLine->text(); |
254 | defaultPasskey = passkeyLine->text(); | 232 | m_defaultPasskey = passkeyLine->text(); |
255 | useEncryption = cryptCheckBox->isChecked(); | 233 | m_useEncryption = cryptCheckBox->isChecked(); |
256 | enableAuthentification = authCheckBox->isChecked(); | 234 | m_enableAuthentification = authCheckBox->isChecked(); |
257 | enablePagescan = pagescanCheckBox->isChecked(); | 235 | m_enablePagescan = pagescanCheckBox->isChecked(); |
258 | enableInquiryscan = inquiryscanCheckBox->isChecked(); | 236 | m_enableInquiryscan = inquiryscanCheckBox->isChecked(); |
259 | 237 | ||
260 | writeConfig(); | 238 | writeConfig(); |
261 | 239 | ||
262 | QMessageBox* box = new QMessageBox( this, "Test" ); | 240 | QMessageBox::information( this, tr("Test") , tr("Changes were applied.") ); |
263 | box->setText( tr( "Changes applied" ) ); | ||
264 | box->show(); | ||
265 | } | 241 | } |
266 | 242 | ||
267 | /** | 243 | /** |
268 | * Add fresh found devices from scan dialog to the listing | 244 | * Add fresh found devices from scan dialog to the listing |
269 | * | 245 | * |
270 | */ | 246 | */ |
271 | void BlueBase::addSearchedDevices( QList<RemoteDevice> &newDevices ) { | 247 | void BlueBase::addSearchedDevices( const QValueList<RemoteDevice> &newDevices ) { |
272 | BTListItem * deviceItem; | 248 | BTListItem * deviceItem; |
273 | QListIterator<RemoteDevice> it( newDevices ); | 249 | QValueList<RemoteDevice>::ConstIterator it; |
274 | 250 | ||
275 | for( ; it.current() ; ++it ) { | 251 | for( it = newDevices.begin(); it != newDevices.end() ; ++it ) { |
276 | 252 | deviceItem = new BTListItem( ListView2 , (*it).name(), (*it).mac(), "device" ); | |
277 | RemoteDevice *dev = it.current(); | ||
278 | deviceItem = new BTListItem( ListView2 , dev->name(), dev->mac(), "device" ); | ||
279 | deviceItem->setExpandable ( true ); | 253 | deviceItem->setExpandable ( true ); |
280 | 254 | ||
281 | // look if device is avail. atm, async | 255 | // look if device is avail. atm, async |
282 | deviceActive( dev ); | 256 | deviceActive( (*it) ); |
283 | 257 | ||
284 | // ggf auch hier? | 258 | // ggf auch hier? |
285 | addServicesToDevice( deviceItem ); | 259 | addServicesToDevice( deviceItem ); |
286 | } | 260 | } |
287 | } | 261 | } |
288 | 262 | ||
289 | 263 | ||
290 | /** | 264 | /** |
291 | * Action that is toggled on entrys on click | 265 | * Action that is toggled on entrys on click |
292 | */ | 266 | */ |
293 | void BlueBase::startServiceActionClicked( QListViewItem *item ) { | 267 | void BlueBase::startServiceActionClicked( QListViewItem */*item*/ ) { |
294 | } | 268 | } |
295 | 269 | ||
296 | /** | 270 | /** |
297 | * Action that are toggled on hold (mostly QPopups i guess) | 271 | * Action that are toggled on hold (mostly QPopups i guess) |
298 | */ | 272 | */ |
299 | void BlueBase::startServiceActionHold( QListViewItem * item, const QPoint & point, int column ) { | 273 | void BlueBase::startServiceActionHold( QListViewItem * item, const QPoint & point, int /*column*/ ) { |
300 | 274 | ||
301 | QPopupMenu *menu = new QPopupMenu(); | 275 | QPopupMenu *menu = new QPopupMenu(); |
302 | int ret=0; | 276 | int ret=0; |
303 | 277 | ||
304 | if ( ((BTListItem*)item)->type() == "device") { | 278 | if ( ((BTListItem*)item)->type() == "device") { |
305 | 279 | ||
306 | QPopupMenu *groups = new QPopupMenu(); | 280 | QPopupMenu *groups = new QPopupMenu(); |
307 | 281 | ||
308 | menu->insertItem( tr("rescan sevices:"), 0); | 282 | menu->insertItem( tr("rescan sevices:"), 0); |
309 | menu->insertItem( tr("to group"), groups , 1); | 283 | menu->insertItem( tr("to group"), groups , 1); |
310 | menu->insertItem( tr("bound device"), 2); | 284 | menu->insertItem( tr("bound device"), 2); |
311 | menu->insertItem( tr("delete"), 3); | 285 | menu->insertItem( tr("delete"), 3); |
312 | 286 | ||
313 | ret = menu->exec( point , 0); | 287 | ret = menu->exec( point , 0); |
314 | 288 | ||
315 | switch(ret) { | 289 | switch(ret) { |
316 | case 0: | 290 | case 0: |
317 | break; | 291 | break; |
318 | case 1: | 292 | case 1: |
319 | break; | 293 | break; |
320 | case 2: | 294 | case 2: |
321 | // make connection | 295 | // make connection |
322 | break; | 296 | break; |
323 | case 3: | 297 | case 3: |
324 | // delete childs too | 298 | // delete childs too |
325 | delete item; | 299 | delete item; |
326 | break; | 300 | break; |
327 | } | 301 | } |
328 | delete groups; | 302 | delete groups; |
329 | 303 | ||
330 | } else if ( ((BTListItem*)item)->type() == "service") { | 304 | } else if ( ((BTListItem*)item)->type() == "service") { |
331 | menu->insertItem( tr("Test1:"), 0); | 305 | menu->insertItem( tr("Test1:"), 0); |
332 | menu->insertItem( tr("connect"), 1); | 306 | menu->insertItem( tr("connect"), 1); |
333 | menu->insertItem( tr("delete"), 2); | 307 | menu->insertItem( tr("delete"), 2); |
334 | 308 | ||
335 | ret = menu->exec( point , 0); | 309 | ret = menu->exec( point , 0); |
336 | 310 | ||
337 | switch(ret) { | 311 | switch(ret) { |
338 | case 0: | 312 | case 0: |
339 | break; | 313 | break; |
340 | case 1: | 314 | case 1: |
341 | break; | 315 | break; |
342 | case 2: | 316 | case 2: |
343 | // delete childs too | 317 | // delete childs too |
344 | delete item; | 318 | delete item; |
345 | break; | 319 | break; |
346 | } | 320 | } |
347 | } | ||
348 | delete menu; | ||
349 | } | 321 | } |
322 | delete menu; | ||
323 | } | ||
350 | 324 | ||
351 | /** | 325 | /** |
352 | * Search and display avail. services for a device (on expand from device listing) | 326 | * Search and display avail. services for a device (on expand from device listing) |
353 | * | 327 | * |
354 | */ | 328 | */ |
355 | void BlueBase::addServicesToDevice( BTListItem * item ) { | 329 | void BlueBase::addServicesToDevice( BTListItem * item ) { |
356 | qDebug("addServicesToDevice"); | 330 | qDebug("addServicesToDevice"); |
357 | // row of mac adress text(3) | 331 | // row of mac adress text(3) |
358 | RemoteDevice *device = new RemoteDevice( item->mac(), item->name() ); | 332 | RemoteDevice device( item->mac(), item->name() ); |
359 | deviceList.insert( item->mac() , item ); | 333 | m_deviceList.insert( item->mac() , item ); |
360 | // and some time later I get a signal foundServices( const QString& device, Services::ValueList ); back | 334 | // and some time later I get a signal foundServices( const QString& device, Services::ValueList ); back |
361 | localDevice->searchServices( *device ); | 335 | m_localDevice->searchServices( device ); |
362 | delete device; | ||
363 | } | 336 | } |
364 | 337 | ||
365 | 338 | ||
366 | /** | 339 | /** |
367 | * Overloaded. This one it the one that is connected to the foundServices signal | 340 | * Overloaded. This one it the one that is connected to the foundServices signal |
368 | * @param device the mac address of the remote device | 341 | * @param device the mac address of the remote device |
369 | * @param servicesList the list with the service the device has. | 342 | * @param servicesList the list with the service the device has. |
370 | */ | 343 | */ |
371 | void BlueBase::addServicesToDevice( const QString& device, Services::ValueList servicesList ) { | 344 | void BlueBase::addServicesToDevice( const QString& device, Services::ValueList servicesList ) { |
372 | qDebug("fill services list"); | 345 | qDebug("fill services list"); |
373 | 346 | ||
374 | QMap<QString,BTListItem*>::Iterator it; | 347 | QMap<QString,BTListItem*>::Iterator it; |
375 | BTListItem* deviceItem = 0; | 348 | BTListItem* deviceItem = 0; |
376 | 349 | ||
377 | // get the right devices which requested the search | 350 | // get the right devices which requested the search |
378 | for( it = deviceList.begin(); it != deviceList.end(); ++it ) { | 351 | for( it = m_deviceList.begin(); it != m_deviceList.end(); ++it ) { |
379 | if ( it.key() == device ) { | 352 | if ( it.key() == device ) { |
380 | deviceItem = it.data(); | 353 | deviceItem = it.data(); |
381 | } | 354 | } |
382 | } | 355 | } |
383 | 356 | ||
384 | QValueList<OpieTooth::Services>::Iterator it2; | 357 | QValueList<OpieTooth::Services>::Iterator it2; |
385 | BTListItem * serviceItem; | 358 | BTListItem * serviceItem; |
386 | 359 | ||
387 | if (!servicesList.isEmpty() ) { | 360 | if (!servicesList.isEmpty() ) { |
388 | // add services | 361 | // add services |
389 | for( it2 = servicesList.begin(); it2 != servicesList.end(); ++it2 ) { | 362 | for( it2 = servicesList.begin(); it2 != servicesList.end(); ++it2 ) { |
390 | serviceItem = new BTListItem( deviceItem , (*it2).serviceName() , "" , "service" ); | 363 | serviceItem = new BTListItem( deviceItem , (*it2).serviceName() , "" , "service" ); |
391 | serviceItem->setPixmap( 0, iconLoader->serviceIcon( (*it2).classIdList() ) ); | 364 | serviceItem->setPixmap( 0, m_iconLoader->serviceIcon( (*it2).classIdList() ) ); |
392 | } | 365 | } |
393 | } else { | 366 | } else { |
394 | serviceItem = new BTListItem( deviceItem , tr("no services found"), "" , "service" ); | 367 | serviceItem = new BTListItem( deviceItem , tr("no services found"), "" , "service" ); |
395 | } | 368 | } |
396 | } | 369 | } |
397 | 370 | ||
398 | 371 | ||
399 | /** | 372 | /** |
400 | * Add the existing connections (pairs) to the connections tab. | 373 | * Add the existing connections (pairs) to the connections tab. |
401 | * This one triggers the search | 374 | * This one triggers the search |
402 | */ | 375 | */ |
403 | void BlueBase::addConnectedDevices() { | 376 | void BlueBase::addConnectedDevices() { |
404 | localDevice->searchConnections(); | 377 | m_localDevice->searchConnections(); |
405 | } | 378 | } |
406 | 379 | ||
407 | 380 | ||
408 | void BlueBase::addConnectedDevices( Connection::ValueList connectionList ) { | 381 | void BlueBase::addConnectedDevices( Connection::ValueList connectionList ) { |
409 | QValueList<OpieTooth::Connection>::Iterator it; | 382 | QValueList<OpieTooth::Connection>::Iterator it; |
410 | BTListItem * connectionItem; | 383 | BTListItem * connectionItem; |
411 | 384 | ||
412 | if ( !connectionList.isEmpty() ) { | 385 | if ( !connectionList.isEmpty() ) { |
413 | 386 | ||
414 | for (it = connectionList.begin(); it != connectionList.end(); ++it) { | 387 | for (it = connectionList.begin(); it != connectionList.end(); ++it) { |
415 | connectionItem = new BTListItem( ListView4 , (*it).mac() , (*it).mac() , "connection" ); | 388 | connectionItem = new BTListItem( ListView4 , (*it).mac() , (*it).mac() , "connection" ); |
416 | } | 389 | } |
417 | } else { | 390 | } else { |
418 | connectionItem = new BTListItem( ListView4 , tr("No connections found"), "", "connection" ); | 391 | connectionItem = new BTListItem( ListView4 , tr("No connections found"), "", "connection" ); |
419 | } | 392 | } |
420 | 393 | ||
421 | // recall connection search after some time | 394 | // recall connection search after some time |
422 | QTimer::singleShot( 20000, this, SLOT( addConnectedDevices() ) ); | 395 | QTimer::singleShot( 20000, this, SLOT( addConnectedDevices() ) ); |
423 | } | 396 | } |
424 | 397 | ||
425 | /** | 398 | /** |
426 | * Find out if a device can currently be reached | 399 | * Find out if a device can currently be reached |
427 | */ | 400 | */ |
428 | void BlueBase::deviceActive( RemoteDevice *device ) { | 401 | void BlueBase::deviceActive( const RemoteDevice &device ) { |
429 | // search by mac, async, gets a signal back | 402 | // search by mac, async, gets a signal back |
430 | localDevice->isAvailable( device->mac() ); | 403 | m_localDevice->isAvailable( device.mac() ); |
431 | } | 404 | } |
432 | 405 | ||
433 | /** | 406 | /** |
434 | * The signal catcher. Set the avail. status on device. | 407 | * The signal catcher. Set the avail. status on device. |
435 | * @param device - the mac address | 408 | * @param device - the mac address |
436 | * @param connected - if it is avail. or not | 409 | * @param connected - if it is avail. or not |
437 | */ | 410 | */ |
438 | void BlueBase::deviceActive( const QString& device, bool connected ) { | 411 | void BlueBase::deviceActive( const QString& device, bool connected ) { |
439 | qDebug("deviceActive slot"); | 412 | qDebug("deviceActive slot"); |
440 | 413 | ||
441 | QMap<QString,BTListItem*>::Iterator it; | 414 | QMap<QString,BTListItem*>::Iterator it; |
442 | BTListItem* deviceItem = 0; | 415 | BTListItem* deviceItem = 0; |
443 | 416 | ||
444 | // get the right devices which requested the search | 417 | // get the right devices which requested the search |
445 | for( it = deviceList.begin(); it != deviceList.end(); ++it ) { | 418 | for( it = m_deviceList.begin(); it != m_deviceList.end(); ++it ) { |
446 | if ( it.key() == device ) { | 419 | if ( it.key() == device ) { |
447 | deviceItem = it.data(); | 420 | deviceItem = it.data(); |
448 | } | 421 | } |
449 | } | 422 | } |
450 | 423 | ||
451 | if ( connected ) { | 424 | if ( connected ) { |
452 | deviceItem->setPixmap( 1, onPix ); | 425 | deviceItem->setPixmap( 1, m_onPix ); |
453 | } else { | 426 | } else { |
454 | deviceItem->setPixmap( 1, offPix ); | 427 | deviceItem->setPixmap( 1, m_offPix ); |
455 | } | 428 | } |
456 | } | 429 | } |
457 | 430 | ||
458 | /** | 431 | /** |
459 | * Open the "scan for devices" dialog | 432 | * Open the "scan for devices" dialog |
460 | */ | 433 | */ |
461 | void BlueBase::startScan() { | 434 | void BlueBase::startScan() { |
462 | ScanDialog *scan = new ScanDialog( this, "", true); | 435 | ScanDialog *scan = new ScanDialog( this, "", true); |
463 | QObject::connect( scan, SIGNAL( selectedDevices( QList<RemoteDevice>& ) ), | 436 | QObject::connect( scan, SIGNAL( selectedDevices( QList<RemoteDevice>& ) ), |
464 | this, SLOT( addSearchedDevices( QList<RemoteDevice>& ) ) ); | 437 | this, SLOT( addSearchedDevices( QList<RemoteDevice>& ) ) ); |
465 | 438 | ||
466 | scan->showMaximized(); | 439 | scan->showMaximized(); |
467 | } | 440 | } |
468 | 441 | ||
469 | 442 | ||
470 | /** | 443 | /** |
471 | * Set the informations about the local device in information Tab | 444 | * Set the informations about the local device in information Tab |
472 | */ | 445 | */ |
473 | void BlueBase::setInfo() { | 446 | void BlueBase::setInfo() { |
474 | StatusLabel->setText( getStatus() ); | 447 | StatusLabel->setText( status() ); |
475 | } | 448 | } |
476 | 449 | ||
477 | /** | 450 | /** |
478 | * Decontructor | 451 | * Decontructor |
479 | */ | 452 | */ |
480 | BlueBase::~BlueBase() { | 453 | BlueBase::~BlueBase() { |
481 | writeSavedDevices(); | 454 | writeSavedDevices(); |
482 | delete iconLoader; | 455 | delete m_iconLoader; |
483 | } | 456 | } |
484 | } | ||
485 | 457 | ||
diff --git a/noncore/net/opietooth/manager/bluebase.h b/noncore/net/opietooth/manager/bluebase.h index ce0483f..73fac97 100644 --- a/noncore/net/opietooth/manager/bluebase.h +++ b/noncore/net/opietooth/manager/bluebase.h | |||
@@ -1,85 +1,85 @@ | |||
1 | 1 | ||
2 | #ifndef BLUEBASE_H | 2 | #ifndef BLUEBASE_H |
3 | #define BLUEBASE_H | 3 | #define BLUEBASE_H |
4 | 4 | ||
5 | #include <qvariant.h> | 5 | #include <qvariant.h> |
6 | #include <qwidget.h> | 6 | #include <qwidget.h> |
7 | #include <qscrollview.h> | 7 | #include <qscrollview.h> |
8 | #include <qsplitter.h> | 8 | #include <qsplitter.h> |
9 | #include <qlist.h> | 9 | #include <qlist.h> |
10 | #include <qpixmap.h> | 10 | #include <qpixmap.h> |
11 | 11 | ||
12 | #include "bluetoothbase.h" | 12 | #include "bluetoothbase.h" |
13 | #include "btlistitem.h" | 13 | #include "btlistitem.h" |
14 | #include "bticonloader.h" | 14 | #include "bticonloader.h" |
15 | 15 | ||
16 | #include <remotedevice.h> | 16 | #include <remotedevice.h> |
17 | #include <manager.h> | 17 | #include <manager.h> |
18 | 18 | ||
19 | class QVBox; | 19 | class QVBox; |
20 | class QHBoxLayout; | 20 | class QHBoxLayout; |
21 | class QGridLayout; | 21 | class QGridLayout; |
22 | class QFrame; | 22 | class QFrame; |
23 | class QLabel; | 23 | class QLabel; |
24 | class QPushButton; | 24 | class QPushButton; |
25 | class QTabWidget; | 25 | class QTabWidget; |
26 | class QCheckBox; | 26 | class QCheckBox; |
27 | 27 | ||
28 | 28 | ||
29 | namespace OpieTooth { | 29 | namespace OpieTooth { |
30 | 30 | ||
31 | class BlueBase : public BluetoothBase { | 31 | class BlueBase : public BluetoothBase { |
32 | Q_OBJECT | 32 | Q_OBJECT |
33 | 33 | ||
34 | public: | 34 | public: |
35 | BlueBase( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); | 35 | BlueBase( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); |
36 | ~BlueBase(); | 36 | ~BlueBase(); |
37 | 37 | ||
38 | protected: | 38 | protected: |
39 | 39 | ||
40 | 40 | ||
41 | private slots: | 41 | private slots: |
42 | void startScan(); | 42 | void startScan(); |
43 | 43 | ||
44 | private: | 44 | private: |
45 | void readConfig(); | 45 | void readConfig(); |
46 | void writeConfig(); | 46 | void writeConfig(); |
47 | void readSavedDevices(); | 47 | void readSavedDevices(); |
48 | void writeSavedDevices(); | 48 | void writeSavedDevices(); |
49 | void writeToHciConfig(); | 49 | void writeToHciConfig(); |
50 | QString getStatus(); | 50 | QString status()const; |
51 | void initGui(); | 51 | void initGui(); |
52 | void setInfo(); | 52 | void setInfo(); |
53 | Manager *localDevice; | 53 | Manager *m_localDevice; |
54 | QMap<QString,BTListItem*> deviceList; | 54 | QMap<QString,BTListItem*> m_deviceList; |
55 | 55 | ||
56 | void deviceActive( RemoteDevice *device ); | 56 | void deviceActive( const RemoteDevice &device ); |
57 | 57 | ||
58 | QString deviceName; | 58 | QString m_deviceName; |
59 | QString defaultPasskey; | 59 | QString m_defaultPasskey; |
60 | int useEncryption; | 60 | bool m_useEncryption; |
61 | int enableAuthentification; | 61 | bool m_enableAuthentification; |
62 | int enablePagescan; | 62 | bool m_enablePagescan; |
63 | int enableInquiryscan; | 63 | bool m_enableInquiryscan; |
64 | 64 | ||
65 | QPixmap offPix; | 65 | QPixmap m_offPix; |
66 | QPixmap onPix; | 66 | QPixmap m_onPix; |
67 | 67 | ||
68 | BTIconLoader *iconLoader; | 68 | BTIconLoader *m_iconLoader; |
69 | 69 | ||
70 | private slots: | 70 | private slots: |
71 | void addSearchedDevices( QList<RemoteDevice> &newDevices ); | 71 | void addSearchedDevices( const QValueList<RemoteDevice> &newDevices ); |
72 | void addServicesToDevice( BTListItem *item ); | 72 | void addServicesToDevice( BTListItem *item ); |
73 | void addServicesToDevice( const QString& device, Services::ValueList ); | 73 | void addServicesToDevice( const QString& device, Services::ValueList ); |
74 | void addConnectedDevices(); | 74 | void addConnectedDevices(); |
75 | void addConnectedDevices( Connection::ValueList ); | 75 | void addConnectedDevices( Connection::ValueList ); |
76 | void startServiceActionClicked( QListViewItem *item ); | 76 | void startServiceActionClicked( QListViewItem *item ); |
77 | void startServiceActionHold( QListViewItem *, const QPoint &, int ); | 77 | void startServiceActionHold( QListViewItem *, const QPoint &, int ); |
78 | void deviceActive( const QString& mac, bool connected ); | 78 | void deviceActive( const QString& mac, bool connected ); |
79 | void applyConfigChanges(); | 79 | void applyConfigChanges(); |
80 | 80 | ||
81 | }; | 81 | }; |
82 | 82 | ||
83 | } | 83 | } |
84 | 84 | ||
85 | #endif | 85 | #endif |