Index: sources/storage/filehandler.cpp =================================================================== diff -u -r44a85c96ab55e424866ec4cca0270aa218355f82 -rc71deaab48699cffdf9db816dfac2778d79c2238 --- sources/storage/filehandler.cpp (.../filehandler.cpp) (revision 44a85c96ab55e424866ec4cca0270aa218355f82) +++ sources/storage/filehandler.cpp (.../filehandler.cpp) (revision c71deaab48699cffdf9db816dfac2778d79c2238) @@ -43,6 +43,15 @@ err << mCritical << endl; } +/*! + * \brief FileHandler::write + * \details Writes the content of vContent into the file vFileName. + * \param vFileName - Source file name + * \param vContent - The content which is going to be written in the file. + * \param vAppend - if set to true the content will be appended at the end of the file. + * \param id - contains the request id, defaults to -1 + * \return false if file can't be opened. + */ bool FileHandler::write(const QString &vFileName, const QString &vContent, bool vAppend) { QFile file(vFileName); @@ -59,6 +68,7 @@ return true; } + /*! * \brief FileHandler::read * \details reads file vFilename content into vContent variable. @@ -79,6 +89,48 @@ } /*! + * \brief FileHandler::readCSV + * \details reads the provided filename's content into the vContent variable. + * \param vFileName - Source file name + * \param vContent - The content of the file which will be written to when done. + * \return false if file can't be read + */ +bool FileHandler::readCSV(const QString &vFileName, QString &vContent) +{ + QFile file(vFileName); + if (! file.open(QFile::Text | QFile::ReadOnly)) { + errOut(QObject::tr("Can't open file for read (%1).Possible corrupted file system").arg(vFileName)); + return false; + } + QTextStream in(&file); + vContent = in.readAll(); + return true; +} + +/*! + * \brief FileHandler::readCSV + * \details reads the provided filename's JSON content into the vContent variable. + * \param vFileName - Source file name + * \param vContent - The content of the file which will be written to when done. + * \return false if file can't be read + */ +bool FileHandler::readJSON(const QString &vFileName, QJsonObject &vContent) +{ + QFile file(vFileName); + if (! file.open(QFile::Text | QFile::ReadOnly)) { + errOut(QObject::tr("Can't open file for read (%1).Possible corrupted file system").arg(vFileName)); + return false; + } + QTextStream in(&file); + QString content = in.readAll(); + + + QJsonDocument doc = QJsonDocument::fromJson(content.toUtf8()); + vContent = doc.object(); + return true; +} + +/*! * \brief FileHandler::copyFolder * \details Copies all the file and folders recursively. * \param vSource - The source folder