Falkon Develop
Cross-platform Qt-based web browser
delayedfilewatcher.cpp
Go to the documentation of this file.
1/* ============================================================
2* Falkon - Qt web browser
3* Copyright (C) 2013-2014 David Rosca <nowrep@gmail.com>
4*
5* This program is free software: you can redistribute it and/or modify
6* it under the terms of the GNU General Public License as published by
7* the Free Software Foundation, either version 3 of the License, or
8* (at your option) any later version.
9*
10* This program is distributed in the hope that it will be useful,
11* but WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with this program. If not, see <http://www.gnu.org/licenses/>.
17* ============================================================ */
18#include "delayedfilewatcher.h"
19
20#include <QTimer>
21
23 : QFileSystemWatcher(parent)
24{
25 init();
26}
27
28DelayedFileWatcher::DelayedFileWatcher(const QStringList &paths, QObject* parent)
29 : QFileSystemWatcher(paths, parent)
30{
31 init();
32}
33
34void DelayedFileWatcher::init()
35{
36 connect(this, &QFileSystemWatcher::directoryChanged, this, &DelayedFileWatcher::slotDirectoryChanged);
37 connect(this, &QFileSystemWatcher::fileChanged, this, &DelayedFileWatcher::slotFileChanged);
38}
39
40void DelayedFileWatcher::slotDirectoryChanged(const QString &path)
41{
42 m_dirQueue.enqueue(path);
43 QTimer::singleShot(500, this, &DelayedFileWatcher::dequeueDirectory);
44}
45
46void DelayedFileWatcher::slotFileChanged(const QString &path)
47{
48 m_fileQueue.enqueue(path);
49 QTimer::singleShot(500, this, &DelayedFileWatcher::dequeueFile);
50}
51
52void DelayedFileWatcher::dequeueDirectory()
53{
54 Q_EMIT delayedDirectoryChanged(m_dirQueue.dequeue());
55}
56
57void DelayedFileWatcher::dequeueFile()
58{
59 Q_EMIT delayedFileChanged(m_fileQueue.dequeue());
60}
DelayedFileWatcher(QObject *parent=nullptr)
void delayedFileChanged(const QString &path)
void delayedDirectoryChanged(const QString &path)