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 QtCore 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 QFILEINFO_H
43
#define QFILEINFO_H
44
45
#include <QtCore/qfile.h>
46
#include <QtCore/qlist.h>
47
48
QT_BEGIN_HEADER
49
50
QT_BEGIN_NAMESPACE
51
52
QT_MODULE(Core)
53
54
class QDir;
55
class QDateTime;
56
class QFileInfoPrivate;
57
58
class Q_CORE_EXPORT QFileInfo
59
{
60
public:
61
    QFileInfo();
62
    QFileInfo(const QString &file);
63
    QFileInfo(const QFile &file);
64
    QFileInfo(const QDir &dir, const QString &file);
65
    QFileInfo(const QFileInfo &fileinfo);
66
    ~QFileInfo();
67
68
    QFileInfo &operator=(const QFileInfo &fileinfo);
69
    bool operator==(const QFileInfo &fileinfo); // 5.0 - remove me
70
    bool operator==(const QFileInfo &fileinfo) const;
71
    inline bool operator!=(const QFileInfo &fileinfo) { return !(operator==(fileinfo)); } // 5.0 - remove me
72
    inline bool operator!=(const QFileInfo &fileinfo) const { return !(operator==(fileinfo)); }
73
74
    void setFile(const QString &file);
75
    void setFile(const QFile &file);
76
    void setFile(const QDir &dir, const QString &file);
77
    bool exists() const;
78
    void refresh();
79
80
    QString filePath() const;
81
    QString absoluteFilePath() const;
82
    QString canonicalFilePath() const;
83
    QString fileName() const;
84
    QString baseName() const;
85
    QString completeBaseName() const;
86
    QString suffix() const;
87
    QString bundleName() const;
88
    QString completeSuffix() const;
89
90
    QString path() const;
91
    QString absolutePath() const;
92
    QString canonicalPath() const;
93
    QDir dir() const;
94
    QDir absoluteDir() const;
95
96
    bool isReadable() const;
97
    bool isWritable() const;
98
    bool isExecutable() const;
99
    bool isHidden() const;
100
101
    bool isRelative() const;
102
    inline bool isAbsolute() const { return !isRelative(); }
103
    bool makeAbsolute();
104
105
    bool isFile() const;
106
    bool isDir() const;
107
    bool isSymLink() const;
108
    bool isRoot() const;
109
    bool isBundle() const;
110
111
    QString readLink() const;
112
    inline QString symLinkTarget() const { return readLink(); }
113
114
    QString owner() const;
115
    uint ownerId() const;
116
    QString group() const;
117
    uint groupId() const;
118
119
    bool permission(QFile::Permissions permissions) const;
120
    QFile::Permissions permissions() const;
121
122
    qint64 size() const;
123
124
    QDateTime created() const;
125
    QDateTime lastModified() const;
126
    QDateTime lastRead() const;
127
128
    void detach();
129
130
    bool caching() const;
131
    void setCaching(bool on);
132
133
#ifdef QT3_SUPPORT
134
    enum Permission {
135
        ReadOwner = QFile::ReadOwner, WriteOwner = QFile::WriteOwner, ExeOwner = QFile::ExeOwner,
136
        ReadUser  = QFile::ReadUser,  WriteUser  = QFile::WriteUser,  ExeUser  = QFile::ExeUser,
137
        ReadGroup = QFile::ReadGroup, WriteGroup = QFile::WriteGroup, ExeGroup = QFile::ExeGroup,
138
        ReadOther = QFile::ReadOther, WriteOther = QFile::WriteOther, ExeOther = QFile::ExeOther
139
    };
140
    Q_DECLARE_FLAGS(PermissionSpec, Permission)
141
142
    inline QT3_SUPPORT QString baseName(bool complete) {
143
        if(complete)
144
            return completeBaseName();
145
        return baseName();
146
    }
147
    inline QT3_SUPPORT QString extension(bool complete = true) const {
148
        if(complete)
149
            return completeSuffix();
150
        return suffix();
151
    }
152
    inline QT3_SUPPORT QString absFilePath() const { return absoluteFilePath(); }
153
154
    inline QT3_SUPPORT QString dirPath(bool absPath = false) const {
155
        if(absPath)
156
            return absolutePath();
157
        return path();
158
    }
159
    QT3_SUPPORT QDir dir(bool absPath) const;
160
    inline QT3_SUPPORT bool convertToAbs() { return makeAbsolute(); }
161
#if !defined(Q_NO_TYPESAFE_FLAGS)
162
    inline QT3_SUPPORT bool permission(PermissionSpec permissions) const
163
    { return permission(QFile::Permissions(static_cast<int>(permissions))); }
164
#endif
165
#endif
166
167
protected:
168
    QFileInfoPrivate *d_ptr;
169
private:
170
    Q_DECLARE_PRIVATE(QFileInfo)
171
};
172
Q_DECLARE_TYPEINFO(QFileInfo, Q_MOVABLE_TYPE);
173
174
#ifdef QT3_SUPPORT
175
Q_DECLARE_OPERATORS_FOR_FLAGS(QFileInfo::PermissionSpec)
176
#endif
177
178
typedef QList<QFileInfo> QFileInfoList;
179
#ifdef QT3_SUPPORT
180
typedef QList<QFileInfo>::Iterator QFileInfoListIterator;
181
#endif
182
183
QT_END_NAMESPACE
184
185
QT_END_HEADER
186
187
#endif // QFILEINFO_H