- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Directories
- Examples

- File List
- File Members

# qfile.h

Go to the documentation of this file.

    00001 /****************************************************************************
    00002 **
    00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
    00004 ** All rights reserved.
    00005 ** Contact: Nokia Corporation (qt-info@nokia.com)
    00006 **
    00007 ** This file is part of the QtCore module of the Qt Toolkit.
    00008 **
    00009 ** $QT_BEGIN_LICENSE:LGPL$
    00010 ** Commercial Usage
    00011 ** Licensees holding valid Qt Commercial licenses may use this file in
    00012 ** accordance with the Qt Commercial License Agreement provided with the
    00013 ** Software or, alternatively, in accordance with the terms contained in
    00014 ** a written agreement between you and Nokia.
    00015 **
    00016 ** GNU Lesser General Public License Usage
    00017 ** Alternatively, this file may be used under the terms of the GNU Lesser
    00018 ** General Public License version 2.1 as published by the Free Software
    00019 ** Foundation and appearing in the file LICENSE.LGPL included in the
    00020 ** packaging of this file.  Please review the following information to
    00021 ** ensure the GNU Lesser General Public License version 2.1 requirements
    00022 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    00023 **
    00024 ** In addition, as a special exception, Nokia gives you certain additional
    00025 ** rights.  These rights are described in the Nokia Qt LGPL Exception
    00026 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this module.
    00027 **
    00028 ** GNU General Public License Usage
    00029 ** Alternatively, this file may be used under the terms of the GNU
    00030 ** General Public License version 3.0 as published by the Free Software
    00031 ** Foundation and appearing in the file LICENSE.GPL included in the
    00032 ** packaging of this file.  Please review the following information to
    00033 ** ensure the GNU General Public License version 3.0 requirements will be
    00034 ** met: http://www.gnu.org/copyleft/gpl.html.
    00035 **
    00036 ** If you have questions regarding the use of this file, please contact
    00037 ** Nokia at qt-info@nokia.com.
    00038 ** $QT_END_LICENSE$
    00039 **
    00040 ****************************************************************************/
    00041
    00042 #ifndef QFILE_H
    00043 #define QFILE_H
    00044
    00045 #include <QtCore/qiodevice.h>
    00046 #include <QtCore/qstring.h>
    00047 #include <stdio.h>
    00048
    00049 #ifdef open
    00050 #error qfile.h must be included before any header file that defines open
    00051 #endif
    00052
    00053 QT_BEGIN_HEADER
    00054
    00055 QT_BEGIN_NAMESPACE
    00056
    00057 QT_MODULE(Core)
    00058
    00059 class QAbstractFileEngine;
    00060 class QFilePrivate;
    00061
    00062 class Q_CORE_EXPORT QFile : public QIODevice
    00063 {
    00064 #ifndef QT_NO_QOBJECT
    00065     Q_OBJECT
    00066 #endif
    00067     Q_DECLARE_PRIVATE(QFile)
    00068
    00069 public:
    00070
    00071     enum FileError {
    00072         NoError = 0,
    00073         ReadError = 1,
    00074         WriteError = 2,
    00075         FatalError = 3,
    00076         ResourceError = 4,
    00077         OpenError = 5,
    00078         AbortError = 6,
    00079         TimeOutError = 7,
    00080         UnspecifiedError = 8,
    00081         RemoveError = 9,
    00082         RenameError = 10,
    00083         PositionError = 11,
    00084         ResizeError = 12,
    00085         PermissionsError = 13,
    00086         CopyError = 14
    00087 #ifdef QT3_SUPPORT
    00088         , ConnectError = 30
    00089 #endif
    00090     };
    00091
    00092     enum Permission {
    00093         ReadOwner = 0x4000, WriteOwner = 0x2000, ExeOwner = 0x1000,
    00094         ReadUser  = 0x0400, WriteUser  = 0x0200, ExeUser  = 0x0100,
    00095         ReadGroup = 0x0040, WriteGroup = 0x0020, ExeGroup = 0x0010,
    00096         ReadOther = 0x0004, WriteOther = 0x0002, ExeOther = 0x0001
    00097     };
    00098     Q_DECLARE_FLAGS(Permissions, Permission)
    00099
    00100     QFile();
    00101     QFile(const QString &name);
    00102 #ifndef QT_NO_QOBJECT
    00103     explicit QFile(QObject *parent);
    00104     QFile(const QString &name, QObject *parent);
    00105 #endif
    00106     ~QFile();
    00107
    00108     FileError error() const;
    00109     void unsetError();
    00110
    00111     QString fileName() const;
    00112     void setFileName(const QString &name);
    00113
    00114     typedef QByteArray (*EncoderFn)(const QString &fileName);
    00115     typedef QString (*DecoderFn)(const QByteArray &localfileName);
    00116     static QByteArray encodeName(const QString &fileName);
    00117     static QString decodeName(const QByteArray &localFileName);
    00118     inline static QString decodeName(const char *localFileName)
    00119         { return decodeName(QByteArray(localFileName)); }
    00120     static void setEncodingFunction(EncoderFn);
    00121     static void setDecodingFunction(DecoderFn);
    00122
    00123     bool exists() const;
    00124     static bool exists(const QString &fileName);
    00125
    00126     QString readLink() const;
    00127     static QString readLink(const QString &fileName);
    00128     inline QString symLinkTarget() const { return readLink(); }
    00129     inline static QString symLinkTarget(const QString &fileName) { return readLink(fileName); }
    00130
    00131     bool remove();
    00132     static bool remove(const QString &fileName);
    00133
    00134     bool rename(const QString &newName);
    00135     static bool rename(const QString &oldName, const QString &newName);
    00136
    00137     bool link(const QString &newName);
    00138     static bool link(const QString &oldname, const QString &newName);
    00139
    00140     bool copy(const QString &newName);
    00141     static bool copy(const QString &fileName, const QString &newName);
    00142
    00143     bool isSequential() const;
    00144
    00145     bool open(OpenMode flags);
    00146     bool open(FILE *f, OpenMode flags);
    00147     bool open(int fd, OpenMode flags);
    00148     virtual void close();
    00149
    00150     qint64 size() const;
    00151     qint64 pos() const;
    00152     bool seek(qint64 offset);
    00153     bool atEnd() const;
    00154     bool flush();
    00155
    00156     bool resize(qint64 sz);
    00157     static bool resize(const QString &filename, qint64 sz);
    00158
    00159     Permissions permissions() const;
    00160     static Permissions permissions(const QString &filename);
    00161     bool setPermissions(Permissions permissionSpec);
    00162     static bool setPermissions(const QString &filename, Permissions permissionSpec);
    00163
    00164     int handle() const;
    00165
    00166     enum MemoryMapFlags {
    00167         NoOptions = 0
    00168     };
    00169
    00170     uchar *map(qint64 offset, qint64 size, MemoryMapFlags flags = NoOptions);
    00171     bool unmap(uchar *address);
    00172
    00173     virtual QAbstractFileEngine *fileEngine() const;
    00174
    00175 #ifdef QT3_SUPPORT
    00176     typedef Permission PermissionSpec;
    00177     inline QT3_SUPPORT QString name() const { return fileName(); }
    00178     inline QT3_SUPPORT void setName(const QString &aName) { setFileName(aName); }
    00179     inline QT3_SUPPORT bool open(OpenMode aFlags, FILE *f) { return open(f, aFlags); }
    00180     inline QT3_SUPPORT bool open(OpenMode aFlags, int fd) { return open(fd, aFlags); }
    00181 #endif
    00182
    00183 protected:
    00184 #ifdef QT_NO_QOBJECT
    00185     QFile(QFilePrivate &dd);
    00186 #else
    00187     QFile(QFilePrivate &dd, QObject *parent = 0);
    00188 #endif
    00189
    00190     qint64 readData(char *data, qint64 maxlen);
    00191     qint64 writeData(const char *data, qint64 len);
    00192     qint64 readLineData(char *data, qint64 maxlen);
    00193
    00194 private:
    00195     Q_DISABLE_COPY(QFile)
    00196 };
    00197
    00198 Q_DECLARE_OPERATORS_FOR_FLAGS(QFile::Permissions)
    00199
    00200 QT_END_NAMESPACE
    00201
    00202 QT_END_HEADER
    00203
    00204 #endif // QFILE_H