qfileinfo.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 QFILEINFO_H
00043 #define QFILEINFO_H
00044 
00045 #include <QtCore/qfile.h>
00046 #include <QtCore/qlist.h>
00047 #include <QtCore/qshareddata.h>
00048 
00049 QT_BEGIN_HEADER
00050 
00051 QT_BEGIN_NAMESPACE
00052 
00053 QT_MODULE(Core)
00054 
00055 class QDir;
00056 class QDateTime;
00057 class QFileInfoPrivate;
00058 
00059 class Q_CORE_EXPORT QFileInfo
00060 {
00061 public:
00062     QFileInfo();
00063     QFileInfo(const QString &file);
00064     QFileInfo(const QFile &file);
00065     QFileInfo(const QDir &dir, const QString &file);
00066     QFileInfo(const QFileInfo &fileinfo);
00067     ~QFileInfo();
00068 
00069     QFileInfo &operator=(const QFileInfo &fileinfo);
00070     bool operator==(const QFileInfo &fileinfo); // 5.0 - remove me
00071     bool operator==(const QFileInfo &fileinfo) const;
00072     inline bool operator!=(const QFileInfo &fileinfo) { return !(operator==(fileinfo)); } // 5.0 - remove me
00073     inline bool operator!=(const QFileInfo &fileinfo) const { return !(operator==(fileinfo)); }
00074 
00075     void setFile(const QString &file);
00076     void setFile(const QFile &file);
00077     void setFile(const QDir &dir, const QString &file);
00078     bool exists() const;
00079     void refresh();
00080 
00081     QString filePath() const;
00082     QString absoluteFilePath() const;
00083     QString canonicalFilePath() const;
00084     QString fileName() const;
00085     QString baseName() const;
00086     QString completeBaseName() const;
00087     QString suffix() const;
00088     QString bundleName() const;
00089     QString completeSuffix() const;
00090 
00091     QString path() const;
00092     QString absolutePath() const;
00093     QString canonicalPath() const;
00094     QDir dir() const;
00095     QDir absoluteDir() const;
00096 
00097     bool isReadable() const;
00098     bool isWritable() const;
00099     bool isExecutable() const;
00100     bool isHidden() const;
00101 
00102     bool isRelative() const;
00103     inline bool isAbsolute() const { return !isRelative(); }
00104     bool makeAbsolute();
00105 
00106     bool isFile() const;
00107     bool isDir() const;
00108     bool isSymLink() const;
00109     bool isRoot() const;
00110     bool isBundle() const;
00111 
00112     QString readLink() const;
00113     inline QString symLinkTarget() const { return readLink(); }
00114 
00115     QString owner() const;
00116     uint ownerId() const;
00117     QString group() const;
00118     uint groupId() const;
00119 
00120     bool permission(QFile::Permissions permissions) const;
00121     QFile::Permissions permissions() const;
00122 
00123     qint64 size() const;
00124 
00125     QDateTime created() const;
00126     QDateTime lastModified() const;
00127     QDateTime lastRead() const;
00128 
00129     void detach();
00130 
00131     bool caching() const;
00132     void setCaching(bool on);
00133 
00134 #ifdef QT3_SUPPORT
00135     enum Permission {
00136         ReadOwner = QFile::ReadOwner, WriteOwner = QFile::WriteOwner, ExeOwner = QFile::ExeOwner,
00137         ReadUser  = QFile::ReadUser,  WriteUser  = QFile::WriteUser,  ExeUser  = QFile::ExeUser,
00138         ReadGroup = QFile::ReadGroup, WriteGroup = QFile::WriteGroup, ExeGroup = QFile::ExeGroup,
00139         ReadOther = QFile::ReadOther, WriteOther = QFile::WriteOther, ExeOther = QFile::ExeOther
00140     };
00141     Q_DECLARE_FLAGS(PermissionSpec, Permission)
00142 
00143     inline QT3_SUPPORT QString baseName(bool complete) {
00144         if(complete)
00145             return completeBaseName();
00146         return baseName();
00147     }
00148     inline QT3_SUPPORT QString extension(bool complete = true) const {
00149         if(complete)
00150             return completeSuffix();
00151         return suffix();
00152     }
00153     inline QT3_SUPPORT QString absFilePath() const { return absoluteFilePath(); }
00154 
00155     inline QT3_SUPPORT QString dirPath(bool absPath = false) const {
00156         if(absPath)
00157             return absolutePath();
00158         return path();
00159     }
00160     QT3_SUPPORT QDir dir(bool absPath) const;
00161     inline QT3_SUPPORT bool convertToAbs() { return makeAbsolute(); }
00162 #if !defined(Q_NO_TYPESAFE_FLAGS)
00163     inline QT3_SUPPORT bool permission(PermissionSpec permissions) const
00164     { return permission(QFile::Permissions(static_cast<int>(permissions))); }
00165 #endif
00166 #endif
00167 
00168 protected:
00169     QSharedDataPointer<QFileInfoPrivate> d_ptr;
00170 private:
00171     inline QFileInfoPrivate* d_func()
00172     {
00173         detach();
00174         return const_cast<QFileInfoPrivate *>(d_ptr.constData());
00175     }
00176 
00177     inline const QFileInfoPrivate* d_func() const
00178     {
00179         return d_ptr.constData();
00180     }
00181 };
00182 
00183 Q_DECLARE_TYPEINFO(QFileInfo, Q_MOVABLE_TYPE);
00184 
00185 #ifdef QT3_SUPPORT
00186 Q_DECLARE_OPERATORS_FOR_FLAGS(QFileInfo::PermissionSpec)
00187 #endif
00188 
00189 typedef QList<QFileInfo> QFileInfoList;
00190 #ifdef QT3_SUPPORT
00191 typedef QList<QFileInfo>::Iterator QFileInfoListIterator;
00192 #endif
00193 
00194 QT_END_NAMESPACE
00195 
00196 QT_END_HEADER
00197 
00198 #endif // QFILEINFO_H