#include "filesaver.h" // Qt #include #include // Project #include "filehandler.h" using namespace Storage; FileSaver::FileSaver(QObject *parent) : QObject(parent) { connect(&_futureWatcher, SIGNAL(finished()), this , SLOT(onFileSaved())); } /** * @brief FileSaver::concurrentSave * @param filename (QString) contains the path to the file to be written to * @param content (QString) the content to write to the file * @param append (bool) if True, append the content. Otherwise, overwrite it * @return (int) the job ID number, emitted by this class once the file has been saved */ void FileSaver::concurrentSave(const QString &filename, const QString &content, bool append) { QFuture future = QtConcurrent::run(&FileHandler::write, filename, content, append); _futureWatcher.setFuture(future); } /** * @brief FileSaver::onFileSaved * Emits a QPair, true if the save was succesful and the job id of the file that has been saved */ void FileSaver::onFileSaved() { emit fileSaved(_futureWatcher.result()); }