Index: sources/device/DeviceController.cpp =================================================================== diff -u -r79a6cfcb10472261f3ec26eaf0baf6f1245cd311 -r86e9dfbff50cb7e16fd94c16c1c818cef3b47eac --- sources/device/DeviceController.cpp (.../DeviceController.cpp) (revision 79a6cfcb10472261f3ec26eaf0baf6f1245cd311) +++ sources/device/DeviceController.cpp (.../DeviceController.cpp) (revision 86e9dfbff50cb7e16fd94c16c1c818cef3b47eac) @@ -200,15 +200,22 @@ bool DeviceController::driveSpaceCheck(const QString &vPath, qint64 &vTotalBytes, qint64 &vAvailableBytes, bool *vIsReadOnly) { // disabled coco begin validated: Needed User Interaction to make the device not ready so tested manually - bool isReadOnly; - if (! FileHandler::isMounted(vPath, &isReadOnly)) return false; - if (vIsReadOnly) *vIsReadOnly = isReadOnly; + bool isReadOnly = true; + bool isMounted = FileHandler::isMounted(vPath, &isReadOnly); + if ( vIsReadOnly ) *vIsReadOnly = isReadOnly; + QStorageInfo storage(vPath); bool isReady = storage.isReady(); - if (isReady) { + if ( isReady ) { vTotalBytes = storage.bytesTotal(); vAvailableBytes = storage.bytesAvailable(); } + + if ( ! isMounted || ! isReady ) { + isReady = false; + vTotalBytes = 0; + vAvailableBytes = 0; + } return isReady; } // disabled coco end @@ -235,6 +242,7 @@ { // disabled coco begin validated: Needed User Interaction so tested manually QString device = ""; + usbSpaceCheck(); if (usbSeek(device)) { if (! _umounted ) { usbMount(device); @@ -250,57 +258,102 @@ } /*! - * \brief DeviceController::sdcardFreeSpaceCheck - * \details Checks the drivers for available free space. + * \brief DeviceController::sdcardSpaceCheck + * \details Checks for the SD-Card drive space. */ void DeviceController::sdcardSpaceCheck() { - // disabled coco begin validated: Needed User Interaction so tested manually - + static bool mInitialized = false; // Old Info ; // Current info static bool mOIsReady ; bool mCIsReady ; static bool mOIsReadOnly; bool mCIsReadOnly ; static qint64 mOTotal ; qint64 mCTotal ; static qint64 mOAvailable ; qint64 mCAvailable ; + quint8 mPercent = 0; + mCIsReady = driveSpaceCheck(Storage::SDCard_Base_Path_Name, mCTotal, mCAvailable, &mCIsReadOnly); - /// DEBUG: qDebug() << " ===== " << Storage::SDCard_Base_Path_Name << mCIsReady; - if (mOIsReadOnly != mCIsReadOnly || mOIsReady != mCIsReady) { + if (mOIsReadOnly != mCIsReadOnly || mOIsReady != mCIsReady || ! mInitialized ) { mOIsReadOnly = mCIsReadOnly; + mOIsReady = mCIsReady; + mInitialized = true; emit didSDCardStateChange(mCIsReady, mCIsReadOnly); } if (! mCIsReady ) { mOIsReady = mCIsReady; mOTotal = 0; mOAvailable = 0; + emit didSDCardSpaceChange(mCIsReady, mCTotal, mCAvailable, mPercent); return; } - quint8 mPercent = mCTotal ? ((100 * mCAvailable) / mCTotal) : 0; + mPercent = mCTotal ? ((100 * mCAvailable) / mCTotal) : 0; if (mPercent < _minRequiredAvailableSpacePercent) { LOG_DEBUG(QString("SD-CARD space lower than %1%").arg(_minRequiredAvailableSpacePercent)); emit didSDCardSpaceChange(mCIsReady, mCTotal, mCAvailable, mPercent); emit didSDCardSpaceTooLow(_minRequiredAvailableSpacePercent); } /// DEBUG: qDebug() << Storage::SDCard_Base_Path_Name << mCIsReady << mOTotal << mCTotal << (mOTotal == mCTotal) << mOAvailable << mCAvailable << (mOAvailable == mCAvailable) << mPercent << mCIsReadOnly; - if (mOTotal == mCTotal && - mOAvailable == mCAvailable) { + mOAvailable == mCAvailable) { return; } mOIsReady = mCIsReady ; mOTotal = mCTotal ; mOAvailable = mCAvailable ; - if (_pauseSpaceCheck) return; + if (_pauseSpaceCheck) return; //TODO: may not be required, but needs a lot of time consuming testing. emit didSDCardSpaceChange(mCIsReady, mCTotal, mCAvailable, mPercent); /// DEBUG: qDebug() << Storage::SDCard_Base_Path_Name << mCIsReady << mCTotal << mCAvailable << mPercent ; } -// disabled coco end /*! + * \brief DeviceController::usbSpaceCheck + * \details Checks for the USB drive space. + */ +void DeviceController::usbSpaceCheck() +{ + static bool mInitialized = false; + // Old Info ; // Current info + static bool mOIsReady ; bool mCIsReady ; + static bool mOIsReadOnly; bool mCIsReadOnly ; + static qint64 mOTotal ; qint64 mCTotal ; + static qint64 mOAvailable ; qint64 mCAvailable ; + + quint8 mPercent = 0; + + mCIsReady = driveSpaceCheck(Storage::USB_Mount_Point, mCTotal, mCAvailable, &mCIsReadOnly); + if (mOIsReadOnly != mCIsReadOnly || mOIsReady != mCIsReady || ! mInitialized ) { + mOIsReadOnly = mCIsReadOnly; + mOIsReady = mCIsReady; + mInitialized = true; + emit didUSBStateChange(mCIsReady, mCIsReadOnly); + } + + if (! mCIsReady ) { + mOIsReady = mCIsReady; + mOTotal = 0; + mOAvailable = 0; + emit didUSBSpaceChange(mCIsReady, mCTotal, mCAvailable, mPercent); + return; + } + + mPercent = mCTotal ? ((100 * mCAvailable) / mCTotal) : 0; + if (mOTotal == mCTotal && + mOAvailable == mCAvailable) { + return; + } + + mOIsReady = mCIsReady ; + mOTotal = mCTotal ; + mOAvailable = mCAvailable ; + emit didUSBSpaceChange(mCIsReady, mCTotal, mCAvailable, mPercent); +} + + +/*! * \brief DeviceController::usbError * \details Logs any error which has been happened * On USB device vDevice @@ -358,7 +411,7 @@ // has been tested manually bool ok; _usbDrive = vDevice.toLatin1().constData(); - ok = ::mount(_usbDrive, USB_Mount_Point, USB_File_System, MS_SYNCHRONOUS, "") == 0; + ok = ::mount(_usbDrive, USB_Mount_Point, USB_File_System, MS_SYNCHRONOUS | MS_NOEXEC, "") == 0; if (ok) { _mounted = true; _removed = false; @@ -591,7 +644,7 @@ void DeviceController::ondoAddWatch(const QString &vFile) { if ( ! QFileInfo::exists(vFile)) { - if ( ! FileHandler::write(vFile, "", false) ) { + if ( ! FileHandler::write(vFile, "", false) ) { // if the file doesn't exist it has to be created to be watched. LOG_DEBUG(DeviceError::deviceErrorText(DeviceError::eDevice_Watch_Error_NotFound, 0)); return; }