[PC-BSD Commits] r15056 - pcbsd/current/src-qt4/libpcbsd
svn at pcbsd.org
svn at pcbsd.org
Tue Jan 24 19:35:36 PST 2012
Author: kenmoore
Date: 2012-01-25 03:35:36 +0000 (Wed, 25 Jan 2012)
New Revision: 15056
Modified:
pcbsd/current/src-qt4/libpcbsd/hardware.cpp
pcbsd/current/src-qt4/libpcbsd/pcbsd-hardware.h
Log:
Add some more functions and fix the (now tested) bluetooth functions in libpcbsd
Modified: pcbsd/current/src-qt4/libpcbsd/hardware.cpp
===================================================================
--- pcbsd/current/src-qt4/libpcbsd/hardware.cpp 2012-01-24 20:35:52 UTC (rev 15055)
+++ pcbsd/current/src-qt4/libpcbsd/hardware.cpp 2012-01-25 03:35:36 UTC (rev 15056)
@@ -63,8 +63,9 @@
}
void Hardware::addBTdevice(QString bdaddr, QString name, QString key, QString pin){
-
//Check inputs and format them properly
+ if(bdaddr.isEmpty() ){return; } //do nothing if no bdaddr given
+
if(name.isEmpty() ){ //if no name given, scan the device and get its name
name = getBTRemoteName(bdaddr);
}
@@ -93,7 +94,7 @@
QFile fileout( "/etc/bluetooth/hcsecd.conf.tmp" );
if( fileout.open( QIODevice::Append ) ){
QTextStream streamout( &fileout );
- streamout << "\ndevice{\n";
+ streamout << "\ndevice {\n";
streamout << " bdaddr "+bdaddr+";\n";
streamout << " name "+name+";\n";
streamout << " key "+key+";\n";
@@ -111,16 +112,62 @@
return;
}
+QStringList Hardware::readAllSavedBTDevices(){
+ //Return QStringList of all BDADDR's saved in hcsecd.conf
+ QStringList bdaddrList;
+ //scan the file and output all the devices
+ QFile filein( "/etc/bluetooth/hcsecd.conf" );
+ if( filein.open( QIODevice::ReadOnly ) ){
+ QTextStream instream( &filein );
+ while(!instream.atEnd() ){
+ QString line = instream.readLine();
+ if( line.contains("device {") && !line.contains("#") ){
+ //grab the value for the bdaddr from the next line
+ bdaddrList << getHcsecsDeviceValue( instream.readLine() );
+ }
+ } //end of loop over file
+ filein.close();
+ }
+ return bdaddrList;
+}
+
+QStringList Hardware::readSavedBTDevice(QString bdaddr){
+ //Returns QStringList of [bdaddr, name, key, pin] from the hcsecd.conf file
+
+ QStringList settings;
+ //scan the file and save only the desired device settings
+ QFile filein( "/etc/bluetooth/hcsecd.conf" );
+ if( filein.open( QIODevice::ReadOnly ) ){
+ QTextStream instream( &filein );
+ while(!instream.atEnd() ){
+ QString line = instream.readLine();
+ if( line.contains("device {") && !line.contains("#") ){
+ //grab the value for the bdaddr from the next line
+ QString bdaddrchk = getHcsecsDeviceValue( instream.readLine() );
+ if(bdaddrchk == bdaddr){//not entry to be removed
+ //save these device configurations
+ settings << bdaddrchk; //bdaddr
+ settings << getHcsecsDeviceValue( instream.readLine() ); //name
+ settings << getHcsecsDeviceValue( instream.readLine() ); //key
+ settings << getHcsecsDeviceValue( instream.readLine() ); //pin
+ break; //end the loop, data already found
+ }
+ }
+ } //end of loop over file
+ filein.close();
+ }
+ return settings;
+}
+
void Hardware::rmBTdevice(QString bdaddr,bool willRestart=true){
QStringList oldbdaddr, oldname, oldkey, oldpin;
//scan the file and save all the devices except the one to be removed
- QFile filein( "/etc/bluetooth/hcsecs.conf" );
+ QFile filein( "/etc/bluetooth/hcsecd.conf" );
if( filein.open( QIODevice::ReadOnly ) ){
QTextStream instream( &filein );
while(!instream.atEnd() ){
QString line = instream.readLine();
- if( line.contains("#") || !line.isEmpty() ){ //ignore commented and empty lines
- if( line.contains("device{") ){
+ if( line.contains("device {") && !line.contains("#") ){
//grab the value for the bdaddr from the next line
QString bdaddrchk = getHcsecsDeviceValue( instream.readLine() );
if(bdaddrchk != bdaddr){//not entry to be removed
@@ -131,18 +178,22 @@
oldpin << getHcsecsDeviceValue( instream.readLine() );
}
}
- } //end of comment check
} //end of loop over file
filein.close();
}
//write a temporary file to not include the removed device
- QFile fileout( "/etc/bluetooth/hcsecs.conf.tmp" );
+ QFile fileout( "/etc/bluetooth/hcsecd.conf.tmp" );
if( fileout.open( QIODevice::WriteOnly ) ){
QTextStream streamout( &fileout );
for(int i=0; i<oldbdaddr.length(); i++){
- streamout << "\ndevice{\n";
+ //Check the formatting of the name/key/pin (put quotes around item when needed)
+ oldname[i] = "\""+oldname[i]+"\"";
+ if(oldkey[i]!="nokey"){oldkey[i] = "\""+oldkey[i]+"\"";}
+ if(oldpin[i]!="nopin"){oldpin[i] = "\""+oldpin[i]+"\"";}
+ //write the device info to the file
+ streamout << "\ndevice {\n";
streamout << " bdaddr "+oldbdaddr[i]+";\n";
streamout << " name "+oldname[i]+";\n";
streamout << " key "+oldkey[i]+";\n";
@@ -160,8 +211,11 @@
QString Hardware::getHcsecsDeviceValue(QString rawline){
//returns the value of the variable on a given raw line from the hcsecs.conf file
- QString line = rawline.section(";",0,0); //remove the ";" at the end of the line
+ QString line = rawline.simplified().section(";",0,0); //remove the ";" at the end of the line
+ //qDebug() << line;
line = line.section(" ",1,1,QString::SectionSkipEmpty); //remove the label at the beginning
+ line.remove("\"");
+ //qDebug() << rawline << "-->" << line;
return line;
}
Modified: pcbsd/current/src-qt4/libpcbsd/pcbsd-hardware.h
===================================================================
--- pcbsd/current/src-qt4/libpcbsd/pcbsd-hardware.h 2012-01-24 20:35:52 UTC (rev 15055)
+++ pcbsd/current/src-qt4/libpcbsd/pcbsd-hardware.h 2012-01-25 03:35:36 UTC (rev 15056)
@@ -40,6 +40,8 @@
static void restartBT();
static QStringList findBTdevices();
static QString getBTRemoteName(QString bdaddr);
+ static QStringList readAllSavedBTDevices();
+ static QStringList readSavedBTDevice(QString bdaddr);
private:
static QString getHcsecsDeviceValue(QString rawline); //for bluetooth functions
More information about the Commits
mailing list