source: trunk/src/gui/dialogs/qfileinfogatherer_p.h@ 187

Last change on this file since 187 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 6.2 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the QtGui module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
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
67QT_BEGIN_NAMESPACE
68
69class QExtendedInformation {
70public:
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
141private :
142 QFileInfo mFileInfo;
143 QFile::Permissions mPermissions;
144};
145
146class QFileIconProvider;
147
148#ifndef QT_NO_FILESYSTEMMODEL
149
150class Q_AUTOTEST_EXPORT QFileInfoGatherer : public QThread
151{
152Q_OBJECT
153
154Q_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
159public:
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
167public 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
176protected:
177 void run();
178 void getFileInfos(const QString &path, const QStringList &files);
179
180private:
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 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
202public :
203 //for testing purpose
204 static bool fetchedRoot;
205};
206#endif // QT_NO_FILESYSTEMMODEL
207
208
209QT_END_NAMESPACE
210#endif // QFILEINFOGATHERER_H
211
Note: See TracBrowser for help on using the repository browser.