[PC-BSD Commits] r17277 - pcbsd/current/src-qt4/pc-mounttray

svn at pcbsd.org svn at pcbsd.org
Thu Jun 14 07:03:11 PDT 2012


Author: kenmoore
Date: 2012-06-14 14:03:10 +0000 (Thu, 14 Jun 2012)
New Revision: 17277

Modified:
   pcbsd/current/src-qt4/pc-mounttray/mountTray.cpp
   pcbsd/current/src-qt4/pc-mounttray/mountTray.h
Log:
Change over the devd detection algorithm for pc-mounttray to a new process, it should now detect device changes much better and work almost instantaneously.



Modified: pcbsd/current/src-qt4/pc-mounttray/mountTray.cpp
===================================================================
--- pcbsd/current/src-qt4/pc-mounttray/mountTray.cpp	2012-06-14 13:50:41 UTC (rev 17276)
+++ pcbsd/current/src-qt4/pc-mounttray/mountTray.cpp	2012-06-14 14:03:10 UTC (rev 17277)
@@ -465,72 +465,54 @@
 }
 
 void MountTray::newDevdMessage(){
-  //Since messages generally come in groups, save all the output for a couple seconds before doing anything
-  QString line = devdProc->readAllStandardOutput();
-  if(devdOutput.isEmpty()){
-    QTimer::singleShot(1500,this,SLOT(parseDevdOutput()) ); //Wait 1.5 seconds to catch all the output from devd
-  }
-  devdOutput << line.split("\n");
-  //qDebug() << "New devd.pipe message:" << line;
-}
-
-void MountTray::parseDevdOutput(){
-
-  //qDebug() << "Devd.pipe output:" << devdOutput;
-  //Parse the output to find whether a device has been added/removed
-  bool isAttached = FALSE;
-  bool isUmass = FALSE;
-  QStringList cdev;
-  for(int i=0; i<devdOutput.length(); i++){
-    if( devdOutput[i].startsWith("+umass") ){
-      isAttached = TRUE;
-      isUmass = TRUE;
-    }else if(devdOutput[i].startsWith("-umass") ){
-      isAttached = FALSE;
-      isUmass = TRUE;
-    }
-    if(devdOutput[i].startsWith("!system=") ){
-      cdev << devdOutput[i].section("cdev=",1,1).section(" vendor=",0,0).simplified();
-    }
-  }
-  
-  //Finished with the saved devd Output, clear it to prepare for another signal
-  devdOutput.clear();
-  //qDebug() << "cdev=" << cdev;
-  //If a USB mass storage device found
-  QString dev,devtype;
-  if(isUmass){
-    devtype = "USB";
-    //Try to find the device, device name, and filesystem type
-    for(int i=0; i<cdev.length(); i++){
-      if( !cdev[i].contains("/") && !cdev.startsWith("ugen") && !cdev.startsWith("pass") ){
-	if(isAttached && QFile::exists("/dev/"+cdev[i]) ){
-          dev = cdev[i];
-        }else if( !isAttached && (findDeviceInList(newDeviceAction(cdev[i])) != -1) ){
-          dev = cdev[i];
+  QString tmpline = devdProc->readAllStandardOutput();
+  //Make sure there are not multiple lines output at the same time
+  QStringList lList = tmpline.split("\n");
+  //Parse each line seperately
+  for(int i=0; i<lList.length(); i++){
+    QString line = lList[i];
+    bool isAttached=FALSE;
+    bool deviceFound=FALSE;
+    QString cdev,cdevtype;
+    if(line.startsWith("!system=DEVFS")){
+      qDebug() << line;
+      QString type = line.section("type=",1,1).section(" ",0,0).simplified();
+      cdev = line.section("cdev=",1,1).section(" ",0,0).simplified();
+      if(type=="CREATE"){isAttached=TRUE;}
+      //Parse out cdev to try and only get a single handle for each device
+      if(!cdev.contains("/") && !cdev.contains("pass")){
+       cdev.prepend("/dev/");
+        if( QFile::symLinkTarget(cdev).isEmpty() && isAttached && QFile::exists(cdev) ){
+          deviceFound=TRUE;
+          cdevtype="USB";
         }
+        else if(!isAttached){
+          //Find out if this device is on the list of currently connected devices
+  	  if( findDeviceInList(newDeviceAction(cdev))!=-1 ){
+	    deviceFound=TRUE;
+	    cdevtype="USB";
+	  }
+        }
       }
     }
-  } //end if umass detected
-  
-  //Create the action for the device if a device detected
-  if(!dev.isEmpty() ){ 
-    QAction* newdev = newDeviceAction(dev,devtype);
-    if(isAttached){
-      qDebug() << "New device detected:" << newdev->text() << newdev->whatsThis() << newdev->statusTip();
-      if( updateDeviceList( 1 , newdev ) ){
-        showDeviceNotification(1,newdev);
+    //Perform action if a device is found
+    if(deviceFound){
+      QAction* newdev = newDeviceAction(cdev,cdevtype);
+      if(isAttached){
+        qDebug() << "New device detected:" << newdev->text() << newdev->whatsThis() << newdev->statusTip();
+        if( updateDeviceList( 1 , newdev ) ){
+          showDeviceNotification(1,newdev);
+        }
+      }else{
+        qDebug() << "Device removal detected:" <<  newdev->whatsThis();
+        if( updateDeviceList( 4 , newdev ) ){
+          showDeviceNotification(4,newdev);
+        }
       }
-    }else{
-      qDebug() << "Device removal detected:" <<  newdev->whatsThis();
-      if( updateDeviceList( 4 , newdev ) ){
-        showDeviceNotification(4,newdev);
-      }
+      //Update the Tray menu
+      updateTrayMenu();
     }
-    //Update the Tray menu
-    updateTrayMenu();
-  }
-  
+  } // end loop over all devd output lines
 }
 
 void MountTray::menuDeviceToggled(QAction* device){

Modified: pcbsd/current/src-qt4/pc-mounttray/mountTray.h
===================================================================
--- pcbsd/current/src-qt4/pc-mounttray/mountTray.h	2012-06-14 13:50:41 UTC (rev 17276)
+++ pcbsd/current/src-qt4/pc-mounttray/mountTray.h	2012-06-14 14:03:10 UTC (rev 17277)
@@ -28,7 +28,6 @@
   void menuDeviceToggled(QAction*);
   void menuDeviceHovered(QAction*);
   void newDevdMessage();
-  void parseDevdOutput();
   void slotTrayActivated(QSystemTrayIcon::ActivationReason);
   void slotOpenMediaDir();
   



More information about the Commits mailing list