1
/****************************************************************************
2
**
3
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4
** All rights reserved.
5
** Contact: Nokia Corporation (qt-info@nokia.com)
6
**
7
** This file is part of the QtCore module of the Qt Toolkit.
8
**
9
** $QT_BEGIN_LICENSE:LGPL$
10
** No Commercial Usage
11
** This file contains pre-release code and may not be distributed.
12
** You may use this file in accordance with the terms and conditions
13
** contained in the Technology Preview License Agreement accompanying
14
** this package.
15
**
16
** GNU Lesser General Public License Usage
17
** Alternatively, this file may be used under the terms of the GNU Lesser
18
** General Public License version 2.1 as published by the Free Software
19
** Foundation and appearing in the file LICENSE.LGPL included in the
20
** packaging of this file.  Please review the following information to
21
** ensure the GNU Lesser General Public License version 2.1 requirements
22
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23
**
24
** In addition, as a special exception, Nokia gives you certain additional
25
** rights.  These rights are described in the Nokia Qt LGPL Exception
26
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27
**
28
** If you have questions regarding the use of this file, please contact
29
** Nokia at qt-info@nokia.com.
30
**
31
**
32
**
33
**
34
**
35
**
36
**
37
**
38
** $QT_END_LICENSE$
39
**
40
****************************************************************************/
41
42
#ifndef QFILESYSTEMWATCHER_WIN_P_H
43
#define QFILESYSTEMWATCHER_WIN_P_H
44
45
//
46
//  W A R N I N G
47
//  -------------
48
//
49
// This file is not part of the Qt API.  It exists for the convenience
50
// of the QLibrary class.  This header file may change from
51
// version to version without notice, or even be removed.
52
//
53
// We mean it.
54
//
55
56
#include "qfilesystemwatcher_p.h"
57
58
#ifndef QT_NO_FILESYSTEMWATCHER
59
60
#include <windows.h>
61
62
#include <QtCore/qdatetime.h>
63
#include <QtCore/qfile.h>
64
#include <QtCore/qfileinfo.h>
65
#include <QtCore/qhash.h>
66
#include <QtCore/qmutex.h>
67
#include <QtCore/qvector.h>
68
69
QT_BEGIN_NAMESPACE
70
71
class QWindowsFileSystemWatcherEngine : public QFileSystemWatcherEngine
72
{
73
    Q_OBJECT
74
75
public:
76
    QWindowsFileSystemWatcherEngine();
77
    ~QWindowsFileSystemWatcherEngine();
78
79
    void run();
80
81
    QStringList addPaths(const QStringList &paths, QStringList *files, QStringList *directories);
82
    QStringList removePaths(const QStringList &paths, QStringList *files, QStringList *directories);
83
84
    void stop();
85
86
private:
87
    void wakeup();
88
89
    QMutex mutex;
90
    QVector<HANDLE> handles;
91
    int msg;
92
93
    class Handle
94
    {
95
    public:
96
        HANDLE handle;
97
        uint flags;
98
99
        Handle()
100
            : handle(INVALID_HANDLE_VALUE), flags(0u)
101
        { }
102
        Handle(const Handle &other)
103
            : handle(other.handle), flags(other.flags)
104
        { }
105
    };
106
    QHash<QString, Handle> handleForDir;
107
108
    class PathInfo {
109
    public:
110
        QString absolutePath;
111
        QString path;
112
        bool isDir;
113
114
        // fileinfo bits
115
        uint ownerId;
116
        uint groupId;
117
        QFile::Permissions permissions;
118
        QDateTime lastModified;
119
120
        PathInfo &operator=(const QFileInfo &fileInfo)
121
        {
122
            ownerId = fileInfo.ownerId();
123
            groupId = fileInfo.groupId();
124
            permissions = fileInfo.permissions();
125
            lastModified = fileInfo.lastModified();
126
            return *this;
127
        }
128
129
        bool operator!=(const QFileInfo &fileInfo) const
130
        {
131
            return (ownerId != fileInfo.ownerId()
132
                    || groupId != fileInfo.groupId()
133
                    || permissions != fileInfo.permissions()
134
                    || lastModified != fileInfo.lastModified());
135
        }
136
    };
137
    QHash<HANDLE, QHash<QString, PathInfo> > pathInfoForHandle;
138
};
139
#endif // QT_NO_FILESYSTEMWATCHER
140
141
QT_END_NAMESPACE
142
143
#endif // QFILESYSTEMWATCHER_WIN_P_H