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

Last change on this file was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 6.0 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 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** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
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** 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 have questions regarding the use of this file, please contact
37** Nokia at qt-info@nokia.com.
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
68QT_BEGIN_NAMESPACE
69
70class QExtendedInformation {
71public:
72 enum Type { Dir, File, System };
73
74 QExtendedInformation() {}
75 QExtendedInformation(const QFileInfo &info) : mFileInfo(info) {}
76
77 inline bool isDir() { return type() == Dir; }
78 inline bool isFile() { return type() == File; }
79 inline bool isSystem() { return type() == System; }
80
81 bool operator ==(const QExtendedInformation &fileInfo) const {
82 return mFileInfo == fileInfo.mFileInfo
83 && displayType == fileInfo.displayType
84 && permissions() == fileInfo.permissions();
85 }
86
87 bool isCaseSensitive() const {
88 QFSFileEngine fe(mFileInfo.absoluteFilePath());
89 return fe.caseSensitive();
90 }
91 QFile::Permissions permissions() const {
92 return mFileInfo.permissions();
93 }
94
95 Type type() const {
96 if (mFileInfo.isDir()) {
97 return QExtendedInformation::Dir;
98 }
99 if (mFileInfo.isFile()) {
100 return QExtendedInformation::File;
101 }
102 if (!mFileInfo.exists() && mFileInfo.isSymLink()) {
103 return QExtendedInformation::System;
104 }
105 return QExtendedInformation::System;
106 }
107
108 bool isSymLink() const {
109 return mFileInfo.isSymLink();
110 }
111
112 bool isHidden() const {
113 return mFileInfo.isHidden();
114 }
115
116 QFileInfo fileInfo() const {
117 return mFileInfo;
118 }
119
120 QDateTime lastModified() const {
121 return mFileInfo.lastModified();
122 }
123
124 qint64 size() const {
125 qint64 size = -1;
126 if (type() == QExtendedInformation::Dir)
127 size = 0;
128 if (type() == QExtendedInformation::File)
129 size = mFileInfo.size();
130 if (!mFileInfo.exists() && !mFileInfo.isSymLink())
131 size = -1;
132 return size;
133 }
134
135 QString displayType;
136 QIcon icon;
137
138private :
139 QFileInfo mFileInfo;
140};
141
142class QFileIconProvider;
143
144#ifndef QT_NO_FILESYSTEMMODEL
145
146class Q_AUTOTEST_EXPORT QFileInfoGatherer : public QThread
147{
148Q_OBJECT
149
150Q_SIGNALS:
151 void updates(const QString &directory, const QList<QPair<QString, QFileInfo> > &updates);
152 void newListOfFiles(const QString &directory, const QStringList &listOfFiles) const;
153 void nameResolved(const QString &fileName, const QString &resolvedName) const;
154 void directoryLoaded(const QString &path);
155
156public:
157 QFileInfoGatherer(QObject *parent = 0);
158 ~QFileInfoGatherer();
159
160 void clear();
161 void removePath(const QString &path);
162 QExtendedInformation getInfo(const QFileInfo &info) const;
163
164public Q_SLOTS:
165 void list(const QString &directoryPath);
166 void fetchExtendedInformation(const QString &path, const QStringList &files);
167 void updateFile(const QString &path);
168 void setResolveSymlinks(bool enable);
169 bool resolveSymlinks() const;
170 void setIconProvider(QFileIconProvider *provider);
171 QFileIconProvider *iconProvider() const;
172
173protected:
174 void run();
175 void getFileInfos(const QString &path, const QStringList &files);
176
177private:
178 void fetch(const QFileInfo &info, QElapsedTimer &base, bool &firstTime, QList<QPair<QString, QFileInfo> > &updatedFiles, const QString &path);
179 QString translateDriveName(const QFileInfo &drive) const;
180
181 QMutex mutex;
182 QWaitCondition condition;
183 volatile bool abort;
184
185 QStack<QString> path;
186 QStack<QStringList> files;
187
188#ifndef QT_NO_FILESYSTEMWATCHER
189 QFileSystemWatcher *watcher;
190#endif
191 bool m_resolveSymlinks;
192 QFileIconProvider *m_iconProvider;
193 QFileIconProvider defaultProvider;
194#ifndef Q_OS_WIN
195 uint userId;
196 uint groupId;
197#endif
198};
199#endif // QT_NO_FILESYSTEMMODEL
200
201
202QT_END_NAMESPACE
203#endif // QFILEINFOGATHERER_H
204
Note: See TracBrowser for help on using the repository browser.