Changeset 38951fa


Ignore:
Timestamp:
03/19/14 11:04:41 (4 months ago)
Author:
Ken Moore <ken@…>
Branches:
master, releng/10.0.2
Children:
bc75ae0
Parents:
37c7d9a
Message:

Another large update to the mounttray.
1) Remove the filesystem detection check from the valid/invalid devices routine, and make it so that if a device has *either* a size or label it will be recognized (instead of "and"). Also adjust the detection of the currently running device/partition, and always show non-parent SD cards (since they often don't report much information).
2) Move the filesystem usage into the DevCheck? class out of the menuItem class, and also add the ability to mount devices as EXT4 or EXFAT filesystems (not auto-detected).
3) If a device has an unknown filesystem, open a dialog asking which filesystem to use when mounting the device - saving this for the device in the future if it works. (saved info is lost when the device is disconnected or computer is restarted).
4) If the filesystem is unknown, display a "?" overlay in the top-right corner of the device icon.

Location:
src-qt4/pc-mounttray
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • src-qt4/pc-mounttray/devCheck.cpp

    rfa4f55f r38951fa  
    1111    devFilter << validDevs[i]+"*"; 
    1212  } 
    13   //Initialize lists of filesystems and detection strings 
     13  //Initialize lists of filesystems and detection strings for automatic detection 
    1414  fsDetection.clear(); 
    1515  fsMatch.clear(); 
     16  fsFilter.clear(); 
    1617  fsDetection << "FAT" << "NTFS" << "EXT" << "ISO 9660" << "Unix Fast File system" << "Reiser" << "XFS"; //string to match for a particular filesystem 
    1718  fsMatch << "FAT" << "NTFS" << "EXT" << "CD9660" << "UFS" << "REISERFS" << "XFS"; //internal labels for the filesystems 
    1819  fsFilter << "fat" << "ntfs" << "ext" << "cdrom" << "ufs" << "reiser" << "xfs"; //label categories in /dev/ 
     20  //Initialize lists of Manual Filesystems that might be available 
     21  fsManual.clear(); fsCMD.clear(); fsBinCheck.clear(); 
     22  fsManual << "FAT"  << "EXFAT" << "NTFS" << "EXT" << "EXT4" << "CD9660" << "UFS" << "REISERFS" << "XFS"; 
     23  //fsCMD: %1 becomes device path, %2 becomes mointpoint path 
     24  fsCMD << "mount -t msdosfs -o large,longnames,-m=755,-L="+QString(getenv("LANG"))+" %1 %2"; //FAT 
     25  fsCMD << "mount.exfat-fuse %1 %2"; //EXFAT 
     26  fsCMD << "ntfs-3g %1 %2"; //NTFS 
     27  fsCMD << "mount -t ext2fs %1 %2"; //EXT 
     28  fsCMD << "ext4fuse %1 %2"; //EXT4 
     29  fsCMD << "mount -t cd9660 %1 %2"; //CD9660 
     30  fsCMD << "mount -t ufs %1 %2"; //UFS 
     31  fsCMD << "mount -t reiserfs %1 %2"; //REISERFS 
     32  fsCMD << "mount -t xfs %1 %2"; //XFS 
     33  fsBinCheck << "/sbin/mount_msdosfs" << "/usr/local/bin/mount.exfat-fuse" << "/usr/local/bin/ntfs-3g" << "/sbin/mount" \ 
     34                << "/usr/local/bin/ext4fuse" << "/sbin/mount_cd9660" << "/sbin/mount" << "/sbin/mount" << "/sbin/mount"; 
    1935  //Initialize the device directory 
    2036  devDir = QDir(DEVICEDIR); 
     
    143159      if( devChildren(node).length() > 0 ){ hasPartitions = TRUE; } 
    144160    //} 
    145     if( !tmp.filter("last mounted on /").isEmpty() && (detType == "SATA")){ 
     161    //if( !tmp.filter("last mounted on /").isEmpty() && (detType == "SATA")){ 
     162    if( !tmp.filter("active").isEmpty() ){ //currently running partition/device 
    146163      isMounted = TRUE; 
    147164    } 
     
    171188  QString dlabel; 
    172189  if(isCD){ 
    173     if( !output.contains("ERROR:") ){ 
     190    if(!output.contains("ERROR:") && (output.section(":",1,1).simplified() != "data") ){ 
    174191      dlabel = output.section("'",-2).remove("'").simplified(); 
    175192      if(dlabel.contains("(")){ dlabel = dlabel.left(dlabel.indexOf("(")+1).trimmed();} 
     
    231248  //Allow devices that match 2 of the 3 criteria 
    232249  else if( hasFS && oksize ){ good = TRUE; } //This will catch most good devices 
    233   else if( hasLabel && oksize ){ good = TRUE; } //allow unknown filesystems if there is a good size reading 
    234250  else if( hasFS && hasLabel ){ good = TRUE; } // allow device if it has a known label and filesystem 
    235    
     251  else if( hasLabel || oksize ){ good = TRUE; } //allow unknown filesystems if there is a good size reading 
     252  else if( detType=="SD" ){ good = TRUE; } //SD cards do not show that much info 
    236253  //Now setup the outputs as appropriate 
    237254  maxsize->append( QString::number(kb) ); 
     
    246263} 
    247264 
     265QStringList DevCheck::AvailableFS(){ 
     266  QStringList avail; 
     267  for(int i=0; i<fsBinCheck.length(); i++){ 
     268    if( QFile::exists(fsBinCheck[i]) ){ avail << fsManual[i]; } 
     269  } 
     270  return avail; 
     271} 
     272 
     273QString DevCheck::getMountCommand(QString FS, QString dev, QString mntpoint){ 
     274  QString CMD = "mount_auto "+dev+" "+mntpoint; 
     275  int index = fsManual.indexOf(FS); 
     276  if(index != -1){ 
     277    CMD = fsCMD[index].arg(dev, mntpoint); 
     278  }else{ 
     279    qDebug() << "Using mount_auto: " << dev <<mntpoint; 
     280  } 
     281  return CMD; 
     282} 
     283 
    248284/* 
    249285  PRIVATE FUNCTIONS 
  • src-qt4/pc-mounttray/devCheck.h

    r1620346 r38951fa  
    2828        QString devLabel(QString, QString); 
    2929        bool devInfo(QString, QString*, QString*, QString*, QString*); 
    30          
     30         
     31        QStringList AvailableFS(); 
     32        QString getMountCommand(QString FS, QString dev, QString mntpoint); 
     33   
    3134  private: 
    3235        QStringList validDevs, validDevTypes, devFilter; 
    3336        QStringList fsDetection, fsMatch, fsFilter; 
     37        QStringList fsManual, fsCMD, fsBinCheck; 
    3438        QDir devDir; 
    3539 
  • src-qt4/pc-mounttray/menuItem.cpp

    r2532cb94 r38951fa  
    33 
    44 
    5 MenuItem::MenuItem(QWidget* parent, QString newdevice, QString newlabel, QString newtype, QString newfs) : QWidgetAction(parent) 
     5MenuItem::MenuItem(QWidget* parent, DevCheck *chk, QString newdevice, QString newlabel, QString newtype, QString newfs) : QWidgetAction(parent) 
    66{ 
    77  AMFILE= QDir::homePath() + "/.pc-automounttray";   //File to save/load all the devices to be automounted 
     
    1111  devType = newtype; 
    1212  filesystem = newfs; 
     13  DEVCHECK = chk; 
    1314  //currentUser = user; 
    1415  mountedHere = false; //not mounted by this app (yet) 
     
    5051  else if(devType == "SD"){ baseicon = QPixmap(":icons/sdcard.png"); } 
    5152  else if(devType == "CD9660"){ baseicon = QPixmap(":icons/dvd.png"); } 
    52   else if(devType == "ISO"){baseicon = QPixmap(":icons/dvd.png"); } 
     53  else if(devType == "ISO"){baseicon = QPixmap(":icons/dvd.png"); rootRequired = true;} 
    5354  else if(devType == "SCSI"){baseicon = QPixmap(":icons/harddrive.png"); } 
    5455  devIcon->setPixmap(baseicon); 
     
    134135      rootRequired = !( mountpoint.startsWith(home) || mountpoint.startsWith(shorthome) ); 
    135136      //qDebug() << "Mountpoint directory in non-user directory:" << rootRequired << mountpoint << home; 
    136     } 
    137   }else if(devType=="ISO"){ 
    138     //Simple check for unmounted items 
    139     rootRequired = true; 
     137    }else if(mountedHere && devType == "ISO"){ 
     138      rootRequired = true; //Requires root to remove the MD device, not necessary to mount it though 
     139    } 
    140140  }else{ 
    141141    //Not mounted and passed known user device limitations 
     
    144144  //qDebug() << "Check for root:" << device << rootRequired; 
    145145  //Now update the icon 
    146     if(rootRequired){ 
     146    if(rootRequired && filesystem=="UNKNOWN"){ 
     147      //Add the root-overlay to the base icon 
     148      QPixmap tmp = baseicon; 
     149      QPixmap overlay1(":icons/root-overlay.png"); 
     150      QPixmap overlay2(":icons/question-overlay.png"); 
     151      QPainter paint(&tmp); 
     152            paint.drawPixmap(devIcon->width()-20, devIcon->height()-20, overlay1 ); //put it in the bottom-right corner 
     153            paint.drawPixmap(devIcon->width()-24,0, overlay2 ); //put it in the top-right corner 
     154      devIcon->setPixmap(tmp);       
     155    }else if(rootRequired){ 
    147156      //Add the root-overlay to the base icon 
    148157      QPixmap tmp = baseicon; 
     
    150159      QPainter paint(&tmp); 
    151160            paint.drawPixmap(devIcon->width()-20, devIcon->height()-20, overlay ); //put it in the bottom-right corner 
     161      devIcon->setPixmap(tmp); 
     162    }else if(filesystem=="UNKNOWN"){ 
     163      //Add the root-overlay to the base icon 
     164      QPixmap tmp = baseicon; 
     165      QPixmap overlay(":icons/question-overlay.png"); 
     166      QPainter paint(&tmp); 
     167           paint.drawPixmap(devIcon->width()-24,0, overlay ); //put it in the top-right corner 
    152168      devIcon->setPixmap(tmp); 
    153169    }else{ 
     
    237253 
    238254  //Create the fileystem specific command for mounting 
    239   QString fstype; 
    240   QString fsopts=""; 
    241   if( filesystem == "FAT" ){ fstype = "mount -t msdosfs"; fsopts = QString("-o large,longnames,-m=755,-L=")+QString(getenv("LANG")); } 
    242   else if(filesystem == "NTFS"){ fstype = "ntfs-3g"; } 
    243   else if(filesystem == "EXT"){ fstype = "mount -t ext2fs"; } 
    244   else if(filesystem == "CD9660"){ fstype = "mount -t cd9660"; } 
    245   else if(filesystem == "UFS"){ fstype = "mount -t ufs"; } 
    246   else if(filesystem == "REISERFS"){ fstype = "mount -t reiserfs"; } 
    247   else if(filesystem == "XFS"){ fstype = "mount -t xfs"; } 
    248   else{ 
    249     qDebug() << "Unknown device filesystem:" << device << filesystem << " attempting mount_auto command"; 
    250     fstype = "mount_auto"; 
    251     //QMessageBox::warning(this,tr("Unknown Device Filesystem"),tr("The filesystem on this device is unknown and cannot be mounted at this time") ); 
    252     //return FALSE; 
    253   } 
     255  QString tmpFileSystem; 
     256  QString cmd; 
     257  if(filesystem=="UNKNOWN"){ 
     258    //prompt for filesystem 
     259    bool selected = false; 
     260    tmpFileSystem = QInputDialog::getItem(0, deviceName+"("+devType+")", tr("Mount as:"), DEVCHECK->AvailableFS(), 0, false, &selected); 
     261    if( !selected || tmpFileSystem.isEmpty() ){ return; } //cancelled 
     262    //Now get the mount command 
     263    cmd = DEVCHECK->getMountCommand(tmpFileSystem, device, mntpoint); 
     264  }else{ 
     265    cmd = DEVCHECK->getMountCommand(filesystem, device, mntpoint); 
     266  } 
     267 
    254268  //Make sure the mntpoint is available 
    255269  QDir mpd(mntpoint); 
     
    260274  } 
    261275  //Prepare the mount command to run 
    262   QString cmd = fstype + " " +fsopts + " " + device + " " + mntpoint; 
     276  //QString cmd = fstype + " " +fsopts + " " + device + " " + mntpoint; 
    263277  qDebug() << "Mounting device" << device << "on" << mntpoint << "("<<filesystem<<")"; 
    264278  if(DEBUG_MODE){ qDebug() << " - command:" << cmd; } 
     
    287301  //Now parse the return code 
    288302  QString result, title; 
     303  mountedHere = true; //need to set this before running isMounted to update icons right 
    289304  ok = isMounted(); 
     305  mountedHere = ok; //now make sure it is the proper value 
    290306  if( ok ){ 
    291307        title = tr("Success"); 
     
    314330    emit itemMounted(mntpoint); 
    315331    mountpoint = mntpoint; 
    316     mountedHere = true; 
     332    if( !tmpFileSystem.isEmpty() ){ filesystem = tmpFileSystem; } //this one worked - use it in the future 
    317333  }else{ 
    318334    mountpoint.clear(); 
    319     mountedHere = false; 
    320335  } 
    321336  if( !checkAutomount->isChecked()  && !(title.isEmpty() && result.isEmpty()) ){ 
  • src-qt4/pc-mounttray/menuItem.h

    r2532cb94 r38951fa  
    1818#include <QPainter> 
    1919#include <QPixmap> 
     20#include <QInputDialog> 
     21 
     22#include "devCheck.h" 
    2023 
    2124extern bool DEBUG_MODE; 
     
    2932 
    3033  public: 
    31         MenuItem(QWidget* parent = 0, QString newdevice="", QString newlabel="", QString newtype="", QString newfs=""); 
     34        MenuItem(QWidget* parent = 0, DevCheck *chk = 0, QString newdevice="", QString newlabel="", QString newtype="", QString newfs=""); 
    3235        ~MenuItem(); 
    3336         
     
    6366        QCheckBox* checkAutomount; 
    6467        QPixmap baseicon; 
     68        DevCheck *DEVCHECK; 
    6569        bool mountedHere; //Whether this utility is the one that mounted the device 
    6670        bool rootRequired, oldroot; 
  • src-qt4/pc-mounttray/mountTray.cpp

    r2532cb94 r38951fa  
    139139  qDebug() << "Valid Device Connection:" << dev << type << label << filesys; 
    140140  //Create the menu item (will automount if necessary) 
    141   MenuItem *tmp = new MenuItem(this, dev, label, type, filesys); 
     141  MenuItem *tmp = new MenuItem(this, DCheck, dev, label, type, filesys); 
    142142  //connect the signals/slots 
    143143  connect(tmp, SIGNAL(itemMounted(QString)), this, SLOT(openMediaDir(QString)) ); 
  • src-qt4/pc-mounttray/pc-mounttray.qrc

    r2532cb94 r38951fa  
    1616    <file>icons/checkmark.png</file> 
    1717    <file>icons/root-overlay.png</file> 
     18    <file>icons/question-overlay.png</file> 
    1819  </qresource> 
    1920</RCC> 
Note: See TracChangeset for help on using the changeset viewer.