mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-24 12:46:35 +01:00
[FileWatcher] Delay emition of file/dir changed signal.
Fixes reloading files edited by eg. vim.
This commit is contained in:
parent
2e853beef4
commit
67dbddedfe
@ -214,7 +214,8 @@ SOURCES += \
|
||||
tools/mactoolbutton.cpp \
|
||||
tools/actioncopy.cpp \
|
||||
network/pac/proxyautoconfig.cpp \
|
||||
network/pac/pacmanager.cpp
|
||||
network/pac/pacmanager.cpp \
|
||||
tools/delayedfilewatcher.cpp
|
||||
|
||||
HEADERS += \
|
||||
webview/tabpreview.h \
|
||||
@ -389,7 +390,8 @@ HEADERS += \
|
||||
tools/actioncopy.h \
|
||||
network/pac/proxyautoconfig.h \
|
||||
network/pac/pacmanager.h \
|
||||
network/pac/pacdatetime.h
|
||||
network/pac/pacdatetime.h \
|
||||
tools/delayedfilewatcher.h
|
||||
|
||||
FORMS += \
|
||||
preferences/autofillmanager.ui \
|
||||
|
60
src/lib/tools/delayedfilewatcher.cpp
Normal file
60
src/lib/tools/delayedfilewatcher.cpp
Normal file
@ -0,0 +1,60 @@
|
||||
/* ============================================================
|
||||
* QupZilla - WebKit based browser
|
||||
* Copyright (C) 2013 David Rosca <nowrep@gmail.com>
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* ============================================================ */
|
||||
#include "delayedfilewatcher.h"
|
||||
|
||||
#include <QTimer>
|
||||
|
||||
DelayedFileWatcher::DelayedFileWatcher(QObject* parent)
|
||||
: QFileSystemWatcher(parent)
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
DelayedFileWatcher::DelayedFileWatcher(const QStringList &paths, QObject* parent)
|
||||
: QFileSystemWatcher(paths, parent)
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
void DelayedFileWatcher::init()
|
||||
{
|
||||
connect(this, SIGNAL(directoryChanged(QString)), this, SLOT(slotDirectoryChanged(QString)));
|
||||
connect(this, SIGNAL(fileChanged(QString)), this, SLOT(slotFileChanged(QString)));
|
||||
}
|
||||
|
||||
void DelayedFileWatcher::slotDirectoryChanged(const QString &path)
|
||||
{
|
||||
m_dirQueue.enqueue(path);
|
||||
QTimer::singleShot(500, this, SLOT(dequeueDirectory()));
|
||||
}
|
||||
|
||||
void DelayedFileWatcher::slotFileChanged(const QString &path)
|
||||
{
|
||||
m_fileQueue.enqueue(path);
|
||||
QTimer::singleShot(500, this, SLOT(dequeueFile()));
|
||||
}
|
||||
|
||||
void DelayedFileWatcher::dequeueDirectory()
|
||||
{
|
||||
emit delayedDirectoryChanged(m_dirQueue.dequeue());
|
||||
}
|
||||
|
||||
void DelayedFileWatcher::dequeueFile()
|
||||
{
|
||||
emit delayedFileChanged(m_fileQueue.dequeue());
|
||||
}
|
53
src/lib/tools/delayedfilewatcher.h
Normal file
53
src/lib/tools/delayedfilewatcher.h
Normal file
@ -0,0 +1,53 @@
|
||||
/* ============================================================
|
||||
* QupZilla - WebKit based browser
|
||||
* Copyright (C) 2013 David Rosca <nowrep@gmail.com>
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* ============================================================ */
|
||||
#ifndef DELAYEDFILEWATCHER_H
|
||||
#define DELAYEDFILEWATCHER_H
|
||||
|
||||
#include <QFileSystemWatcher>
|
||||
#include <QPointer>
|
||||
#include <QQueue>
|
||||
|
||||
#include "qz_namespace.h"
|
||||
|
||||
class QT_QUPZILLA_EXPORT DelayedFileWatcher : public QFileSystemWatcher
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit DelayedFileWatcher(QObject* parent = 0);
|
||||
explicit DelayedFileWatcher(const QStringList &paths, QObject* parent = 0);
|
||||
|
||||
signals:
|
||||
void delayedDirectoryChanged(const QString &path);
|
||||
void delayedFileChanged(const QString &path);
|
||||
|
||||
private slots:
|
||||
void slotDirectoryChanged(const QString &path);
|
||||
void slotFileChanged(const QString &path);
|
||||
|
||||
void dequeueDirectory();
|
||||
void dequeueFile();
|
||||
|
||||
private:
|
||||
void init();
|
||||
|
||||
QQueue<QString> m_dirQueue;
|
||||
QQueue<QString> m_fileQueue;
|
||||
};
|
||||
|
||||
#endif // DELAYEDFILEWATCHER_H
|
@ -35,6 +35,7 @@
|
||||
#include "iconprovider.h"
|
||||
#include "qzsettings.h"
|
||||
#include "useragentmanager.h"
|
||||
#include "delayedfilewatcher.h"
|
||||
#include "recoverywidget.h"
|
||||
#include "html5permissions/html5permissionsmanager.h"
|
||||
#include "schemehandlers/fileschemehandler.h"
|
||||
@ -50,7 +51,6 @@
|
||||
#include <QDir>
|
||||
#include <QMouseEvent>
|
||||
#include <QWebHistory>
|
||||
#include <QFileSystemWatcher>
|
||||
#include <QTimer>
|
||||
#include <QNetworkReply>
|
||||
#include <QDebug>
|
||||
@ -233,8 +233,8 @@ void WebPage::finished()
|
||||
QFileInfo info(url().toLocalFile());
|
||||
if (info.isFile()) {
|
||||
if (!m_fileWatcher) {
|
||||
m_fileWatcher = new QFileSystemWatcher(this);
|
||||
connect(m_fileWatcher, SIGNAL(fileChanged(QString)), this, SLOT(watchedFileChanged(QString)));
|
||||
m_fileWatcher = new DelayedFileWatcher(this);
|
||||
connect(m_fileWatcher, SIGNAL(delayedFileChanged(QString)), this, SLOT(watchedFileChanged(QString)));
|
||||
}
|
||||
|
||||
const QString &filePath = url().toLocalFile();
|
||||
|
@ -26,7 +26,6 @@
|
||||
#include "autofill.h"
|
||||
|
||||
class QWebSecurityOrigin;
|
||||
class QFileSystemWatcher;
|
||||
class QEventLoop;
|
||||
|
||||
class QupZilla;
|
||||
@ -34,6 +33,7 @@ class AdBlockRule;
|
||||
class TabbedWebView;
|
||||
class SpeedDial;
|
||||
class NetworkManagerProxy;
|
||||
class DelayedFileWatcher;
|
||||
|
||||
class QT_QUPZILLA_EXPORT WebPage : public QWebPage
|
||||
{
|
||||
@ -132,7 +132,7 @@ private:
|
||||
NetworkManagerProxy* m_networkProxy;
|
||||
TabbedWebView* m_view;
|
||||
SpeedDial* m_speedDial;
|
||||
QFileSystemWatcher* m_fileWatcher;
|
||||
DelayedFileWatcher* m_fileWatcher;
|
||||
QEventLoop* m_runningLoop;
|
||||
|
||||
QSslCertificate m_sslCert;
|
||||
|
@ -17,19 +17,20 @@
|
||||
* ============================================================ */
|
||||
#include "gm_script.h"
|
||||
#include "gm_manager.h"
|
||||
|
||||
#include "qzregexp.h"
|
||||
#include "delayedfilewatcher.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QStringList>
|
||||
#include <QWebFrame>
|
||||
#include <QDebug>
|
||||
#include <QCryptographicHash>
|
||||
#include <QFileSystemWatcher>
|
||||
|
||||
GM_Script::GM_Script(GM_Manager* manager, const QString &filePath)
|
||||
: QObject(manager)
|
||||
, m_manager(manager)
|
||||
, m_fileWatcher(new QFileSystemWatcher(this))
|
||||
, m_fileWatcher(new DelayedFileWatcher(this))
|
||||
, m_namespace("GreaseMonkeyNS")
|
||||
, m_startAt(DocumentEnd)
|
||||
, m_fileName(filePath)
|
||||
@ -38,8 +39,7 @@ GM_Script::GM_Script(GM_Manager* manager, const QString &filePath)
|
||||
{
|
||||
parseScript();
|
||||
|
||||
connect(m_fileWatcher, SIGNAL(fileChanged(QString)),
|
||||
this, SLOT(watchedFileChanged(QString)));
|
||||
connect(m_fileWatcher, SIGNAL(delayedFileChanged(QString)), this, SLOT(watchedFileChanged(QString)));
|
||||
}
|
||||
|
||||
bool GM_Script::isValid() const
|
||||
@ -150,10 +150,6 @@ void GM_Script::watchedFileChanged(const QString &file)
|
||||
if (m_fileName == file) {
|
||||
parseScript();
|
||||
|
||||
if (!isValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_manager->removeScript(this, false);
|
||||
m_manager->addScript(this);
|
||||
}
|
||||
|
@ -25,11 +25,12 @@
|
||||
#include <QUrl>
|
||||
|
||||
class QWebFrame;
|
||||
class QFileSystemWatcher;
|
||||
|
||||
class GM_Manager;
|
||||
class GM_UrlMatcher;
|
||||
|
||||
class DelayedFileWatcher;
|
||||
|
||||
class GM_Script : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -67,7 +68,7 @@ private:
|
||||
void parseScript();
|
||||
|
||||
GM_Manager* m_manager;
|
||||
QFileSystemWatcher* m_fileWatcher;
|
||||
DelayedFileWatcher* m_fileWatcher;
|
||||
|
||||
QString m_name;
|
||||
QString m_namespace;
|
||||
|
Loading…
Reference in New Issue
Block a user