| 1 | // Copyright (C) 2012 David Faure <faure@kde.org> |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | // Qt-Security score:significant reason:header-decls-only |
| 4 | |
| 5 | #ifndef QSAVEFILE_H |
| 6 | #define QSAVEFILE_H |
| 7 | |
| 8 | #include <QtCore/qglobal.h> |
| 9 | |
| 10 | #if QT_CONFIG(temporaryfile) |
| 11 | |
| 12 | #include <QtCore/qfiledevice.h> |
| 13 | #include <QtCore/qstring.h> |
| 14 | |
| 15 | #ifdef open |
| 16 | #error qsavefile.h must be included before any header file that defines open |
| 17 | #endif |
| 18 | |
| 19 | QT_BEGIN_NAMESPACE |
| 20 | |
| 21 | class QAbstractFileEngine; |
| 22 | class QSaveFilePrivate; |
| 23 | |
| 24 | class Q_CORE_EXPORT QSaveFile : public QFileDevice |
| 25 | { |
| 26 | #ifndef QT_NO_QOBJECT |
| 27 | Q_OBJECT |
| 28 | #endif |
| 29 | Q_DECLARE_PRIVATE(QSaveFile) |
| 30 | |
| 31 | public: |
| 32 | |
| 33 | explicit QSaveFile(const QString &name); |
| 34 | #ifndef QT_NO_QOBJECT |
| 35 | explicit QSaveFile(QObject *parent = nullptr); |
| 36 | explicit QSaveFile(const QString &name, QObject *parent); |
| 37 | #endif |
| 38 | ~QSaveFile(); |
| 39 | |
| 40 | QString fileName() const override; |
| 41 | void setFileName(const QString &name); |
| 42 | |
| 43 | QFILE_MAYBE_NODISCARD bool open(OpenMode flags) override; |
| 44 | bool commit(); |
| 45 | |
| 46 | void cancelWriting(); |
| 47 | |
| 48 | void setDirectWriteFallback(bool enabled); |
| 49 | bool directWriteFallback() const; |
| 50 | |
| 51 | protected: |
| 52 | qint64 writeData(const char *data, qint64 len) override; |
| 53 | |
| 54 | private: |
| 55 | void close() override; |
| 56 | #if !QT_CONFIG(translation) |
| 57 | static QString tr(const char *string) { return QString::fromLatin1(string); } |
| 58 | #endif |
| 59 | |
| 60 | private: |
| 61 | Q_DISABLE_COPY(QSaveFile) |
| 62 | friend class QFilePrivate; |
| 63 | }; |
| 64 | |
| 65 | QT_END_NAMESPACE |
| 66 | |
| 67 | #endif // QT_CONFIG(temporaryfile) |
| 68 | |
| 69 | #endif // QSAVEFILE_H |
| 70 | |