6#ifndef QT_NO_TEMPORARYFILE
8#include "qplatformdefs.h"
9#include "private/qsavefile_p.h"
14#include "private/qiodevice_p.h"
15#include "private/qtemporaryfile_p.h"
26 useTemporaryFile(true),
27 directWriteFallback(
false)
118 d->fileEngine->remove();
119 d->fileEngine.reset();
131 return d_func()->fileName;
142 d_func()->fileName =
name;
167 qWarning(
"QSaveFile::open: Open mode not specified");
173 qWarning(
"QSaveFile::open: Unsupported open mode 0x%x",
uint(
mode.toInt()));
185 if (existingFile.
isDir()) {
193 d->finalFileName =
d->fileName;
196 while (--maxDepth && existingFile.
isSymLink())
199 d->finalFileName = existingFile.
filePath();
202 auto openDirectly = [&]() {
205 d->useTemporaryFile =
false;
212 bool requiresDirectWrite =
false;
215 requiresDirectWrite =
d->finalFileName ==
d->fileName &&
d->fileName.indexOf(u
':', 2) > 1;
216#elif defined(Q_OS_ANDROID)
218 requiresDirectWrite =
d->fileName.startsWith(
"content://"_L1);
220 if (requiresDirectWrite) {
222 if (
d->directWriteFallback) {
225 d->setError(
d->fileEngine->error(),
d->fileEngine->errorString());
226 d->fileEngine.reset();
229 QSaveFile::tr(
"QSaveFile cannot open '%1' without direct write fallback enabled.")
240 int perm = (existingFile.
exists() ? 0600 : 0666);
249 err =
d->fileEngine->error();
254 d->setError(err,
d->fileEngine->errorString());
255 d->fileEngine.reset();
259 d->useTemporaryFile =
true;
261 if (existingFile.
exists())
274 qFatal(
"QSaveFile::close called");
301 const auto fe = std::move(
d->fileEngine);
306 if (
d->useTemporaryFile) {
315 if (!fe->renameOverwrite(
d->finalFileName)) {
316 d->setError(fe->error(), fe->errorString());
363 d->writeError =
d->error;
406 return d->directWriteFallback;
412#include "moc_qsavefile.cpp"
static QAbstractFileEngine * create(const QString &fileName)
Creates and returns a QAbstractFileEngine suitable for processing fileName.
static QString toNativeSeparators(const QString &pathName)
void unsetError()
Sets the file's error to QFileDevice::NoError.
qint64 writeData(const char *data, qint64 len) override
\reimp
FileError
This enum describes the errors that may be returned by the error() function.
virtual bool setPermissions(Permissions permissionSpec)
Sets the permissions for the file to the permissions specified.
void close() override
Calls QFileDevice::flush() and closes the file.
\inmodule QtCore \reentrant
bool isSymLink() const
Returns true if this object points to a symbolic link, shortcut, or alias; otherwise returns false.
QString symLinkTarget() const
void setFile(const QString &file)
Sets the file that the QFileInfo provides information about to file.
bool isDir() const
Returns true if this object points to a directory or to a symbolic link to a directory.
bool isWritable() const
Returns true if the user can write to the file; otherwise returns false.
QString filePath() const
Returns the file name, including the path (which may be absolute or relative).
bool exists() const
Returns true if the file exists; otherwise returns false.
QFile::Permissions permissions() const
Returns the complete OR-ed together combination of QFile::Permissions for the file.
virtual bool open(QIODeviceBase::OpenMode mode)
Opens the device and sets its OpenMode to mode.
bool isOpen() const
Returns true if the device is open; otherwise returns false.
QSaveFile(const QString &name)
Constructs a new file object to represent the file with the given name.
void setDirectWriteFallback(bool enabled)
Allows writing over the existing file if necessary.
~QSaveFile()
Destroys the file object, discarding the saved contents unless commit() was called.
void setFileName(const QString &name)
Sets the name of the file.
QString fileName() const override
Returns the name set by setFileName() or to the QSaveFile constructor.
bool open(OpenMode flags) override
Opens the file using OpenMode mode, returning true if successful; otherwise false.
qint64 writeData(const char *data, qint64 len) override
\reimp
bool commit()
Commits the changes to disk, if all previous writes were successful.
void cancelWriting()
Cancels writing the new file.
bool directWriteFallback() const
Returns true if the fallback solution for saving files in read-only directories is enabled.
void close() override
\reimp This method has been made private so that it cannot be called, in order to prevent mistakes.
\macro QT_RESTRICTED_CAST_FROM_ASCII
QString arg(qlonglong a, int fieldwidth=0, int base=10, QChar fillChar=u' ') const
Combined button and popup list for selecting options.
GLenum GLenum GLsizei const GLuint GLboolean enabled
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
#define qUtf16Printable(string)
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent