Line data Source code
1 : /****************************************************************************
2 : **
3 : ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
4 : ** Contact: http://www.qt-project.org/legal
5 : **
6 : ** This file is part of the QtCore module of the Qt Toolkit.
7 : **
8 : ** $QT_BEGIN_LICENSE:LGPL$
9 : ** Commercial License Usage
10 : ** Licensees holding valid commercial Qt licenses may use this file in
11 : ** accordance with the commercial license agreement provided with the
12 : ** Software or, alternatively, in accordance with the terms contained in
13 : ** a written agreement between you and Digia. For licensing terms and
14 : ** conditions see http://qt.digia.com/licensing. For further information
15 : ** use the contact form at http://qt.digia.com/contact-us.
16 : **
17 : ** GNU Lesser General Public License Usage
18 : ** Alternatively, this file may be used under the terms of the GNU Lesser
19 : ** General Public License version 2.1 as published by the Free Software
20 : ** Foundation and appearing in the file LICENSE.LGPL included in the
21 : ** packaging of this file. Please review the following information to
22 : ** ensure the GNU Lesser General Public License version 2.1 requirements
23 : ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 : **
25 : ** In addition, as a special exception, Digia gives you certain additional
26 : ** rights. These rights are described in the Digia Qt LGPL Exception
27 : ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 : **
29 : ** GNU General Public License Usage
30 : ** Alternatively, this file may be used under the terms of the GNU
31 : ** General Public License version 3.0 as published by the Free Software
32 : ** Foundation and appearing in the file LICENSE.GPL included in the
33 : ** packaging of this file. Please review the following information to
34 : ** ensure the GNU General Public License version 3.0 requirements will be
35 : ** met: http://www.gnu.org/copyleft/gpl.html.
36 : **
37 : **
38 : ** $QT_END_LICENSE$
39 : **
40 : ****************************************************************************/
41 :
42 : #ifndef QFILE_H
43 : #define QFILE_H
44 :
45 : #include <QtCore/qfiledevice.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_NAMESPACE
54 :
55 : class QTemporaryFile;
56 : class QFilePrivate;
57 :
58 : class Q_CORE_EXPORT QFile : public QFileDevice
59 : {
60 : #ifndef QT_NO_QOBJECT
61 : Q_OBJECT
62 : #endif
63 : Q_DECLARE_PRIVATE(QFile)
64 :
65 : public:
66 : QFile();
67 : QFile(const QString &name);
68 : #ifndef QT_NO_QOBJECT
69 : explicit QFile(QObject *parent);
70 : QFile(const QString &name, QObject *parent);
71 : #endif
72 : ~QFile();
73 :
74 : QString fileName() const;
75 : void setFileName(const QString &name);
76 :
77 : #if defined(Q_OS_DARWIN)
78 : // Mac always expects filenames in UTF-8... and decomposed...
79 : static inline QByteArray encodeName(const QString &fileName)
80 : {
81 : return fileName.normalized(QString::NormalizationForm_D).toUtf8();
82 : }
83 : static QString decodeName(const QByteArray &localFileName)
84 : {
85 : return QString::fromUtf8(localFileName).normalized(QString::NormalizationForm_C);
86 : }
87 : #else
88 0 : static inline QByteArray encodeName(const QString &fileName)
89 : {
90 0 : return fileName.toLocal8Bit();
91 : }
92 0 : static QString decodeName(const QByteArray &localFileName)
93 : {
94 0 : return QString::fromLocal8Bit(localFileName);
95 : }
96 : #endif
97 0 : inline static QString decodeName(const char *localFileName)
98 0 : { return decodeName(QByteArray(localFileName)); }
99 :
100 : #if QT_DEPRECATED_SINCE(5,0)
101 : typedef QByteArray (*EncoderFn)(const QString &fileName);
102 : typedef QString (*DecoderFn)(const QByteArray &localfileName);
103 : QT_DEPRECATED static void setEncodingFunction(EncoderFn) {}
104 : QT_DEPRECATED static void setDecodingFunction(DecoderFn) {}
105 : #endif
106 :
107 : bool exists() const;
108 : static bool exists(const QString &fileName);
109 :
110 : QString readLink() const;
111 : static QString readLink(const QString &fileName);
112 : inline QString symLinkTarget() const { return readLink(); }
113 : inline static QString symLinkTarget(const QString &fileName) { return readLink(fileName); }
114 :
115 : bool remove();
116 : static bool remove(const QString &fileName);
117 :
118 : bool rename(const QString &newName);
119 : static bool rename(const QString &oldName, const QString &newName);
120 :
121 : bool link(const QString &newName);
122 : static bool link(const QString &oldname, const QString &newName);
123 :
124 : bool copy(const QString &newName);
125 : static bool copy(const QString &fileName, const QString &newName);
126 :
127 : bool open(OpenMode flags);
128 : bool open(FILE *f, OpenMode ioFlags, FileHandleFlags handleFlags=DontCloseHandle);
129 : bool open(int fd, OpenMode ioFlags, FileHandleFlags handleFlags=DontCloseHandle);
130 :
131 : qint64 size() const;
132 :
133 : bool resize(qint64 sz);
134 : static bool resize(const QString &filename, qint64 sz);
135 :
136 : Permissions permissions() const;
137 : static Permissions permissions(const QString &filename);
138 : bool setPermissions(Permissions permissionSpec);
139 : static bool setPermissions(const QString &filename, Permissions permissionSpec);
140 :
141 : protected:
142 : #ifdef QT_NO_QOBJECT
143 : QFile(QFilePrivate &dd);
144 : #else
145 : QFile(QFilePrivate &dd, QObject *parent = 0);
146 : #endif
147 :
148 : private:
149 : friend class QTemporaryFile;
150 : Q_DISABLE_COPY(QFile)
151 : };
152 :
153 : QT_END_NAMESPACE
154 :
155 : #endif // QFILE_H
|