Qt 4.8
qfileinfogatherer_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QFILEINFOGATHERER_H
43 #define QFILEINFOGATHERER_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 purely as an
50 // implementation detail. This header file may change from version to
51 // version without notice, or even be removed.
52 //
53 // We mean it.
54 //
55 
56 #include <qthread.h>
57 #include <qmutex.h>
58 #include <qwaitcondition.h>
59 #include <qfilesystemwatcher.h>
60 #include <qfileiconprovider.h>
61 #include <qfsfileengine.h>
62 #include <qpair.h>
63 #include <qstack.h>
64 #include <qdatetime.h>
65 #include <qdir.h>
66 #include <qelapsedtimer.h>
67 
69 
71 public:
72  enum Type { Dir, File, System };
73 
76 
77  inline bool isDir() { return type() == Dir; }
78  inline bool isFile() { return type() == File; }
79  inline bool isSystem() { return type() == System; }
80 
82  return mFileInfo == fileInfo.mFileInfo
83  && displayType == fileInfo.displayType
84  && permissions() == fileInfo.permissions();
85  }
86 
87 #ifndef QT_NO_FSFILEENGINE
88  bool isCaseSensitive() const {
90  return fe.caseSensitive();
91  }
92 #endif
93 
94  QFile::Permissions permissions() const {
95  return mFileInfo.permissions();
96  }
97 
98  Type type() const {
99  if (mFileInfo.isDir()) {
101  }
102  if (mFileInfo.isFile()) {
104  }
105  if (!mFileInfo.exists() && mFileInfo.isSymLink()) {
107  }
109  }
110 
111  bool isSymLink(bool ignoreNtfsSymLinks = false) const
112  {
113  if (ignoreNtfsSymLinks) {
114 #ifdef Q_WS_WIN
116 #endif
117  }
118  return mFileInfo.isSymLink();
119  }
120 
121  bool isHidden() const {
122  return mFileInfo.isHidden();
123  }
124 
125  QFileInfo fileInfo() const {
126  return mFileInfo;
127  }
128 
130  return mFileInfo.lastModified();
131  }
132 
133  qint64 size() const {
134  qint64 size = -1;
136  size = 0;
138  size = mFileInfo.size();
139  if (!mFileInfo.exists() && !mFileInfo.isSymLink())
140  size = -1;
141  return size;
142  }
143 
146 
147 private :
149 };
150 
151 class QFileIconProvider;
152 
153 #ifndef QT_NO_FILESYSTEMMODEL
154 
156 {
157 Q_OBJECT
158 
159 Q_SIGNALS:
160  void updates(const QString &directory, const QList<QPair<QString, QFileInfo> > &updates);
161  void newListOfFiles(const QString &directory, const QStringList &listOfFiles) const;
162  void nameResolved(const QString &fileName, const QString &resolvedName) const;
163  void directoryLoaded(const QString &path);
164 
165 public:
166  QFileInfoGatherer(QObject *parent = 0);
168 
169  void clear();
170  void removePath(const QString &path);
171  QExtendedInformation getInfo(const QFileInfo &info) const;
172 
173 public Q_SLOTS:
174  void list(const QString &directoryPath);
175  void fetchExtendedInformation(const QString &path, const QStringList &files);
176  void updateFile(const QString &path);
177  void setResolveSymlinks(bool enable);
178  bool resolveSymlinks() const;
179  void setIconProvider(QFileIconProvider *provider);
180  QFileIconProvider *iconProvider() const;
181 
182 protected:
183  void run();
184  void getFileInfos(const QString &path, const QStringList &files);
185 
186 private:
187  void fetch(const QFileInfo &info, QElapsedTimer &base, bool &firstTime, QList<QPair<QString, QFileInfo> > &updatedFiles, const QString &path);
188  QString translateDriveName(const QFileInfo &drive) const;
189 
192  volatile bool abort;
193 
196 
197 #ifndef QT_NO_FILESYSTEMWATCHER
199 #endif
203 #ifndef Q_OS_WIN
204  uint userId;
205  uint groupId;
206 #endif
207 };
208 #endif // QT_NO_FILESYSTEMMODEL
209 
210 
212 #endif // QFILEINFOGATHERER_H
213 
bool operator==(const QExtendedInformation &fileInfo) const
QStack< QStringList > files
QFile::Permissions permissions() const
bool isHidden() const
Returns true if this is a `hidden&#39; file; otherwise returns false.
Definition: qfileinfo.cpp:951
static mach_timebase_info_data_t info
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
The QMutex class provides access serialization between threads.
Definition: qmutex.h:60
The QFileSystemWatcher class provides an interface for monitoring files and directories for modificat...
static void clear(QVariant::Private *d)
Definition: qvariant.cpp:197
QFileIconProvider defaultProvider
QString absoluteFilePath() const
Returns an absolute path including the file name.
Definition: qfileinfo.cpp:534
QFileSystemWatcher * watcher
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
bool exists() const
Returns true if the file exists; otherwise returns false.
Definition: qfileinfo.cpp:675
#define Q_SLOTS
Definition: qobjectdefs.h:71
The QString class provides a Unicode character string.
Definition: qstring.h:83
QFile::Permissions permissions() const
Returns the complete OR-ed together combination of QFile::Permissions for the file.
Definition: qfileinfo.cpp:1228
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
#define Q_SIGNALS
Definition: qobjectdefs.h:72
The QElapsedTimer class provides a fast way to calculate elapsed times.
Definition: qelapsedtimer.h:53
static const uint base
Definition: qurl.cpp:268
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
bool isDir() const
Returns true if this object points to a directory or to a symbolic link to a directory; otherwise ret...
Definition: qfileinfo.cpp:990
QDateTime lastModified() const
QFileInfo fileInfo() const
bool isSymLink(bool ignoreNtfsSymLinks=false) const
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
QStack< QString > path
The QFileIconProvider class provides file icons for the QDirModel and the QFileSystemModel classes...
bool caseSensitive() const
Returns true for Windows, false for Unix.
unsigned int uint
Definition: qglobal.h:996
QFileIconProvider * m_iconProvider
__int64 qint64
Definition: qglobal.h:942
#define Q_OBJECT
Definition: qobjectdefs.h:157
QWaitCondition condition
int compare(const QString &s) const
Definition: qstring.cpp:5037
qint64 size() const
Returns the file size in bytes.
Definition: qfileinfo.cpp:1248
The QDateTime class provides date and time functions.
Definition: qdatetime.h:216
QString suffix() const
Returns the suffix of the file.
Definition: qfileinfo.cpp:834
#define Q_AUTOTEST_EXPORT
Definition: qglobal.h:1510
bool isFile() const
Returns true if this object points to a file or to a symbolic link to a file.
Definition: qfileinfo.cpp:971
QFuture< T > run(Function function,...)
QExtendedInformation(const QFileInfo &info)
bool isSymLink() const
Returns true if this object points to a symbolic link (or to a shortcut on Windows); otherwise return...
Definition: qfileinfo.cpp:1044
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:60
The QThread class provides a platform-independent way to manage threads.
Definition: qthread.h:59
#define private
Definition: qregion_qws.cpp:43
static QString fileName(const QString &fileUrl)
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
The QFSFileEngine class implements Qt&#39;s default file engine.
Definition: qfsfileengine.h:60
QDateTime lastModified() const
Returns the date and time when the file was last modified.
Definition: qfileinfo.cpp:1296
The QIcon class provides scalable icons in different modes and states.
Definition: qicon.h:60