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
@@ -19,6 +19,8 @@
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>
@@ -44,6 +46,7 @@
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;
@@ -66,8 +69,8 @@ using namespace OpieTooth;
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" );
@@ -103,6 +106,7 @@ using namespace OpieTooth;
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 /**
@@ -140,8 +144,9 @@ using namespace OpieTooth;
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
@@ -152,6 +157,7 @@ using namespace OpieTooth;
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
@@ -162,26 +168,9 @@ using namespace OpieTooth;
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
@@ -193,18 +182,22 @@ using namespace OpieTooth;
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
@@ -263,6 +256,9 @@ using namespace OpieTooth;
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
@@ -333,10 +329,14 @@ void BlueBase::startServiceActionHold( QListViewItem * item, const QPoint & poin
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");
@@ -405,9 +405,10 @@ void BlueBase::startServiceActionHold( QListViewItem * item, const QPoint & poin
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 {
@@ -510,3 +511,24 @@ void BlueBase::startServiceActionHold( QListViewItem * item, const QPoint & poin
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}