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