Changeset 2532cb9


Ignore:
Timestamp:
Mar 18, 2014 12:28:14 PM (5 weeks ago)
Author:
Ken Moore <ken@…>
Branches:
master
Children:
37c7d9a
Parents:
40cafc7
Message:

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)

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

Legend:

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

    r1620346 r2532cb9  
    1818QString DEVICEDIR; 
    1919QString MOUNTDIR; 
     20//QString ROOTMOUNTDIR; 
     21//QString USERNAME; 
    2022 
    2123int  main(int argc, char ** argv) 
     
    2426   QString id = QProcessEnvironment::systemEnvironment().toStringList().filter("LOGNAME=").join(" ").remove("LOGNAME=").simplified(); 
    2527   //qDebug() << id; 
    26     if( id != "root" ){ 
    27       qDebug() << "pc-mounttray requires root permissions for device management!"; 
    28       qDebug() << " - HINT: run 'sudo pc-mounttray' instead"; 
     28    if( id == "root" ){ 
     29      qDebug() << "pc-mounttray should not be started with root permissions"; 
    2930      exit(1); 
    30     } 
     31    }/*else{ 
     32      USERNAME = id; 
     33    }*/ 
    3134   //Check for "-v" flag for debugging 
    3235   QString flag = QString(argv[1]); 
     
    3639   //Now start the application 
    3740   DEVICEDIR = "/dev/"; 
    38    MOUNTDIR = "/media/"; 
     41   MOUNTDIR = QDir::homePath()+"/Media/"; 
     42   //ROOTMOUNTDIR = "/media/"; 
     43   if(!QFile::exists(MOUNTDIR)){ 
     44     QDir dir(MOUNTDIR); 
     45     bool ok = dir.mkpath(dir.absolutePath()); 
     46     if(!ok){ 
     47       qDebug() << "Error: Could not create the user media directory:" << MOUNTDIR; 
     48       qDebug() << " - No way to mount devices: exiting...."; 
     49       exit(1); 
     50     } 
     51   } 
    3952   QtSingleApplication a(argc, argv); 
    4053   if ( a.isRunning() ) 
  • src-qt4/pc-mounttray/menuItem.cpp

    r40cafc7 r2532cb9  
    33 
    44 
    5 MenuItem::MenuItem(QWidget* parent, QString newdevice, QString newlabel, QString newtype, QString newfs, QString user) : QWidgetAction(parent) 
     5MenuItem::MenuItem(QWidget* parent, 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   currentUser = user; 
     13  //currentUser = user; 
    1414  mountedHere = false; //not mounted by this app (yet) 
     15  rootRequired = false; //assume user device for the moment 
    1516  //Create the layout 
    1617  QGridLayout* layout = new QGridLayout(); 
     
    4546 
    4647  //Setup the device Icon based on the type 
    47   if(devType == "USB"){ devIcon->setPixmap(QPixmap(":icons/usb.png")); } 
    48   else if(devType == "SATA"){ devIcon->setPixmap(QPixmap(":icons/harddrive.png")); } 
    49   else if(devType == "SD"){ devIcon->setPixmap(QPixmap(":icons/sdcard.png")); } 
    50   else if(devType == "CD9660"){ devIcon->setPixmap(QPixmap(":icons/dvd.png")); } 
    51   else if(devType == "ISO"){devIcon->setPixmap(QPixmap(":icons/dvd.png")); } 
    52   else if(devType == "SCSI"){devIcon->setPixmap(QPixmap(":icons/harddrive.png")); } 
     48  if(devType == "USB"){ baseicon = QPixmap(":icons/usb.png"); } 
     49  else if(devType == "SATA"){ baseicon = QPixmap(":icons/harddrive.png"); } 
     50  else if(devType == "SD"){ baseicon = QPixmap(":icons/sdcard.png"); } 
     51  else if(devType == "CD9660"){ baseicon = QPixmap(":icons/dvd.png"); } 
     52  else if(devType == "ISO"){baseicon = QPixmap(":icons/dvd.png"); } 
     53  else if(devType == "SCSI"){baseicon = QPixmap(":icons/harddrive.png"); } 
     54  devIcon->setPixmap(baseicon); 
    5355  //Start the automount procedure if necessary 
    5456  if(checkAutomount->isChecked() || devType=="ISO"){ 
     
    123125    } 
    124126  } 
     127  //Set the rootRequired flag as appropriate 
     128  if(mounted){ 
     129    //Only check the mountpoint owner if not already flagged for root perms 
     130    if(!rootRequired && !mountedHere){  
     131      QString home = QDir::homePath(); 
     132      QString shorthome = home; shorthome.replace("/usr/home/", "/home/"); 
     133      //Check if the mountpoint is in the current user's home directory 
     134      rootRequired = !( mountpoint.startsWith(home) || mountpoint.startsWith(shorthome) ); 
     135      //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; 
     140  }else{ 
     141    //Not mounted and passed known user device limitations 
     142    rootRequired = false; 
     143  } 
     144  //qDebug() << "Check for root:" << device << rootRequired; 
     145  //Now update the icon 
     146    if(rootRequired){ 
     147      //Add the root-overlay to the base icon 
     148      QPixmap tmp = baseicon; 
     149      QPixmap overlay(":icons/root-overlay.png"); 
     150      QPainter paint(&tmp); 
     151            paint.drawPixmap(devIcon->width()-20, devIcon->height()-20, overlay ); //put it in the bottom-right corner 
     152      devIcon->setPixmap(tmp); 
     153    }else{ 
     154      devIcon->setPixmap(baseicon); //base icon w/ no overlay 
     155    } 
     156 
    125157  return mounted; 
    126158} 
     
    132164  }else{ 
    133165    //Just check for mountpoint removal 
    134     if(QFile::exists(mountpoint)){ 
     166    if(QFile::exists(mountpoint) && mountedHere){ 
    135167      qDebug() << "Removing old mountpoint:" << mountpoint; 
    136       QString output = pcbsd::Utils::runShellCommand("rmdir "+mountpoint).join(" "); 
     168      QString output = systemCMD("rmdir "+mountpoint).join(" "); 
    137169      if(!output.isEmpty()){ qDebug() << " -Error:" <<output; } 
    138170    } 
     
    143175*/ 
    144176void MenuItem::slotMountClicked(){ 
     177  //Hide the parent menu 
     178  emit itemWorking(); 
     179  //Now  
    145180  if( isConnected() ){ 
    146181    if( !isMounted() ){ 
     
    204239  QString fstype; 
    205240  QString fsopts=""; 
    206   if( filesystem == "FAT" ){ fstype = "mount -t msdosfs"; fsopts = QString("-o large,longnames,-m=644,-M=777,-L=")+QString(getenv("LANG")); } 
     241  if( filesystem == "FAT" ){ fstype = "mount -t msdosfs"; fsopts = QString("-o large,longnames,-m=755,-L=")+QString(getenv("LANG")); } 
    207242  else if(filesystem == "NTFS"){ fstype = "ntfs-3g"; } 
    208243  else if(filesystem == "EXT"){ fstype = "mount -t ext2fs"; } 
     
    219254  //Make sure the mntpoint is available 
    220255  QDir mpd(mntpoint); 
    221   if(mpd.exists()){ 
     256  if(mpd.exists() && !rootRequired){ 
    222257    //Remove the existing directory (will work only if it is empty) 
    223258    mpd.cdUp(); 
    224259    mpd.rmdir(mntpoint); 
    225260  } 
    226   //Prepare the commands to run 
    227   QString cmd1 = "mkdir " + mntpoint; 
    228   QString cmd2 = fstype + " " +fsopts + " " + device + " " + mntpoint; 
    229   //cmd2 = "su -m "+currentUser+" -c \""+cmd2+"\""; //add command to run as user 
    230   QString cmd3 = "chmod 755 " + mntpoint; //to set full user/root access 
    231   //QString cmd4 = "chown "+currentUser+":"+currentUser+" "+mntpoint; //make the current user the owner 
     261  //Prepare the mount command to run 
     262  QString cmd = fstype + " " +fsopts + " " + device + " " + mntpoint; 
    232263  qDebug() << "Mounting device" << device << "on" << mntpoint << "("<<filesystem<<")"; 
    233   if(DEBUG_MODE){ qDebug() << " - command:" << cmd2; } 
     264  if(DEBUG_MODE){ qDebug() << " - command:" << cmd; } 
     265  //Generate the run script 
     266  QString runscript = createRunScript( mntpoint, cmd); 
     267  //Now run the script  
     268  bool ok = !runscript.isEmpty(); 
     269  bool tryroot = false; 
     270  QStringList outL("ERROR:SCRIPT"); 
     271  //Run the mounting commands 
     272  if(ok && !rootRequired){ 
     273    outL.clear(); 
     274    outL = systemCMD(runscript); 
     275    //qDebug() << "Mount return code 1:" << outL; 
     276    //if it could not mount device with permissions issues - try as root 
     277    if( !outL.filter("Permission denied").isEmpty() || !outL.filter("not permitted").isEmpty() ){  
     278      qDebug() << " - Permissions issue, try as root"; 
     279      tryroot = true;  
     280    }  
     281  } 
     282  if( (ok && rootRequired) || tryroot ){ 
     283    outL.clear(); 
     284    outL = systemCMD("pc-su "+runscript); 
     285    //qDebug() << "Mount return code 2:" << outL; 
     286  } 
     287  //Now parse the return code 
     288  QString result, title; 
     289  ok = isMounted(); 
     290  if( ok ){ 
     291        title = tr("Success"); 
     292        result = QString( tr("%1 mounted at %2") ).arg(deviceName).arg(mntpoint); 
     293        if(tryroot){ rootRequired = true; } //flag this as requiring root for later 
     294  }else if( !outL.filter("ERROR:MOUNTPOINT").isEmpty() ){ 
     295        title = tr("Failure"); 
     296        result = QString( tr("Could not create mountpoint: %1") ).arg(mntpoint); 
     297  }else if( !outL.filter("ERROR:MOUNTING").isEmpty() ){ 
     298        title = tr("Failure"); 
     299        result = QString( tr("Could not mount device %1 on %2 (%3)") ).arg(deviceName, mntpoint, filesystem); 
     300  }else{ 
     301        QString tmp = outL.join(""); 
     302          tmp.remove("password:"); //pc-su sometimes outputs this 
     303        if(!tmp.simplified().isEmpty() || !(rootRequired || tryroot) ){ //check for pc-su cancellation 
     304          qDebug() << "General Error output:" << outL; 
     305          title = tr("General Error"); 
     306          result = tr("Could not create/run the device mounting script"); 
     307        } 
     308  } 
     309  qDebug() << "pc-mounttray: "<<title << result; 
     310  if(DEBUG_MODE){ qDebug() << " - output:" << outL; } 
    234311   
    235   bool ok = FALSE; 
    236   QString result, title; 
    237   //Run the mounting commands 
    238   QStringList output = pcbsd::Utils::runShellCommand(cmd1); 
    239   if( output.join(" ").simplified().isEmpty() ){ 
    240     //directory created, run the next commands 
    241     //system(cmd4.toUtf8()); //set directory ownershipt before mounting device 
    242     system(cmd3.toUtf8()); //set directory permissions 
    243     output = pcbsd::Utils::runShellCommand(cmd2); 
    244     if( output.join(" ").simplified().isEmpty() ){ 
    245       title = tr("Success"); 
    246       result = QString( tr("%1 mounted at %2") ).arg(deviceName).arg(mntpoint); 
    247       ok = TRUE; 
    248     }else{ 
    249       qDebug() << "pc-mounttray: Error mounting device:" << device; 
    250       qDebug() << " - Error message:" << output; 
    251       title = QString( tr("Error mounting %1 at %2") ).arg(deviceName).arg(mntpoint); 
    252       result =  output.join(" "); 
    253       //Remove the mount point just created 
    254       pcbsd::Utils::runShellCommand("rmdir "+mntpoint); 
    255     } 
    256   }else{ 
    257     qDebug() << "pc-mounttray: Error creating mountpoint:" << mntpoint; 
    258     qDebug() << " - Error message:" << output; 
    259     title = QString( tr("Error mounting %1") ).arg(deviceName); 
    260     result =  QString( tr("Could not create mount point at %1") ).arg(mntpoint); 
    261   } 
    262312  //Output the proper signals depending upon success 
    263313  if(ok){ 
     
    269319    mountedHere = false; 
    270320  } 
    271   if( !checkAutomount->isChecked() ){ 
     321  if( !checkAutomount->isChecked()  && !(title.isEmpty() && result.isEmpty()) ){ 
    272322    emit newMessage(title, result); //suppress the output message if it was automounted 
    273323  } 
     324  //Now remove the runscript 
     325  //if(ok)  //only for testing purposes 
     326    QFile::remove(runscript); 
    274327   
    275328} 
     
    285338    } 
    286339  } 
    287    
    288   //Unmount all the NULLFS mountpoints first (in case it has been mounted into a PBI container) 
    289   QStringList nullfs = systemCMD("mount").filter(mountpoint).filter("nullfs"); 
    290   bool ok= true; 
    291   for(int i=0; i<nullfs.length() && ok; i++){ 
    292     QString nfspoint = nullfs[i].section(" on ",1,10).section("(",0,0).simplified(); 
    293     ok = umount(force, nfspoint); 
    294   } 
    295   //If successful, also unmount the main mountpoint 
    296   if(ok){ 
    297     ok = umount(force, mountpoint); 
    298   } 
    299   //Make sure there are no spaces in the mounpoint path 
    300   //QString cmd1 = "umount \"" + mountpoint +"\""; 
    301   //if(force){ cmd1.replace("umount ","umount -f "); } 
    302   //QString cmd2 = "rmdir \"" + mountpoint +"\""; 
    303   //qDebug() << "Unmounting device from" << mountpoint; 
    304   //Run the commands 
    305   //QStringList output; 
     340  bool ok = umount(force, mountpoint); 
    306341  QString result, title; 
    307   /*bool ok = umount(force, mountpoint); 
    308   output = pcbsd::Utils::runShellCommand(cmd1); 
    309   if(output.join(" ").simplified().isEmpty()){ 
    310     //unmounting successful, remove the mount point directory 
    311     if(mountpoint != "/mnt" && mountpoint != "/media"){ //make sure not to remove base directories 
    312       output = pcbsd::Utils::runShellCommand(cmd2); 
    313     } 
    314     if(!output.join(" ").simplified().isEmpty()){ 
    315       qDebug() << "pc-mounttray: Error removing mountpoint:" << mountpoint; 
    316       qDebug() << " - Error message:" << output; 
    317     } 
    318     ok = TRUE;*/ 
    319342  if(ok){ 
    320343    title = QString( tr("%1 has been successfully unmounted.") ).arg(devLabel->text()); 
    321344    if(devType == "ISO"){ 
    322       result = tr("The ISO file has been completely detached from the system."); 
     345      result = tr("The ISO file has been detached from the system."); 
    323346    }else{ 
    324347      result = tr("It is now safe to remove the device"); 
    325348    } 
    326349  }else{ 
    327     if(!force){ 
    328       if(QMessageBox::Yes == QMessageBox::question(0,tr("Device Busy"), 
    329                  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."), 
    330                  QMessageBox::Yes | QMessageBox::No, QMessageBox::No) ){ 
    331         unmountItem(true); //force the unmount recursively 
    332         return; 
    333       } 
    334     } 
    335     //qDebug() << "pc-mounttray: Error unmounting mountpoint:" << mountpoint; 
    336     //qDebug() << " - Error message:" << output; 
    337     title = QString( tr("Error: %1 could not be unmounted") ).arg(devLabel->text()); 
    338     //result = output.join(" "); 
     350    title = QString( tr("Error: %1 was not unmounted") ).arg(devLabel->text()); 
    339351  } 
    340352  //emit the proper signals 
    341353  if(ok){ 
     354    qDebug() << " *Success*"; 
    342355    mountpoint.clear(); 
    343     if(devType=="ISO" && device.section("/",-1).startsWith("md") ){ 
    344       //Get the md number 
    345       QString num = device.section("/md",-1).simplified(); 
    346       //also remove the MD device from the system using "mdconfig" 
    347       qDebug() << "Detaching Memory Disk:" << num; 
    348       QString cmd = "mdconfig -d -u "+num; 
    349       system(cmd.toUtf8()); 
    350     } 
    351356    emit itemUnmounted(device); 
     357  }else{ 
     358    qDebug() << " *Failure*"; 
    352359  } 
    353360  emit newMessage(title, result); 
     
    425432} 
    426433 
     434QString MenuItem::createRunScript(QString mntpoint, QString mntcmd){ 
     435  //generate the run script filename 
     436  QString filename = QDir::homePath()+"/.mounttrayrunscript"; 
     437  if(QFile::exists(filename)){ 
     438    int i=2; 
     439    while(QFile::exists(filename+QString::number(i))){ i++; } 
     440    filename = filename+QString::number(i); 
     441  } 
     442  //Now generate the run script 
     443  QFile file(filename); 
     444  if( !file.open(QFile::WriteOnly | QFile::Text) ){ 
     445    return ""; //could not create run script 
     446  } 
     447  QTextStream out(&file); 
     448  out << "#!/bin/sh\n"; 
     449    //Create the mountpoint 
     450    out << "mkdir \""+mntpoint+"\"\n"; 
     451    out << "if [ $? -ne 0 ]; then\n  echo ERROR:MOUNTPOINT\n  exit 1\nfi\n"; 
     452    //Now set the mountpoint permissions 
     453    if(filesystem != "FAT"){ //FAT command sets permissions itself 
     454      out << "chmod 755 "+mntpoint+"\n"; 
     455      out << "if [ $? -ne 0 ]; then\n  echo ERROR:PERMS\nfi\n"; 
     456    } 
     457    //run the mount command 
     458    out << mntcmd + "\n"; 
     459    out << "if [ $? -ne 0 ]; then\n  rmdir "+mntpoint+"\n  echo ERROR:MOUNTING\n  exit 2\nfi\n"; 
     460   
     461  //Now exit with the success signal 
     462  out << "exit 0"; 
     463  file.close(); 
     464  QFile::setPermissions(filename, QFile::permissions(filename) | QFile::ExeOwner); //make it executable 
     465  return filename; 
     466} 
     467 
     468QString MenuItem::createRemoveScript(QString mntpoint, bool force){ 
     469 //generate the run script filename 
     470  QString filename = QDir::homePath()+"/.mounttrayrunscript"; 
     471  if(QFile::exists(filename)){ 
     472    int i=2; 
     473    while(QFile::exists(filename+QString::number(i))){ i++; } 
     474    filename = filename+QString::number(i); 
     475  } 
     476  //Now generate the run script 
     477  QFile file(filename); 
     478  if( !file.open(QFile::WriteOnly | QFile::Text) ){ 
     479    return ""; //could not create run script 
     480  } 
     481  QTextStream out(&file); 
     482  out << "#!/bin/sh\n"; 
     483     //Unmount all the NULLFS mountpoints first (in case it has been mounted into a PBI container) 
     484    QStringList nullfs = systemCMD("mount").filter(mntpoint).filter("nullfs"); 
     485    bool ok= true; 
     486    for(int i=0; i<nullfs.length() && ok; i++){ 
     487      QString nfspoint = nullfs[i].section(" on ",1,10).section("(",0,0).simplified(); 
     488      if(!force){ out << "umount \""+nfspoint+"\"\n"; } 
     489      else{        out << "umount -f \""+nfspoint+"\"\n"; } 
     490      out << "if [ $? -ne 0 ]; then\n  echo ERROR:UNMOUNT\n exit 1\nfi\n"; 
     491      qDebug() << " - will unmount nullfs point:" << nfspoint; 
     492    } 
     493    //Unmount the device 
     494    if(!force){ out << "umount \""+mntpoint+"\"\n";  } 
     495    else{        out << "umount -f \""+mntpoint+"\"\n";  } 
     496    out << "if [ $? -ne 0 ]; then\n  echo ERROR:UNMOUNT\n  exit 1\nfi\n"; 
     497    //Remove the mountpoint if appropriate 
     498    if(mountedHere){ 
     499      qDebug() << " - will remove mountpoint directory"; 
     500      out << "rmdir \""+mntpoint+ "\"\n"; 
     501      out << "if [ $? -ne 0 ]; then\n  echo ERROR:RMDIR\nfi\n"; 
     502    } 
     503    //If an MD device, also remove it 
     504    if(devType=="ISO" && device.section("/",-1).startsWith("md") && mountedHere ){ 
     505      //Get the md number 
     506      QString num = device.section("/md",-1).simplified(); 
     507      //also remove the MD device from the system using "mdconfig" 
     508      qDebug() << " - will detach memory disk #"<< num; 
     509      out << "mdconfig -d -u "+num+"\n"; 
     510      out << "if [ $? -ne 0 ]; then\n  echo ERROR:MDDETACH\nfi\n"; 
     511    } 
     512  //Now exit with the success signal 
     513  out << "exit 0"; 
     514  file.close(); 
     515  QFile::setPermissions(filename, QFile::permissions(filename) | QFile::ExeOwner); //make it executable 
     516  return filename; 
     517} 
     518 
    427519bool MenuItem::umount(bool force, QString mntpoint){ 
    428   QString cmd1 = "umount \"" + mntpoint +"\""; 
    429   if(force){ cmd1.replace("umount ","umount -f "); } 
    430   QString cmd2 = "rmdir \"" + mountpoint +"\""; 
    431520  qDebug() << "Unmounting device from" << mntpoint; 
     521  if(rootRequired){ qDebug() << " - prompt for root"; } 
     522  QString runscript = createRemoveScript(mntpoint, force); 
    432523  //Run the commands 
    433524  QStringList output; 
    434525  QString result, title; 
    435   bool ok = FALSE; 
    436   output = systemCMD(cmd1); 
    437   if(output.join(" ").simplified().isEmpty()){ 
    438     //unmounting successful, remove the mount point directory 
    439     if(mountpoint != "/mnt" && mountpoint != "/media" && mountedHere){ //make sure not to remove base directories 
    440       output = systemCMD(cmd2); 
    441     } 
    442     if(!output.join(" ").simplified().isEmpty()){ 
     526  bool ok = !runscript.isEmpty(); 
     527  if(ok && rootRequired){ output = systemCMD("pc-su "+runscript); } 
     528  else if(ok){ output = systemCMD(runscript); } 
     529  else{ return false; } //could not even create the runscript 
     530  //Check output 
     531  if(output.filter("ERROR:UNMOUNT").isEmpty() && !isMounted() ){ 
     532    //unmounting successful 
     533    if( !output.filter("ERROR:RMDIR").isEmpty() ){ 
    443534      qDebug() << "pc-mounttray: Error removing mountpoint:" << mountpoint; 
    444535      qDebug() << " - Error message:" << output; 
    445536    } 
    446     ok = TRUE; 
     537    if( !output.filter("ERROR:MDDETACH").isEmpty() ){ 
     538      qDebug() << "pc-mounttray: Error detaching MD device"; 
     539      qDebug() << " - Error message:" << output; 
     540    } 
     541    ok = true; 
    447542    mountedHere = false; //not mounted by this app anymore 
     543  }else if( !output.filter("Device busy").isEmpty() && !force){ 
     544    qDebug() << " - Device Busy"; 
     545    //Ask whether to force the removal 
     546    if(QMessageBox::Yes == QMessageBox::question(0,tr("Device Busy"), 
     547                 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."), 
     548                 QMessageBox::Yes | QMessageBox::No, QMessageBox::No) ){ 
     549        ok = umount(true, mntpoint); //force the unmount recursively 
     550    } 
    448551  }else{ 
    449552    qDebug() << "pc-mounttray: Error unmounting mountpoint:" << mountpoint; 
    450553    qDebug() << " - Error message:" << output; 
    451   } 
     554    ok = false; 
     555  } 
     556  if(DEBUG_MODE){ qDebug() << " - output:" << output; } 
     557  QFile::remove(runscript); 
     558   
    452559  return ok; 
    453560} 
  • src-qt4/pc-mounttray/menuItem.h

    r40cafc7 r2532cb9  
    1616#include <QLabel> 
    1717#include <QTimer> 
     18#include <QPainter> 
     19#include <QPixmap> 
    1820 
    1921extern bool DEBUG_MODE; 
    2022extern QString DEVICEDIR; 
    2123extern QString MOUNTDIR; 
     24//extern QString USERNAME; 
    2225 
    2326class MenuItem : public QWidgetAction 
     
    2629 
    2730  public: 
    28         MenuItem(QWidget* parent = 0, QString newdevice="", QString newlabel="", QString newtype="", QString newfs="", QString user=""); 
     31        MenuItem(QWidget* parent = 0, QString newdevice="", QString newlabel="", QString newtype="", QString newfs=""); 
    2932        ~MenuItem(); 
    3033         
     
    3639        QString currentSize; //number in KB saved as a QString 
    3740        QString AMFILE; 
    38         QString currentUser; //username of current user (for setting mount dir ownership) 
     41        //QString currentUser; //username of current user (for setting mount dir ownership) 
    3942         
    4043        //Setters 
     
    5962        QPushButton* pushMount; 
    6063        QCheckBox* checkAutomount; 
     64        QPixmap baseicon; 
    6165        bool mountedHere; //Whether this utility is the one that mounted the device 
     66        bool rootRequired, oldroot; 
    6267   
    6368        void unmountItem(bool force = false); 
     
    6671        bool checkSavedAutoMount(); 
    6772        QStringList systemCMD(QString); 
     73        QString createRunScript(QString mntpoint, QString mntcmd); 
     74        QString createRemoveScript(QString mntpoint, bool force); 
    6875   
    6976        bool umount(bool force, QString mntpoint); 
     
    8087        void itemRemoved(QString);      //device node 
    8188        void newMessage(QString, QString);      //message to be displayed 
     89        void itemWorking(); 
    8290 
    8391}; 
  • src-qt4/pc-mounttray/mountTray.cpp

    r9adce5d r2532cb9  
    2020  qDebug() << "pc-mounttray: starting up"; 
    2121  MTINIT=true; //set the flag that the mount tray is initializing; 
    22   getInitialUsername(); //try to detect the non-root user who is running the program with root permissions 
     22  //getInitialUsername(); //try to detect the non-root user who is running the program with root permissions 
    2323  getFileManager(); 
    2424     
     
    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, USERNAME); 
     141  MenuItem *tmp = new MenuItem(this, dev, label, type, filesys); 
    142142  //connect the signals/slots 
    143143  connect(tmp, SIGNAL(itemMounted(QString)), this, SLOT(openMediaDir(QString)) ); 
    144144  connect(tmp, SIGNAL(newMessage(QString,QString)), this, SLOT(slotDisplayPopup(QString,QString)) ); 
    145145  connect(tmp, SIGNAL(itemRemoved(QString)), this, SLOT(removeDevice(QString)) ); 
     146  connect(tmp, SIGNAL(itemWorking()), this, SLOT(slotCloseMenu()) ); 
    146147  deviceList << tmp; 
    147148  //Update the menu 
     
    257258} 
    258259 
    259 void MountTray::getInitialUsername(){ 
     260/*void MountTray::getInitialUsername(){ 
    260261  //Get the original user who started the tray app 
    261262  QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); 
     
    287288  USERNAME=username.simplified(); //set the global variable 
    288289  if(DEBUG_MODE){ qDebug() << "-User detected:" << USERNAME; } 
    289 } 
     290}*/ 
    290291 
    291292void MountTray::getFileManager(){ 
     
    315316  if(dir.isEmpty()){ dir = MOUNTDIR; } 
    316317  if(!dir.endsWith("/")){ dir.append("/"); } //make sure the filemanager knows it is a directory 
    317   //Make sure we can setup user permissions 
    318   if(USERNAME=="root"){ 
    319     qDebug() << "Cannot open filemanager with root permissions"; 
    320     return; 
    321   } 
    322   //Open the default file manager to the given directory as that user 
    323   qDebug() << "Opening the media directory with user permissions"; 
    324   QString cmd = "su -m "+USERNAME+" -c \""+FMCMD+" \'"+dir+"\' \""; 
     318  //Open the default file manager to the given directory 
     319  qDebug() << "Opening the media directory"; 
     320  QString cmd = FMCMD+" \""+dir+"\""; 
    325321  if(DEBUG_MODE){ qDebug() << " -cmd:" << cmd ; } 
    326   cmd.prepend("("); cmd.append(") &"); 
    327   system( cmd.toUtf8() ); 
     322  //cmd.prepend("("); cmd.append(") &"); 
     323  QProcess::startDetached(cmd); 
    328324} 
    329325 
     
    377373  while( QFile::exists("/dev/md"+QString::number(num)) ){ num++; } 
    378374  //add it to the device tree (will automatically get picked up by the device detection method) 
    379   QString cmd = "mdconfig -a -f "+file+" -u "+QString::number(num); 
    380   system(cmd.toUtf8()); 
     375  QString cmd = "pc-su mdconfig -a -f "+file+" -u "+QString::number(num); 
     376  QProcess::startDetached(cmd); 
    381377} 
    382378 
     
    390386void MountTray::slotDisplayPopup(QString title, QString msg, QString device){ 
    391387  popupSave = device; //so we know what to do when it is clicked 
    392   //Display a popup bubble with the given message for 3 seconds 
     388  //Display a popup bubble with the given message for 2 seconds 
    393389  trayIcon->contextMenu()->hide(); //close the menu list 
    394   trayIcon->showMessage(title, msg , QSystemTrayIcon::NoIcon,3000 ); 
     390  trayIcon->showMessage(title, msg , QSystemTrayIcon::NoIcon,2000 ); 
    395391} 
    396392 
     
    487483  file.close(); 
    488484} 
     485 
     486void MountTray::slotCloseMenu(){ 
     487  trayIcon->contextMenu()->hide(); 
     488} 
  • src-qt4/pc-mounttray/mountTray.h

    r74b4950 r2532cb9  
    5656  void slotOpenSettings(); 
    5757  void slotOpenISO(); 
     58  void slotCloseMenu(); 
    5859   
    5960private: 
    6061  DevCheck *DCheck; 
    61   QString USERNAME; 
     62  //QString USERNAME; 
    6263  QLocalSocket* devdProc; 
    6364  QTimer *devdTimer;   
     
    8384  bool addDevice(QString,QString,QString,QString); 
    8485  void startupDevdProc(); 
    85   void getInitialUsername(); 
     86  //void getInitialUsername(); 
    8687  void getFileManager(); 
    8788  void loadSavedSettings(); 
  • src-qt4/pc-mounttray/pc-mounttray.qrc

    r891636a r2532cb9  
    1515    <file>icons/config.png</file> 
    1616    <file>icons/checkmark.png</file> 
     17    <file>icons/root-overlay.png</file> 
    1718  </qresource> 
    1819</RCC> 
Note: See TracChangeset for help on using the changeset viewer.