Index: sources/storage/filehandler.cpp =================================================================== diff -u -r781e62c996e81897517fbdb1bc79fe3bbcf165c1 -r90d3f5b31186834168c9ad869f8d2d038200dfcf --- sources/storage/filehandler.cpp (.../filehandler.cpp) (revision 781e62c996e81897517fbdb1bc79fe3bbcf165c1) +++ sources/storage/filehandler.cpp (.../filehandler.cpp) (revision 90d3f5b31186834168c9ad869f8d2d038200dfcf) @@ -13,6 +13,7 @@ */ #include "filehandler.h" +#include //Qt #include #include @@ -35,11 +36,43 @@ void FileHandler::directoryChanged(const QString &vPath) { Q_UNUSED(vPath) - // qDebug() << QFileInfo::exists("/dev/sda"); + bool available = false; + QString device = ""; + if ( ! _mounted ) { + for (int a = 'a'; a <= 'z'; a++) { + device = QString("/dev/sd%1%2").arg(QChar(a)).arg(QChar('1')); + if (QFileInfo::exists(device)) { + available = true; + break; + } + umount(device.toLatin1().constData()); + } + } + if (available) { + if ( ! _mounted ) { + if ( mountUsb(device) ) { + _mounted = true; + } else { + qDebug() << tr("1 - USB drive %1 can't be mounted").arg(_usbMount); + } + } + } else { + umount(_usbMount); + _mounted = false; + qDebug() << tr("2 - USB drive %1 can't be mounted").arg(_usbMount); + return; + } + emit usbStatusChanged(available); } -bool FileHandler::mountUsb() +bool FileHandler::mountUsb(QString device) { + int result = mount(device.toLatin1().constData(), _usbMount, _usbfsys, 0, ""); + if (result == 0) { + qDebug() << tr("USB flash drive %1 has been mounted to %2").arg(device).arg(_usbMount); + } else { + return false; + } return true; }