Skip to content
This repository has been archived by the owner on Dec 4, 2020. It is now read-only.

Commit

Permalink
Merge branch 'master' of github.com:pcbsd/pcbsd
Browse files Browse the repository at this point in the history
  • Loading branch information
Kris Moore committed Aug 7, 2013
2 parents bf837d6 + 84cc3f1 commit 2d2d3cd
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 22 deletions.
25 changes: 15 additions & 10 deletions src-qt4/pc-mounttray/devCheck.cpp
Expand Up @@ -4,8 +4,8 @@

DevCheck::DevCheck(){
//Initialize the lists of valid device types
validDevs << "da" << "ad" << "mmcsd" << "cd" << "acd";
validDevTypes << "USB" << "SATA" << "SD" << "CD9660" << "CD9660";
validDevs << "da" << "ad" << "mmcsd" << "cd" << "acd" << "md";
validDevTypes << "USB" << "SATA" << "SD" << "CD9660" << "CD9660" << "ISO";
for(int i=0; i<validDevs.length(); i++){
devFilter << validDevs[i]+"*";
}
Expand All @@ -29,7 +29,7 @@ DevCheck::~DevCheck(){
bool DevCheck::isValid(QString node){
bool ok = FALSE;
for(int i=0; i<validDevs.length(); i++){
if(node.startsWith(validDevs[i])){
if(node.startsWith(validDevs[i]) && node!="mdctl"){
ok = TRUE;
break;
}
Expand Down Expand Up @@ -96,7 +96,7 @@ bool DevCheck::devInfo(QString dev, QString* type, QString* label, QString* file
//Double check for valid device types (just in case)
QString detType;
for(int i=0; i<validDevs.length(); i++){
if(node.startsWith(validDevs[i])){
if(node.startsWith(validDevs[i]) && node != "mdctl"){
detType = validDevTypes[i];
break;
}
Expand All @@ -106,7 +106,7 @@ bool DevCheck::devInfo(QString dev, QString* type, QString* label, QString* file
if(detType.isEmpty() || !QFile::exists(fullDev) ){return FALSE;}
else{type->append(detType);}
bool isCD=FALSE;
if(detType == "CD9660"){ isCD=TRUE; }
if(detType == "CD9660" || detType == "ISO"){ isCD=TRUE; }

//Read the Device Info using "file -s <device>"
QString cmd = "file -s "+fullDev;
Expand Down Expand Up @@ -153,9 +153,7 @@ bool DevCheck::devInfo(QString dev, QString* type, QString* label, QString* file
if(isCD){
if( !output.contains("ERROR:") ){
dlabel = output.section("'",-2).remove("'").simplified();
//qDebug() << dlabel;
//while( dlabel.endsWith(" ") || dlabel.endsWith("\n") ){ dlabel.chop(1); }
//qDebug() << dlabel;
if(dlabel.contains("(")){ dlabel = dlabel.left(dlabel.indexOf("(")+1).trimmed();}
}
}else{
dlabel = output.section("label: \"",1,1).section("\"",0,0).simplified(); //device name
Expand Down Expand Up @@ -189,12 +187,19 @@ bool DevCheck::devInfo(QString dev, QString* type, QString* label, QString* file
else{
//Assign a device label
if(isCD){
dlabel = "Optical_Disk";
if(detType == "ISO"){
dlabel = "ISO_File";
}else{
dlabel = "Optical_Disk";
}
}else{
dlabel = detType+"-Device"; //this is not a "detected" label
}
}

//make sure that a device label does not contain "(" or ")"
if(dlabel.contains("(")){ dlabel.remove("(").simplified(); }
if(dlabel.contains(")")){ dlabel.remove(")").simplified(); }
dlabel = dlabel.simplified();
//Now perform the final checks to see if it is a good device
bool good = FALSE;
if( isMounted ){}//Always ignore this device (local FreeBSD installation that is being used)
Expand Down
2 changes: 1 addition & 1 deletion src-qt4/pc-mounttray/fsWatcher.cpp
Expand Up @@ -54,7 +54,7 @@ QStringList FSWatcher::getFSmountpoints(){
//Now parse out the info
dfout[i].replace("\t"," ");
QString fs = dfout[i].section(" ",1,1,QString::SectionSkipEmpty).simplified();
if(fs != "zfs"){ //ignore zfs filesystems (already taken care of)
if(fs != "zfs" && fs!="cd9660"){ //ignore zfs filesystems (already taken care of)
QString name = dfout[i].section(" ",6,6,QString::SectionSkipEmpty).simplified();
QString total = dfout[i].section(" ",2,2,QString::SectionSkipEmpty).simplified();
QString used = dfout[i].section(" ",3,3,QString::SectionSkipEmpty).simplified();
Expand Down
30 changes: 19 additions & 11 deletions src-qt4/pc-mounttray/menuItem.cpp
Expand Up @@ -46,9 +46,10 @@ MenuItem::MenuItem(QWidget* parent, QString newdevice, QString newlabel, QString
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")); }
if(devType == "CD9660"){ devIcon->setPixmap(QPixmap(":icons/dvd.png")); }
else if(devType == "CD9660"){ devIcon->setPixmap(QPixmap(":icons/dvd.png")); }
else if(devType == "ISO"){devIcon->setPixmap(QPixmap(":icons/dvd.png")); }
//Start the automount procedure if necessary
if(checkAutomount->isChecked()){
if(checkAutomount->isChecked() || devType=="ISO"){
QTimer::singleShot(500,this,SLOT( slotMountClicked() ));
}
//Update the Item based upon current device status
Expand Down Expand Up @@ -76,7 +77,8 @@ void MenuItem::updateItem(){
devIcon->setToolTip(device+"\n"+QString(tr("Mounted at %1")).arg(mountpoint));
pushMount->setText(tr("Eject"));
pushMount->setIcon(QIcon(":icons/eject.png"));
checkAutomount->setVisible(TRUE);
if(devType != "ISO"){ checkAutomount->setVisible(TRUE); }
else{ checkAutomount->setVisible(FALSE); }
}else{
devIcon->setEnabled(FALSE); //Grey out the icon if not mounted
devIcon->setToolTip(device);
Expand Down Expand Up @@ -116,12 +118,6 @@ bool MenuItem::isMounted(){
}
}
return mounted;
/*
QString chk = pcbsd::Utils::runShellCommandSearch("mount",device);
if(chk.isEmpty() ){ chk = pcbsd::Utils::runShellCommandSearch("mount",devLabel->text().replace(" ","-")); }
if(chk.isEmpty() ){ return FALSE; }
else{ return TRUE; }
*/
}

//Cleanup function
Expand Down Expand Up @@ -285,7 +281,11 @@ void MenuItem::unmountItem(){
}
ok = TRUE;
title = QString( tr("%1 has been successfully unmounted.") ).arg(devLabel->text());
result = tr("It is now safe to remove the device");
if(devType == "ISO"){
result = tr("The ISO file has been completely detached from the system.");
}else{
result = tr("It is now safe to remove the device");
}
}else{
qDebug() << "pc-mounttray: Error unmounting mountpoint:" << mountpoint;
qDebug() << " - Error message:" << output;
Expand All @@ -294,8 +294,16 @@ void MenuItem::unmountItem(){
}
//emit the proper signals
if(ok){
emit itemUnmounted(device);
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);
}
emit newMessage(title, result);
}
Expand Down
13 changes: 13 additions & 0 deletions src-qt4/pc-mounttray/mountTray.cpp
Expand Up @@ -33,6 +33,7 @@ void MountTray::programInit()
sysMenu->addAction( QIcon(":icons/refresh.png"),tr("Rescan Devices"), this, SLOT(slotRescan()) );
//Add the setting dialog option seperately
sysMenu->addSeparator();
sysMenu->addAction( QIcon(":icons/dvd.png"), tr("Load ISO File"), this, SLOT(slotOpenISO()) );
sysMenu->addAction( QIcon(":icons/config.png"), tr("Change Settings"), this, SLOT(slotOpenSettings()) );
//Add the Close button seperately
sysMenu->addSeparator();
Expand Down Expand Up @@ -356,6 +357,18 @@ void MountTray::slotOpenSettings(){
if(useDiskWatcher){ diskWatcher->start(diskTimerMaxMS); }
}

void MountTray::slotOpenISO(){
//prompt for the user to select a file
QString file = QFileDialog::getOpenFileName( this, tr("Select ISO File"), QDir::homePath(), tr("ISO Files (*.iso)") );
if(file.isEmpty()){ return; } //cancelled
//check for available device node number /dev/md<number>
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());
}

void MountTray::slotSingleInstance()
{
trayIcon->show();
Expand Down
2 changes: 2 additions & 0 deletions src-qt4/pc-mounttray/mountTray.h
Expand Up @@ -13,6 +13,7 @@
#include <QDir>
#include <QFile>
#include <QTextStream>
#include <QFileDialog>

#include "menuItem.h"
#include "devCheck.h"
Expand Down Expand Up @@ -52,6 +53,7 @@ private slots:
void slotRescan();
void slotOpenFSDialog();
void slotOpenSettings();
void slotOpenISO();

private:
DevCheck *DCheck;
Expand Down

0 comments on commit 2d2d3cd

Please sign in to comment.