kdelibs/kdecore/io/kdirwatch.h
Ivailo Monev 03aba012a0 kdecore: KDirWatch rewrite
I rewrote QFileSystemWatcher some time ago for it to be able to watch
non-existing directories, did rewrite KDirWatch too to not use FAM
and inotify making the created() and deleted() signals non-operational
(with the plan to maybe implement them in QFileSystemWatcher but that
will be hack-ish for directories with stat()-based implementation)

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2022-12-21 00:24:49 +02:00

124 lines
3.4 KiB
C++

/* This file is part of the KDE libraries
Copyright (C) 2019 Ivailo Monev <xakepa10@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2, as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef KDIRWATCH_H
#define KDIRWATCH_H
#include <QtCore/qobject.h>
#include <QtCore/qstring.h>
#include <kdecore_export.h>
class KDirWatchPrivate;
/**
* @short Class for watching directory and file changes.
*
* The watched directories or files do not have to exist. When a watched
* directory is changed, i.e. when files therein are created or deleted,
* KDirWatch will emit the signal dirty(). Scanning begins immediately when a
* dir or file watch is added.
*
* @see self()
*/
class KDECORE_EXPORT KDirWatch : public QObject
{
Q_OBJECT
public:
/**
* Constructor.
* @param parent the parent of the QObject (or 0 for parent-less KDirWatch)
*/
KDirWatch(QObject* parent = 0);
/**
* Destructor.
*
* Stops scanning and cleans up.
*/
~KDirWatch();
/**
* Adds a directory to be watched.
* @param path the path to watch
*/
void addDir(const QString &path);
/**
* Adds a file to be watched.
* @param file the file to watch
*/
void addFile(const QString &file);
/**
* Removes a directory from the list of scanned directories.
* @param path the path of the dir to be removed from the list
*/
void removeDir(const QString &path);
/**
* Removes a file from the list of watched files.
* @param file the file to be removed from the list
*/
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
*/
bool contains(const QString &path) const;
/**
* The KDirWatch instance usually globally used in an application.
* It is automatically deleted when the application exits.
*
* However, you can create an arbitrary number of KDirWatch instances
* aside from this one - for those you have to take care of memory management.
*
* This function returns an instance of KDirWatch. If there is none, it
* will be created.
*
* @return a KDirWatch instance
*/
static KDirWatch* self();
public Q_SLOTS:
/**
* Emits dirty().
* @param path the path of the file or directory
*/
void setDirty(const QString &path);
Q_SIGNALS:
/**
* Emitted when a watched object is changed.
*
* For a directory this signal is emitted when files therein are created or
* deleted. For a file this signal is emitted when its size or attributes
* change.
*
* @param path the path of the file or directory
*/
void dirty(const QString &path);
private:
KDirWatchPrivate* d;
};
#endif // KDIRWATCH_H