[PC-BSD Commits] r16468 - pcbsd-projects/pc-mounttray

svn at pcbsd.org svn at pcbsd.org
Thu Apr 19 12:31:23 PDT 2012


Author: kenmoore
Date: 2012-04-19 19:31:23 +0000 (Thu, 19 Apr 2012)
New Revision: 16468

Modified:
   pcbsd-projects/pc-mounttray/mountTray.cpp
   pcbsd-projects/pc-mounttray/mountTray.h
Log:
Add a lot more functionality to pc-mounttray. Now just need to add the autodetection and signals/slots



Modified: pcbsd-projects/pc-mounttray/mountTray.cpp
===================================================================
--- pcbsd-projects/pc-mounttray/mountTray.cpp	2012-04-19 17:22:34 UTC (rev 16467)
+++ pcbsd-projects/pc-mounttray/mountTray.cpp	2012-04-19 19:31:23 UTC (rev 16468)
@@ -46,22 +46,18 @@
   }else if(ident==1){
     //Device connected
     trayIcon->showMessage( tr("Device Connected"), tr("New device detected"), QSystemTrayIcon::NoIcon,3000 );
-    numAvail++;
     
   }else if(ident==2){
     //Device mounted
     trayIcon->showMessage( tr("Device Mounted"), tr("Device ")+"\""+device->text()+"\""+tr(" has been mounted at ")+"/media/"+device, QSystemTrayIcon::NoIcon,3000 );
-    numMount++;
     
   }else if(ident==3){
     //Device unmounted
     trayIcon->showMessage( tr("Device Unmounted"), tr("Device ")+"\""+device->text()+"\""+tr(" may now be safely removed"), QSystemTrayIcon::NoIcon,3000 );
-    numMount--;
     
   }else if(ident==4){
     //Device disconnected
     //DOn't show a message
-    numAvail--;
   
   }else{
     //Unknown identifier
@@ -82,33 +78,155 @@
   
 }
 
+QAction MountTray::newDeviceAction(QString deviceLocation){
+  //Turn a device location into a QAction for use in this program
+  
+  QAction newdev = new QAction(this);
+  newdev.setWhatsThis(deviceLocation);
+  newdev.setCheckable(TRUE);
+  
+  //ping the device to get the information
+  
+  //Device Name
+  qDebug() << "Device name detection needs to be written";
+  QString devname = "USB Device";
+  newdev.setText(devname);
+  
+  //Check if device is mounted
+  qDebug() << "Mount check code needs to be written";
+  newdev.setChecked(FALSE);
+  
+}
+
 bool MountTray::updateDeviceList(int act, QAction device){
-  //act: 0-  1-  2-  
+  //act: 0-verify device  1-add device  2-mount device 3-unmount device 4-remove device  
 
+  bool status = FALSE;
   if(act==0){
     //verify that device is still valid
+    if( isConnected(device) ){
+      status = TRUE;
+    }else{
+      updateDeviceList(4, device);
+    }
     
-  }else if(zct==1){
+  }else if(act==1){
     //Device connected (add new device entry)
-  
+    if( findDeviceInList(device) == -1 ){
+      device->setIcon( QIcon(":icons/USBgrey.png") );
+      device->setStatusTip(tr("Unmounted - May be removed"));
+      devList << device;
+      numAvail++;
+      status = TRUE;
+    }
+      
   }else if(act==2){
     //Mount device
+    if( mountDevice(device) ){
+      device->setChecked(TRUE);
+      device->setIcon( QIcon(":icons/USBred.png") );
+      device->setStatusTip( tr("Mounted")+" - /media/"+device->text() );
+      numMount++;
+      status = TRUE;
+    }
   
   }else if(act==3){
-    //Unmount device 
+    //Unmount device
+    if( unmountDevice(device) ){
+      device->setChecked(FALSE);
+      device->setIcon( QIcon(":icons/USBblue.png") );
+      device->setStatusTip(tr("Unmounted - May be removed"));
+      numMount--;
+      status = TRUE;
+    } 
     
   }else if(act==4){
     //Device disconnected
-  
+    int index = findDeviceInList(device);
+    if(index != -1){
+      devList.removeAt(index);
+      numAvail--;
+      status = TRUE;
+    }
+      
   }else{
     //Unknown identifier
     qDebug() << "pc-mounttray: unknown device update identifier";
-    return FALSE;
+  }
   
+  return status;
+}
+
+int MountTray::findDeviceInList(QAction device){
+  for(int i=0; i<devList.length(); i++){
+    if( devList[i]->whatsThis() == device->whatsThis() ){
+      return i;
+    }
   }
+  return -1;
+}
+
+bool MountTray::mountDevice(QAction devAct){
+  //Mount the device
+  bool status = FALSE;
   
+  QString dev = devAct->whatsThis();
+  QString mntpoint = "/media/" + devAct->text();
+  QString fstype = "msdosfs"; //make this dynamic later
+  
+  QString cmd1 = "mkdir " + mntpoint;
+  QString cmd2 = "mount -t " + fstype + " -o -m=644 " + dev + " " + mntpoint;
+  
+  //Run the mounting commands
+  QStringList output;
+  output = Utils::runShellCommandList(cmd1);
+  if( ouput.isEmpty() ){
+    //directory created, run the next command
+    output = Utils::runShellCommandList(cmd2);
+    if(output.isEmpty()){
+      //Mounted successfully
+      status = TRUE;
+    }else{
+      qDebug() << "pc-mounttray: Error mounting device:" << dev;
+      qDebug() << " - Error message:" << output;
+    }
+  }else{
+    qDebug() << "pc-mounttray: Error creating mountpoint:" << mntpoint;
+    qDebug() << " - Error message:" << output;
+  }
+  
+  return status;
 }
 
+bool MountTray::unmountDevice(QAction devAct){
+  //Unmount the device
+  bool status = FALSE;
+  QString mntpoint = "/media/" + devAct->text();
+  
+  QString cmd1 = "umount " + mntpoint;
+  QString cmd2 = "rmdir " + mntpoint;
+  
+  //Run the commands
+  QStringList output;
+  output = Utils::runShellCommandList(cmd1);
+  if(output.isEmpty()){
+    //unmounting successful, remove the mount point directory
+    output = Utils::runShellCommandList(cmd2);
+    if(output.isEmpty()){
+      //Directory removed
+      status = TRUE;
+    }else{
+      qDebug() << "pc-mounttray: Error removing mountpoint:" << mntpoint;
+      qDebug() << " - Error message:" << output;
+    }
+  }else{
+    qDebug() << "pc-mounttray: Error unmounting mountpoint:" << mntpoint;
+    qDebug() << " - Error message:" << output;
+  }
+    
+  return status;
+}
+
 bool MountTray::isMounted(QAction device){
   if(device->isChecked() ){
     return TRUE;
@@ -139,6 +257,9 @@
   
   //Scan for all the "umass" devices and add them to the device list
    qDebug() << "Still need to add USB device detection";
+   //Parse out the "dmesg | grep umass" command - does not find the device names though....
+   
+   
   
   //Add all the elements in the saved list to the menu
   for(int i=0; i<devList.length(); i++){
@@ -162,11 +283,11 @@
   QTimer::singleShot(600000,this,SLOT(refreshTray() )); //10 minute refresh timer
 }
 
-void MountTray::slotTrayActivated(QSystemTrayIcon::ActivationReason reason) {
-   if(reason == QSystemTrayIcon::Trigger) {
-       startBluetoothManager();
-   }
-}
+//void MountTray::slotTrayActivated(QSystemTrayIcon::ActivationReason reason) {
+  // if(reason == QSystemTrayIcon::Trigger) {
+    //   startBluetoothManager();
+   //}
+//}
 
 void MountTray::closeTray(){
   qDebug() << "pc-mounttray: closing down";

Modified: pcbsd-projects/pc-mounttray/mountTray.h
===================================================================
--- pcbsd-projects/pc-mounttray/mountTray.h	2012-04-19 17:22:34 UTC (rev 16467)
+++ pcbsd-projects/pc-mounttray/mountTray.h	2012-04-19 19:31:23 UTC (rev 16468)
@@ -36,5 +36,10 @@
   void showDeviceNotification(int, QAction);
   bool isMounted(QAction);
   bool isConnected(QAction);
+  bool updateDeviceList(int, QAction);
+  int findDeviceInList(QAction);
+  bool mountDevice(QAction);
+  bool unmountDevice(QAction);
+  QAction newDeviceAction(QString);
   
 };



More information about the Commits mailing list