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