summaryrefslogtreecommitdiff
path: root/noncore/net/opietooth/manager/bluebase.cpp
Unidiff
Diffstat (limited to 'noncore/net/opietooth/manager/bluebase.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/net/opietooth/manager/bluebase.cpp84
1 files changed, 53 insertions, 31 deletions
diff --git a/noncore/net/opietooth/manager/bluebase.cpp b/noncore/net/opietooth/manager/bluebase.cpp
index 3f2f138..598ce16 100644
--- a/noncore/net/opietooth/manager/bluebase.cpp
+++ b/noncore/net/opietooth/manager/bluebase.cpp
@@ -16,12 +16,14 @@
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 <stdlib.h>
23
22#include <qframe.h> 24#include <qframe.h>
23#include <qlabel.h> 25#include <qlabel.h>
24#include <qpushbutton.h> 26#include <qpushbutton.h>
25#include <qlayout.h> 27#include <qlayout.h>
26#include <qvariant.h> 28#include <qvariant.h>
27#include <qwhatsthis.h> 29#include <qwhatsthis.h>
@@ -41,12 +43,13 @@
41#include <qpe/resource.h> 43#include <qpe/resource.h>
42#include <qpe/config.h> 44#include <qpe/config.h>
43 45
44#include <remotedevice.h> 46#include <remotedevice.h>
45#include <services.h> 47#include <services.h>
46 48
49#include "devicehandler.h"
47#include "btconnectionitem.h" 50#include "btconnectionitem.h"
48 51
49using namespace OpieTooth; 52using namespace OpieTooth;
50 53
51 BlueBase::BlueBase( QWidget* parent, const char* name, WFlags fl ) 54 BlueBase::BlueBase( QWidget* parent, const char* name, WFlags fl )
52 : BluetoothBase( parent, name, fl ) { 55 : BluetoothBase( parent, name, fl ) {
@@ -63,14 +66,14 @@ using namespace OpieTooth;
63 connect( ListView2, SIGNAL( rightButtonClicked( QListViewItem *, const QPoint &, int ) ), 66 connect( ListView2, SIGNAL( rightButtonClicked( QListViewItem *, const QPoint &, int ) ),
64 this, SLOT(startServiceActionHold( QListViewItem *, const QPoint &, int) ) ); 67 this, SLOT(startServiceActionHold( QListViewItem *, const QPoint &, int) ) );
65 connect( m_localDevice , SIGNAL( foundServices( const QString& , Services::ValueList ) ), 68 connect( m_localDevice , SIGNAL( foundServices( const QString& , Services::ValueList ) ),
66 this, SLOT( addServicesToDevice( const QString& , Services::ValueList ) ) ); 69 this, SLOT( addServicesToDevice( const QString& , Services::ValueList ) ) );
67 connect( m_localDevice, SIGNAL( available( const QString&, bool ) ), 70 connect( m_localDevice, SIGNAL( available( const QString&, bool ) ),
68 this, SLOT( deviceActive( const QString& , bool ) ) ); 71 this, SLOT( deviceActive( const QString& , bool ) ) );
69 connect( m_localDevice, SIGNAL( connections( Connection::ValueList ) ), 72 connect( m_localDevice, SIGNAL( connections( ConnectionState::ValueList ) ),
70 this, SLOT( addConnectedDevices( Connection::ValueList ) ) ); 73 this, SLOT( addConnectedDevices( ConnectionState::ValueList ) ) );
71 74
72 //Load all icons needed 75 //Load all icons needed
73 m_offPix = Resource::loadPixmap( "editdelete" ); 76 m_offPix = Resource::loadPixmap( "editdelete" );
74 m_onPix = Resource::loadPixmap( "installed" ); 77 m_onPix = Resource::loadPixmap( "installed" );
75 78
76 QPalette pal = this->palette(); 79 QPalette pal = this->palette();
@@ -100,12 +103,13 @@ using namespace OpieTooth;
100 (void) new BTServiceItem( topLV2, s1 ); 103 (void) new BTServiceItem( topLV2, s1 );
101 104
102 writeToHciConfig(); 105 writeToHciConfig();
103 // search conncetions 106 // search conncetions
104 addConnectedDevices(); 107 addConnectedDevices();
105 m_iconLoader = new BTIconLoader(); 108 m_iconLoader = new BTIconLoader();
109 readSavedDevices();
106 } 110 }
107 111
108 /** 112 /**
109 * Reads all options from the config file 113 * Reads all options from the config file
110 */ 114 */
111 void BlueBase::readConfig() { 115 void BlueBase::readConfig() {
@@ -137,77 +141,66 @@ using namespace OpieTooth;
137 cfg.writeEntry( "enableInquiryscan" , m_enableInquiryscan ); 141 cfg.writeEntry( "enableInquiryscan" , m_enableInquiryscan );
138 142
139 writeToHciConfig(); 143 writeToHciConfig();
140 } 144 }
141 145
142 void BlueBase::writeToHciConfig() { 146 void BlueBase::writeToHciConfig() {
143 147 qWarning("writeToHciConfig");
144 HciConfWrapper hciconf ( "/tmp/hcid.conf" ); 148 HciConfWrapper hciconf ( "/etc/bluetooth/hcid.conf" );
149 hciconf.load();
145 hciconf.setPinHelper( "/bin/QtPalmtop/bin/blue-pin" ); 150 hciconf.setPinHelper( "/bin/QtPalmtop/bin/blue-pin" );
146 151
147 152
148 // hciconf->setPinHelper( "/bin/QtPalmtop/bin/blue-pin" ); 153 // hciconf->setPinHelper( "/bin/QtPalmtop/bin/blue-pin" );
149 154
150 hciconf.setName( m_deviceName ); 155 hciconf.setName( m_deviceName );
151 hciconf.setEncrypt( m_useEncryption ); 156 hciconf.setEncrypt( m_useEncryption );
152 hciconf.setAuth( m_enableAuthentification ); 157 hciconf.setAuth( m_enableAuthentification );
153 hciconf.setPscan( m_enablePagescan ); 158 hciconf.setPscan( m_enablePagescan );
154 hciconf.setIscan( m_enableInquiryscan ); 159 hciconf.setIscan( m_enableInquiryscan );
160 hciconf.save();
155 } 161 }
156 162
157 163
158 /** 164 /**
159 * Read the list of allready known devices 165 * Read the list of allready known devices
160 * 166 *
161 */ 167 */
162 void BlueBase::readSavedDevices() { 168 void BlueBase::readSavedDevices() {
163 169
164 QValueList<RemoteDevice> loadedDevices; 170 QValueList<RemoteDevice> loadedDevices;
171 DeviceHandler handler;
172 loadedDevices = handler.load();
165 173
166 QDir deviceListSave( QDir::homeDirPath() + "/Settings/bluetooth/");
167 // list of .conf files
168 QStringList devicesFileList = deviceListSave.entryList();
169
170 // cut .conf of to get the mac and also read the name entry in it.
171
172 for ( QStringList::Iterator it = devicesFileList.begin(); it != devicesFileList.end(); ++it ) {
173
174 QString name;
175 QString mac;
176 qDebug((*it).latin1() );
177 Config conf((*it));
178 conf.setGroup("Info");
179 name = conf.readEntry("name", "Error");
180 qDebug("MAC: " + mac);
181 qDebug("NAME: " + name);
182 RemoteDevice currentDevice( mac , name );
183 loadedDevices.append( currentDevice );
184 }
185 addSearchedDevices( loadedDevices ); 174 addSearchedDevices( loadedDevices );
186 } 175 }
187 176
188 /** 177 /**
189 * Write the list of allready known devices 178 * Write the list of allready known devices
190 * 179 *
191 */ 180 */
192 void BlueBase::writeSavedDevices() { 181 void BlueBase::writeSavedDevices() {
193 QListViewItemIterator it( ListView2 ); 182 QListViewItemIterator it( ListView2 );
194 BTListItem* item; 183 BTListItem* item;
195 BTDeviceItem* device; 184 BTDeviceItem* device;
196 185 RemoteDevice::ValueList list;
197 for ( ; it.current(); ++it ) { 186 for ( ; it.current(); ++it ) {
198 item = (BTListItem*)it.current(); 187 item = (BTListItem*)it.current();
199 if(item->typeId() != BTListItem::Device ) 188 if(item->typeId() != BTListItem::Device )
200 continue; 189 continue;
201 device = (BTDeviceItem*)item; 190 device = (BTDeviceItem*)item;
202 // seperate config file for each device, to store more information in future. 191
203 qDebug( "/Settings/bluetooth/" + device->mac() + ".conf"); 192 list.append( device->remoteDevice() );
204 Config conf( QDir::homeDirPath() + "/Settings/bluetooth/" + device->mac() + ".conf", Config::File );
205 conf.setGroup( "Info" );
206 conf.writeEntry( "name", device->name() );
207 } 193 }
194 /*
195 * if not empty save the List through DeviceHandler
196 */
197 if ( list.isEmpty() )
198 return;
199 DeviceHandler handler;
200 handler.save( list );
208 } 201 }
209 202
210 203
211 /** 204 /**
212 * Set up the gui 205 * Set up the gui
213 */ 206 */
@@ -260,12 +253,15 @@ using namespace OpieTooth;
260 void BlueBase::addSearchedDevices( const QValueList<RemoteDevice> &newDevices ) { 253 void BlueBase::addSearchedDevices( const QValueList<RemoteDevice> &newDevices ) {
261 BTDeviceItem * deviceItem; 254 BTDeviceItem * deviceItem;
262 QValueList<RemoteDevice>::ConstIterator it; 255 QValueList<RemoteDevice>::ConstIterator it;
263 256
264 for( it = newDevices.begin(); it != newDevices.end() ; ++it ) { 257 for( it = newDevices.begin(); it != newDevices.end() ; ++it ) {
265 258
259 if (find( (*it) )) // is already inserted
260 continue;
261
266 deviceItem = new BTDeviceItem( ListView2 , (*it) ); 262 deviceItem = new BTDeviceItem( ListView2 , (*it) );
267 deviceItem->setExpandable ( true ); 263 deviceItem->setExpandable ( true );
268 264
269 // look if device is avail. atm, async 265 // look if device is avail. atm, async
270 deviceActive( (*it) ); 266 deviceActive( (*it) );
271 267
@@ -330,16 +326,20 @@ void BlueBase::startServiceActionHold( QListViewItem * item, const QPoint & poin
330 */ 326 */
331 else if ( ((BTListItem*)item)->type() == "service") { 327 else if ( ((BTListItem*)item)->type() == "service") {
332 BTServiceItem* service = (BTServiceItem*)item; 328 BTServiceItem* service = (BTServiceItem*)item;
333 QMap<int, QString> list = service->services().classIdList(); 329 QMap<int, QString> list = service->services().classIdList();
334 QMap<int, QString>::Iterator it = list.begin(); 330 QMap<int, QString>::Iterator it = list.begin();
335 QPopupMenu *popup =0l; 331 QPopupMenu *popup =0l;
336 if ( it != list.end() ) 332 if ( it != list.end() ) {
333 qWarning("Searching id %d %s", it.key(), it.data().latin1() );
337 popup = m_popHelper.find( it.key(), 334 popup = m_popHelper.find( it.key(),
338 service->services(), 335 service->services(),
339 service->parent() ); 336 service->parent() );
337 }else {
338 qWarning("Empty");
339 }
340 340
341 if ( popup == 0l ) { 341 if ( popup == 0l ) {
342 qWarning("factory returned 0l"); 342 qWarning("factory returned 0l");
343 popup = new QPopupMenu(); 343 popup = new QPopupMenu();
344 } 344 }
345 345
@@ -402,15 +402,16 @@ void BlueBase::startServiceActionHold( QListViewItem * item, const QPoint & poin
402 QMap<int, QString> list; 402 QMap<int, QString> list;
403 QMap<int, QString>::Iterator classIt; 403 QMap<int, QString>::Iterator classIt;
404 for( it2 = servicesList.begin(); it2 != servicesList.end(); ++it2 ) { 404 for( it2 = servicesList.begin(); it2 != servicesList.end(); ++it2 ) {
405 serviceItem = new BTServiceItem( deviceItem , (*it2) ); 405 serviceItem = new BTServiceItem( deviceItem , (*it2) );
406 list = (*it2).classIdList(); 406 list = (*it2).classIdList();
407 classIt = list.begin(); 407 classIt = list.begin();
408 int classId; 408 int classId=0;
409 if ( classIt != list.end() ) 409 if ( classIt != list.end() )
410 classId = classIt.key(); 410 classId = classIt.key();
411
411 serviceItem->setPixmap( 0, m_iconLoader->serviceIcon( classId ) ); 412 serviceItem->setPixmap( 0, m_iconLoader->serviceIcon( classId ) );
412 } 413 }
413 } else { 414 } else {
414 Services s1; 415 Services s1;
415 s1.setServiceName( tr("no serives found") ); 416 s1.setServiceName( tr("no serives found") );
416 serviceItem = new BTServiceItem( deviceItem, s1 ); 417 serviceItem = new BTServiceItem( deviceItem, s1 );
@@ -507,6 +508,27 @@ void BlueBase::startServiceActionHold( QListViewItem * item, const QPoint & poin
507 */ 508 */
508 BlueBase::~BlueBase() { 509 BlueBase::~BlueBase() {
509 writeSavedDevices(); 510 writeSavedDevices();
510 delete m_iconLoader; 511 delete m_iconLoader;
511 } 512 }
512 513
514/**
515 * find searches the ListView for a BTDeviceItem containig
516 * the same Device if found return true else false
517 * @param dev RemoteDevice to find
518 * @return returns true if found
519 */
520bool BlueBase::find( const RemoteDevice& rem ) {
521 QListViewItemIterator it( ListView2 );
522 BTListItem* item;
523 BTDeviceItem* device;
524 for (; it.current(); ++it ) {
525 item = (BTListItem*) it.current();
526 if ( item->typeId() != BTListItem::Device )
527 continue;
528
529 device = (BTDeviceItem*)item;
530 if ( rem.equals( device->remoteDevice() ) )
531 return true;
532 }
533 return false; // not found
534}