mirror of
https://bitbucket.org/smil3y/katie.git
synced 2025-02-24 19:02:59 +00:00
simplify emision of QFileSystemWatcher signals
the proxy signals are just redundant Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
279e569c51
commit
668ccbb7c4
5 changed files with 22 additions and 59 deletions
|
@ -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
|
\class QFileSystemWatcher
|
||||||
\brief The QFileSystemWatcher class provides an interface for monitoring files and directories for modifications.
|
\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)
|
QFileSystemWatcher::QFileSystemWatcher(QObject *parent)
|
||||||
: QObject(*new QFileSystemWatcherPrivate, 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)
|
QFileSystemWatcher::QFileSystemWatcher(const QStringList &paths, QObject *parent)
|
||||||
: QObject(*new QFileSystemWatcherPrivate, 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);
|
addPaths(paths);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,10 +53,6 @@ public:
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void fileChanged(const QString &path);
|
void fileChanged(const QString &path);
|
||||||
void directoryChanged(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
|
QT_END_NAMESPACE
|
||||||
|
|
|
@ -50,14 +50,9 @@ class QFileSystemWatcherPrivate : public QObjectPrivate
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QFileSystemWatcherPrivate();
|
QFileSystemWatcherPrivate();
|
||||||
void init();
|
|
||||||
|
|
||||||
QFileSystemWatcherEngineUnix *watcher;
|
QFileSystemWatcherEngineUnix *watcher;
|
||||||
QStringList files, directories;
|
QStringList files, directories;
|
||||||
|
|
||||||
// private slots
|
|
||||||
void _q_fileChanged(const QString &path, bool removed);
|
|
||||||
void _q_directoryChanged(const QString &path, bool removed);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
|
@ -34,7 +34,6 @@ QFileSystemWatcherEngineUnix::QFileSystemWatcherEngineUnix()
|
||||||
: timer(this)
|
: timer(this)
|
||||||
{
|
{
|
||||||
connect(&timer, SIGNAL(timeout()), this, SLOT(timeout()));
|
connect(&timer, SIGNAL(timeout()), this, SLOT(timeout()));
|
||||||
timer.start(PollingInterval);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList QFileSystemWatcherEngineUnix::addPaths(const QStringList &paths,
|
QStringList QFileSystemWatcherEngineUnix::addPaths(const QStringList &paths,
|
||||||
|
@ -96,11 +95,10 @@ void QFileSystemWatcherEngineUnix::timeout()
|
||||||
if (x.value() != fi) {
|
if (x.value() != fi) {
|
||||||
if (!fi.exists()) {
|
if (!fi.exists()) {
|
||||||
fit.remove();
|
fit.remove();
|
||||||
emit fileChanged(path, true);
|
|
||||||
} else {
|
} else {
|
||||||
x.value() = fi;
|
x.value() = fi;
|
||||||
emit fileChanged(path, false);
|
|
||||||
}
|
}
|
||||||
|
emit fileChanged(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
QMutableHashIterator<QString, QStatInfo> dit(directories);
|
QMutableHashIterator<QString, QStatInfo> dit(directories);
|
||||||
|
@ -113,11 +111,10 @@ void QFileSystemWatcherEngineUnix::timeout()
|
||||||
if (!fi.dirEquals(x.value())) {
|
if (!fi.dirEquals(x.value())) {
|
||||||
if (!fi.exists()) {
|
if (!fi.exists()) {
|
||||||
dit.remove();
|
dit.remove();
|
||||||
emit directoryChanged(path, true);
|
|
||||||
} else {
|
} else {
|
||||||
x.value() = fi;
|
x.value() = fi;
|
||||||
emit directoryChanged(path, false);
|
|
||||||
}
|
}
|
||||||
|
emit directoryChanged(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,8 +61,8 @@ public:
|
||||||
QStringList removePaths(const QStringList &paths, QStringList *files, QStringList *directories);
|
QStringList removePaths(const QStringList &paths, QStringList *files, QStringList *directories);
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void fileChanged(const QString &path, bool removed);
|
void fileChanged(const QString &path);
|
||||||
void directoryChanged(const QString &path, bool removed);
|
void directoryChanged(const QString &path);
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void timeout();
|
void timeout();
|
||||||
|
|
Loading…
Add table
Reference in a new issue