Permalink
Browse files

Large update to pc-mounttray:

1) Convert over to running with user permissions
2) All devices will now be mounted in the ~/Media directory (it gets created as necessary when the application starts up)
3) If a device gets a permissions error when mounting, it will immediately fall back to asking the user to mount the device as root with pc-su.
4) Once a device is flagged as requiring root permissions, it will update the icon with a little yellow shield in the corner for easy identification.

Currently tested with FAT, NTFS, UFS, and ISO/CD9660 filesystems.
Some new quirks:
1) The first FAT device to get mounted after system bootup will require root permissions, while subsequent FAT devices/mounts will only need user perms. This is because of a FreeBSD bug in mount_ntfs when the localization flag is used (-L=<mylocale>)
2) NTFS filesystems appear to always need root permissions to mount (have not explicitly flagged that filesystem for root yet until after additional testing)
  • Loading branch information...
1 parent 40cafc7 commit 2532cb94e1bec49a11aaf71d888f634155f82876 @beanpole135 beanpole135 committed Mar 18, 2014
View
BIN src-qt4/pc-mounttray/icons/root-overlay.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
23 src-qt4/pc-mounttray/main.cpp
@@ -17,25 +17,38 @@
bool DEBUG_MODE;
QString DEVICEDIR;
QString MOUNTDIR;
+//QString ROOTMOUNTDIR;
+//QString USERNAME;
int main(int argc, char ** argv)
{
//Check for root permissions
QString id = QProcessEnvironment::systemEnvironment().toStringList().filter("LOGNAME=").join(" ").remove("LOGNAME=").simplified();
//qDebug() << id;
- if( id != "root" ){
- qDebug() << "pc-mounttray requires root permissions for device management!";
- qDebug() << " - HINT: run 'sudo pc-mounttray' instead";
+ if( id == "root" ){
+ qDebug() << "pc-mounttray should not be started with root permissions";
exit(1);
- }
+ }/*else{
+ USERNAME = id;
+ }*/
//Check for "-v" flag for debugging
QString flag = QString(argv[1]);
if( flag == "-v" || flag == "-debug" ){ DEBUG_MODE=TRUE; }
else{ DEBUG_MODE=FALSE; }
//Now start the application
DEVICEDIR = "/dev/";
- MOUNTDIR = "/media/";
+ MOUNTDIR = QDir::homePath()+"/Media/";
+ //ROOTMOUNTDIR = "/media/";
+ if(!QFile::exists(MOUNTDIR)){
+ QDir dir(MOUNTDIR);
+ bool ok = dir.mkpath(dir.absolutePath());
+ if(!ok){
+ qDebug() << "Error: Could not create the user media directory:" << MOUNTDIR;
+ qDebug() << " - No way to mount devices: exiting....";
+ exit(1);
+ }
+ }
QtSingleApplication a(argc, argv);
if ( a.isRunning() )
return !(a.sendMessage("show"));
View
325 src-qt4/pc-mounttray/menuItem.cpp
@@ -2,16 +2,17 @@
#include "menuItem.h"
-MenuItem::MenuItem(QWidget* parent, QString newdevice, QString newlabel, QString newtype, QString newfs, QString user) : QWidgetAction(parent)
+MenuItem::MenuItem(QWidget* parent, 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;
- currentUser = user;
+ //currentUser = user;
mountedHere = false; //not mounted by this app (yet)
+ rootRequired = false; //assume user device for the moment
//Create the layout
QGridLayout* layout = new QGridLayout();
QHBoxLayout* hlayout = new QHBoxLayout();
@@ -44,12 +45,13 @@ MenuItem::MenuItem(QWidget* parent, QString newdevice, QString newlabel, QString
connect(checkAutomount,SIGNAL(toggled(bool)),this,SLOT(slotAutoMountToggled(bool)));
//Setup the device Icon based on the type
- if(devType == "USB"){ devIcon->setPixmap(QPixmap(":icons/usb.png")); }
- else if(devType == "SATA"){ devIcon->setPixmap(QPixmap(":icons/harddrive.png")); }
- else if(devType == "SD"){ devIcon->setPixmap(QPixmap(":icons/sdcard.png")); }
- else if(devType == "CD9660"){ devIcon->setPixmap(QPixmap(":icons/dvd.png")); }
- else if(devType == "ISO"){devIcon->setPixmap(QPixmap(":icons/dvd.png")); }
- else if(devType == "SCSI"){devIcon->setPixmap(QPixmap(":icons/harddrive.png")); }
+ if(devType == "USB"){ baseicon = QPixmap(":icons/usb.png"); }
+ 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 == "SCSI"){baseicon = QPixmap(":icons/harddrive.png"); }
+ devIcon->setPixmap(baseicon);
//Start the automount procedure if necessary
if(checkAutomount->isChecked() || devType=="ISO"){
QTimer::singleShot(500,this,SLOT( slotAutoMount() ));
@@ -122,6 +124,36 @@ bool MenuItem::isMounted(){
break;
}
}
+ //Set the rootRequired flag as appropriate
+ if(mounted){
+ //Only check the mountpoint owner if not already flagged for root perms
+ if(!rootRequired && !mountedHere){
+ QString home = QDir::homePath();
+ QString shorthome = home; shorthome.replace("/usr/home/", "/home/");
+ //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(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){
+ //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{
+ devIcon->setPixmap(baseicon); //base icon w/ no overlay
+ }
+
return mounted;
}
@@ -131,9 +163,9 @@ void MenuItem::cleanup(){
unmountItem(); //unmount and remove mountpoint
}else{
//Just check for mountpoint removal
- if(QFile::exists(mountpoint)){
+ if(QFile::exists(mountpoint) && mountedHere){
qDebug() << "Removing old mountpoint:" << mountpoint;
- QString output = pcbsd::Utils::runShellCommand("rmdir "+mountpoint).join(" ");
+ QString output = systemCMD("rmdir "+mountpoint).join(" ");
if(!output.isEmpty()){ qDebug() << " -Error:" <<output; }
}
}
@@ -142,6 +174,9 @@ void MenuItem::cleanup(){
PRIVATE FUNCTIONS
*/
void MenuItem::slotMountClicked(){
+ //Hide the parent menu
+ emit itemWorking();
+ //Now
if( isConnected() ){
if( !isMounted() ){
mountItem();
@@ -203,7 +238,7 @@ void MenuItem::mountItem(){
//Create the fileystem specific command for mounting
QString fstype;
QString fsopts="";
- if( filesystem == "FAT" ){ fstype = "mount -t msdosfs"; fsopts = QString("-o large,longnames,-m=644,-M=777,-L=")+QString(getenv("LANG")); }
+ 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"; }
@@ -218,47 +253,62 @@ void MenuItem::mountItem(){
}
//Make sure the mntpoint is available
QDir mpd(mntpoint);
- if(mpd.exists()){
+ if(mpd.exists() && !rootRequired){
//Remove the existing directory (will work only if it is empty)
mpd.cdUp();
mpd.rmdir(mntpoint);
}
- //Prepare the commands to run
- QString cmd1 = "mkdir " + mntpoint;
- QString cmd2 = fstype + " " +fsopts + " " + device + " " + mntpoint;
- //cmd2 = "su -m "+currentUser+" -c \""+cmd2+"\""; //add command to run as user
- QString cmd3 = "chmod 755 " + mntpoint; //to set full user/root access
- //QString cmd4 = "chown "+currentUser+":"+currentUser+" "+mntpoint; //make the current user the owner
+ //Prepare the mount command to run
+ QString cmd = fstype + " " +fsopts + " " + device + " " + mntpoint;
qDebug() << "Mounting device" << device << "on" << mntpoint << "("<<filesystem<<")";
- if(DEBUG_MODE){ qDebug() << " - command:" << cmd2; }
-
- bool ok = FALSE;
- QString result, title;
+ if(DEBUG_MODE){ qDebug() << " - command:" << cmd; }
+ //Generate the run script
+ QString runscript = createRunScript( mntpoint, cmd);
+ //Now run the script
+ bool ok = !runscript.isEmpty();
+ bool tryroot = false;
+ QStringList outL("ERROR:SCRIPT");
//Run the mounting commands
- QStringList output = pcbsd::Utils::runShellCommand(cmd1);
- if( output.join(" ").simplified().isEmpty() ){
- //directory created, run the next commands
- //system(cmd4.toUtf8()); //set directory ownershipt before mounting device
- system(cmd3.toUtf8()); //set directory permissions
- output = pcbsd::Utils::runShellCommand(cmd2);
- if( output.join(" ").simplified().isEmpty() ){
- title = tr("Success");
- result = QString( tr("%1 mounted at %2") ).arg(deviceName).arg(mntpoint);
- ok = TRUE;
- }else{
- qDebug() << "pc-mounttray: Error mounting device:" << device;
- qDebug() << " - Error message:" << output;
- title = QString( tr("Error mounting %1 at %2") ).arg(deviceName).arg(mntpoint);
- result = output.join(" ");
- //Remove the mount point just created
- pcbsd::Utils::runShellCommand("rmdir "+mntpoint);
- }
+ if(ok && !rootRequired){
+ outL.clear();
+ outL = systemCMD(runscript);
+ //qDebug() << "Mount return code 1:" << outL;
+ //if it could not mount device with permissions issues - try as root
+ if( !outL.filter("Permission denied").isEmpty() || !outL.filter("not permitted").isEmpty() ){
+ qDebug() << " - Permissions issue, try as root";
+ tryroot = true;
+ }
+ }
+ if( (ok && rootRequired) || tryroot ){
+ outL.clear();
+ outL = systemCMD("pc-su "+runscript);
+ //qDebug() << "Mount return code 2:" << outL;
+ }
+ //Now parse the return code
+ QString result, title;
+ ok = isMounted();
+ if( ok ){
+ title = tr("Success");
+ result = QString( tr("%1 mounted at %2") ).arg(deviceName).arg(mntpoint);
+ if(tryroot){ rootRequired = true; } //flag this as requiring root for later
+ }else if( !outL.filter("ERROR:MOUNTPOINT").isEmpty() ){
+ title = tr("Failure");
+ result = QString( tr("Could not create mountpoint: %1") ).arg(mntpoint);
+ }else if( !outL.filter("ERROR:MOUNTING").isEmpty() ){
+ title = tr("Failure");
+ result = QString( tr("Could not mount device %1 on %2 (%3)") ).arg(deviceName, mntpoint, filesystem);
}else{
- qDebug() << "pc-mounttray: Error creating mountpoint:" << mntpoint;
- qDebug() << " - Error message:" << output;
- title = QString( tr("Error mounting %1") ).arg(deviceName);
- result = QString( tr("Could not create mount point at %1") ).arg(mntpoint);
+ QString tmp = outL.join("");
+ tmp.remove("password:"); //pc-su sometimes outputs this
+ if(!tmp.simplified().isEmpty() || !(rootRequired || tryroot) ){ //check for pc-su cancellation
+ qDebug() << "General Error output:" << outL;
+ title = tr("General Error");
+ result = tr("Could not create/run the device mounting script");
+ }
}
+ qDebug() << "pc-mounttray: "<<title << result;
+ if(DEBUG_MODE){ qDebug() << " - output:" << outL; }
+
//Output the proper signals depending upon success
if(ok){
emit itemMounted(mntpoint);
@@ -268,9 +318,12 @@ void MenuItem::mountItem(){
mountpoint.clear();
mountedHere = false;
}
- if( !checkAutomount->isChecked() ){
+ if( !checkAutomount->isChecked() && !(title.isEmpty() && result.isEmpty()) ){
emit newMessage(title, result); //suppress the output message if it was automounted
}
+ //Now remove the runscript
+ //if(ok) //only for testing purposes
+ QFile::remove(runscript);
}
@@ -284,71 +337,25 @@ void MenuItem::unmountItem(bool force){
return;
}
}
-
- //Unmount all the NULLFS mountpoints first (in case it has been mounted into a PBI container)
- QStringList nullfs = systemCMD("mount").filter(mountpoint).filter("nullfs");
- bool ok= true;
- for(int i=0; i<nullfs.length() && ok; i++){
- QString nfspoint = nullfs[i].section(" on ",1,10).section("(",0,0).simplified();
- ok = umount(force, nfspoint);
- }
- //If successful, also unmount the main mountpoint
- if(ok){
- ok = umount(force, mountpoint);
- }
- //Make sure there are no spaces in the mounpoint path
- //QString cmd1 = "umount \"" + mountpoint +"\"";
- //if(force){ cmd1.replace("umount ","umount -f "); }
- //QString cmd2 = "rmdir \"" + mountpoint +"\"";
- //qDebug() << "Unmounting device from" << mountpoint;
- //Run the commands
- //QStringList output;
+ bool ok = umount(force, mountpoint);
QString result, title;
- /*bool ok = umount(force, mountpoint);
- output = pcbsd::Utils::runShellCommand(cmd1);
- if(output.join(" ").simplified().isEmpty()){
- //unmounting successful, remove the mount point directory
- if(mountpoint != "/mnt" && mountpoint != "/media"){ //make sure not to remove base directories
- output = pcbsd::Utils::runShellCommand(cmd2);
- }
- if(!output.join(" ").simplified().isEmpty()){
- qDebug() << "pc-mounttray: Error removing mountpoint:" << mountpoint;
- qDebug() << " - Error message:" << output;
- }
- ok = TRUE;*/
if(ok){
title = QString( tr("%1 has been successfully unmounted.") ).arg(devLabel->text());
if(devType == "ISO"){
- result = tr("The ISO file has been completely detached from the system.");
+ result = tr("The ISO file has been detached from the system.");
}else{
result = tr("It is now safe to remove the device");
}
}else{
- if(!force){
- if(QMessageBox::Yes == QMessageBox::question(0,tr("Device Busy"),
- tr("The device appears to be busy. Would you like to unmount it anyway?")+"\n\n"+tr("NOTE: This is generally not recommended unless you are sure that you don't have any applications using the device."),
- QMessageBox::Yes | QMessageBox::No, QMessageBox::No) ){
- unmountItem(true); //force the unmount recursively
- return;
- }
- }
- //qDebug() << "pc-mounttray: Error unmounting mountpoint:" << mountpoint;
- //qDebug() << " - Error message:" << output;
- title = QString( tr("Error: %1 could not be unmounted") ).arg(devLabel->text());
- //result = output.join(" ");
+ title = QString( tr("Error: %1 was not unmounted") ).arg(devLabel->text());
}
//emit the proper signals
if(ok){
+ qDebug() << " *Success*";
mountpoint.clear();
- if(devType=="ISO" && device.section("/",-1).startsWith("md") ){
- //Get the md number
- QString num = device.section("/md",-1).simplified();
- //also remove the MD device from the system using "mdconfig"
- qDebug() << "Detaching Memory Disk:" << num;
- QString cmd = "mdconfig -d -u "+num;
- system(cmd.toUtf8());
- }
emit itemUnmounted(device);
+ }else{
+ qDebug() << " *Failure*";
}
emit newMessage(title, result);
}
@@ -424,31 +431,131 @@ QStringList MenuItem::systemCMD(QString command){
return out;
}
+QString MenuItem::createRunScript(QString mntpoint, QString mntcmd){
+ //generate the run script filename
+ QString filename = QDir::homePath()+"/.mounttrayrunscript";
+ if(QFile::exists(filename)){
+ int i=2;
+ while(QFile::exists(filename+QString::number(i))){ i++; }
+ filename = filename+QString::number(i);
+ }
+ //Now generate the run script
+ QFile file(filename);
+ if( !file.open(QFile::WriteOnly | QFile::Text) ){
+ return ""; //could not create run script
+ }
+ QTextStream out(&file);
+ out << "#!/bin/sh\n";
+ //Create the mountpoint
+ out << "mkdir \""+mntpoint+"\"\n";
+ out << "if [ $? -ne 0 ]; then\n echo ERROR:MOUNTPOINT\n exit 1\nfi\n";
+ //Now set the mountpoint permissions
+ if(filesystem != "FAT"){ //FAT command sets permissions itself
+ out << "chmod 755 "+mntpoint+"\n";
+ out << "if [ $? -ne 0 ]; then\n echo ERROR:PERMS\nfi\n";
+ }
+ //run the mount command
+ out << mntcmd + "\n";
+ out << "if [ $? -ne 0 ]; then\n rmdir "+mntpoint+"\n echo ERROR:MOUNTING\n exit 2\nfi\n";
+
+ //Now exit with the success signal
+ out << "exit 0";
+ file.close();
+ QFile::setPermissions(filename, QFile::permissions(filename) | QFile::ExeOwner); //make it executable
+ return filename;
+}
+
+QString MenuItem::createRemoveScript(QString mntpoint, bool force){
+ //generate the run script filename
+ QString filename = QDir::homePath()+"/.mounttrayrunscript";
+ if(QFile::exists(filename)){
+ int i=2;
+ while(QFile::exists(filename+QString::number(i))){ i++; }
+ filename = filename+QString::number(i);
+ }
+ //Now generate the run script
+ QFile file(filename);
+ if( !file.open(QFile::WriteOnly | QFile::Text) ){
+ return ""; //could not create run script
+ }
+ QTextStream out(&file);
+ out << "#!/bin/sh\n";
+ //Unmount all the NULLFS mountpoints first (in case it has been mounted into a PBI container)
+ QStringList nullfs = systemCMD("mount").filter(mntpoint).filter("nullfs");
+ bool ok= true;
+ for(int i=0; i<nullfs.length() && ok; i++){
+ QString nfspoint = nullfs[i].section(" on ",1,10).section("(",0,0).simplified();
+ if(!force){ out << "umount \""+nfspoint+"\"\n"; }
+ else{ out << "umount -f \""+nfspoint+"\"\n"; }
+ out << "if [ $? -ne 0 ]; then\n echo ERROR:UNMOUNT\n exit 1\nfi\n";
+ qDebug() << " - will unmount nullfs point:" << nfspoint;
+ }
+ //Unmount the device
+ if(!force){ out << "umount \""+mntpoint+"\"\n"; }
+ else{ out << "umount -f \""+mntpoint+"\"\n"; }
+ out << "if [ $? -ne 0 ]; then\n echo ERROR:UNMOUNT\n exit 1\nfi\n";
+ //Remove the mountpoint if appropriate
+ if(mountedHere){
+ qDebug() << " - will remove mountpoint directory";
+ out << "rmdir \""+mntpoint+ "\"\n";
+ out << "if [ $? -ne 0 ]; then\n echo ERROR:RMDIR\nfi\n";
+ }
+ //If an MD device, also remove it
+ if(devType=="ISO" && device.section("/",-1).startsWith("md") && mountedHere ){
+ //Get the md number
+ QString num = device.section("/md",-1).simplified();
+ //also remove the MD device from the system using "mdconfig"
+ qDebug() << " - will detach memory disk #"<< num;
+ out << "mdconfig -d -u "+num+"\n";
+ out << "if [ $? -ne 0 ]; then\n echo ERROR:MDDETACH\nfi\n";
+ }
+ //Now exit with the success signal
+ out << "exit 0";
+ file.close();
+ QFile::setPermissions(filename, QFile::permissions(filename) | QFile::ExeOwner); //make it executable
+ return filename;
+}
+
bool MenuItem::umount(bool force, QString mntpoint){
- QString cmd1 = "umount \"" + mntpoint +"\"";
- if(force){ cmd1.replace("umount ","umount -f "); }
- QString cmd2 = "rmdir \"" + mountpoint +"\"";
qDebug() << "Unmounting device from" << mntpoint;
+ if(rootRequired){ qDebug() << " - prompt for root"; }
+ QString runscript = createRemoveScript(mntpoint, force);
//Run the commands
QStringList output;
QString result, title;
- bool ok = FALSE;
- output = systemCMD(cmd1);
- if(output.join(" ").simplified().isEmpty()){
- //unmounting successful, remove the mount point directory
- if(mountpoint != "/mnt" && mountpoint != "/media" && mountedHere){ //make sure not to remove base directories
- output = systemCMD(cmd2);
- }
- if(!output.join(" ").simplified().isEmpty()){
+ bool ok = !runscript.isEmpty();
+ if(ok && rootRequired){ output = systemCMD("pc-su "+runscript); }
+ else if(ok){ output = systemCMD(runscript); }
+ else{ return false; } //could not even create the runscript
+ //Check output
+ if(output.filter("ERROR:UNMOUNT").isEmpty() && !isMounted() ){
+ //unmounting successful
+ if( !output.filter("ERROR:RMDIR").isEmpty() ){
qDebug() << "pc-mounttray: Error removing mountpoint:" << mountpoint;
qDebug() << " - Error message:" << output;
}
- ok = TRUE;
+ if( !output.filter("ERROR:MDDETACH").isEmpty() ){
+ qDebug() << "pc-mounttray: Error detaching MD device";
+ qDebug() << " - Error message:" << output;
+ }
+ ok = true;
mountedHere = false; //not mounted by this app anymore
+ }else if( !output.filter("Device busy").isEmpty() && !force){
+ qDebug() << " - Device Busy";
+ //Ask whether to force the removal
+ if(QMessageBox::Yes == QMessageBox::question(0,tr("Device Busy"),
+ tr("The device appears to be busy. Would you like to unmount it anyway?")+"\n\n"+tr("NOTE: This is generally not recommended unless you are sure that you don't have any applications using the device."),
+ QMessageBox::Yes | QMessageBox::No, QMessageBox::No) ){
+ ok = umount(true, mntpoint); //force the unmount recursively
+ }
}else{
qDebug() << "pc-mounttray: Error unmounting mountpoint:" << mountpoint;
qDebug() << " - Error message:" << output;
+ ok = false;
}
+ if(DEBUG_MODE){ qDebug() << " - output:" << output; }
+ QFile::remove(runscript);
+
return ok;
}
View
12 src-qt4/pc-mounttray/menuItem.h
@@ -15,17 +15,20 @@
#include <QDebug>
#include <QLabel>
#include <QTimer>
+#include <QPainter>
+#include <QPixmap>
extern bool DEBUG_MODE;
extern QString DEVICEDIR;
extern QString MOUNTDIR;
+//extern QString USERNAME;
class MenuItem : public QWidgetAction
{
Q_OBJECT
public:
- MenuItem(QWidget* parent = 0, QString newdevice="", QString newlabel="", QString newtype="", QString newfs="", QString user="");
+ MenuItem(QWidget* parent = 0, QString newdevice="", QString newlabel="", QString newtype="", QString newfs="");
~MenuItem();
QString device;
@@ -35,7 +38,7 @@ class MenuItem : public QWidgetAction
QString maxSize; //number in KB saved as a QString
QString currentSize; //number in KB saved as a QString
QString AMFILE;
- QString currentUser; //username of current user (for setting mount dir ownership)
+ //QString currentUser; //username of current user (for setting mount dir ownership)
//Setters
void updateItem();
@@ -58,13 +61,17 @@ class MenuItem : public QWidgetAction
QProgressBar* currentSpace;
QPushButton* pushMount;
QCheckBox* checkAutomount;
+ QPixmap baseicon;
bool mountedHere; //Whether this utility is the one that mounted the device
+ bool rootRequired, oldroot;
void unmountItem(bool force = false);
void updateSizes();
QString getSizeDisplay(int);
bool checkSavedAutoMount();
QStringList systemCMD(QString);
+ QString createRunScript(QString mntpoint, QString mntcmd);
+ QString createRemoveScript(QString mntpoint, bool force);
bool umount(bool force, QString mntpoint);
@@ -79,6 +86,7 @@ class MenuItem : public QWidgetAction
void itemUnmounted(QString); //device node
void itemRemoved(QString); //device node
void newMessage(QString, QString); //message to be displayed
+ void itemWorking();
};
#endif
View
36 src-qt4/pc-mounttray/mountTray.cpp
@@ -19,7 +19,7 @@ void MountTray::programInit()
DCheck = new DevCheck(); //initialize class for checking devices
qDebug() << "pc-mounttray: starting up";
MTINIT=true; //set the flag that the mount tray is initializing;
- getInitialUsername(); //try to detect the non-root user who is running the program with root permissions
+ //getInitialUsername(); //try to detect the non-root user who is running the program with root permissions
getFileManager();
loadSavedSettings();
@@ -138,11 +138,12 @@ 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, USERNAME);
+ MenuItem *tmp = new MenuItem(this, 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)) );
connect(tmp, SIGNAL(itemRemoved(QString)), this, SLOT(removeDevice(QString)) );
+ connect(tmp, SIGNAL(itemWorking()), this, SLOT(slotCloseMenu()) );
deviceList << tmp;
//Update the menu
updateMenu();
@@ -256,7 +257,7 @@ void MountTray::closeTray(){
exit(0);
}
-void MountTray::getInitialUsername(){
+/*void MountTray::getInitialUsername(){
//Get the original user who started the tray app
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
//qDebug() << "System Environment:" << env.toStringList();
@@ -286,7 +287,7 @@ void MountTray::getInitialUsername(){
}
USERNAME=username.simplified(); //set the global variable
if(DEBUG_MODE){ qDebug() << "-User detected:" << USERNAME; }
-}
+}*/
void MountTray::getFileManager(){
//Check for broken DE's that need a FM manually set
@@ -314,17 +315,12 @@ void MountTray::openMediaDir(QString dir){
//Open the default file-manager to the directory listed
if(dir.isEmpty()){ dir = MOUNTDIR; }
if(!dir.endsWith("/")){ dir.append("/"); } //make sure the filemanager knows it is a directory
- //Make sure we can setup user permissions
- if(USERNAME=="root"){
- qDebug() << "Cannot open filemanager with root permissions";
- return;
- }
- //Open the default file manager to the given directory as that user
- qDebug() << "Opening the media directory with user permissions";
- QString cmd = "su -m "+USERNAME+" -c \""+FMCMD+" \'"+dir+"\' \"";
+ //Open the default file manager to the given directory
+ qDebug() << "Opening the media directory";
+ QString cmd = FMCMD+" \""+dir+"\"";
if(DEBUG_MODE){ qDebug() << " -cmd:" << cmd ; }
- cmd.prepend("("); cmd.append(") &");
- system( cmd.toUtf8() );
+ //cmd.prepend("("); cmd.append(") &");
+ QProcess::startDetached(cmd);
}
void MountTray::slotRescan(){
@@ -376,8 +372,8 @@ void MountTray::slotOpenISO(){
int num = 1;
while( QFile::exists("/dev/md"+QString::number(num)) ){ num++; }
//add it to the device tree (will automatically get picked up by the device detection method)
- QString cmd = "mdconfig -a -f "+file+" -u "+QString::number(num);
- system(cmd.toUtf8());
+ QString cmd = "pc-su mdconfig -a -f "+file+" -u "+QString::number(num);
+ QProcess::startDetached(cmd);
}
void MountTray::slotSingleInstance()
@@ -389,9 +385,9 @@ void MountTray::slotSingleInstance()
void MountTray::slotDisplayPopup(QString title, QString msg, QString device){
popupSave = device; //so we know what to do when it is clicked
- //Display a popup bubble with the given message for 3 seconds
+ //Display a popup bubble with the given message for 2 seconds
trayIcon->contextMenu()->hide(); //close the menu list
- trayIcon->showMessage(title, msg , QSystemTrayIcon::NoIcon,3000 );
+ trayIcon->showMessage(title, msg , QSystemTrayIcon::NoIcon,2000 );
}
void MountTray::slotDisplayWarning(QString title, QString msg){
@@ -486,3 +482,7 @@ void MountTray::saveCurrentSettings(){
//Now close the file
file.close();
}
+
+void MountTray::slotCloseMenu(){
+ trayIcon->contextMenu()->hide();
+}
View
5 src-qt4/pc-mounttray/mountTray.h
@@ -55,10 +55,11 @@ private slots:
void slotOpenFSDialog();
void slotOpenSettings();
void slotOpenISO();
+ void slotCloseMenu();
private:
DevCheck *DCheck;
- QString USERNAME;
+ //QString USERNAME;
QLocalSocket* devdProc;
QTimer *devdTimer;
int numMount, numAvail;
@@ -82,7 +83,7 @@ private slots:
int findDeviceInList(QString);
bool addDevice(QString,QString,QString,QString);
void startupDevdProc();
- void getInitialUsername();
+ //void getInitialUsername();
void getFileManager();
void loadSavedSettings();
void saveCurrentSettings();
View
1 src-qt4/pc-mounttray/pc-mounttray.qrc
@@ -14,5 +14,6 @@
<file>icons/refresh.png</file>
<file>icons/config.png</file>
<file>icons/checkmark.png</file>
+ <file>icons/root-overlay.png</file>
</qresource>
</RCC>

0 comments on commit 2532cb9

Please sign in to comment.