diff --git a/src/webview/webpage.cpp b/src/webview/webpage.cpp index 0339beddc..5639a999f 100644 --- a/src/webview/webpage.cpp +++ b/src/webview/webpage.cpp @@ -39,6 +39,7 @@ WebPage::WebPage(WebView* parent, QupZilla* mainClass) , p_QupZilla(mainClass) , m_view(parent) , m_speedDial(mApp->plugins()->speedDial()) + , m_fileWatcher(0) , m_runningLoop(0) , m_blockAlerts(false) , m_secureStatus(false) @@ -99,9 +100,33 @@ void WebPage::finished() mainFrame()->setZoomFactor(mainFrame()->zoomFactor() - 1); } + if (mainFrame()->url().scheme() == "file") { + if (!m_fileWatcher) { + m_fileWatcher = new QFileSystemWatcher(this); + connect(m_fileWatcher, SIGNAL(fileChanged(QString)), this, SLOT(watchedFileChanged(QString))); + } + + QString absPath = mainFrame()->url().toLocalFile(); + + if (!m_fileWatcher->files().contains(absPath)) { + m_fileWatcher->addPath(absPath); + } + } + else if (m_fileWatcher) { + m_fileWatcher->removePaths(m_fileWatcher->files()); + } + QTimer::singleShot(100, this, SLOT(cleanBlockedObjects())); } +void WebPage::watchedFileChanged(const QString &file) +{ + qDebug() << file; + if (mainFrame()->url().toLocalFile() == file) { + triggerAction(QWebPage::Reload); + } +} + //void WebPage::loadingStarted() //{ // m_adBlockedEntries.clear(); diff --git a/src/webview/webpage.h b/src/webview/webpage.h index 5d1c252fa..6fd55356c 100644 --- a/src/webview/webpage.h +++ b/src/webview/webpage.h @@ -31,6 +31,7 @@ #include #include #include +#include class QupZilla; class WebView; @@ -86,6 +87,8 @@ private slots: void urlChanged(const QUrl &url); void addJavaScriptObject(); + void watchedFileChanged(const QString &file); + private: virtual bool supportsExtension(Extension extension) const { return (extension == ErrorPageExtension); } virtual bool extension(Extension extension, const ExtensionOption* option, ExtensionReturn* output = 0); @@ -102,6 +105,7 @@ private: QSslCertificate m_SslCert; QList m_SslCerts; QList m_adBlockedEntries; + QFileSystemWatcher* m_fileWatcher; QEventLoop* m_runningLoop;