/***************************************************************************
 *   Copyright (C) 2004-2017 by Pere Constans
 *   constans@molspaces.com
 *   cb2Bib version 1.9.7. Licensed under the GNU GPL version 3.
 *   See the LICENSE file that comes with this distribution.
 ***************************************************************************/
#include "c2bFileSystemWatcher.h"

#include <QTimer>


/**
    Workaround to avoid reading a file when external writing has not yet finished
*/
c2bFileSystemWatcher::c2bFileSystemWatcher(QObject* parento) : QObject(parento)
{
    connect(&_filewatcher, SIGNAL(fileChanged(const QString&)), this, SLOT(waitForSaved(const QString&)));
}

void c2bFileSystemWatcher::waitForSaved(const QString& path)
{
    _path = path;
    QTimer::singleShot(500, this, SLOT(fileSaved()));
}

void c2bFileSystemWatcher::fileSaved()
{
    emit fileChanged(_path);
}
