only include Applications by default on OS X
[ambit.git] / src / qfileinfogatherer_p.h
blob74b01e9e0e2d8942b8c03fa0b4f3a047fad1217e
1 /****************************************************************************
2 **
3 ** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.
4 **
5 ** This file is part of the QtGui module of the Qt Toolkit.
6 **
7 ** This file may be used under the terms of the GNU General Public
8 ** License version 2.0 as published by the Free Software Foundation
9 ** and appearing in the file LICENSE.GPL included in the packaging of
10 ** this file. Please review the following information to ensure GNU
11 ** General Public Licensing requirements will be met:
12 ** http://www.trolltech.com/products/qt/opensource.html
14 ** If you are unsure which license is appropriate for your use, please
15 ** review the following information:
16 ** http://www.trolltech.com/products/qt/licensing.html or contact the
17 ** sales department at sales@trolltech.com.
19 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
20 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
22 ****************************************************************************/
24 #ifndef QFILEINFOGATHERER_H
25 #define QFILEINFOGATHERER_H
27 #include <qthread.h>
28 #include <qmutex.h>
29 #include <qwaitcondition.h>
30 #include <qfilesystemwatcher.h>
31 #if QT_VERSION >= 0x040300
32 #include <qfileiconprovider.h>
33 #else
34 #include <qdirmodel.h>
35 #endif
36 #include <qpair.h>
37 #include <qdatetime.h>
38 #include <qstack.h>
39 #include <qdir.h>
41 class QExtendedInformation {
42 public:
43 enum Type { Dir, File, System };
45 QExtendedInformation() : size(0), fileType(System), isHidden(false),
46 isSymLink(false), caseSensitive(true) {}
48 qint64 size;
49 QString displayType;
50 QIcon icon;
51 QDateTime lastModified;
52 QFile::Permissions permissions;
53 Type fileType;
54 bool isHidden : 1;
55 bool isSymLink : 1;
56 bool caseSensitive : 1;
58 inline bool isDir() { return fileType == Dir; }
59 inline bool isFile() { return fileType == File; }
60 inline bool isSystem() { return fileType == System; }
62 bool operator ==(const QExtendedInformation &fileInfo) const {
63 return fileInfo.size == size
64 && fileInfo.displayType == displayType
65 && fileInfo.lastModified == lastModified
66 && fileInfo.permissions == permissions
67 && fileInfo.fileType == fileType
68 && fileInfo.isHidden == isHidden
69 && fileInfo.isSymLink == isSymLink
70 && fileInfo.caseSensitive == caseSensitive;
72 void operator =(const QExtendedInformation &fileInfo) {
73 size = fileInfo.size;
74 displayType = fileInfo.displayType;
75 icon = fileInfo.icon;
76 lastModified = fileInfo.lastModified;
77 permissions = fileInfo.permissions;
78 fileType = fileInfo.fileType;
79 isHidden = fileInfo.isHidden;
80 isSymLink = fileInfo.isSymLink;
81 caseSensitive = fileInfo.caseSensitive;
85 class QFileIconProvider;
87 class Q_AUTOTEST_EXPORT QFileInfoGatherer : public QThread
89 Q_OBJECT
91 Q_SIGNALS:
92 void updates(const QString &directory, const QList<QPair<QString, QExtendedInformation> > &updates);
93 void newListOfFiles(const QString &directory, const QStringList &listOfFiles) const;
94 void nameResolved(const QString &fileName, const QString &resolvedName) const;
96 public:
97 QFileInfoGatherer(QObject *parent = 0);
98 ~QFileInfoGatherer();
100 void clear();
101 QExtendedInformation getInfo(const QFileInfo &info) const;
103 public Q_SLOTS:
104 void list(const QString &directoryPath);
105 void fetchExtendedInformation(const QString &path, const QStringList &files);
106 void updateFile(const QString &path);
107 void setResolveSymlinks(bool enable);
108 bool resolveSymlinks() const;
109 void setIconProvider(QFileIconProvider *provider);
110 QFileIconProvider *iconProvider() const;
112 protected:
113 void run();
114 void getFileInfos(const QString &path, const QStringList &files);
116 private:
117 void fetch(const QFileInfo &info, QTime &base, bool &firstTime, QList<QPair<QString,QExtendedInformation> > &updatedFiles, const QString &path);
118 QString translateDriveName(const QFileInfo &drive) const;
119 QFile::Permissions translatePermissions(const QFileInfo &fileInfo) const;
121 QMutex mutex;
122 QWaitCondition condition;
123 bool abort;
125 QStack<QString> path;
126 QStack<QStringList> files;
128 QFileSystemWatcher *watcher;
129 bool m_resolveSymlinks;
130 QFileIconProvider *m_iconProvider;
131 QFileIconProvider defaultProvider;
132 #ifndef Q_OS_WIN
133 uint userId;
134 uint groupId;
135 #endif
138 #endif // QFILEINFOGATHERER_H