src/corelib/io/qfilesystemwatcher_win_p.h
changeset 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     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 <qt_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 QWindowsFileSystemWatcherEngineThread;
       
    72 
       
    73 // Even though QWindowsFileSystemWatcherEngine is derived of QThread
       
    74 // via QFileSystemWatcher, it does not start a thread.
       
    75 // Instead QWindowsFileSystemWatcher creates QWindowsFileSystemWatcherEngineThreads
       
    76 // to do the actually watching.
       
    77 class QWindowsFileSystemWatcherEngine : public QFileSystemWatcherEngine
       
    78 {
       
    79     Q_OBJECT
       
    80 public:
       
    81     QWindowsFileSystemWatcherEngine();
       
    82     ~QWindowsFileSystemWatcherEngine();
       
    83 
       
    84     QStringList addPaths(const QStringList &paths, QStringList *files, QStringList *directories);
       
    85     QStringList removePaths(const QStringList &paths, QStringList *files, QStringList *directories);
       
    86 
       
    87     void stop();
       
    88 
       
    89 
       
    90     class Handle
       
    91     {
       
    92     public:
       
    93         HANDLE handle;
       
    94         uint flags;
       
    95 
       
    96         Handle()
       
    97                 : handle(INVALID_HANDLE_VALUE), flags(0u)
       
    98         { }
       
    99         Handle(const Handle &other)
       
   100                 : handle(other.handle), flags(other.flags)
       
   101         { }
       
   102     };
       
   103 
       
   104     class PathInfo {
       
   105     public:
       
   106         QString absolutePath;
       
   107         QString path;
       
   108         bool isDir;
       
   109 
       
   110         // fileinfo bits
       
   111         uint ownerId;
       
   112         uint groupId;
       
   113         QFile::Permissions permissions;
       
   114         QDateTime lastModified;
       
   115 
       
   116         PathInfo &operator=(const QFileInfo &fileInfo)
       
   117                            {
       
   118             ownerId = fileInfo.ownerId();
       
   119             groupId = fileInfo.groupId();
       
   120             permissions = fileInfo.permissions();
       
   121             lastModified = fileInfo.lastModified();
       
   122             return *this;
       
   123         }
       
   124 
       
   125         bool operator!=(const QFileInfo &fileInfo) const
       
   126         {
       
   127             return (ownerId != fileInfo.ownerId()
       
   128                     || groupId != fileInfo.groupId()
       
   129                     || permissions != fileInfo.permissions()
       
   130                     || lastModified != fileInfo.lastModified());
       
   131         }
       
   132     };
       
   133 private:
       
   134     QList<QWindowsFileSystemWatcherEngineThread *> threads;
       
   135 
       
   136 };
       
   137 
       
   138 class QWindowsFileSystemWatcherEngineThread : public QThread
       
   139 {
       
   140     Q_OBJECT
       
   141 
       
   142 public:
       
   143     QWindowsFileSystemWatcherEngineThread();
       
   144     ~QWindowsFileSystemWatcherEngineThread();
       
   145     void run();
       
   146     void stop();
       
   147     void wakeup();
       
   148 
       
   149     QMutex mutex;
       
   150     QVector<HANDLE> handles;
       
   151     int msg;
       
   152 
       
   153     QHash<QString, QWindowsFileSystemWatcherEngine::Handle> handleForDir;
       
   154 
       
   155     QHash<HANDLE, QHash<QString, QWindowsFileSystemWatcherEngine::PathInfo> > pathInfoForHandle;
       
   156 
       
   157 Q_SIGNALS:
       
   158     void fileChanged(const QString &path, bool removed);
       
   159     void directoryChanged(const QString &path, bool removed);
       
   160 };
       
   161 
       
   162 #endif // QT_NO_FILESYSTEMWATCHER
       
   163 
       
   164 QT_END_NAMESPACE
       
   165 
       
   166 #endif // QFILESYSTEMWATCHER_WIN_P_H