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

svn at pcbsd.org svn at pcbsd.org
Fri Mar 22 09:27:31 PDT 2013


Author: kenmoore
Date: 2013-03-22 16:27:31 +0000 (Fri, 22 Mar 2013)
New Revision: 21948

Modified:
   pcbsd/current/src-qt4/pc-mounttray/devCheck.cpp
   pcbsd/current/src-qt4/pc-mounttray/menuItem.cpp
   pcbsd/current/src-qt4/pc-mounttray/mountTray.cpp
Log:
The Mounttray now has full cd/DVD support for data disks (audio disks still cause al sorts of issues - not autodetected right now). The only thing missing is the devd prompt that the cd/dvd drive has changed somehow. The work-around right now is to manually click the "rescan" button after adding/removing a disk.



Modified: pcbsd/current/src-qt4/pc-mounttray/devCheck.cpp
===================================================================
--- pcbsd/current/src-qt4/pc-mounttray/devCheck.cpp	2013-03-22 16:19:28 UTC (rev 21947)
+++ pcbsd/current/src-qt4/pc-mounttray/devCheck.cpp	2013-03-22 16:27:31 UTC (rev 21948)
@@ -105,52 +105,69 @@
   //Make sure we quit before running commands on any invalid device nodes
   if(detType.isEmpty() || !QFile::exists(fullDev) ){return FALSE;}
   else{type->append(detType);}
-    
+  bool isCD=FALSE;
+  if(detType == "CD9660"){ isCD=TRUE; }
+  
   //Read the Device Info using "file -s <device>"
   QString cmd = "file -s "+fullDev;
   QString output = Utils::runShellCommand(cmd).join(" ");
-  //qDebug() << "File -s output:" << output;
+  //if(isCD){ qDebug() << "File -s output:" << output; }
   
   // ** Get the max storage size **
-  QStringList tmp = output.split(",");
   int kb = 0;
   bool hasPartitions = FALSE; 
   bool isMounted = FALSE;
-  //qDebug() << "tmp:" << tmp;
-  if( !tmp.filter("partition ").isEmpty() ){
-    //Check for actual sub-devices (*s[#][a/b/c/....])
-    if( devChildren(node).length() > 1 ){ hasPartitions = TRUE; } //the main device will always make it length 1
-  }
-  if( !tmp.filter("last mounted on /").isEmpty() && (detType == "SATA")){
-    isMounted = TRUE;
-  }
-  //Now try to get the size of the disk
-  if( !tmp.filter("number of data blocks").isEmpty() ){
-    tmp = tmp.filter("number of data blocks");
-    kb = tmp[0].remove("number of data blocks").simplified().toInt();
-  }else if( !tmp.filter("number of blocks").isEmpty() ){
-    tmp = tmp.filter("number of blocks");
-    kb = tmp[0].remove("number of blocks").simplified().toInt();
-  }else if( !tmp.filter("hidden sectors").isEmpty()){
-    tmp = tmp.filter("hidden sectors");
-    kb = tmp[0].remove("hidden sectors").simplified().toInt();
-  }else if( !tmp.filter("sectors").isEmpty()){
-    tmp = tmp.filter("sectors");
-    //qDebug() << "Det Sectors line:"<<tmp;
-    int num=0;
-    for(int i=0; i<tmp.length(); i++){
-      int n = tmp[i].remove("sectors").section("(",0,0).simplified().toInt();
-      if(n > num){ num = n; }
+  if( !isCD ){
+    QStringList tmp = output.split(",");
+    if( !tmp.filter("partition ").isEmpty() ){
+      //Check for actual sub-devices (*s[#][a/b/c/....])
+      if( devChildren(node).length() > 1 ){ hasPartitions = TRUE; } //the main device will always make it length 1
     }
-    kb = num;
-  }else{ kb = -1; }
+    if( !tmp.filter("last mounted on /").isEmpty() && (detType == "SATA")){
+      isMounted = TRUE;
+    }
+    //Now try to get the size of the disk
+    if( !tmp.filter("number of data blocks").isEmpty() ){
+      tmp = tmp.filter("number of data blocks");
+      kb = tmp[0].remove("number of data blocks").simplified().toInt();
+    }else if( !tmp.filter("number of blocks").isEmpty() ){
+      tmp = tmp.filter("number of blocks");
+      kb = tmp[0].remove("number of blocks").simplified().toInt();
+    }else if( !tmp.filter("hidden sectors").isEmpty()){
+      tmp = tmp.filter("hidden sectors");
+      kb = tmp[0].remove("hidden sectors").simplified().toInt();
+    }else if( !tmp.filter("sectors").isEmpty()){
+      tmp = tmp.filter("sectors");
+      //qDebug() << "Det Sectors line:"<<tmp;
+      int num=0;
+      for(int i=0; i<tmp.length(); i++){
+        int n = tmp[i].remove("sectors").section("(",0,0).simplified().toInt();
+        if(n > num){ num = n; }
+      }
+      kb = num;
+    }else{ kb = -1; }
+  } //end non-CD size and isMounted detection
   bool oksize = (kb > 0);
   //First try to get the device label using the "file -s" output
-  QString dlabel = output.section("label: \"",1,1).section("\"",0,0).simplified(); //device name
+  QString dlabel;
+  if(isCD){
+    if( !output.contains("ERROR:") ){
+      dlabel = output.section("'",-2).remove("'").simplified();
+      //qDebug() << dlabel;
+      //while( dlabel.endsWith(" ") || dlabel.endsWith("\n") ){ dlabel.chop(1); }
+      //qDebug() << dlabel;
+    }
+  }else{
+   dlabel = output.section("label: \"",1,1).section("\"",0,0).simplified(); //device name
+  }
   // - trim the label out of the output line for filesystem type detection
-  QString devFSsec = output.section("label:",0,0);
-  QString devFSsec2 = output.section("label:",1,3).section(",",1,1,QString::SectionSkipEmpty);
-  
+  QString devFSsec, devFSsec2;
+  if(!isCD){
+    devFSsec = output.section("label:",0,0);
+    devFSsec2 = output.section("label:",1,3).section(",",1,1,QString::SectionSkipEmpty);
+  }else{
+    devFSsec = output.simplified();	  
+  }
   // ** Find the filesystem type for the device **
   QString filesys;
   for(int i=0; i<fsDetection.length(); i++){
@@ -164,18 +181,25 @@
   
   //Now get the device label (if there is one) using glabel
   bool hasLabel = FALSE;
-  QString glabel = devLabel(node, filesys);
+  QString glabel;
+  if(!isCD){ glabel = devLabel(node, filesys); }
   //Check to see if we have a label, otherwise assign one
   if( !glabel.isEmpty() ){ dlabel = glabel; hasLabel = TRUE; } //glabel
   else if(!dlabel.isEmpty()){ hasLabel = TRUE; } //file -s label
   else{
-    dlabel = *type+"-Device"; //this is not a "detected" label
+    //Assign a device label
+    if(isCD){
+      dlabel = "Optical_Disk";
+    }else{
+      dlabel = detType+"-Device"; //this is not a "detected" label
+    }
   }
   
   //Now perform the final checks to see if it is a good device
   bool good = FALSE;
   if( isMounted ){}//Always ignore this device (local FreeBSD installation that is being used)
   else if( hasPartitions ){} //Ignore devices that have partitions accessible as seperate devices
+  else if( hasFS && isCD ){ good = TRUE; } //CD/DVD data disks don't have as much info
   //Allow devices that match 2 of the 3 criteria
   else if( hasFS && oksize ){ good = TRUE; } //This will catch most good devices
   else if( hasLabel && oksize ){ good = TRUE; } //allow unknown filesystems if there is a good size reading

Modified: pcbsd/current/src-qt4/pc-mounttray/menuItem.cpp
===================================================================
--- pcbsd/current/src-qt4/pc-mounttray/menuItem.cpp	2013-03-22 16:19:28 UTC (rev 21947)
+++ pcbsd/current/src-qt4/pc-mounttray/menuItem.cpp	2013-03-22 16:27:31 UTC (rev 21948)
@@ -67,12 +67,19 @@
   //Update the item visuals, based upon current device status
   if( isConnected() ){
     if( isMounted() ){
+      if(mountpoint.isEmpty()){
+      	//detect the current mountpoint
+      	QString output = Utils::runShellCommandSearch("mount",device);
+        mountpoint = output.section(" on ",1,1).section(" (",0,0).replace(" ","-");
+      }
       devIcon->setEnabled(TRUE);  //Make the icon full color
+      devIcon->setToolTip(device+"\n"+QString(tr("Mounted at %1")).arg(mountpoint));
       pushMount->setText(tr("Eject"));
       pushMount->setIcon(QIcon(":icons/eject.png"));
       checkAutomount->setVisible(TRUE);
     }else{	  
       devIcon->setEnabled(FALSE); //Grey out the icon if not mounted
+      devIcon->setToolTip(device);
       pushMount->setText(tr("Mount"));
       pushMount->setIcon(QIcon(":icons/mount.png"));
       checkAutomount->setVisible(FALSE);
@@ -292,7 +299,7 @@
     if(output.length() > 1){
       //parse the output (1K blocks) and save them
       QString line = output[1].replace("\t"," ");
-      qDebug() << "df output:" << output << cmd;
+      //qDebug() << "df output:" << output << cmd;
       maxSize = line.section(" ",1,1,QString::SectionSkipEmpty).simplified();
       currentSize = line.section(" ",2,2,QString::SectionSkipEmpty).simplified();
       ok=TRUE;
@@ -311,9 +318,9 @@
     currentSpace->setVisible(TRUE);
     //display the actual size available in the tooltip
     QString diskAvailable = getSizeDisplay( maxSize.toInt() - currentSize.toInt() );
-    qDebug() << "MaxSize:" << maxSize << maxSize.toInt();
-    qDebug() << "CurrentSize:" << currentSize << currentSize.toInt();
-    qDebug() << "Disk Available:" << diskAvailable;
+    //qDebug() << "MaxSize:" << maxSize << maxSize.toInt();
+    //qDebug() << "CurrentSize:" << currentSize << currentSize.toInt();
+    //qDebug() << "Disk Available:" << diskAvailable;
     currentSpace->setToolTip( QString( tr("%1 of disk space available") ).arg(diskAvailable) );
   }else{
     currentSpace->setVisible(FALSE);

Modified: pcbsd/current/src-qt4/pc-mounttray/mountTray.cpp
===================================================================
--- pcbsd/current/src-qt4/pc-mounttray/mountTray.cpp	2013-03-22 16:19:28 UTC (rev 21947)
+++ pcbsd/current/src-qt4/pc-mounttray/mountTray.cpp	2013-03-22 16:27:31 UTC (rev 21948)
@@ -165,6 +165,9 @@
 }
 
 void MountTray::slotDevChanges(bool showPopup){
+  //This function actually checks the system device list for changes
+  //  and updates the available devices appropriately
+  
   if(DEBUG_MODE){ qDebug() << "Checking for Device Changes:"; }
   //oldsysdev is the old device list for the system
   QStringList osd = oldsysdev;
@@ -209,8 +212,34 @@
       }
     }
   }
+  //==== CD/DVD Devices ====
+  //Always check cd/dvd devices because the device node will never be added/removed
+  QStringList diskList;
+  diskList << DCheck->devChildren("cd");
+  diskList << DCheck->devChildren("acd");
+  if(DEBUG_MODE){ qDebug() << "Checking CD/DVD devices:" << diskList; }
+  for(int i=0; i<diskList.length(); i++){
+    if( rmList.contains(diskList[i]) || nsd.contains(diskList[i]) ){
+      continue; //do not double check a device that was just checked;	    
+    }
+    //Check if it is a good device
+    QString dlabel, dtype, dfs, dsize; //additional output info
+    bool good = DCheck->devInfo(diskList[i],&dtype,&dlabel,&dfs,&dsize);
+    if(good){
+      //Now create a new entry for this device
+      addDevice(diskList[i],dlabel,dtype,dfs);  
+      //Show a message bubble
+      if(showPopup){
+        QString title = tr("New Device");
+        QString message = QString( tr("%1 can now be accessed")).arg(dlabel);
+        slotDisplayPopup(title, message);
+      }
+    }else{ //not good device
+      removeDevice(diskList[i]);	    
+    }
+  } //end loop over cd/dvd devices
+}
 
-}
 void MountTray::closeTray(){
   qDebug() << "pc-mounttray: closing down";
   //Kill the devd watching process



More information about the Commits mailing list