1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Copyright (C) 2016 Intel Corporation.
5** Contact: https://www.qt.io/licensing/
6**
7** This file is part of the QtCore module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial License Usage
11** Licensees holding valid commercial Qt licenses may use this file in
12** accordance with the commercial license agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and The Qt Company. For licensing terms
15** and conditions see https://www.qt.io/terms-conditions. For further
16** information use the contact form at https://www.qt.io/contact-us.
17**
18** GNU Lesser General Public License Usage
19** Alternatively, this file may be used under the terms of the GNU Lesser
20** General Public License version 3 as published by the Free Software
21** Foundation and appearing in the file LICENSE.LGPL3 included in the
22** packaging of this file. Please review the following information to
23** ensure the GNU Lesser General Public License version 3 requirements
24** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
25**
26** GNU General Public License Usage
27** Alternatively, this file may be used under the terms of the GNU
28** General Public License version 2.0 or (at your option) the GNU General
29** Public license version 3 or any later version approved by the KDE Free
30** Qt Foundation. The licenses are as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
32** included in the packaging of this file. Please review the following
33** information to ensure the GNU General Public License requirements will
34** be met: https://www.gnu.org/licenses/gpl-2.0.html and
35** https://www.gnu.org/licenses/gpl-3.0.html.
36**
37** $QT_END_LICENSE$
38**
39****************************************************************************/
40
41#ifndef QFILE_H
42#define QFILE_H
43
44#include <QtCore/qfiledevice.h>
45#include <QtCore/qstring.h>
46#include <stdio.h>
47
48#ifdef open
49#error qfile.h must be included before any header file that defines open
50#endif
51
52QT_BEGIN_NAMESPACE
53
54class QTemporaryFile;
55class QFilePrivate;
56
57class Q_CORE_EXPORT QFile : public QFileDevice
58{
59#ifndef QT_NO_QOBJECT
60 Q_OBJECT
61#endif
62 Q_DECLARE_PRIVATE(QFile)
63
64public:
65 QFile();
66 QFile(const QString &name);
67#ifndef QT_NO_QOBJECT
68 explicit QFile(QObject *parent);
69 QFile(const QString &name, QObject *parent);
70#endif
71 ~QFile();
72
73 QString fileName() const override;
74 void setFileName(const QString &name);
75
76#if defined(Q_OS_DARWIN)
77 // Mac always expects filenames in UTF-8... and decomposed...
78 static inline QByteArray encodeName(const QString &fileName)
79 {
80 return fileName.normalized(QString::NormalizationForm_D).toUtf8();
81 }
82 static QString decodeName(const QByteArray &localFileName)
83 {
84 // note: duplicated in qglobal.cpp (qEnvironmentVariable)
85 return QString::fromUtf8(localFileName).normalized(QString::NormalizationForm_C);
86 }
87 static inline QString decodeName(const char *localFileName)
88 {
89 return QString::fromUtf8(localFileName).normalized(QString::NormalizationForm_C);
90 }
91#else
92 static inline QByteArray encodeName(const QString &fileName)
93 {
94 return fileName.toLocal8Bit();
95 }
96 static QString decodeName(const QByteArray &localFileName)
97 {
98 return QString::fromLocal8Bit(localFileName);
99 }
100 static inline QString decodeName(const char *localFileName)
101 {
102 return QString::fromLocal8Bit(localFileName);
103 }
104#endif
105
106#if QT_DEPRECATED_SINCE(5,0)
107 typedef QByteArray (*EncoderFn)(const QString &fileName);
108 typedef QString (*DecoderFn)(const QByteArray &localfileName);
109 QT_DEPRECATED static void setEncodingFunction(EncoderFn) {}
110 QT_DEPRECATED static void setDecodingFunction(DecoderFn) {}
111#endif
112
113 bool exists() const;
114 static bool exists(const QString &fileName);
115
116#if QT_DEPRECATED_SINCE(5, 13)
117 QT_DEPRECATED_X("Use QFile::symLinkTarget() instead")
118 QString readLink() const;
119 QT_DEPRECATED_X("Use QFile::symLinkTarget(QString) instead")
120 static QString readLink(const QString &fileName);
121#endif
122 QString symLinkTarget() const;
123 static QString symLinkTarget(const QString &fileName);
124
125 bool remove();
126 static bool remove(const QString &fileName);
127
128 bool moveToTrash();
129 static bool moveToTrash(const QString &fileName, QString *pathInTrash = nullptr);
130
131 bool rename(const QString &newName);
132 static bool rename(const QString &oldName, const QString &newName);
133
134 bool link(const QString &newName);
135 static bool link(const QString &oldname, const QString &newName);
136
137 bool copy(const QString &newName);
138 static bool copy(const QString &fileName, const QString &newName);
139
140 bool open(OpenMode flags) override;
141 bool open(FILE *f, OpenMode ioFlags, FileHandleFlags handleFlags=DontCloseHandle);
142 bool open(int fd, OpenMode ioFlags, FileHandleFlags handleFlags=DontCloseHandle);
143
144 qint64 size() const override;
145
146 bool resize(qint64 sz) override;
147 static bool resize(const QString &filename, qint64 sz);
148
149 Permissions permissions() const override;
150 static Permissions permissions(const QString &filename);
151 bool setPermissions(Permissions permissionSpec) override;
152 static bool setPermissions(const QString &filename, Permissions permissionSpec);
153
154protected:
155#ifdef QT_NO_QOBJECT
156 QFile(QFilePrivate &dd);
157#else
158 QFile(QFilePrivate &dd, QObject *parent = nullptr);
159#endif
160
161private:
162 friend class QTemporaryFile;
163 Q_DISABLE_COPY(QFile)
164};
165
166QT_END_NAMESPACE
167
168#endif // QFILE_H
169