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

svn at pcbsd.org svn at pcbsd.org
Thu Mar 21 08:44:58 PDT 2013


Author: kenmoore
Date: 2013-03-21 15:44:58 +0000 (Thu, 21 Mar 2013)
New Revision: 21938

Modified:
   pcbsd/current/src-qt4/pc-mounttray/main.cpp
   pcbsd/current/src-qt4/pc-mounttray/menuItem.cpp
   pcbsd/current/src-qt4/pc-mounttray/menuItem.h
   pcbsd/current/src-qt4/pc-mounttray/mountTray.cpp
   pcbsd/current/src-qt4/pc-mounttray/mountTray.h
Log:
Temporary fix for the mount tray on the partition detection. Still working on a more permanent fix for the dtection routines.



Modified: pcbsd/current/src-qt4/pc-mounttray/main.cpp
===================================================================
--- pcbsd/current/src-qt4/pc-mounttray/main.cpp	2013-03-21 09:22:37 UTC (rev 21937)
+++ pcbsd/current/src-qt4/pc-mounttray/main.cpp	2013-03-21 15:44:58 UTC (rev 21938)
@@ -8,13 +8,34 @@
 #include <QApplication>
 #include <QMessageBox>
 #include <QtGui>
+#include <QProcessEnvironment>
 #include <qtsingleapplication.h>
 
 #include "mountTray.h"
 #include "../config.h"
 
+bool DEBUG_MODE;
+QString DEVICEDIR;
+QString MOUNTDIR;
+
 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";
+      exit(1);
+    }
+   //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/";
    QtSingleApplication a(argc, argv);
    if ( a.isRunning() )
      return !(a.sendMessage("show"));

Modified: pcbsd/current/src-qt4/pc-mounttray/menuItem.cpp
===================================================================
--- pcbsd/current/src-qt4/pc-mounttray/menuItem.cpp	2013-03-21 09:22:37 UTC (rev 21937)
+++ pcbsd/current/src-qt4/pc-mounttray/menuItem.cpp	2013-03-21 15:44:58 UTC (rev 21938)
@@ -1,9 +1,10 @@
 #include <pcbsd-utils.h>
 #include "menuItem.h"
 
+
 MenuItem::MenuItem(QWidget* parent, QString newdevice, QString label) : QWidgetAction(parent)
 {
-  MOUNTDIR="/media/";   //Set the direcectory to mount devices in
+  //MOUNTDIR="/media/";   //Set the direcectory to mount devices in
   AMFILE= QDir::homePath() + "/.pc-automounttray";   //File to save/load all the devices to be automounted
   //Set the device
   device = newdevice;
@@ -114,25 +115,25 @@
   //Clear the output variables
   type->clear(); label->clear(); filesystem->clear(); maxsize->clear();
   //make sure to use the absolute path
-  if(!dev.startsWith("/dev/")){ dev.prepend("/dev/"); }
+  if(!dev.startsWith(DEVICEDIR)){ dev.prepend(DEVICEDIR); }
   
   if(!QFile::symLinkTarget(dev).isEmpty()){ return; } //do not follow sym-links
   //Check for valid device types
   QStringList validdev, devtype;
-  validdev << "da" << "ad"    << "mmcsd" << "cd"         << "acd";
-  devtype << "USB"<<"SATA"<< "SD"        << "CD9660" << "CD9660";
+  validdev << "da" << "ad" << "mmcsd" << "cd"         << "acd";
+  devtype << "USB" << "SATA" << "SD"  << "CD9660" << "CD9660";
   QString node = dev.section("/",-1);
   QString detType;
-  QString sptype = node;
+  //QString sptype = node;
   for(int i=0; i<validdev.length(); i++){
     if(node.startsWith(validdev[i])){ 
 	detType = devtype[i]; 
-	sptype.remove(devtype[i]);
+	//sptype.remove(devtype[i]);
 	break; 
     }
   }
-  if(sptype.startsWith("s")){ sptype = "SLICE"; }
-  else{ sptype = "PARTITION"; }
+  //if(sptype.startsWith("s")){ sptype = "SLICE"; }
+  //else{ sptype = "PARTITION"; }
   
   //Make sure we quit before running commands on any invalid device nodes
   if(detType.isEmpty() || !QFile::exists(dev) ){return;}
@@ -150,13 +151,10 @@
   bool isMounted = FALSE;
   //qDebug() << "tmp:" << tmp;
   if( !tmp.filter("partition ").isEmpty() ){
-    QString pdev = dev;
-    if(sptype == "PARTITION"){ pdev += "s1"; }
-    else if( sptype == "SLICE"){ pdev += "a"; }
-    //if neither type, it will always register as having partitions
-    
-    //Find out if the partitions are available as seperate devices
-    if( QFile::exists(pdev)){ hasPartitions = TRUE; }
+    //Check for actual sub-devices (*s[#][a/b/c/....])
+    QDir devDir(DEVICEDIR);
+    QStringList subdevs = devDir.entryList(QStringList(node+"*"), QDir::NoDotAndDotDot | QDir::NoSymLinks | QDir::System, QDir::NoSort); 
+    if(subdevs.length() > 1){ hasPartitions = TRUE; } //the main device will always make it length 1
   }
   if( !tmp.filter("last mounted on /").isEmpty() ){
     isMounted = TRUE;
@@ -240,8 +238,8 @@
     label->append(dlabel);
     filesystem->append(filesys);
   }else{
-    qDebug() << "Ignoring Device:" << node << detType << dlabel << filesys << kb; 
-    qDebug() << " -Detected Flags:" << isMounted << hasPartitions << hasLabel << hasFS << oksize; 
+    qDebug() << "Invalid Device:" << node << detType << dlabel << filesys << kb; 
+    if(DEBUG_MODE){qDebug() << " -Detected Flags:" << isMounted << hasPartitions << hasLabel << hasFS << oksize;} 
   }
 
 }
@@ -324,7 +322,7 @@
   QString cmd2 = fstype + " " +fsopts + " " + device + " " + mntpoint;
   
   qDebug() << "Mounting device" << device << "on" << mntpoint << "("<<filesystem<<")";
-  qDebug() << " - command:" << cmd2;
+  if(DEBUG_MODE){ qDebug() << " - command:" << cmd2; }
   
   bool ok = FALSE;
   QString result, title;

Modified: pcbsd/current/src-qt4/pc-mounttray/menuItem.h
===================================================================
--- pcbsd/current/src-qt4/pc-mounttray/menuItem.h	2013-03-21 09:22:37 UTC (rev 21937)
+++ pcbsd/current/src-qt4/pc-mounttray/menuItem.h	2013-03-21 15:44:58 UTC (rev 21938)
@@ -16,6 +16,10 @@
 #include <QLabel>
 #include <QTimer>
 
+extern bool DEBUG_MODE;
+extern QString DEVICEDIR;
+extern QString MOUNTDIR;
+
 class MenuItem : public QWidgetAction
 {
 	Q_OBJECT
@@ -46,7 +50,7 @@
         
   private:
 	QWidget *frame;
-	QString MOUNTDIR;
+	//QString MOUNTDIR;
   	QLabel* devLabel;
   	QLabel* devIcon;
   	QProgressBar* currentSpace;

Modified: pcbsd/current/src-qt4/pc-mounttray/mountTray.cpp
===================================================================
--- pcbsd/current/src-qt4/pc-mounttray/mountTray.cpp	2013-03-21 09:22:37 UTC (rev 21937)
+++ pcbsd/current/src-qt4/pc-mounttray/mountTray.cpp	2013-03-21 15:44:58 UTC (rev 21938)
@@ -15,8 +15,8 @@
 void MountTray::programInit()
 {
   qDebug() << "pc-mounttray: starting up";
-  DEVICEDIR = "/dev/";  //Directory that new devices are discovered
-  MOUNTDIR = "/media/"; //Directory that all devices get mounted to
+  //DEVICEDIR = "/dev/";  //Directory that new devices are discovered
+  //MOUNTDIR = "/media/"; //Directory that all devices get mounted to
   getInitialUsername(); //try to detect the non-root user who is running the program with root permissions
   getDefaultFileManager(); //try to detect the default file-manager for opening the mount directory
 
@@ -183,7 +183,7 @@
       cdev.prepend("/dev/");
       if(type=="CREATE"){ 
         isAttached=TRUE;
-        qDebug() << "New device attached:" << cdev;
+        if(DEBUG_MODE){qDebug() << "New device attached:" << cdev;}
       }
       MenuItem::getDevInfo(cdev, &cdevtype, &dlab, &dfs, &dmax);
 	    
@@ -197,15 +197,11 @@
     //Perform action if a device is found
     if(deviceFound){
       if(isAttached){
-        qDebug() << "New valid device:" << dlab << cdev << cdevtype << dfs << dmax +" blocks";
-	if(dmax.toInt() > 60){     
-	   addDevice(cdev,dlab);  
-	   QString title = tr("New Device");
-	   QString message = QString( tr("%1 can now be accessed")).arg(dlab);
-	   slotDisplayPopup(title, message);
-	}else{ 
-	  qDebug() << " - Ignoring device (less than 60 blocks/sectors detected)";
-	}
+        qDebug() << "New valid device:" << dlab << cdev << cdevtype << dfs << dmax;
+	addDevice(cdev,dlab);  
+	QString title = tr("New Device");
+	QString message = QString( tr("%1 can now be accessed")).arg(dlab);
+	slotDisplayPopup(title, message);
       }else{
 	removeDevice(cdev);
         qDebug() << "Valid device removal detected:" <<  cdev;
@@ -251,7 +247,7 @@
     return;
   }
   USERNAME=username.simplified(); //set the global variable
-  qDebug() << "-User detected:" << USERNAME;
+  if(DEBUG_MODE){ qDebug() << "-User detected:" << USERNAME; }
 }
 
 void MountTray::getDefaultFileManager(){
@@ -263,7 +259,7 @@
   if( fmcmd.isEmpty() || fmcmd.contains("File ") ){fmcmd= "openwith"; } //Default to the "openwith" command
 
   FILEMAN = fmcmd.simplified();
-  qDebug() << "-File manager detected:" << FILEMAN;
+  if(DEBUG_MODE){ qDebug() << "-File manager detected:" << FILEMAN; }
 }
 
 void MountTray::slotOpenMediaDir(){

Modified: pcbsd/current/src-qt4/pc-mounttray/mountTray.h
===================================================================
--- pcbsd/current/src-qt4/pc-mounttray/mountTray.h	2013-03-21 09:22:37 UTC (rev 21937)
+++ pcbsd/current/src-qt4/pc-mounttray/mountTray.h	2013-03-21 15:44:58 UTC (rev 21938)
@@ -2,17 +2,23 @@
 #define MOUNT_TRAY_H
 
 // QT Includes
-#include <qpair.h>
+//#include <qpair.h>
 #include <QDialog>
 #include <QSystemTrayIcon>
 #include <QMenu>
 #include <QLocalSocket>
+#include <QString>
+#include <QPixmap>
 
 #include "menuItem.h"
 
-class QString;
-class QPixmap;
+extern bool DEBUG_MODE;
+extern QString DEVICEDIR;
+extern QString MOUNTDIR;
 
+//class QString;
+//class QPixmap;
+
 class MountTray : public QDialog {
    Q_OBJECT
    
@@ -37,7 +43,8 @@
   void slotRescan();
   
 private:
-  QString MOUNTDIR, DEVICEDIR, USERNAME, FILEMAN;
+  //QString MOUNTDIR, DEVICEDIR;
+  QString USERNAME, FILEMAN;
   QLocalSocket* devdProc;
   int numMount, numAvail;
   QSystemTrayIcon* trayIcon;



More information about the Commits mailing list