0
|
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 QtGui 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 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 <qdatetime.h>
|
|
64 |
#include <qstack.h>
|
|
65 |
#include <qdir.h>
|
|
66 |
|
|
67 |
QT_BEGIN_NAMESPACE
|
|
68 |
|
|
69 |
class QExtendedInformation {
|
|
70 |
public:
|
|
71 |
enum Type { Dir, File, System };
|
|
72 |
|
|
73 |
QExtendedInformation() {}
|
|
74 |
QExtendedInformation(const QFileInfo &info) : mFileInfo(info) {}
|
|
75 |
|
|
76 |
inline bool isDir() { return type() == Dir; }
|
|
77 |
inline bool isFile() { return type() == File; }
|
|
78 |
inline bool isSystem() { return type() == System; }
|
|
79 |
|
|
80 |
bool operator ==(const QExtendedInformation &fileInfo) const {
|
|
81 |
return mFileInfo == fileInfo.mFileInfo
|
|
82 |
&& displayType == fileInfo.displayType
|
|
83 |
&& permissions() == fileInfo.permissions();
|
|
84 |
}
|
|
85 |
|
|
86 |
bool isCaseSensitive() const {
|
|
87 |
QFSFileEngine fe(mFileInfo.absoluteFilePath());
|
|
88 |
return fe.caseSensitive();
|
|
89 |
}
|
|
90 |
QFile::Permissions permissions() const {
|
|
91 |
return mPermissions;
|
|
92 |
}
|
|
93 |
|
|
94 |
void setPermissions (QFile::Permissions permissions) {
|
|
95 |
mPermissions = permissions;
|
|
96 |
}
|
|
97 |
|
|
98 |
Type type() const {
|
|
99 |
if (mFileInfo.isDir()) {
|
|
100 |
return QExtendedInformation::Dir;
|
|
101 |
}
|
|
102 |
if (mFileInfo.isFile()) {
|
|
103 |
return QExtendedInformation::File;
|
|
104 |
}
|
|
105 |
if (!mFileInfo.exists() && mFileInfo.isSymLink()) {
|
|
106 |
return QExtendedInformation::System;
|
|
107 |
}
|
|
108 |
return QExtendedInformation::System;
|
|
109 |
}
|
|
110 |
|
|
111 |
bool isSymLink() const {
|
|
112 |
return mFileInfo.isSymLink();
|
|
113 |
}
|
|
114 |
|
|
115 |
bool isHidden() const {
|
|
116 |
return mFileInfo.isHidden();
|
|
117 |
}
|
|
118 |
|
|
119 |
QFileInfo fileInfo() const {
|
|
120 |
return mFileInfo;
|
|
121 |
}
|
|
122 |
|
|
123 |
QDateTime lastModified() const {
|
|
124 |
return mFileInfo.lastModified();
|
|
125 |
}
|
|
126 |
|
|
127 |
qint64 size() const {
|
|
128 |
qint64 size = -1;
|
|
129 |
if (type() == QExtendedInformation::Dir)
|
|
130 |
size = 0;
|
|
131 |
if (type() == QExtendedInformation::File)
|
|
132 |
size = mFileInfo.size();
|
|
133 |
if (!mFileInfo.exists() && !mFileInfo.isSymLink())
|
|
134 |
size = -1;
|
|
135 |
return size;
|
|
136 |
}
|
|
137 |
|
|
138 |
QString displayType;
|
|
139 |
QIcon icon;
|
|
140 |
|
|
141 |
private :
|
|
142 |
QFileInfo mFileInfo;
|
|
143 |
QFile::Permissions mPermissions;
|
|
144 |
};
|
|
145 |
|
|
146 |
class QFileIconProvider;
|
|
147 |
|
|
148 |
#ifndef QT_NO_FILESYSTEMMODEL
|
|
149 |
|
|
150 |
class Q_AUTOTEST_EXPORT QFileInfoGatherer : public QThread
|
|
151 |
{
|
|
152 |
Q_OBJECT
|
|
153 |
|
|
154 |
Q_SIGNALS:
|
|
155 |
void updates(const QString &directory, const QList<QPair<QString, QFileInfo> > &updates);
|
|
156 |
void newListOfFiles(const QString &directory, const QStringList &listOfFiles) const;
|
|
157 |
void nameResolved(const QString &fileName, const QString &resolvedName) const;
|
|
158 |
|
|
159 |
public:
|
|
160 |
QFileInfoGatherer(QObject *parent = 0);
|
|
161 |
~QFileInfoGatherer();
|
|
162 |
|
|
163 |
void clear();
|
|
164 |
void removePath(const QString &path);
|
|
165 |
QExtendedInformation getInfo(const QFileInfo &info) const;
|
|
166 |
|
|
167 |
public Q_SLOTS:
|
|
168 |
void list(const QString &directoryPath);
|
|
169 |
void fetchExtendedInformation(const QString &path, const QStringList &files);
|
|
170 |
void updateFile(const QString &path);
|
|
171 |
void setResolveSymlinks(bool enable);
|
|
172 |
bool resolveSymlinks() const;
|
|
173 |
void setIconProvider(QFileIconProvider *provider);
|
|
174 |
QFileIconProvider *iconProvider() const;
|
|
175 |
|
|
176 |
protected:
|
|
177 |
void run();
|
|
178 |
void getFileInfos(const QString &path, const QStringList &files);
|
|
179 |
|
|
180 |
private:
|
|
181 |
void fetch(const QFileInfo &info, QTime &base, bool &firstTime, QList<QPair<QString, QFileInfo> > &updatedFiles, const QString &path);
|
|
182 |
QString translateDriveName(const QFileInfo &drive) const;
|
|
183 |
QFile::Permissions translatePermissions(const QFileInfo &fileInfo) const;
|
|
184 |
|
|
185 |
QMutex mutex;
|
|
186 |
QWaitCondition condition;
|
|
187 |
volatile bool abort;
|
|
188 |
|
|
189 |
QStack<QString> path;
|
|
190 |
QStack<QStringList> files;
|
|
191 |
|
|
192 |
#ifndef QT_NO_FILESYSTEMWATCHER
|
|
193 |
QFileSystemWatcher *watcher;
|
|
194 |
#endif
|
|
195 |
bool m_resolveSymlinks;
|
|
196 |
QFileIconProvider *m_iconProvider;
|
|
197 |
QFileIconProvider defaultProvider;
|
|
198 |
#ifndef Q_OS_WIN
|
|
199 |
uint userId;
|
|
200 |
uint groupId;
|
|
201 |
#endif
|
|
202 |
public :
|
|
203 |
//for testing purpose
|
|
204 |
static bool fetchedRoot;
|
|
205 |
};
|
|
206 |
#endif // QT_NO_FILESYSTEMMODEL
|
|
207 |
|
|
208 |
|
|
209 |
QT_END_NAMESPACE
|
|
210 |
#endif // QFILEINFOGATHERER_H
|
|
211 |
|