2016-04-29 17:14:18 +03:00
|
|
|
/*
|
|
|
|
* Copyright (C) by Christian Kamm <mail@ckamm.de>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
2016-10-25 12:00:07 +03:00
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
2016-04-29 17:14:18 +03:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "lockwatcher.h"
|
|
|
|
#include "filesystem.h"
|
|
|
|
|
2017-05-09 15:24:11 +03:00
|
|
|
#include <QLoggingCategory>
|
2016-04-29 17:14:18 +03:00
|
|
|
#include <QTimer>
|
|
|
|
|
|
|
|
using namespace OCC;
|
|
|
|
|
2017-05-09 15:24:11 +03:00
|
|
|
Q_LOGGING_CATEGORY(lcLockWatcher, "gui.lockwatcher", QtInfoMsg)
|
|
|
|
|
2016-04-29 17:14:18 +03:00
|
|
|
static const int check_frequency = 20 * 1000; // ms
|
|
|
|
|
|
|
|
LockWatcher::LockWatcher(QObject *parent)
|
|
|
|
: QObject(parent)
|
|
|
|
{
|
|
|
|
connect(&_timer, SIGNAL(timeout()),
|
|
|
|
SLOT(checkFiles()));
|
|
|
|
_timer.start(check_frequency);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LockWatcher::addFile(const QString &path)
|
|
|
|
{
|
2017-05-11 16:36:47 +03:00
|
|
|
qCInfo(lcLockWatcher) << "Watching for lock of" << path << "being released";
|
2016-04-29 17:14:18 +03:00
|
|
|
_watchedPaths.insert(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LockWatcher::checkFiles()
|
|
|
|
{
|
|
|
|
QSet<QString> unlocked;
|
|
|
|
|
|
|
|
foreach (const QString &path, _watchedPaths) {
|
|
|
|
if (!FileSystem::isFileLocked(path)) {
|
2017-05-11 16:36:47 +03:00
|
|
|
qCInfo(lcLockWatcher) << "Lock of" << path << "was released";
|
2016-04-29 17:14:18 +03:00
|
|
|
emit fileUnlocked(path);
|
|
|
|
unlocked.insert(path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Doing it this way instead of with a QMutableSetIterator
|
|
|
|
// ensures that calling back into addFile from connected
|
|
|
|
// slots isn't a problem.
|
|
|
|
_watchedPaths.subtract(unlocked);
|
|
|
|
}
|