C++ toolkit derived from the Qt 4.8 framework
Revision | 668ccbb7c4b8f7768ba637791dc5309f87f48a2e (tree) |
---|---|
Time | 2022-12-21 03:57:33 |
Author | Ivailo Monev <xakepa10@gmai...> |
Commiter | Ivailo Monev |
simplify emision of QFileSystemWatcher signals
the proxy signals are just redundant
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
@@ -35,47 +35,6 @@ QFileSystemWatcherPrivate::QFileSystemWatcherPrivate() | ||
35 | 35 | { |
36 | 36 | } |
37 | 37 | |
38 | - | |
39 | -void QFileSystemWatcherPrivate::init() | |
40 | -{ | |
41 | - Q_Q(const QFileSystemWatcher); | |
42 | - QObject::connect(watcher, | |
43 | - SIGNAL(fileChanged(QString,bool)), | |
44 | - q, | |
45 | - SLOT(_q_fileChanged(QString,bool))); | |
46 | - QObject::connect(watcher, | |
47 | - SIGNAL(directoryChanged(QString,bool)), | |
48 | - q, | |
49 | - SLOT(_q_directoryChanged(QString,bool))); | |
50 | -} | |
51 | - | |
52 | - | |
53 | -void QFileSystemWatcherPrivate::_q_fileChanged(const QString &path, bool removed) | |
54 | -{ | |
55 | - Q_Q(QFileSystemWatcher); | |
56 | - if (!files.contains(path)) { | |
57 | - // the path was removed after a change was detected, but before we delivered the signal | |
58 | - return; | |
59 | - } | |
60 | - if (removed) | |
61 | - files.removeAll(path); | |
62 | - emit q->fileChanged(path); | |
63 | -} | |
64 | - | |
65 | -void QFileSystemWatcherPrivate::_q_directoryChanged(const QString &path, bool removed) | |
66 | -{ | |
67 | - Q_Q(QFileSystemWatcher); | |
68 | - if (!directories.contains(path)) { | |
69 | - // perhaps the path was removed after a change was detected, but before we delivered the signal | |
70 | - return; | |
71 | - } | |
72 | - if (removed) | |
73 | - directories.removeAll(path); | |
74 | - emit q->directoryChanged(path); | |
75 | -} | |
76 | - | |
77 | - | |
78 | - | |
79 | 38 | /*! |
80 | 39 | \class QFileSystemWatcher |
81 | 40 | \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 | ||
111 | 70 | QFileSystemWatcher::QFileSystemWatcher(QObject *parent) |
112 | 71 | : QObject(*new QFileSystemWatcherPrivate, parent) |
113 | 72 | { |
114 | - d_func()->init(); | |
73 | + Q_D(QFileSystemWatcher); | |
74 | + connect( | |
75 | + d->watcher, SIGNAL(fileChanged(QString)), | |
76 | + this, SIGNAL(fileChanged(QString)) | |
77 | + ); | |
78 | + connect( | |
79 | + d->watcher, SIGNAL(directoryChanged(QString)), | |
80 | + this, SIGNAL(directoryChanged(QString)) | |
81 | + ); | |
115 | 82 | } |
116 | 83 | |
117 | 84 | /*! |
@@ -121,7 +88,15 @@ QFileSystemWatcher::QFileSystemWatcher(QObject *parent) | ||
121 | 88 | QFileSystemWatcher::QFileSystemWatcher(const QStringList &paths, QObject *parent) |
122 | 89 | : QObject(*new QFileSystemWatcherPrivate, parent) |
123 | 90 | { |
124 | - d_func()->init(); | |
91 | + Q_D(QFileSystemWatcher); | |
92 | + connect( | |
93 | + d->watcher, SIGNAL(fileChanged(QString)), | |
94 | + this, SIGNAL(fileChanged(QString)) | |
95 | + ); | |
96 | + connect( | |
97 | + d->watcher, SIGNAL(directoryChanged(QString)), | |
98 | + this, SIGNAL(directoryChanged(QString)) | |
99 | + ); | |
125 | 100 | addPaths(paths); |
126 | 101 | } |
127 | 102 |
@@ -53,10 +53,6 @@ public: | ||
53 | 53 | Q_SIGNALS: |
54 | 54 | void fileChanged(const QString &path); |
55 | 55 | void directoryChanged(const QString &path); |
56 | - | |
57 | -private: | |
58 | - Q_PRIVATE_SLOT(d_func(), void _q_fileChanged(const QString &path, bool removed)) | |
59 | - Q_PRIVATE_SLOT(d_func(), void _q_directoryChanged(const QString &path, bool removed)) | |
60 | 56 | }; |
61 | 57 | |
62 | 58 | QT_END_NAMESPACE |
@@ -50,14 +50,9 @@ class QFileSystemWatcherPrivate : public QObjectPrivate | ||
50 | 50 | |
51 | 51 | public: |
52 | 52 | QFileSystemWatcherPrivate(); |
53 | - void init(); | |
54 | 53 | |
55 | 54 | QFileSystemWatcherEngineUnix *watcher; |
56 | 55 | QStringList files, directories; |
57 | - | |
58 | - // private slots | |
59 | - void _q_fileChanged(const QString &path, bool removed); | |
60 | - void _q_directoryChanged(const QString &path, bool removed); | |
61 | 56 | }; |
62 | 57 | |
63 | 58 | QT_END_NAMESPACE |
@@ -34,7 +34,6 @@ QFileSystemWatcherEngineUnix::QFileSystemWatcherEngineUnix() | ||
34 | 34 | : timer(this) |
35 | 35 | { |
36 | 36 | connect(&timer, SIGNAL(timeout()), this, SLOT(timeout())); |
37 | - timer.start(PollingInterval); | |
38 | 37 | } |
39 | 38 | |
40 | 39 | QStringList QFileSystemWatcherEngineUnix::addPaths(const QStringList &paths, |
@@ -96,11 +95,10 @@ void QFileSystemWatcherEngineUnix::timeout() | ||
96 | 95 | if (x.value() != fi) { |
97 | 96 | if (!fi.exists()) { |
98 | 97 | fit.remove(); |
99 | - emit fileChanged(path, true); | |
100 | 98 | } else { |
101 | 99 | x.value() = fi; |
102 | - emit fileChanged(path, false); | |
103 | 100 | } |
101 | + emit fileChanged(path); | |
104 | 102 | } |
105 | 103 | } |
106 | 104 | QMutableHashIterator<QString, QStatInfo> dit(directories); |
@@ -113,11 +111,10 @@ void QFileSystemWatcherEngineUnix::timeout() | ||
113 | 111 | if (!fi.dirEquals(x.value())) { |
114 | 112 | if (!fi.exists()) { |
115 | 113 | dit.remove(); |
116 | - emit directoryChanged(path, true); | |
117 | 114 | } else { |
118 | 115 | x.value() = fi; |
119 | - emit directoryChanged(path, false); | |
120 | 116 | } |
117 | + emit directoryChanged(path); | |
121 | 118 | } |
122 | 119 | } |
123 | 120 | } |
@@ -61,8 +61,8 @@ public: | ||
61 | 61 | QStringList removePaths(const QStringList &paths, QStringList *files, QStringList *directories); |
62 | 62 | |
63 | 63 | Q_SIGNALS: |
64 | - void fileChanged(const QString &path, bool removed); | |
65 | - void directoryChanged(const QString &path, bool removed); | |
64 | + void fileChanged(const QString &path); | |
65 | + void directoryChanged(const QString &path); | |
66 | 66 | |
67 | 67 | private Q_SLOTS: |
68 | 68 | void timeout(); |