Index: sources/storage/filehandler.cpp =================================================================== diff -u -r5963f00ffd2c557d3ae06a5deea05032a3a3bd68 -rfeb3423b373dc2a2c4267ef9fcb4d924d738423d --- sources/storage/filehandler.cpp (.../filehandler.cpp) (revision 5963f00ffd2c557d3ae06a5deea05032a3a3bd68) +++ sources/storage/filehandler.cpp (.../filehandler.cpp) (revision feb3423b373dc2a2c4267ef9fcb4d924d738423d) @@ -13,18 +13,15 @@ */ #include "filehandler.h" -// Linux -#include -#include -//#include - //Qt #include #include #include // Project -#include "maintimer.h" +#include "storageglobals.h" +#include "usbwatcher.h" +#include "applicationcontroller.h" // namespace using namespace Storage; @@ -34,16 +31,6 @@ FileHandler::FileHandler(QObject *parent) : QObject(parent) { } -bool FileHandler::umounted() const -{ - return _umounted; -} - -void FileHandler::umounted(bool vUmounted) -{ - _umounted = vUmounted; -} - bool FileHandler::init() { initConnections(); @@ -56,25 +43,10 @@ void FileHandler::initConnections() { - connect(_MainTimer , SIGNAL( didTimeout()), - this , SLOT(onMainTimerTimeout())); - //connect(&_processCopyFolder, SIGNAL(finished(int)), - // this , SLOT(copyFolder)); + connect(_ApplicationController, SIGNAL(didExportLog()), + this , SLOT( onExportLog())); } -bool FileHandler::usbSeek(QString &vDevice) { - QString device = ""; - for (char a = 'a'; a <= 'z'; a++) { - device = QString("/dev/sd%1%2").arg(a).arg('1'); - if (QFileInfo::exists(device)) { - vDevice = device; - return true; // application is deciding on the first existing drive - } - } - vDevice = device; - return false; -} - bool FileHandler::write(const QString &vFileName, const QString &vContent, bool vAppend) { QFile file(vFileName); @@ -103,22 +75,8 @@ return true; } -void FileHandler::doUSBDriveMount() -{ - QString device = ""; - if (usbSeek(device)) { - if (! umounted()) { - usbMount(device); - } else { - usbUmount(_usbMount); // release - qDebug() << tr("USB drive umounted"); - } - } else { - usbRemove(); - } -} -bool FileHandler::doWrite(const QString &vFileName, const QString &vContent, bool vAppend) +bool FileHandler::onWrite(const QString &vFileName, const QString &vContent, bool vAppend) { bool ok = write(vFileName, vContent, vAppend); if (ok) { @@ -127,7 +85,7 @@ return ok; } -bool FileHandler::doRead(const QString &vFileName) +bool FileHandler::onRead(const QString &vFileName) { QString mContent; bool ok = read(vFileName, mContent); @@ -137,70 +95,14 @@ return ok; } -bool FileHandler::doExportFolder(const QString &vFolder) +bool FileHandler::onExportLog() { - if ( _mounted ) { - QString cp = "cp"; - QStringList arguments; - arguments << "-r" << vFolder << _usbMount; - _processCopyFolder.start(cp, arguments); - return true; - } - return false; -} + QString vSource = Storage::Log_Base_Path_Name_Location; + QString vDestination = Storage::USB_Mount_Point; -void FileHandler::usbError(const QString &vDevice) -{ - switch (errno) { - case EBUSY: - qDebug() << tr("%1 - Device or resource busy (%2)").arg(errno).arg(vDevice); - _mounted = true; - break; - default: - qDebug() << tr("%1 - %2 (%3 , %4)").arg(errno).arg(strerror(errno)).arg(vDevice).arg(_usbMount); - break; - } + QString cp = "cp"; + QStringList arguments; + arguments << "-r" << vSource << vDestination; + _processCopyFolder.start(cp, arguments); + return true; } - -bool FileHandler::usbMount(const QString &vDevice) -{ - bool ok; - _usbDrive = vDevice.toLatin1().constData(); - ok = mount(_usbDrive, _usbMount, _usbfsys, 0, "") == 0; - if (ok) { - _mounted = true; - qDebug() << tr("USB flash drive %1 has been mounted on %2").arg(vDevice).arg(_usbMount); - emit didUSBDriveMount(); - } else { - usbError(vDevice); - } - return ok; -} - -bool FileHandler::usbUmount(const QString &vDevice) -{ - bool ok; - ok = umount(vDevice.toLatin1().constData()) == 0; - if (ok) { - _mounted = false; - emit didUSBDriveUmount(); - } else { - // the error is irrelevant, commented out for now - //usbError(vDevice); - } - return ok; -} - -void FileHandler::usbRemove() -{ - usbUmount(_usbMount); - umounted(false); - emit didUSBDriveRemove(); - qDebug() << tr("USB drive removed"); -} - -void FileHandler::onMainTimerTimeout() -{ - doUSBDriveMount(); -} -