summaryrefslogtreecommitdiff
authorzecke <zecke>2002-07-14 18:04:14 (UTC)
committer zecke <zecke>2002-07-14 18:04:14 (UTC)
commit26c7e63572e729b4846e4f7551bb041aa6d4bd83 (patch) (unidiff)
tree5c3bc09142bd19e84fbebb88f2e37b02e6d603cd
parent31e233a6cf72bc853137ea05285f4d0f41665365 (diff)
downloadopie-26c7e63572e729b4846e4f7551bb041aa6d4bd83.zip
opie-26c7e63572e729b4846e4f7551bb041aa6d4bd83.tar.gz
opie-26c7e63572e729b4846e4f7551bb041aa6d4bd83.tar.bz2
- able to configure HCID
- able to save and restore known devices - able to scan servivces and shows the right pixmap too - able to do some more - scan dialog clean up ( tiny )
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/net/opietooth/manager/bluebase.cpp84
-rw-r--r--noncore/net/opietooth/manager/bluebase.h1
-rw-r--r--noncore/net/opietooth/manager/bticonloader.cpp2
-rw-r--r--noncore/net/opietooth/manager/devicehandler.cpp87
-rw-r--r--noncore/net/opietooth/manager/devicehandler.h41
-rw-r--r--noncore/net/opietooth/manager/hciconfwrapper.cpp74
-rw-r--r--noncore/net/opietooth/manager/hciconfwrapper.h4
-rw-r--r--noncore/net/opietooth/manager/manager.pro17
-rw-r--r--noncore/net/opietooth/manager/popuphelper.cpp4
-rw-r--r--noncore/net/opietooth/manager/scandialog.cpp35
-rw-r--r--noncore/net/opietooth/manager/scandialog.h6
11 files changed, 281 insertions, 74 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}
diff --git a/noncore/net/opietooth/manager/bluebase.h b/noncore/net/opietooth/manager/bluebase.h
index bbc519c..a68a04b 100644
--- a/noncore/net/opietooth/manager/bluebase.h
+++ b/noncore/net/opietooth/manager/bluebase.h
@@ -43,12 +43,13 @@ namespace OpieTooth {
43 43
44 44
45 private slots: 45 private slots:
46 void startScan(); 46 void startScan();
47 47
48 private: 48 private:
49 bool find( const RemoteDevice& device );
49 void readConfig(); 50 void readConfig();
50 void writeConfig(); 51 void writeConfig();
51 void readSavedDevices(); 52 void readSavedDevices();
52 void writeSavedDevices(); 53 void writeSavedDevices();
53 void writeToHciConfig(); 54 void writeToHciConfig();
54 QString status()const; 55 QString status()const;
diff --git a/noncore/net/opietooth/manager/bticonloader.cpp b/noncore/net/opietooth/manager/bticonloader.cpp
index f299117..a26af54 100644
--- a/noncore/net/opietooth/manager/bticonloader.cpp
+++ b/noncore/net/opietooth/manager/bticonloader.cpp
@@ -63,13 +63,13 @@ namespace OpieTooth {
63 QPixmap BTIconLoader::serviceIcon( int serviceClass ) { 63 QPixmap BTIconLoader::serviceIcon( int serviceClass ) {
64 64
65 QString iconName; 65 QString iconName;
66 66
67 QMap<int, QString>::Iterator it; 67 QMap<int, QString>::Iterator it;
68 68
69 it = deviceIcons.find( serviceClass ); 69 it = serviceIcons.find( serviceClass );
70 iconName = it.data(); 70 iconName = it.data();
71 71
72 if ( iconName.isEmpty() ) { 72 if ( iconName.isEmpty() ) {
73 iconName = "unknown_16"; 73 iconName = "unknown_16";
74 } 74 }
75 return( Resource::loadPixmap( "opietooth/icons/" + iconName ) ); 75 return( Resource::loadPixmap( "opietooth/icons/" + iconName ) );
diff --git a/noncore/net/opietooth/manager/devicehandler.cpp b/noncore/net/opietooth/manager/devicehandler.cpp
new file mode 100644
index 0000000..9c5b817
--- a/dev/null
+++ b/noncore/net/opietooth/manager/devicehandler.cpp
@@ -0,0 +1,87 @@
1
2#include <stdlib.h>
3
4#include <qdir.h>
5#include <qpe/config.h>
6
7#include "devicehandler.h"
8
9using namespace OpieTooth;
10
11DeviceHandler::DeviceHandler() {
12
13};
14DeviceHandler::~DeviceHandler() {
15
16}
17
18RemoteDevice::ValueList DeviceHandler::load() {
19 RemoteDevice::ValueList list;
20QString path = QDir::homeDirPath() + "/Settings/bluetooth";
21 QDir deviceListSave( path);
22
23 // list of .conf files
24 QStringList devicesFileList = deviceListSave.entryList();
25
26
27 // cut .conf of to get the mac and also read the name entry in it.
28 if (!devicesFileList.isEmpty() ) {
29 QString name;
30 QString mac;
31 QStringList::Iterator it;
32 for (it = devicesFileList.begin(); it != devicesFileList.end(); ++it ) {
33 if ( (*it) == "." || (*it) == ".." )
34 continue;
35
36 qDebug((*it).latin1() );
37 Config conf(path + "/"+(*it), Config::File);
38 conf.setGroup("Info");
39 name = conf.readEntry("name", "Error");
40 mac = conf.readEntry("mac", QString::null);
41 qDebug("MAC: " + mac);
42 qDebug("NAME: " + name);
43 if (mac.isEmpty() )
44 continue;
45 RemoteDevice currentDevice( mac , name );
46 list.append( currentDevice );
47 }
48 }
49 return list;
50};
51/*
52 * This is some how rude but make sure all old devices
53 * are getting deleted
54 */
55void DeviceHandler::save( const RemoteDevice::ValueList& list) {
56 QCString rm;
57 rm += "rm -rf ";
58 rm += QDir::homeDirPath() + "/Settings/bluetooth";
59 system ( rm.data() );
60
61 if (list.isEmpty() ) // no need to create the dir
62 return;
63
64 /**
65 * Create a new dir
66 */
67 rm = "mkdir ";
68 rm += QDir::homeDirPath() + "/Settings/bluetooth";
69 qWarning("out %s", rm.data() );
70 system( rm.data() );
71
72 RemoteDevice::ValueList::ConstIterator it;
73 // write the config
74
75 for ( it = list.begin(); it != list.end(); ++it ) {
76 qDebug( "/Settings/bluetooth/" + (*it).mac() + ".conf");
77
78 Config conf( QDir::homeDirPath() +
79 "/Settings/bluetooth/" +
80 (*it).mac() + ".conf", Config::File );
81
82 conf.setGroup( "Info" );
83 conf.writeEntry( "name", (*it).name() );
84 conf.writeEntry( "mac", (*it).mac() );
85 }
86
87}
diff --git a/noncore/net/opietooth/manager/devicehandler.h b/noncore/net/opietooth/manager/devicehandler.h
new file mode 100644
index 0000000..5cfe048
--- a/dev/null
+++ b/noncore/net/opietooth/manager/devicehandler.h
@@ -0,0 +1,41 @@
1
2#ifndef OPIE_TOOTH_DEVICE_HANDLER_H
3#define OPIE_TOOTH_DEVICE_HANDLER_H
4
5#include <qvaluelist.h>
6
7#include <remotedevice.h>
8
9namespace OpieTooth {
10 /**
11 * DeviceHandler is responsible for loading
12 * and saving devices from a config File
13 */
14 class DeviceHandler {
15 public:
16 /**
17 * c'tor
18 */
19 DeviceHandler();
20
21 /**
22 * d'tor
23 */
24 ~DeviceHandler();
25
26 /**
27 * loads from $HOME/Settings/bluetooth/ *
28 */
29 RemoteDevice::ValueList load();
30
31 /**
32 * Saves to $HOME/Settings/bluetooth
33 */
34 void save( const RemoteDevice::ValueList & );
35
36 };
37
38
39};
40
41#endif
diff --git a/noncore/net/opietooth/manager/hciconfwrapper.cpp b/noncore/net/opietooth/manager/hciconfwrapper.cpp
index 5f74fee..46eed42 100644
--- a/noncore/net/opietooth/manager/hciconfwrapper.cpp
+++ b/noncore/net/opietooth/manager/hciconfwrapper.cpp
@@ -63,50 +63,78 @@ namespace OpieTooth {
63 } 63 }
64 } 64 }
65 65
66 66
67 void HciConfWrapper::setValue(const QString &key, const QString &value ) { 67 void HciConfWrapper::setValue(const QString &key, const QString &value ) {
68 68
69 QFile f( m_fileName ); 69 if (m_file.isEmpty() ) // load first
70 QFile f2( m_fileName );
71
72 if ( !f.open( IO_ReadOnly) ) {
73 qDebug("Could not open readonly");
74 return; 70 return;
75 }
76
77 if ( !f2.open( IO_ReadWrite ) ) {
78 qDebug("Just readonly - not enough");
79 return;
80 }
81 71
82 QStringList list; 72 QStringList::Iterator it;
83 qDebug(m_fileName);
84 QTextStream stream ( &f);
85 QTextStream outstream (&f2);
86 73
87 QString str; 74 QString str;
88 while ( !(str=stream.readLine()).isNull() ) { 75 for (it = m_file.begin(); it != m_file.end(); ++it ) {
89 76 str = (*it);
90
91 //qDebug(str);
92 if( (str.contains(key)) > 0 ) { 77 if( (str.contains(key)) > 0 ) {
93 qDebug("Found"); 78 qDebug("Found");
94 // still need to look if its commented out!!! 79 // still need to look if its commented out!!!
95 str.simplifyWhiteSpace(); 80 str.simplifyWhiteSpace();
96 qDebug( key ); 81 qDebug( key );
97 if (str.startsWith("#")) { 82 if (str.startsWith("#")) {
98 str = (key + " " + value + ";"); 83 str = (key + " " + value + ";");
99 } else { 84 } else {
100 str = str.replace( QRegExp( "\\s*"+key+"\\s+[^\\s][^;]*;" ), key + " " + value + ";"); 85 str = str.replace( QRegExp( "\\s*"+key+"\\s+[^\\s][^;]*;" ), key + " " + value + ";");
101 } 86 }
102 qDebug( str ); 87 qDebug( str );
88 it = m_file.remove( it );
89 it = m_file.insert( it, str );
90 //return; the regexp is too wide -zecke // all set
91 }
103 } 92 }
104 outstream << str << endl; 93
94
105 } 95 }
106 96
107 f.close(); 97 /**
98 * This loads the config file and stores it inside
99 * the m_file
100 */
101 void HciConfWrapper::load() {
102 qWarning("loaded");
103 m_file.clear();
104 QFile file( m_fileName );
105 if (!file.open( IO_ReadOnly ) ) {
106 qDebug("Could not open");
107 return;
108 }
109
110 /**
111 * readAll() into a QByteArray
112 * QStringList::split('\n', array )
113 * would this be faster? -zecke
114 */
115 QTextStream stream(&file );
116 QString tmp;
117 while ( !stream.atEnd() ) {
118 tmp = stream.readLine();
119 m_file.append( tmp );
120 }
121 }
122 void HciConfWrapper::save() {
123 qWarning("save");
124 if (m_file.isEmpty() ) // load first
125 return;
126
127 QFile file( m_fileName );
128 if ( !file.open(IO_WriteOnly ) ) {
129 qWarning("could not open %s", m_fileName.latin1() );
130 return;
131 }
108 132
109 f2.flush(); 133 QTextStream stream(&file );
110 f2.close(); 134 QStringList::Iterator it;
135 for ( it = m_file.begin(); it != m_file.end(); ++it ) {
136 stream << (*it) << endl;
111 } 137 }
138 qWarning("saved");
139 };
112} 140}
diff --git a/noncore/net/opietooth/manager/hciconfwrapper.h b/noncore/net/opietooth/manager/hciconfwrapper.h
index de8c9a8..0c4b290 100644
--- a/noncore/net/opietooth/manager/hciconfwrapper.h
+++ b/noncore/net/opietooth/manager/hciconfwrapper.h
@@ -1,18 +1,21 @@
1#ifndef HCICONFWRAPPER_H 1#ifndef HCICONFWRAPPER_H
2#define HCICONFWRAPPER_H 2#define HCICONFWRAPPER_H
3 3
4#include <qstring.h> 4#include <qstring.h>
5#include <qstringlist.h>
5 6
6namespace OpieTooth { 7namespace OpieTooth {
7 8
8 class HciConfWrapper { 9 class HciConfWrapper {
9 10
10 public: 11 public:
11 HciConfWrapper( const QString &fileName ); 12 HciConfWrapper( const QString &fileName );
12 ~HciConfWrapper(); 13 ~HciConfWrapper();
14 void load();
15 void save();
13 16
14 void setPinHelper( const QString& app ); 17 void setPinHelper( const QString& app );
15 void setName( const QString& name ); 18 void setName( const QString& name );
16 void setIscan( bool enable ); 19 void setIscan( bool enable );
17 void setPscan( bool enable ); 20 void setPscan( bool enable );
18 void setAuth( bool enable); 21 void setAuth( bool enable);
@@ -20,11 +23,12 @@ namespace OpieTooth {
20 23
21 private: 24 private:
22 25
23 void setValue(const QString &entry, const QString &value ); 26 void setValue(const QString &entry, const QString &value );
24 27
25 QString m_fileName; 28 QString m_fileName;
29 QStringList m_file;
26 }; 30 };
27 31
28} 32}
29 33
30#endif 34#endif
diff --git a/noncore/net/opietooth/manager/manager.pro b/noncore/net/opietooth/manager/manager.pro
index 0bdd6b9..762b028 100644
--- a/noncore/net/opietooth/manager/manager.pro
+++ b/noncore/net/opietooth/manager/manager.pro
@@ -1,11 +1,24 @@
1TEMPLATE = app 1TEMPLATE = app
2CONFIG = qt warn_on debug 2CONFIG = qt warn_on debug
3#CONFIG = qt warn_on release 3#CONFIG = qt warn_on release
4HEADERS = btconnectionitem.h btdeviceitem.h btserviceitem.h stdpopups.h popuphelper.h bluebase.h scandialog.h btlistitem.h hciconfwrapper.h bticonloader.h pppdialog.h obexdialog.h 4HEADERS = btconnectionitem.h btdeviceitem.h \
5SOURCES = btconnectionitem.cpp btdeviceitem.cpp btserviceitem.h stdpopups.cpp popuphelper.cpp main.cpp bluebase.cpp scandialog.cpp btlistitem.cpp hciconfwrapper.cpp bticonloader.cpp pppdialog.cpp obexdialog.cpp 5 btserviceitem.h stdpopups.h \
6 popuphelper.h bluebase.h \
7 scandialog.h btlistitem.h \
8 hciconfwrapper.h bticonloader.h \
9 pppdialog.h obexdialog.h \
10 devicehandler.h
11
12SOURCES = btconnectionitem.cpp btdeviceitem.cpp \
13 btserviceitem.cpp stdpopups.cpp \
14 popuphelper.cpp main.cpp \
15 bluebase.cpp scandialog.cpp \
16 btlistitem.cpp hciconfwrapper.cpp \
17 bticonloader.cpp pppdialog.cpp \
18 obexdialog.cpp devicehandler.cpp
6INCLUDEPATH += $(OPIEDIR)/include 19INCLUDEPATH += $(OPIEDIR)/include
7INCLUDEPATH += $(OPIEDIR)/noncore/net/opietooth/lib 20INCLUDEPATH += $(OPIEDIR)/noncore/net/opietooth/lib
8DEPENDPATH += $(OPIEDIR)/include 21DEPENDPATH += $(OPIEDIR)/include
9LIBS += -lqpe -lopietooth -lopie 22LIBS += -lqpe -lopietooth -lopie
10INTERFACES = bluetoothbase.ui devicedialog.ui 23INTERFACES = bluetoothbase.ui devicedialog.ui
11DESTDIR = $(OPIEDIR)/bin 24DESTDIR = $(OPIEDIR)/bin
diff --git a/noncore/net/opietooth/manager/popuphelper.cpp b/noncore/net/opietooth/manager/popuphelper.cpp
index 26c4b02..4ef1ed5 100644
--- a/noncore/net/opietooth/manager/popuphelper.cpp
+++ b/noncore/net/opietooth/manager/popuphelper.cpp
@@ -12,16 +12,16 @@ PopupHelper::~PopupHelper() {
12 12
13} 13}
14void PopupHelper::insert( int id, popupFactory fact ) { 14void PopupHelper::insert( int id, popupFactory fact ) {
15 m_map.insert(id, fact ); 15 m_map.insert(id, fact );
16} 16}
17QPopupMenu* PopupHelper::find( int id, const Services& ser, QListViewItem* item ) { 17QPopupMenu* PopupHelper::find( int id, const Services& ser, QListViewItem* item ) {
18 qWarning("find"); 18 //qWarning("find");
19 FactoryMap::Iterator it = m_map.find(id ); 19 FactoryMap::Iterator it = m_map.find(id );
20 if ( it != m_map.end() ) { 20 if ( it != m_map.end() ) {
21 qWarning("found"); 21 //qWarning("found");
22 popupFactory fact = it.data(); 22 popupFactory fact = it.data();
23 return (*fact)(ser, item); 23 return (*fact)(ser, item);
24 } 24 }
25 return 0l; 25 return 0l;
26} 26}
27void PopupHelper::init() { 27void PopupHelper::init() {
diff --git a/noncore/net/opietooth/manager/scandialog.cpp b/noncore/net/opietooth/manager/scandialog.cpp
index 3d6c928..9ce1b6a 100644
--- a/noncore/net/opietooth/manager/scandialog.cpp
+++ b/noncore/net/opietooth/manager/scandialog.cpp
@@ -62,22 +62,20 @@ namespace OpieTooth {
62 62
63 progress = new QProgressBar(privateLayoutWidget, "progbar"); 63 progress = new QProgressBar(privateLayoutWidget, "progbar");
64 progress->setTotalSteps(20); 64 progress->setTotalSteps(20);
65 65
66 QFrame *buttonFrame = new QFrame(Frame7, ""); 66 QFrame *buttonFrame = new QFrame(Frame7, "");
67 67
68 StartButton = new QPushButton( buttonFrame, "StartButton" ); 68 StartStopButton = new QPushButton( buttonFrame, "StartButton" );
69 StartButton->setText( tr( "Start scan" ) ); 69 StartStopButton->setText( tr( "Start scan" ) );
70 70
71 StopButton = new QPushButton( buttonFrame, "StopButton" );
72 StopButton->setText( tr( "Cancel scan" ) );
73 71
74 QHBoxLayout *buttonLayout = new QHBoxLayout(buttonFrame); 72 QHBoxLayout *buttonLayout = new QHBoxLayout(buttonFrame);
75 73
76 buttonLayout->addWidget(StartButton); 74 buttonLayout->addWidget(StartStopButton);
77 buttonLayout->addWidget(StopButton); 75 //buttonLayout->addWidget(StopButton);
78 76
79 ListView1 = new QListView( privateLayoutWidget, "ListView1" ); 77 ListView1 = new QListView( privateLayoutWidget, "ListView1" );
80 78
81 //ListView1->addColumn( tr( "Add" ) ); 79 //ListView1->addColumn( tr( "Add" ) );
82 ListView1->addColumn( tr( "Add Device" ) ); 80 ListView1->addColumn( tr( "Add Device" ) );
83 //ListView1->addColumn( tr( "Type" ) ); 81 //ListView1->addColumn( tr( "Type" ) );
@@ -85,69 +83,79 @@ namespace OpieTooth {
85 Layout11->addWidget( ListView1); 83 Layout11->addWidget( ListView1);
86 Layout11->addWidget(progress); 84 Layout11->addWidget(progress);
87 Layout11->addWidget( buttonFrame); 85 Layout11->addWidget( buttonFrame);
88 86
89 localDevice = new Manager( "hci0" ); 87 localDevice = new Manager( "hci0" );
90 88
91 connect( StartButton, SIGNAL( clicked() ), this, SLOT( startSearch() ) ); 89 connect( StartStopButton, SIGNAL( clicked() ), this, SLOT( startSearch() ) );
92 connect( StopButton, SIGNAL( clicked() ), this, SLOT( stopSearch() ) );
93 connect( localDevice, SIGNAL( foundDevices( const QString& , RemoteDevice::ValueList ) ), 90 connect( localDevice, SIGNAL( foundDevices( const QString& , RemoteDevice::ValueList ) ),
94 this, SLOT(fillList(const QString& , RemoteDevice::ValueList ) ) ) ; 91 this, SLOT(fillList(const QString& , RemoteDevice::ValueList ) ) ) ;
95 // connect( this, SIGNAL( accept() ), this, SLOT( emitToManager() )); 92 // connect( this, SIGNAL( accept() ), this, SLOT( emitToManager() ));
96 progressStat = 0; 93 progressStat = 0;
94 m_search = false;
97 } 95 }
98 96
99// hack, make cleaner later 97// hack, make cleaner later
100 void ScanDialog::progressTimer() { 98 void ScanDialog::progressTimer() {
101 99
102 progressStat++; 100 progressStat++;
103 if (progressStat++ < 20) { 101 if (progressStat++ < 20 && m_search ) {
104 QTimer::singleShot( 2000, this, SLOT(progressTimer() ) ); 102 QTimer::singleShot( 2000, this, SLOT(progressTimer() ) );
105 }
106 progress->setProgress(progressStat++); 103 progress->setProgress(progressStat++);
104 }
107 105
108 } 106 }
109 107
110 void ScanDialog::accept() { 108 void ScanDialog::accept() {
111 emitToManager(); 109 emitToManager();
112 QDialog::accept(); 110 QDialog::accept();
113 } 111 }
114 112
115 113
116 void ScanDialog::startSearch() { 114 void ScanDialog::startSearch() {
115 if ( m_search ) {
116 stopSearch();
117 return;
118 }
119 m_search = true;
117 progress->setProgress(0); 120 progress->setProgress(0);
118 progressStat = 0; 121 progressStat = 0;
119 122
120 // empty list before a new scan 123 // empty list before a new scan
121 ListView1->clear(); 124 ListView1->clear();
122 125
123 QCheckListItem *deviceItem2 = new QCheckListItem( ListView1, "Test1", QCheckListItem::CheckBox ); 126 QCheckListItem *deviceItem2 = new QCheckListItem( ListView1, "Test1", QCheckListItem::CheckBox );
124 deviceItem2->setText(1, "BLAH" ); 127 deviceItem2->setText(1, "BLAH" );
125 128
126 progressTimer(); 129 progressTimer();
127 // when finished, it emmite foundDevices() 130 // when finished, it emmite foundDevices()
128 // checken ob initialisiert , qcop ans applet. 131 // checken ob initialisiert , qcop ans applet.
132 StartStopButton->setText( tr("Stop scan"));
133
129 localDevice->searchDevices(); 134 localDevice->searchDevices();
130 135
131 } 136 }
132 137
133 void ScanDialog::stopSearch() { 138 void ScanDialog::stopSearch() {
134 139 m_search = true;
135 } 140 }
136 141
137 void ScanDialog::fillList(const QString& device, RemoteDevice::ValueList deviceList) { 142 void ScanDialog::fillList(const QString&, RemoteDevice::ValueList deviceList) {
138 143 progress->setProgress(0);
144 progressStat = 0;
139 qDebug("fill List"); 145 qDebug("fill List");
140 QCheckListItem * deviceItem; 146 QCheckListItem * deviceItem;
141 147
142 RemoteDevice::ValueList::Iterator it; 148 RemoteDevice::ValueList::Iterator it;
143 for( it = deviceList.begin(); it != deviceList.end(); ++it ) { 149 for( it = deviceList.begin(); it != deviceList.end(); ++it ) {
144 150
145 deviceItem = new QCheckListItem( ListView1, (*it).name(), QCheckListItem::CheckBox ); 151 deviceItem = new QCheckListItem( ListView1, (*it).name(), QCheckListItem::CheckBox );
146 deviceItem->setText(1, (*it).mac() ); 152 deviceItem->setText(1, (*it).mac() );
147 } 153 }
154 m_search = false;
155 StartStopButton->setText(tr ("Start scan") );
148 } 156 }
149 157
150/* 158/*
151 * Iterates trough the items, and collects the checked items. 159 * Iterates trough the items, and collects the checked items.
152 * Then it emits it, so the manager can connect to the signal to fill the listing. 160 * Then it emits it, so the manager can connect to the signal to fill the listing.
153 */ 161 */
@@ -172,10 +180,11 @@ namespace OpieTooth {
172 } 180 }
173 181
174/* 182/*
175 * Cleanup 183 * Cleanup
176 */ 184 */
177 ScanDialog::~ScanDialog() { 185 ScanDialog::~ScanDialog() {
186 qWarning("delete scan dialog");
178 delete localDevice; 187 delete localDevice;
179 } 188 }
180 189
181} 190}
diff --git a/noncore/net/opietooth/manager/scandialog.h b/noncore/net/opietooth/manager/scandialog.h
index f18784d..8f8d39a 100644
--- a/noncore/net/opietooth/manager/scandialog.h
+++ b/noncore/net/opietooth/manager/scandialog.h
@@ -43,16 +43,17 @@ class Device;
43 Q_OBJECT 43 Q_OBJECT
44 44
45 public: 45 public:
46 ScanDialog( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 ); 46 ScanDialog( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 );
47 ~ScanDialog(); 47 ~ScanDialog();
48 48
49 private: // make them private -zecke
49 QFrame* Frame7; 50 QFrame* Frame7;
50 QProgressBar* progress; 51 QProgressBar* progress;
51 QPushButton* StartButton; 52 QPushButton* StartStopButton;
52 QPushButton* StopButton; 53// QPushButton* StopButton;
53 QListView* ListView1; 54 QListView* ListView1;
54 55
55public slots: 56public slots:
56 void accept(); 57 void accept();
57 58
58 protected: 59 protected:
@@ -62,12 +63,13 @@ public slots:
62 void stopSearch(); 63 void stopSearch();
63 void startSearch(); 64 void startSearch();
64 void progressTimer(); 65 void progressTimer();
65 void fillList(const QString& device, RemoteDevice::ValueList list); 66 void fillList(const QString& device, RemoteDevice::ValueList list);
66 67
67 private: 68 private:
69 bool m_search:1;
68 void emitToManager(); 70 void emitToManager();
69 Manager *localDevice; 71 Manager *localDevice;
70 int progressStat; 72 int progressStat;
71 73
72 signals: 74 signals:
73 void selectedDevices(const QValueList<RemoteDevice>&); 75 void selectedDevices(const QValueList<RemoteDevice>&);