[PC-BSD Commits] r15052 - pcbsd/current/src-qt4/libpcbsd

svn at pcbsd.org svn at pcbsd.org
Tue Jan 24 10:54:30 PST 2012


Author: kenmoore
Date: 2012-01-24 18:54:30 +0000 (Tue, 24 Jan 2012)
New Revision: 15052

Modified:
   pcbsd/current/src-qt4/libpcbsd/hardware.cpp
   pcbsd/current/src-qt4/libpcbsd/pcbsd-hardware.h
   pcbsd/current/src-qt4/libpcbsd/pcbsd-utils.h
   pcbsd/current/src-qt4/libpcbsd/utils.cpp
Log:
Add a couple new functions to libpcbsd



Modified: pcbsd/current/src-qt4/libpcbsd/hardware.cpp
===================================================================
--- pcbsd/current/src-qt4/libpcbsd/hardware.cpp	2012-01-24 18:25:15 UTC (rev 15051)
+++ pcbsd/current/src-qt4/libpcbsd/hardware.cpp	2012-01-24 18:54:30 UTC (rev 15052)
@@ -35,7 +35,7 @@
 
 Hardware::Hardware(QString devName)
 {
-   name = devName;
+   HardwareName = devName;
 }
 
 // --------- BLUETOOTH HARDWARE ----------
@@ -68,13 +68,10 @@
 }
 
 void Hardware::addBTdevice(QString bdaddr, QString name, QString key, QString pin){
-  QString cmd;
+
   //Check inputs and format them properly
   if(name.isEmpty() ){ //if no name given, scan the device and get its name
-    cmd = "hccontrol remote_name_request "+bdaddr;
-    name = Utils::runShellCommandSearch(cmd,"Name:");
-    name = name.section(":",1,1);
-    name = name.simplified(); //remove extra white space
+    name = getBTRemoteName(bdaddr);
   }
   name = "\""+name+"\""; //put quotes around the name  
   
@@ -88,7 +85,7 @@
 
   //check to make sure the bdaddr is not already added
   bool newDevice = false;  
-  cmd = "grep "+bdaddr+" /etc/bluetooth/hcsecd.conf";
+  QString cmd = "grep "+bdaddr+" /etc/bluetooth/hcsecd.conf";
   QStringList chk = Utils::runShellCommand(cmd);
   if( chk.isEmpty() ){newDevice = true;}
   
@@ -176,3 +173,22 @@
 void Hardware::restartBT(){
   Utils::runShellCommand("/etc/rc.d/hcsecd restart");
 }
+
+QStringList Hardware::findBTdevices(){
+  //Returns a QStringList of uniqe BD_ADDR discovered
+  QStringList bdaddrlist;
+  QStringList output = Utils::listShellCommandSearch("hccontrol -n ubt0hci inquiry","BD_ADDR");
+  for(int i=0; i<output.length(); i++){
+    QString bdaddr = output[i].section(":",1,6,QString::SectionSkipEmpty).simplified();
+    if( !bdaddrlist.contains(bdaddr) ){bdaddrlist << bdaddr;} //add to the list if it is unique
+  }
+  return bdaddrlist;
+}
+
+QString Hardware::getBTRemoteName(QString bdaddr){
+    QString cmd = "hccontrol remote_name_request "+bdaddr;
+    QString name = Utils::runShellCommandSearch(cmd,"Name:");
+    name = name.section(":",1,1);
+    name = name.simplified(); //remove extra white space
+    return name;
+}

Modified: pcbsd/current/src-qt4/libpcbsd/pcbsd-hardware.h
===================================================================
--- pcbsd/current/src-qt4/libpcbsd/pcbsd-hardware.h	2012-01-24 18:25:15 UTC (rev 15051)
+++ pcbsd/current/src-qt4/libpcbsd/pcbsd-hardware.h	2012-01-24 18:54:30 UTC (rev 15052)
@@ -1,5 +1,5 @@
 /***************************************************************************
- *   Copyright (C) 2008 by Tim McCormick   				   *
+ *   Copyright (C) 2011 by Ken Moore	   				   *
  *   ken at pcbsd.org   							   *
  *                                                                         *
  *   Permission is hereby granted, free of charge, to any person obtaining *
@@ -33,15 +33,17 @@
 public:
    Hardware(QString devName);
    //---BLUETOOTH FUNCTIONS---
-   QStringList getBTdevNames();
-   void setBTdevName(QString newName, QString devName);
-   void addBTdevice(QString bdaddr, QString name, QString key, QString pin);
-   void rmBTdevice(QString bdaddr, bool willRestart);
-   void restartBT();
+   static QStringList getBTdevNames();
+   static void setBTdevName(QString newName, QString devName);
+   static void addBTdevice(QString bdaddr, QString name, QString key, QString pin);
+   static void rmBTdevice(QString bdaddr, bool willRestart);
+   static void restartBT();
+   static QStringList findBTdevices();
+   static QString getBTRemoteName(QString bdaddr);
 
 private:
-   QString name;
-   QString getHcsecsDeviceValue(QString rawline); //for bluetooth functions
+   static QString HardwareName;
+   static QString getHcsecsDeviceValue(QString rawline); //for bluetooth functions
 };
 
 #endif

Modified: pcbsd/current/src-qt4/libpcbsd/pcbsd-utils.h
===================================================================
--- pcbsd/current/src-qt4/libpcbsd/pcbsd-utils.h	2012-01-24 18:25:15 UTC (rev 15051)
+++ pcbsd/current/src-qt4/libpcbsd/pcbsd-utils.h	2012-01-24 18:54:30 UTC (rev 15052)
@@ -56,6 +56,7 @@
    static QString getConfFileValue( QString oFile, QString Key, QString ValRx, int occur );
    static QStringList runShellCommand( QString command );
    static QString runShellCommandSearch( QString command, QString sch );
+   static QStringList listShellCommandSearch( QString command, QString sch );
 };
 
 #endif

Modified: pcbsd/current/src-qt4/libpcbsd/utils.cpp
===================================================================
--- pcbsd/current/src-qt4/libpcbsd/utils.cpp	2012-01-24 18:25:15 UTC (rev 15051)
+++ pcbsd/current/src-qt4/libpcbsd/utils.cpp	2012-01-24 18:54:30 UTC (rev 15052)
@@ -420,11 +420,17 @@
 //Example command: ls | grep X -> runShellCommandSearch("ls","X")
 QString Utils::runShellCommandSearch( QString command, QString sch)
 {
- QStringList L = Utils::runShellCommand(command);
- QStringList schList = sch.split(" "); //make a list of the words to search for in a single line
- for(int i=0; i<schList.size(); i++){
-   L = L.filter(schList[i]);
- }
+ QStringList L = listShellCommandSearch(command,sch);
  QString outstr = L.join("\n"); //combine the remaining lines into a single string
  return outstr;
 }
+
+QStringList Utils::listShellCommandSearch( QString command, QString sch)
+{
+  QStringList L = Utils::runShellCommand(command);
+  QStringList schList = sch.split(" "); //make a list of the words to search for in a single line
+  for(int i=0; i<schList.size(); i++){
+    L = L.filter(schList[i]);
+  }
+  return L;
+}



More information about the Commits mailing list