mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-23 18:32:49 +00:00
kdecore: implement option to recurse into sub-directories from KDirWatch::addDir()
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
6160da3e6a
commit
e921df61cf
3 changed files with 21 additions and 13 deletions
|
@ -55,7 +55,7 @@ KDirWatch::~KDirWatch()
|
|||
delete d;
|
||||
}
|
||||
|
||||
void KDirWatch::addDir(const QString &path)
|
||||
void KDirWatch::addDir(const QString &path, bool recurse)
|
||||
{
|
||||
if (path.isEmpty() || path.startsWith(QLatin1String("/dev"))) {
|
||||
return; // Don't even go there.
|
||||
|
@ -64,15 +64,22 @@ void KDirWatch::addDir(const QString &path)
|
|||
}
|
||||
|
||||
kDebug(7001) << "watching directory" << path;
|
||||
QString dirpath = path;
|
||||
// watching non-existing directory requires a trailing slash
|
||||
if (!path.endsWith(QDir::separator())) {
|
||||
const QString dirpath = path + QDir::separator();
|
||||
d->watcheddirs.append(dirpath);
|
||||
d->watcher->addPath(dirpath);
|
||||
return;
|
||||
if (!dirpath.endsWith(QDir::separator())) {
|
||||
dirpath.append(QDir::separator());
|
||||
}
|
||||
d->watcheddirs.append(dirpath);
|
||||
d->watcher->addPath(dirpath);
|
||||
|
||||
if (recurse) {
|
||||
QDir dir(dirpath);
|
||||
foreach(const QFileInfo &info, dir.entryInfoList(QDir::NoDotAndDotDot | QDir::Dirs)) {
|
||||
if (info.isDir()) {
|
||||
addDir(info.absoluteFilePath(), recurse);
|
||||
}
|
||||
}
|
||||
}
|
||||
d->watcheddirs.append(path);
|
||||
d->watcher->addPath(path);
|
||||
}
|
||||
|
||||
void KDirWatch::addFile(const QString &path)
|
||||
|
|
|
@ -56,8 +56,9 @@ public:
|
|||
/**
|
||||
* Adds a directory to be watched.
|
||||
* @param path the path to watch
|
||||
* @param recurse add sub-directories aswell
|
||||
*/
|
||||
void addDir(const QString &path);
|
||||
void addDir(const QString &path, bool recurse = false);
|
||||
|
||||
/**
|
||||
* Adds a file to be watched.
|
||||
|
@ -78,9 +79,9 @@ public:
|
|||
void removeFile(const QString &file);
|
||||
|
||||
/**
|
||||
* Check if a directory is being watched by this KDirWatch instance
|
||||
* @param path the directory to check
|
||||
* @return true if the directory is being watched
|
||||
* Check if a file or directory is being watched by this KDirWatch instance
|
||||
* @param path the file or directory to check
|
||||
* @return true if the path is being watched
|
||||
*/
|
||||
bool contains(const QString &path) const;
|
||||
|
||||
|
|
|
@ -460,7 +460,7 @@ void Kded::updateDirWatch()
|
|||
if (m_pDirWatch->contains(path)) {
|
||||
continue;
|
||||
}
|
||||
m_pDirWatch->addDir(path);
|
||||
m_pDirWatch->addDir(path, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue