Index: sources/storage/filehandler.cpp =================================================================== diff -u -rfeb3423b373dc2a2c4267ef9fcb4d924d738423d -r5e78f0799b46963feb5756decb1a27b952cd19b3 --- sources/storage/filehandler.cpp (.../filehandler.cpp) (revision feb3423b373dc2a2c4267ef9fcb4d924d738423d) +++ sources/storage/filehandler.cpp (.../filehandler.cpp) (revision 5e78f0799b46963feb5756decb1a27b952cd19b3) @@ -14,47 +14,26 @@ #include "filehandler.h" //Qt -#include #include #include +#include +#include // Project #include "storageglobals.h" -#include "usbwatcher.h" -#include "applicationcontroller.h" +#include "logger.h" // namespace using namespace Storage; -// Singleton -SINGLETON_INIT(FileHandler) - -FileHandler::FileHandler(QObject *parent) : QObject(parent) { } - -bool FileHandler::init() -{ - initConnections(); - return true; -} - -void FileHandler::quit() -{ -} - -void FileHandler::initConnections() -{ - connect(_ApplicationController, SIGNAL(didExportLog()), - this , SLOT( onExportLog())); -} - bool FileHandler::write(const QString &vFileName, const QString &vContent, bool vAppend) { QFile file(vFileName); QIODevice::OpenMode openMode = vAppend ? QFile::Text | QFile::Append : QFile::Text | QFile::WriteOnly; if (! file.open(openMode)) { - qDebug() << "ERROR :" << tr("Can't open file for write (%1)").arg(vFileName); + LOG_ERROR(QObject::tr("Can't open file for write (%1)").arg(vFileName)); return false; } QTextStream out(&file); @@ -67,42 +46,30 @@ { QFile file(vFileName); if (! file.open(QFile::Text | QFile::ReadOnly)) { - qDebug() << "ERROR :" << tr("Can't open file for read (%1)").arg(vFileName); + LOG_ERROR(QObject::tr("Can't open file for read (%1)").arg(vFileName)); return false; } QTextStream in(&file); vContent = in.readAll(); return true; } - -bool FileHandler::onWrite(const QString &vFileName, const QString &vContent, bool vAppend) +int FileHandler::copyFolder(const QString &vSource, const QString &vDestination ) { - bool ok = write(vFileName, vContent, vAppend); - if (ok) { - emit didWrite(vFileName); - } - return ok; -} + PRINT_THREAD_NAME; -bool FileHandler::onRead(const QString &vFileName) -{ - QString mContent; - bool ok = read(vFileName, mContent); - if (ok) { - emit didRead(vFileName, mContent); - } - return ok; -} - -bool FileHandler::onExportLog() -{ - QString vSource = Storage::Log_Base_Path_Name_Location; - QString vDestination = Storage::USB_Mount_Point; - QString cp = "cp"; QStringList arguments; arguments << "-r" << vSource << vDestination; - _processCopyFolder.start(cp, arguments); - return true; + return QProcess::execute(cp, arguments); } + +bool FileHandler::exportLog() +{ + QString mSource = Storage::Log_Base_Path_Name_Location; + QString mDestination = Storage::USB_Mount_Point; + //QFuture future = + QtConcurrent::run(this, &FileHandler::copyFolder, mSource, mDestination); + //return future.result(); + return 0; +}