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 QFILE_H
43
#define QFILE_H
44
45
#include <QtCore/qiodevice.h>
46
#include <QtCore/qstring.h>
47
#include <stdio.h>
48
49
#ifdef open
50
#error qfile.h must be included before any header file that defines open
51
#endif
52
53
QT_BEGIN_HEADER
54
55
QT_BEGIN_NAMESPACE
56
57
QT_MODULE(Core)
58
59
class QAbstractFileEngine;
60
class QFilePrivate;
61
62
class Q_CORE_EXPORT QFile : public QIODevice
63
{
64
#ifndef QT_NO_QOBJECT
65
    Q_OBJECT
66
#endif
67
    Q_DECLARE_PRIVATE(QFile)
68
69
public:
70
71
    enum FileError {
72
        NoError = 0,
73
        ReadError = 1,
74
        WriteError = 2,
75
        FatalError = 3,
76
        ResourceError = 4,
77
        OpenError = 5,
78
        AbortError = 6,
79
        TimeOutError = 7,
80
        UnspecifiedError = 8,
81
        RemoveError = 9,
82
        RenameError = 10,
83
        PositionError = 11,
84
        ResizeError = 12,
85
        PermissionsError = 13,
86
        CopyError = 14
87
#ifdef QT3_SUPPORT
88
        , ConnectError = 30
89
#endif
90
    };
91
92
    enum Permission {
93
        ReadOwner = 0x4000, WriteOwner = 0x2000, ExeOwner = 0x1000,
94
        ReadUser  = 0x0400, WriteUser  = 0x0200, ExeUser  = 0x0100,
95
        ReadGroup = 0x0040, WriteGroup = 0x0020, ExeGroup = 0x0010,
96
        ReadOther = 0x0004, WriteOther = 0x0002, ExeOther = 0x0001
97
    };
98
    Q_DECLARE_FLAGS(Permissions, Permission)
99
100
    QFile();
101
    QFile(const QString &name);
102
#ifndef QT_NO_QOBJECT
103
    explicit QFile(QObject *parent);
104
    QFile(const QString &name, QObject *parent);
105
#endif
106
    ~QFile();
107
108
    FileError error() const;
109
    void unsetError();
110
111
    QString fileName() const;
112
    void setFileName(const QString &name);
113
114
    typedef QByteArray (*EncoderFn)(const QString &fileName);
115
    typedef QString (*DecoderFn)(const QByteArray &localfileName);
116
    static QByteArray encodeName(const QString &fileName);
117
    static QString decodeName(const QByteArray &localFileName);
118
    inline static QString decodeName(const char *localFileName)
119
        { return decodeName(QByteArray(localFileName)); };
120
    static void setEncodingFunction(EncoderFn);
121
    static void setDecodingFunction(DecoderFn);
122
123
    bool exists() const;
124
    static bool exists(const QString &fileName);
125
126
    QString readLink() const;
127
    static QString readLink(const QString &fileName);
128
    inline QString symLinkTarget() const { return readLink(); }
129
    inline static QString symLinkTarget(const QString &fileName) { return readLink(fileName); }
130
131
    bool remove();
132
    static bool remove(const QString &fileName);
133
134
    bool rename(const QString &newName);
135
    static bool rename(const QString &oldName, const QString &newName);
136
137
    bool link(const QString &newName);
138
    static bool link(const QString &oldname, const QString &newName);
139
140
    bool copy(const QString &newName);
141
    static bool copy(const QString &fileName, const QString &newName);
142
143
    bool isSequential() const;
144
145
    bool open(OpenMode flags);
146
    bool open(FILE *f, OpenMode flags);
147
    bool open(int fd, OpenMode flags);
148
    virtual void close();
149
150
    qint64 size() const;
151
    qint64 pos() const;
152
    bool seek(qint64 offset);
153
    bool atEnd() const;
154
    bool flush();
155
156
    bool resize(qint64 sz);
157
    static bool resize(const QString &filename, qint64 sz);
158
159
    Permissions permissions() const;
160
    static Permissions permissions(const QString &filename);
161
    bool setPermissions(Permissions permissionSpec);
162
    static bool setPermissions(const QString &filename, Permissions permissionSpec);
163
164
    int handle() const;
165
166
    enum MemoryMapFlags {
167
        NoOptions = 0
168
    };
169
170
    uchar *map(qint64 offset, qint64 size, MemoryMapFlags flags = NoOptions);
171
    bool unmap(uchar *address);
172
173
    virtual QAbstractFileEngine *fileEngine() const;
174
175
#ifdef QT3_SUPPORT
176
    typedef Permission PermissionSpec;
177
    inline QT3_SUPPORT QString name() const { return fileName(); }
178
    inline QT3_SUPPORT void setName(const QString &aName) { setFileName(aName); }
179
    inline QT3_SUPPORT bool open(OpenMode aFlags, FILE *f) { return open(f, aFlags); }
180
    inline QT3_SUPPORT bool open(OpenMode aFlags, int fd) { return open(fd, aFlags); }
181
#endif
182
183
protected:
184
#ifdef QT_NO_QOBJECT
185
    QFile(QFilePrivate &dd);
186
#else
187
    QFile(QFilePrivate &dd, QObject *parent = 0);
188
#endif
189
190
    qint64 readData(char *data, qint64 maxlen);
191
    qint64 writeData(const char *data, qint64 len);
192
    qint64 readLineData(char *data, qint64 maxlen);
193
194
private:
195
    Q_DISABLE_COPY(QFile)
196
};
197
198
Q_DECLARE_OPERATORS_FOR_FLAGS(QFile::Permissions)
199
200
QT_END_NAMESPACE
201
202
QT_END_HEADER
203
204
#endif // QFILE_H