[PC-BSD Commits] r15120 - pcbsd/current/src-qt4/pc-bluetoothmanager
svn at pcbsd.org
svn at pcbsd.org
Tue Jan 31 15:41:33 PST 2012
Author: kenmoore
Date: 2012-01-31 23:41:33 +0000 (Tue, 31 Jan 2012)
New Revision: 15120
Modified:
pcbsd/current/src-qt4/pc-bluetoothmanager/btmaingui.cpp
pcbsd/current/src-qt4/pc-bluetoothmanager/btmaingui.h
Log:
Add the ability to configure bluetooth device settings and add better check for root permissions.
Modified: pcbsd/current/src-qt4/pc-bluetoothmanager/btmaingui.cpp
===================================================================
--- pcbsd/current/src-qt4/pc-bluetoothmanager/btmaingui.cpp 2012-01-31 23:39:53 UTC (rev 15119)
+++ pcbsd/current/src-qt4/pc-bluetoothmanager/btmaingui.cpp 2012-01-31 23:41:33 UTC (rev 15120)
@@ -33,6 +33,7 @@
connect(ui->pushRemoveOld,SIGNAL(clicked()),this,SLOT(removeOldDevice()));
connect(ui->listOldDevice,SIGNAL(currentRowChanged(int)),this,SLOT(updateOldDeviceInfo(int)));
connect(ui->pushAddDevice,SIGNAL(clicked()),this,SLOT(addNewDevice()));
+ connect(ui->pushConfigureOld,SIGNAL(clicked()),this,SLOT(configureOldDevice()));
//Setup GUI enables/disables
//Start on the system settings tab
@@ -84,17 +85,21 @@
ui->listOldDevice->setCurrentRow(-1);
ui->oldDeviceInfo->clear();
ui->oldDeviceInfo->append(tr("Reading saved Bluetooth devices. Please wait."));
+ //Make sure there is root permissions to read/write the settings
+ if( !rootPermissions() ){
+ ui->oldDeviceInfo->clear();
+ ui->oldDeviceInfo->append(tr("This program must be run with root permissions to view/edit saved configurations"));
+ return;
+ }
+
//Get all the Old Devices saved in hcsecd.conf and load them into memory
QStringList oldBdaddrList = Hardware::readAllSavedBTDevices();
oldSaveKeyList.clear(); oldSavePinList.clear(); oldSaveNameList.clear(); oldSaveBdaddrList.clear(); //reset the saved variables
+
+ //Stop earlier if there is no saved devices
if(oldBdaddrList.isEmpty()){
ui->oldDeviceInfo->clear();
- QString userID = Utils::runShellCommand("id -u").join("");
- if( userID.toInt() == 0){
- ui->oldDeviceInfo->append(tr("No saved configurations found"));
- }else{
- ui->oldDeviceInfo->append(tr("This program must be run as root to view/edit saved configurations"));
- }
+ ui->oldDeviceInfo->append(tr("No saved configurations found"));
return;
}
for(int i=0; i<oldBdaddrList.length(); i++){
@@ -128,6 +133,13 @@
}
void btmaingui::addNewDevice(){
+ //Check for root permissions
+ if( !rootPermissions() ){
+ //No root permissions to save device
+ QMessageBox::warning(this,tr("Invalid Permissions"),tr("This program must be run with root permissions to save device settings"));
+ return;
+ }
+
//Get the BDADDR of the selected device
int row = ui->listNewDevice->currentRow();
if(row == -1){
@@ -136,10 +148,24 @@
return;
}
QString bdaddr = newSaveBdaddrList[row];
+
//Ask for PIN and KEY for configuration
- //----Add configuration GUI here----
- QString pin = "";
- QString key = "";
+ QStringList requests;
+ requests << tr("PIN Code (Examples: 0000, 1234, or none)") << tr("Link Key (Leave blank for automatic)");
+ QStringList outputs = Utils::quickUserInputBox(tr("Device Configuration"),requests);
+ if( outputs.length() != requests.length() ){ //rememberempty strings are valid
+ //Error/cancelled operation - do nothing
+ qDebug() << "Add new device: Cancelled";
+ return;
+ }
+ QString pin = outputs[0];
+ QString key = outputs[1];
+ //Quick Check for pin validity
+ if( pin.length()!=4 && !pin.isEmpty() ){
+ QMessageBox::warning(this,tr("Warning"),tr("Invalid Pin length: Defaulting to none"));
+ pin = "";
+ }
+ if(pin == "none"){ pin=""; }
//Add the entry to hcsecd.conf
Hardware::addBTdevice(bdaddr,"",key,pin);
@@ -182,3 +208,37 @@
}
}
+bool btmaingui::rootPermissions(){
+ QString userID = Utils::runShellCommand("id -u").join("");
+ if( userID.toInt() == 0){ return TRUE; }
+ else{ return FALSE; }
+}
+
+void btmaingui::configureOldDevice(){
+ //Get the selected device information
+ int row = ui->listOldDevice->currentRow();
+ if(row == -1){
+ //No device selected
+ QMessageBox::warning(this,tr("Warning"),tr("No device has been selected. Please choose a device first."));
+ return;
+ }
+ QString bdaddr = oldSaveBdaddrList[row];
+
+ //Get the new PIN and KEY
+ QStringList requests;
+ requests << tr("PIN Code (Examples: 0000, 1234, or none)") << tr("Link Key (Leave blank for automatic)");
+ QStringList outputs = Utils::quickUserInputBox(tr("Device Configuration"),requests);
+ if( outputs.length() != requests.length() ){ //rememberempty strings are valid
+ //Error/cancelled operation - do nothing
+ qDebug() << "Configure old device: Cancelled";
+ return;
+ }
+ QString pin = outputs[0];
+ QString key = outputs[1];
+ //Quick Check for pin validity
+ if( pin.length()!=4 && !pin.isEmpty() ){
+ QMessageBox::warning(this,tr("Warning"),tr("Invalid Pin length: Defaulting to none"));
+ pin = "";
+ }
+ if(pin == "none"){ pin=""; }
+}
Modified: pcbsd/current/src-qt4/pc-bluetoothmanager/btmaingui.h
===================================================================
--- pcbsd/current/src-qt4/pc-bluetoothmanager/btmaingui.h 2012-01-31 23:39:53 UTC (rev 15119)
+++ pcbsd/current/src-qt4/pc-bluetoothmanager/btmaingui.h 2012-01-31 23:41:33 UTC (rev 15120)
@@ -20,6 +20,7 @@
private:
Ui::btmaingui *ui;
void firstRun();
+ bool rootPermissions();
private slots:
void scanForDevices();
@@ -30,7 +31,7 @@
void updateCompInfo();
void updateNewDeviceInfo();
void updateOldDeviceInfo(int);
-
+ void configureOldDevice();
};
#endif // BTMAINGUI_H
More information about the Commits
mailing list