Permalink
Browse files

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.
  • Loading branch information...
1 parent 37c7d9a commit 38951fab780d1cfa8790e2461676fd83ba902767 Ken Moore committed Mar 19, 2014
View
46 src-qt4/pc-mounttray/devCheck.cpp
@@ -10,12 +10,28 @@ DevCheck::DevCheck(){
for(int i=0; i<validDevs.length(); i++){
devFilter << validDevs[i]+"*";
}
- //Initialize lists of filesystems and detection strings
+ //Initialize lists of filesystems and detection strings for automatic detection
fsDetection.clear();
fsMatch.clear();
+ fsFilter.clear();
fsDetection << "FAT" << "NTFS" << "EXT" << "ISO 9660" << "Unix Fast File system" << "Reiser" << "XFS"; //string to match for a particular filesystem
fsMatch << "FAT" << "NTFS" << "EXT" << "CD9660" << "UFS" << "REISERFS" << "XFS"; //internal labels for the filesystems
fsFilter << "fat" << "ntfs" << "ext" << "cdrom" << "ufs" << "reiser" << "xfs"; //label categories in /dev/
+ //Initialize lists of Manual Filesystems that might be available
+ fsManual.clear(); fsCMD.clear(); fsBinCheck.clear();
+ fsManual << "FAT" << "EXFAT" << "NTFS" << "EXT" << "EXT4" << "CD9660" << "UFS" << "REISERFS" << "XFS";
+ //fsCMD: %1 becomes device path, %2 becomes mointpoint path
+ fsCMD << "mount -t msdosfs -o large,longnames,-m=755,-L="+QString(getenv("LANG"))+" %1 %2"; //FAT
+ fsCMD << "mount.exfat-fuse %1 %2"; //EXFAT
+ fsCMD << "ntfs-3g %1 %2"; //NTFS
+ fsCMD << "mount -t ext2fs %1 %2"; //EXT
+ fsCMD << "ext4fuse %1 %2"; //EXT4
+ fsCMD << "mount -t cd9660 %1 %2"; //CD9660
+ fsCMD << "mount -t ufs %1 %2"; //UFS
+ fsCMD << "mount -t reiserfs %1 %2"; //REISERFS
+ fsCMD << "mount -t xfs %1 %2"; //XFS
+ fsBinCheck << "/sbin/mount_msdosfs" << "/usr/local/bin/mount.exfat-fuse" << "/usr/local/bin/ntfs-3g" << "/sbin/mount" \
+ << "/usr/local/bin/ext4fuse" << "/sbin/mount_cd9660" << "/sbin/mount" << "/sbin/mount" << "/sbin/mount";
//Initialize the device directory
devDir = QDir(DEVICEDIR);
}
@@ -142,7 +158,8 @@ bool DevCheck::devInfo(QString dev, QString* type, QString* label, QString* file
//Check for actual sub-devices (*s[#][a/b/c/....])
if( devChildren(node).length() > 0 ){ hasPartitions = TRUE; }
//}
- if( !tmp.filter("last mounted on /").isEmpty() && (detType == "SATA")){
+ //if( !tmp.filter("last mounted on /").isEmpty() && (detType == "SATA")){
+ if( !tmp.filter("active").isEmpty() ){ //currently running partition/device
isMounted = TRUE;
}
//Now try to get the size of the disk
@@ -170,7 +187,7 @@ bool DevCheck::devInfo(QString dev, QString* type, QString* label, QString* file
//First try to get the device label using the "file -s" output
QString dlabel;
if(isCD){
- if( !output.contains("ERROR:") ){
+ if(!output.contains("ERROR:") && (output.section(":",1,1).simplified() != "data") ){
dlabel = output.section("'",-2).remove("'").simplified();
if(dlabel.contains("(")){ dlabel = dlabel.left(dlabel.indexOf("(")+1).trimmed();}
}
@@ -230,9 +247,9 @@ bool DevCheck::devInfo(QString dev, QString* type, QString* label, QString* file
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
else if( hasFS && hasLabel ){ good = TRUE; } // allow device if it has a known label and filesystem
-
+ else if( hasLabel || oksize ){ good = TRUE; } //allow unknown filesystems if there is a good size reading
+ else if( detType=="SD" ){ good = TRUE; } //SD cards do not show that much info
//Now setup the outputs as appropriate
maxsize->append( QString::number(kb) );
label->append(dlabel);
@@ -245,6 +262,25 @@ bool DevCheck::devInfo(QString dev, QString* type, QString* label, QString* file
return good;
}
+QStringList DevCheck::AvailableFS(){
+ QStringList avail;
+ for(int i=0; i<fsBinCheck.length(); i++){
+ if( QFile::exists(fsBinCheck[i]) ){ avail << fsManual[i]; }
+ }
+ return avail;
+}
+
+QString DevCheck::getMountCommand(QString FS, QString dev, QString mntpoint){
+ QString CMD = "mount_auto "+dev+" "+mntpoint;
+ int index = fsManual.indexOf(FS);
+ if(index != -1){
+ CMD = fsCMD[index].arg(dev, mntpoint);
+ }else{
+ qDebug() << "Using mount_auto: " << dev <<mntpoint;
+ }
+ return CMD;
+}
+
/*
PRIVATE FUNCTIONS
*/
View
6 src-qt4/pc-mounttray/devCheck.h
@@ -27,10 +27,14 @@ class DevCheck
QStringList devChildren(QString);
QString devLabel(QString, QString);
bool devInfo(QString, QString*, QString*, QString*, QString*);
-
+
+ QStringList AvailableFS();
+ QString getMountCommand(QString FS, QString dev, QString mntpoint);
+
private:
QStringList validDevs, validDevTypes, devFilter;
QStringList fsDetection, fsMatch, fsFilter;
+ QStringList fsManual, fsCMD, fsBinCheck;
QDir devDir;
};
View
BIN src-qt4/pc-mounttray/icons/question-overlay.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
61 src-qt4/pc-mounttray/menuItem.cpp
@@ -2,14 +2,15 @@
#include "menuItem.h"
-MenuItem::MenuItem(QWidget* parent, QString newdevice, QString newlabel, QString newtype, QString newfs) : QWidgetAction(parent)
+MenuItem::MenuItem(QWidget* parent, DevCheck *chk, QString newdevice, QString newlabel, QString newtype, QString newfs) : QWidgetAction(parent)
{
AMFILE= QDir::homePath() + "/.pc-automounttray"; //File to save/load all the devices to be automounted
//Set the device info variables
if( !newdevice.startsWith(DEVICEDIR) ){ newdevice.prepend(DEVICEDIR); }
device = newdevice;
devType = newtype;
filesystem = newfs;
+ DEVCHECK = chk;
//currentUser = user;
mountedHere = false; //not mounted by this app (yet)
rootRequired = false; //assume user device for the moment
@@ -49,7 +50,7 @@ MenuItem::MenuItem(QWidget* parent, QString newdevice, QString newlabel, QString
else if(devType == "SATA"){ baseicon = QPixmap(":icons/harddrive.png"); }
else if(devType == "SD"){ baseicon = QPixmap(":icons/sdcard.png"); }
else if(devType == "CD9660"){ baseicon = QPixmap(":icons/dvd.png"); }
- else if(devType == "ISO"){baseicon = QPixmap(":icons/dvd.png"); }
+ else if(devType == "ISO"){baseicon = QPixmap(":icons/dvd.png"); rootRequired = true;}
else if(devType == "SCSI"){baseicon = QPixmap(":icons/harddrive.png"); }
devIcon->setPixmap(baseicon);
//Start the automount procedure if necessary
@@ -133,23 +134,38 @@ bool MenuItem::isMounted(){
//Check if the mountpoint is in the current user's home directory
rootRequired = !( mountpoint.startsWith(home) || mountpoint.startsWith(shorthome) );
//qDebug() << "Mountpoint directory in non-user directory:" << rootRequired << mountpoint << home;
+ }else if(mountedHere && devType == "ISO"){
+ rootRequired = true; //Requires root to remove the MD device, not necessary to mount it though
}
- }else if(devType=="ISO"){
- //Simple check for unmounted items
- rootRequired = true;
}else{
//Not mounted and passed known user device limitations
rootRequired = false;
}
//qDebug() << "Check for root:" << device << rootRequired;
//Now update the icon
- if(rootRequired){
+ if(rootRequired && filesystem=="UNKNOWN"){
+ //Add the root-overlay to the base icon
+ QPixmap tmp = baseicon;
+ QPixmap overlay1(":icons/root-overlay.png");
+ QPixmap overlay2(":icons/question-overlay.png");
+ QPainter paint(&tmp);
+ paint.drawPixmap(devIcon->width()-20, devIcon->height()-20, overlay1 ); //put it in the bottom-right corner
+ paint.drawPixmap(devIcon->width()-24,0, overlay2 ); //put it in the top-right corner
+ devIcon->setPixmap(tmp);
+ }else if(rootRequired){
//Add the root-overlay to the base icon
QPixmap tmp = baseicon;
QPixmap overlay(":icons/root-overlay.png");
QPainter paint(&tmp);
paint.drawPixmap(devIcon->width()-20, devIcon->height()-20, overlay ); //put it in the bottom-right corner
devIcon->setPixmap(tmp);
+ }else if(filesystem=="UNKNOWN"){
+ //Add the root-overlay to the base icon
+ QPixmap tmp = baseicon;
+ QPixmap overlay(":icons/question-overlay.png");
+ QPainter paint(&tmp);
+ paint.drawPixmap(devIcon->width()-24,0, overlay ); //put it in the top-right corner
+ devIcon->setPixmap(tmp);
}else{
devIcon->setPixmap(baseicon); //base icon w/ no overlay
}
@@ -236,21 +252,19 @@ void MenuItem::mountItem(){
QString mntpoint = MOUNTDIR + deviceName.replace(" ","-"); //take into account spaces in the name
//Create the fileystem specific command for mounting
- QString fstype;
- QString fsopts="";
- if( filesystem == "FAT" ){ fstype = "mount -t msdosfs"; fsopts = QString("-o large,longnames,-m=755,-L=")+QString(getenv("LANG")); }
- else if(filesystem == "NTFS"){ fstype = "ntfs-3g"; }
- else if(filesystem == "EXT"){ fstype = "mount -t ext2fs"; }
- else if(filesystem == "CD9660"){ fstype = "mount -t cd9660"; }
- else if(filesystem == "UFS"){ fstype = "mount -t ufs"; }
- else if(filesystem == "REISERFS"){ fstype = "mount -t reiserfs"; }
- else if(filesystem == "XFS"){ fstype = "mount -t xfs"; }
- else{
- qDebug() << "Unknown device filesystem:" << device << filesystem << " attempting mount_auto command";
- fstype = "mount_auto";
- //QMessageBox::warning(this,tr("Unknown Device Filesystem"),tr("The filesystem on this device is unknown and cannot be mounted at this time") );
- //return FALSE;
+ QString tmpFileSystem;
+ QString cmd;
+ if(filesystem=="UNKNOWN"){
+ //prompt for filesystem
+ bool selected = false;
+ tmpFileSystem = QInputDialog::getItem(0, deviceName+"("+devType+")", tr("Mount as:"), DEVCHECK->AvailableFS(), 0, false, &selected);
+ if( !selected || tmpFileSystem.isEmpty() ){ return; } //cancelled
+ //Now get the mount command
+ cmd = DEVCHECK->getMountCommand(tmpFileSystem, device, mntpoint);
+ }else{
+ cmd = DEVCHECK->getMountCommand(filesystem, device, mntpoint);
}
+
//Make sure the mntpoint is available
QDir mpd(mntpoint);
if(mpd.exists() && !rootRequired){
@@ -259,7 +273,7 @@ void MenuItem::mountItem(){
mpd.rmdir(mntpoint);
}
//Prepare the mount command to run
- QString cmd = fstype + " " +fsopts + " " + device + " " + mntpoint;
+ //QString cmd = fstype + " " +fsopts + " " + device + " " + mntpoint;
qDebug() << "Mounting device" << device << "on" << mntpoint << "("<<filesystem<<")";
if(DEBUG_MODE){ qDebug() << " - command:" << cmd; }
//Generate the run script
@@ -286,7 +300,9 @@ void MenuItem::mountItem(){
}
//Now parse the return code
QString result, title;
+ mountedHere = true; //need to set this before running isMounted to update icons right
ok = isMounted();
+ mountedHere = ok; //now make sure it is the proper value
if( ok ){
title = tr("Success");
result = QString( tr("%1 mounted at %2") ).arg(deviceName).arg(mntpoint);
@@ -313,10 +329,9 @@ void MenuItem::mountItem(){
if(ok){
emit itemMounted(mntpoint);
mountpoint = mntpoint;
- mountedHere = true;
+ if( !tmpFileSystem.isEmpty() ){ filesystem = tmpFileSystem; } //this one worked - use it in the future
}else{
mountpoint.clear();
- mountedHere = false;
}
if( !checkAutomount->isChecked() && !(title.isEmpty() && result.isEmpty()) ){
emit newMessage(title, result); //suppress the output message if it was automounted
View
6 src-qt4/pc-mounttray/menuItem.h
@@ -17,6 +17,9 @@
#include <QTimer>
#include <QPainter>
#include <QPixmap>
+#include <QInputDialog>
+
+#include "devCheck.h"
extern bool DEBUG_MODE;
extern QString DEVICEDIR;
@@ -28,7 +31,7 @@ class MenuItem : public QWidgetAction
Q_OBJECT
public:
- MenuItem(QWidget* parent = 0, QString newdevice="", QString newlabel="", QString newtype="", QString newfs="");
+ MenuItem(QWidget* parent = 0, DevCheck *chk = 0, QString newdevice="", QString newlabel="", QString newtype="", QString newfs="");
~MenuItem();
QString device;
@@ -62,6 +65,7 @@ class MenuItem : public QWidgetAction
QPushButton* pushMount;
QCheckBox* checkAutomount;
QPixmap baseicon;
+ DevCheck *DEVCHECK;
bool mountedHere; //Whether this utility is the one that mounted the device
bool rootRequired, oldroot;
View
2 src-qt4/pc-mounttray/mountTray.cpp
@@ -138,7 +138,7 @@ bool MountTray::addDevice(QString dev, QString label, QString type, QString file
qDebug() << "Valid Device Connection:" << dev << type << label << filesys;
//Create the menu item (will automount if necessary)
- MenuItem *tmp = new MenuItem(this, dev, label, type, filesys);
+ MenuItem *tmp = new MenuItem(this, DCheck, dev, label, type, filesys);
//connect the signals/slots
connect(tmp, SIGNAL(itemMounted(QString)), this, SLOT(openMediaDir(QString)) );
connect(tmp, SIGNAL(newMessage(QString,QString)), this, SLOT(slotDisplayPopup(QString,QString)) );
View
1 src-qt4/pc-mounttray/pc-mounttray.qrc
@@ -15,5 +15,6 @@
<file>icons/config.png</file>
<file>icons/checkmark.png</file>
<file>icons/root-overlay.png</file>
+ <file>icons/question-overlay.png</file>
</qresource>
</RCC>

0 comments on commit 38951fa

Please sign in to comment.