OSDN Git Service

simplify emision of QFileSystemWatcher signals
authorIvailo Monev <xakepa10@gmail.com>
Tue, 20 Dec 2022 18:49:17 +0000 (20:49 +0200)
committerIvailo Monev <xakepa10@gmail.com>
Tue, 20 Dec 2022 18:57:33 +0000 (20:57 +0200)
the proxy signals are just redundant

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
src/core/io/qfilesystemwatcher.cpp
src/core/io/qfilesystemwatcher.h
src/core/io/qfilesystemwatcher_p.h
src/core/io/qfilesystemwatcher_unix.cpp
src/core/io/qfilesystemwatcher_unix_p.h

index 8e97665..f88313e 100644 (file)
@@ -35,47 +35,6 @@ QFileSystemWatcherPrivate::QFileSystemWatcherPrivate()
 {
 }
 
-
-void QFileSystemWatcherPrivate::init()
-{
-    Q_Q(const QFileSystemWatcher);
-    QObject::connect(watcher,
-                     SIGNAL(fileChanged(QString,bool)),
-                     q,
-                     SLOT(_q_fileChanged(QString,bool)));
-    QObject::connect(watcher,
-                     SIGNAL(directoryChanged(QString,bool)),
-                     q,
-                     SLOT(_q_directoryChanged(QString,bool)));
-}
-
-
-void QFileSystemWatcherPrivate::_q_fileChanged(const QString &path, bool removed)
-{
-    Q_Q(QFileSystemWatcher);
-    if (!files.contains(path)) {
-        // the path was removed after a change was detected, but before we delivered the signal
-        return;
-    }
-    if (removed)
-        files.removeAll(path);
-    emit q->fileChanged(path);
-}
-
-void QFileSystemWatcherPrivate::_q_directoryChanged(const QString &path, bool removed)
-{
-    Q_Q(QFileSystemWatcher);
-    if (!directories.contains(path)) {
-        // perhaps the path was removed after a change was detected, but before we delivered the signal
-        return;
-    }
-    if (removed)
-        directories.removeAll(path);
-    emit q->directoryChanged(path);
-}
-
-
-
 /*!
     \class QFileSystemWatcher
     \brief The QFileSystemWatcher class provides an interface for monitoring files and directories for modifications.
@@ -111,7 +70,15 @@ void QFileSystemWatcherPrivate::_q_directoryChanged(const QString &path, bool re
 QFileSystemWatcher::QFileSystemWatcher(QObject *parent)
     : QObject(*new QFileSystemWatcherPrivate, parent)
 {
-    d_func()->init();
+    Q_D(QFileSystemWatcher);
+    connect(
+        d->watcher, SIGNAL(fileChanged(QString)),
+        this, SIGNAL(fileChanged(QString))
+    );
+    connect(
+        d->watcher, SIGNAL(directoryChanged(QString)),
+        this, SIGNAL(directoryChanged(QString))
+    );
 }
 
 /*!
@@ -121,7 +88,15 @@ QFileSystemWatcher::QFileSystemWatcher(QObject *parent)
 QFileSystemWatcher::QFileSystemWatcher(const QStringList &paths, QObject *parent)
     : QObject(*new QFileSystemWatcherPrivate, parent)
 {
-    d_func()->init();
+    Q_D(QFileSystemWatcher);
+    connect(
+        d->watcher, SIGNAL(fileChanged(QString)),
+        this, SIGNAL(fileChanged(QString))
+    );
+    connect(
+        d->watcher, SIGNAL(directoryChanged(QString)),
+        this, SIGNAL(directoryChanged(QString))
+    );
     addPaths(paths);
 }
 
index 2e09143..5ec63da 100644 (file)
@@ -53,10 +53,6 @@ public:
 Q_SIGNALS:
     void fileChanged(const QString &path);
     void directoryChanged(const QString &path);
-
-private:
-    Q_PRIVATE_SLOT(d_func(), void _q_fileChanged(const QString &path, bool removed))
-    Q_PRIVATE_SLOT(d_func(), void _q_directoryChanged(const QString &path, bool removed))
 };
 
 QT_END_NAMESPACE
index 954572f..7c9a7f5 100644 (file)
@@ -50,14 +50,9 @@ class QFileSystemWatcherPrivate : public QObjectPrivate
 
 public:
     QFileSystemWatcherPrivate();
-    void init();
 
     QFileSystemWatcherEngineUnix *watcher;
     QStringList files, directories;
-
-    // private slots
-    void _q_fileChanged(const QString &path, bool removed);
-    void _q_directoryChanged(const QString &path, bool removed);
 };
 
 QT_END_NAMESPACE
index 085b877..bb6efdc 100644 (file)
@@ -34,7 +34,6 @@ QFileSystemWatcherEngineUnix::QFileSystemWatcherEngineUnix()
     : timer(this)
 {
     connect(&timer, SIGNAL(timeout()), this, SLOT(timeout()));
-    timer.start(PollingInterval);
 }
 
 QStringList QFileSystemWatcherEngineUnix::addPaths(const QStringList &paths,
@@ -96,11 +95,10 @@ void QFileSystemWatcherEngineUnix::timeout()
         if (x.value() != fi) {
             if (!fi.exists()) {
                 fit.remove();
-                emit fileChanged(path, true);
             } else {
                 x.value() = fi;
-                emit fileChanged(path, false);
             }
+            emit fileChanged(path);
         }
     }
     QMutableHashIterator<QString, QStatInfo> dit(directories);
@@ -113,11 +111,10 @@ void QFileSystemWatcherEngineUnix::timeout()
         if (!fi.dirEquals(x.value())) {
             if (!fi.exists()) {
                 dit.remove();
-                emit directoryChanged(path, true);
             } else {
                 x.value() = fi;
-                emit directoryChanged(path, false);
             }
+            emit directoryChanged(path);
         }
     }
 }
index 36dd309..1c83898 100644 (file)
@@ -61,8 +61,8 @@ public:
     QStringList removePaths(const QStringList &paths, QStringList *files, QStringList *directories);
 
 Q_SIGNALS:
-    void fileChanged(const QString &path, bool removed);
-    void directoryChanged(const QString &path, bool removed);
+    void fileChanged(const QString &path);
+    void directoryChanged(const QString &path);
 
 private Q_SLOTS:
     void timeout();