c2bFileSystemWatcher.cpp 901 Bytes
Newer Older
1
/***************************************************************************
2
 *   Copyright (C) 2004-2018 by Pere Constans
3
 *   constans@molspaces.com
4
 *   cb2Bib version 1.9.9. Licensed under the GNU GPL version 3.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
 *   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);
}