~ubuntu-branches/debian/sid/baloo-kf5/sid

« back to all changes in this revision

Viewing changes to src/file/kinotify.h

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2014-07-10 21:13:07 UTC
  • Revision ID: package-import@ubuntu.com-20140710211307-iku0qs6vlplgn06m
Tags: upstream-5.0.0b
ImportĀ upstreamĀ versionĀ 5.0.0b

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of the KDE libraries
 
2
   Copyright (C) 2007-2010 Sebastian Trueg <trueg@kde.org>
 
3
 
 
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.
 
8
 
 
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.
 
13
 
 
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.
 
18
*/
 
19
 
 
20
#ifndef _KINOTIFY_H_
 
21
#define _KINOTIFY_H_
 
22
 
 
23
#include <QObject>
 
24
 
 
25
/**
 
26
 * A simple wrapper around inotify which only allows
 
27
 * to add folders recursively.
 
28
 *
 
29
 * Warning: moving of top-level folders is not supported and
 
30
 * results in undefined behaviour.
 
31
 */
 
32
class KInotify : public QObject
 
33
{
 
34
    Q_OBJECT
 
35
 
 
36
public:
 
37
    KInotify(QObject* parent = 0);
 
38
    virtual ~KInotify();
 
39
 
 
40
    /**
 
41
     * Inotify events that can occur. Use with addWatch
 
42
     * to define the events that should be watched.
 
43
     *
 
44
     * These flags correspond to the native Linux inotify flags.
 
45
     */
 
46
    enum WatchEvent {
 
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 |
 
65
                    EventCloseWrite |
 
66
                    EventCloseRead |
 
67
                    EventCreate |
 
68
                    EventDelete |
 
69
                    EventDeleteSelf |
 
70
                    EventModify |
 
71
                    EventMoveSelf |
 
72
                    EventMoveFrom |
 
73
                    EventMoveTo |
 
74
                    EventOpen)
 
75
    };
 
76
    Q_DECLARE_FLAGS(WatchEvents, WatchEvent)
 
77
 
 
78
    /**
 
79
     * Watch flags
 
80
     *
 
81
     * These flags correspond to the native Linux inotify flags.
 
82
     */
 
83
    enum WatchFlag {
 
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) */
 
88
    };
 
89
    Q_DECLARE_FLAGS(WatchFlags, WatchFlag)
 
90
 
 
91
    /**
 
92
     * \return \p true if inotify is available and usable.
 
93
     */
 
94
    bool available() const;
 
95
 
 
96
    bool watchingPath(const QString& path) const;
 
97
 
 
98
    /**
 
99
     * Call this when the inotify limit has been increased.
 
100
     */
 
101
    void resetUserLimit();
 
102
 
 
103
protected:
 
104
    /**
 
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.
 
107
     */
 
108
    virtual bool filterWatch(const QString& path, WatchEvents& modes, WatchFlags& flags);
 
109
 
 
110
public Q_SLOTS:
 
111
    virtual bool addWatch(const QString& path, WatchEvents modes, WatchFlags flags = WatchFlags());
 
112
    bool removeWatch(const QString& path);
 
113
 
 
114
Q_SIGNALS:
 
115
    /**
 
116
     * Emitted if a file is accessed (KInotify::EventAccess)
 
117
     */
 
118
    void accessed(const QString& file);
 
119
 
 
120
    /**
 
121
     * Emitted if file attributes are changed (KInotify::EventAttributeChange)
 
122
     */
 
123
    void attributeChanged(const QString& file);
 
124
 
 
125
    /**
 
126
     * Emitted if FIXME (KInotify::EventCloseWrite)
 
127
     */
 
128
    void closedWrite(const QString& file);
 
129
 
 
130
    /**
 
131
     * Emitted if FIXME (KInotify::EventCloseRead)
 
132
     */
 
133
    void closedRead(const QString& file);
 
134
 
 
135
    /**
 
136
     * Emitted if a new file has been created in one of the watched
 
137
     * folders (KInotify::EventCreate)
 
138
     */
 
139
    void created(const QString& file, bool isDir);
 
140
 
 
141
    /**
 
142
     * Emitted if a watched file or folder has been deleted.
 
143
     * This includes files in watched foldes (KInotify::EventDelete and KInotify::EventDeleteSelf)
 
144
     */
 
145
    void deleted(const QString& file, bool isDir);
 
146
 
 
147
    /**
 
148
     * Emitted if a watched file is modified (KInotify::EventModify)
 
149
     */
 
150
    void modified(const QString& file);
 
151
 
 
152
    /**
 
153
     * Emitted if a file or folder has been moved or renamed.
 
154
     *
 
155
     * \warning The moved signal will only be emitted if both the source and target folder
 
156
     * are being watched.
 
157
     */
 
158
    void moved(const QString& oldName, const QString& newName);
 
159
 
 
160
    /**
 
161
     * Emitted if a file is opened (KInotify::EventOpen)
 
162
     */
 
163
    void opened(const QString& file);
 
164
 
 
165
    /**
 
166
     * Emitted if a watched path has been unmounted (KInotify::EventUnmount)
 
167
     */
 
168
    void unmounted(const QString& file);
 
169
 
 
170
    /**
 
171
     * Emitted if during updating the internal watch structures (recursive watches)
 
172
     * the inotify user watch limit was reached.
 
173
     *
 
174
     * This means that not all requested paths can be watched until the user watch
 
175
     * limit is increased.
 
176
     *
 
177
     * The argument is the path being added when the limit was reached.
 
178
     *
 
179
     * This signal will only be emitted once until resetUserLimit is called.
 
180
     */
 
181
    void watchUserLimitReached(const QString& path);
 
182
 
 
183
    /**
 
184
     * This is emitted once watches have been installed in all the directories
 
185
     * indicated by addWatch
 
186
     */
 
187
    void installedWatches();
 
188
 
 
189
private Q_SLOTS:
 
190
    void slotEvent(int);
 
191
    void slotClearCookies();
 
192
 
 
193
private:
 
194
    class Private;
 
195
    Private* const d;
 
196
 
 
197
    Q_PRIVATE_SLOT(d, bool _k_addWatches())
 
198
};
 
199
 
 
200
#endif