1
/* This file is part of the KDE libraries
2
Copyright (C) 2007-2010 Sebastian Trueg <trueg@kde.org>
4
This library is free software; you can redistribute it and/or
5
modify it under the terms of the GNU Library General Public
6
License as published by the Free Software Foundation; either
7
version 2 of the License, or (at your option) any later version.
9
This library is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
Library General Public License for more details.
14
You should have received a copy of the GNU Library General Public License
15
along with this library; see the file COPYING.LIB. If not, write to
16
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
Boston, MA 02110-1301, USA.
26
* A simple wrapper around inotify which only allows
27
* to add folders recursively.
29
* Warning: moving of top-level folders is not supported and
30
* results in undefined behaviour.
32
class KInotify : public QObject
37
KInotify(QObject* parent = 0);
41
* Inotify events that can occur. Use with addWatch
42
* to define the events that should be watched.
44
* These flags correspond to the native Linux inotify flags.
47
EventAccess = 0x00000001, /**< File was accessed (read, compare inotify's IN_ACCESS) */
48
EventAttributeChange = 0x00000004, /**< Metadata changed (permissions, timestamps, extended attributes, etc., compare inotify's IN_ATTRIB) */
49
EventCloseWrite = 0x00000008, /**< File opened for writing was closed (compare inotify's IN_CLOSE_WRITE) */
50
EventCloseRead = 0x00000010, /**< File not opened for writing was closed (compare inotify's IN_CLOSE_NOWRITE) */
51
EventCreate = 0x00000100, /** File/directory created in watched directory (compare inotify's IN_CREATE) */
52
EventDelete = 0x00000200, /**< File/directory deleted from watched directory (compare inotify's IN_DELETE) */
53
EventDeleteSelf = 0x00000400, /**< Watched file/directory was itself deleted (compare inotify's IN_DELETE_SELF) */
54
EventModify = 0x00000002, /**< File was modified (compare inotify's IN_MODIFY) */
55
EventMoveSelf = 0x00000800, /**< Watched file/directory was itself moved (compare inotify's IN_MOVE_SELF) */
56
EventMoveFrom = 0x00000040, /**< File moved out of watched directory (compare inotify's IN_MOVED_FROM) */
57
EventMoveTo = 0x00000080, /**< File moved into watched directory (compare inotify's IN_MOVED_TO) */
58
EventOpen = 0x00000020, /**< File was opened (compare inotify's IN_OPEN) */
59
EventUnmount = 0x00002000, /**< Backing fs was unmounted (compare inotify's IN_UNMOUNT) */
60
EventQueueOverflow = 0x00004000, /**< Event queued overflowed (compare inotify's IN_Q_OVERFLOW) */
61
EventIgnored = 0x00008000, /**< File was ignored (compare inotify's IN_IGNORED) */
62
EventMove = (EventMoveFrom | EventMoveTo),
63
EventAll = (EventAccess |
64
EventAttributeChange |
76
Q_DECLARE_FLAGS(WatchEvents, WatchEvent)
81
* These flags correspond to the native Linux inotify flags.
84
FlagOnlyDir = 0x01000000, /**< Only watch the path if it is a directory (IN_ONLYDIR) */
85
FlagDoNotFollow = 0x02000000, /**< Don't follow a sym link (IN_DONT_FOLLOW) */
86
FlagOneShot = 0x80000000, /**< Only send event once (IN_ONESHOT) */
87
FlagExclUnlink = 0x04000000 /**< Do not generate events for unlinked files (IN_EXCL_UNLINK) */
89
Q_DECLARE_FLAGS(WatchFlags, WatchFlag)
92
* \return \p true if inotify is available and usable.
94
bool available() const;
96
bool watchingPath(const QString& path) const;
99
* Call this when the inotify limit has been increased.
101
void resetUserLimit();
105
* Called for every folder that is being watched.
106
* Returns true if the watch should be add or false if it should NOT be added.
108
virtual bool filterWatch(const QString& path, WatchEvents& modes, WatchFlags& flags);
111
virtual bool addWatch(const QString& path, WatchEvents modes, WatchFlags flags = WatchFlags());
112
bool removeWatch(const QString& path);
116
* Emitted if a file is accessed (KInotify::EventAccess)
118
void accessed(const QString& file);
121
* Emitted if file attributes are changed (KInotify::EventAttributeChange)
123
void attributeChanged(const QString& file);
126
* Emitted if FIXME (KInotify::EventCloseWrite)
128
void closedWrite(const QString& file);
131
* Emitted if FIXME (KInotify::EventCloseRead)
133
void closedRead(const QString& file);
136
* Emitted if a new file has been created in one of the watched
137
* folders (KInotify::EventCreate)
139
void created(const QString& file, bool isDir);
142
* Emitted if a watched file or folder has been deleted.
143
* This includes files in watched foldes (KInotify::EventDelete and KInotify::EventDeleteSelf)
145
void deleted(const QString& file, bool isDir);
148
* Emitted if a watched file is modified (KInotify::EventModify)
150
void modified(const QString& file);
153
* Emitted if a file or folder has been moved or renamed.
155
* \warning The moved signal will only be emitted if both the source and target folder
158
void moved(const QString& oldName, const QString& newName);
161
* Emitted if a file is opened (KInotify::EventOpen)
163
void opened(const QString& file);
166
* Emitted if a watched path has been unmounted (KInotify::EventUnmount)
168
void unmounted(const QString& file);
171
* Emitted if during updating the internal watch structures (recursive watches)
172
* the inotify user watch limit was reached.
174
* This means that not all requested paths can be watched until the user watch
175
* limit is increased.
177
* The argument is the path being added when the limit was reached.
179
* This signal will only be emitted once until resetUserLimit is called.
181
void watchUserLimitReached(const QString& path);
184
* This is emitted once watches have been installed in all the directories
185
* indicated by addWatch
187
void installedWatches();
191
void slotClearCookies();
197
Q_PRIVATE_SLOT(d, bool _k_addWatches())