src/corelib/io/qfile.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 1992-2006 Trolltech ASA. All rights reserved.
00004 **
00005 ** This file is part of the QtCore module of the Qt Toolkit.
00006 **
00007 ** This file may be used under the terms of the GNU General Public
00008 ** License version 2.0 as published by the Free Software Foundation
00009 ** and appearing in the file LICENSE.GPL included in the packaging of
00010 ** this file.  Please review the following information to ensure GNU
00011 ** General Public Licensing requirements will be met:
00012 ** http://www.trolltech.com/products/qt/opensource.html
00013 **
00014 ** If you are unsure which license is appropriate for your use, please
00015 ** review the following information:
00016 ** http://www.trolltech.com/products/qt/licensing.html or contact the
00017 ** sales department at sales@trolltech.com.
00018 **
00019 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00020 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00021 **
00022 ****************************************************************************/
00023 
00024 #ifndef QFILE_H
00025 #define QFILE_H
00026 
00027 #include <QtCore/qiodevice.h>
00028 #include <QtCore/qstring.h>
00029 #include <stdio.h>
00030 
00031 #ifdef open
00032 #error qfile.h must be included before any header file that defines open
00033 #endif
00034 
00035 QT_BEGIN_HEADER
00036 
00037 QT_MODULE(Core)
00038 
00039 class QAbstractFileEngine;
00040 class QFilePrivate;
00041 
00042 class Q_CORE_EXPORT QFile : public QIODevice
00043 {
00044 #ifndef QT_NO_QOBJECT
00045     Q_OBJECT
00046 #endif
00047     Q_DECLARE_PRIVATE(QFile)
00048 
00049 public:
00050 
00051     enum FileError {
00052         NoError = 0,
00053         ReadError = 1,
00054         WriteError = 2,
00055         FatalError = 3,
00056         ResourceError = 4,
00057         OpenError = 5,
00058         AbortError = 6,
00059         TimeOutError = 7,
00060         UnspecifiedError = 8,
00061         RemoveError = 9,
00062         RenameError = 10,
00063         PositionError = 11,
00064         ResizeError = 12,
00065         PermissionsError = 13,
00066         CopyError = 14
00067 #ifdef QT3_SUPPORT
00068         , ConnectError = 30
00069 #endif
00070     };
00071 
00072     enum Permission {
00073         ReadOwner = 0x4000, WriteOwner = 0x2000, ExeOwner = 0x1000,
00074         ReadUser  = 0x0400, WriteUser  = 0x0200, ExeUser  = 0x0100,
00075         ReadGroup = 0x0040, WriteGroup = 0x0020, ExeGroup = 0x0010,
00076         ReadOther = 0x0004, WriteOther = 0x0002, ExeOther = 0x0001
00077     };
00078     Q_DECLARE_FLAGS(Permissions, Permission)
00079 
00080     QFile();
00081     QFile(const QString &name);
00082 #ifndef QT_NO_QOBJECT
00083     explicit QFile(QObject *parent);
00084     QFile(const QString &name, QObject *parent);
00085 #endif
00086     ~QFile();
00087 
00088     FileError error() const;
00089     void unsetError();
00090 
00091     QString fileName() const;
00092     void setFileName(const QString &name);
00093 
00094     typedef QByteArray (*EncoderFn)(const QString &fileName);
00095     typedef QString (*DecoderFn)(const QByteArray &localfileName);
00096     static QByteArray encodeName(const QString &fileName);
00097     static QString decodeName(const QByteArray &localFileName);
00098     inline static QString decodeName(const char *localFileName)
00099         { return decodeName(QByteArray(localFileName)); };
00100     static void setEncodingFunction(EncoderFn);
00101     static void setDecodingFunction(DecoderFn);
00102 
00103     bool exists() const;
00104     static bool exists(const QString &fileName);
00105 
00106     QString readLink() const;
00107     static QString readLink(const QString &fileName);
00108     inline QString symLinkTarget() const { return readLink(); }
00109     inline static QString symLinkTarget(const QString &fileName) { return readLink(fileName); }
00110 
00111     bool remove();
00112     static bool remove(const QString &fileName);
00113 
00114     bool rename(const QString &newName);
00115     static bool rename(const QString &oldName, const QString &newName);
00116 
00117     bool link(const QString &newName);
00118     static bool link(const QString &oldname, const QString &newName);
00119 
00120     bool copy(const QString &newName);
00121     static bool copy(const QString &fileName, const QString &newName);
00122 
00123     bool isSequential() const;
00124 
00125     bool open(OpenMode flags);
00126     bool open(FILE *f, OpenMode flags);
00127     bool open(int fd, OpenMode flags);
00128     virtual void close();
00129 
00130     qint64 size() const;
00131     qint64 pos() const;
00132     bool seek(qint64 offset);
00133     bool atEnd() const;
00134     bool flush();
00135 
00136     bool resize(qint64 sz);
00137     static bool resize(const QString &filename, qint64 sz);
00138 
00139     Permissions permissions() const;
00140     static Permissions permissions(const QString &filename);
00141     bool setPermissions(Permissions permissionSpec);
00142     static bool setPermissions(const QString &filename, Permissions permissionSpec);
00143 
00144     int handle() const;
00145 
00146     virtual QAbstractFileEngine *fileEngine() const;
00147 
00148 #ifdef QT3_SUPPORT
00149     typedef Permission PermissionSpec;
00150     inline QT3_SUPPORT QString name() const { return fileName(); }
00151     inline QT3_SUPPORT void setName(const QString &name) { setFileName(name); }
00152     inline QT3_SUPPORT bool open(OpenMode flags, FILE *f) { return open(f, flags); }
00153     inline QT3_SUPPORT bool open(OpenMode flags, int fd) { return open(fd, flags); }
00154 #endif
00155 
00156 protected:
00157 #ifdef QT_NO_QOBJECT
00158     QFile(QFilePrivate &dd);
00159 #else
00160     QFile(QFilePrivate &dd, QObject *parent = 0);
00161 #endif
00162 
00163     qint64 readData(char *data, qint64 maxlen);
00164     qint64 writeData(const char *data, qint64 len);
00165     qint64 readLineData(char *data, qint64 maxlen);
00166 
00167 private:
00168     Q_DISABLE_COPY(QFile)
00169 };
00170 
00171 Q_DECLARE_OPERATORS_FOR_FLAGS(QFile::Permissions)
00172 
00173 QT_END_HEADER
00174 
00175 #endif // QFILE_H

Generated on Thu Mar 15 11:53:14 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1