44 #ifndef QT_NO_TEMPORARYFILE 46 #include "qplatformdefs.h" 47 #include "private/qfile_p.h" 48 #include "private/qfsfileengine_p.h" 49 #include "private/qsystemerror_p.h" 50 #include "private/qfilesystemengine_p.h" 52 #if defined(Q_OS_SYMBIAN) 53 #include "private/qcore_symbian_p.h" 56 #if !defined(Q_OS_WIN) && !defined(Q_OS_SYMBIAN) 57 #include "private/qcore_unix_p.h" 61 #if defined(QT_BUILD_CORE_LIB) 67 #if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN) 77 # else // Q_OS_SYMBIAN 78 # ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API 143 Char *
const placeholderStart = (
Char *)path.
data() + pos;
144 Char *
const placeholderEnd = placeholderStart + length;
148 Char *rIter = placeholderEnd;
150 #if defined(QT_BUILD_CORE_LIB) 155 }
while (rIter != placeholderStart && pid != 0);
158 while (rIter != placeholderStart) {
159 char ch = char((
qrand() & 0xffff) % (26 + 26));
168 RFs& fs = qt_s60GetRFs();
173 #if defined(Q_OS_WIN) 174 file = CreateFile((
const wchar_t *)path.
constData(),
175 GENERIC_READ | GENERIC_WRITE,
176 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_NEW,
177 FILE_ATTRIBUTE_NORMAL, NULL);
179 if (file != INVALID_HANDLE_VALUE)
182 DWORD err = GetLastError();
183 if (err != ERROR_FILE_EXISTS) {
187 #elif defined(Q_OS_SYMBIAN) 188 TInt err = file.Create(fs, qt_QString2TPtrC(path),
189 EFileRead | EFileWrite | EFileShareReadersOrWriters);
194 if (err != KErrAlreadyExists) {
200 QT_OPEN_CREAT |
O_EXCL | QT_OPEN_RDWR | QT_OPEN_LARGEFILE,
214 for (
Char *iter = placeholderStart;;) {
217 switch (
char(*iter)) {
221 if (++iter == placeholderEnd) {
229 case '0':
case '1':
case '2':
case '3':
case '4':
230 case '5':
case '6':
case '7':
case '8':
case '9':
271 bool open(QIODevice::OpenMode flags);
288 if (!((0 ==
d->fh) && (-1 ==
d->fd)
289 #
if defined (Q_OS_SYMBIAN)
290 && (0 ==
d->symbianFile.SubSessionHandle())
293 && (INVALID_HANDLE_VALUE ==
d->fileHandle)
326 QString qfilename =
d->fileEntry.filePath();
359 phPos = filename.
length();
381 #if defined(Q_OS_WIN) 383 #elif defined(Q_OS_SYMBIAN) 396 #if !defined(Q_OS_WIN) 397 d->closeFileHandle =
true;
402 d->openMode = openMode;
403 d->lastFlushFailed =
false;
416 d->fileEntry.clear();
555 d->templateName = templateName;
590 d->templateName = templateName;
605 if (!
d->fileName.isEmpty() &&
d->autoRemove)
638 return d->autoRemove;
666 if(
d->fileName.isEmpty())
680 return d->templateName;
698 d->templateName =
name;
724 bool wasOpen = file.
isOpen();
727 old_off = file.
pos();
739 ret->
write(buffer, len);
761 if (
d->fileName.isEmpty())
766 return d->fileEngine;
782 if (!
d->fileName.isEmpty()) {
783 if (static_cast<QTemporaryFileEngine*>(
fileEngine())->isReallyOpen()) {
798 #endif // QT_NO_TEMPORARYFILE void setError(QFile::FileError error, const QString &str)
Sets the error type to error, and the error string to errorString.
QTemporaryFileEngine(const QString &file, bool fileIsTemplate=true)
void setAutoRemove(bool b)
Sets the QTemporaryFile into auto-remove mode if b is true.
#define QT_END_NAMESPACE
This macro expands to.
static bool createFileFromTemplate(NativeFileHandle &file, QFileSystemEntry::NativePath &path, size_t pos, size_t length, QSystemError &error)
Generates a unique file path and returns a native handle to the open file.
void setOpenMode(OpenMode openMode)
Sets the OpenMode of the device to openMode.
virtual QString fileName(FileName file=DefaultName) const
Return the file engine's current file name in the format specified by file.
bool open(OpenMode flags)
Opens the file using OpenMode mode, returning true if successful; otherwise false.
static Char Latin1Char(char ch)
static QTemporaryFile * createLocalFile(const QString &fileName)
This is an overloaded member function, provided for convenience. It differs from the above function o...
int length() const
Returns the number of characters in this string.
The QTemporaryFile class is an I/O device that operates on temporary files.
virtual QAbstractFileEngine * fileEngine() const
Returns the QIOEngine for this QFile object.
bool open()
A QTemporaryFile will always be opened in QIODevice::ReadWrite mode, this allows easy access to the d...
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
~QTemporaryFile()
Destroys the temporary file object, the file is automatically closed if necessary and if in auto remo...
The QString class provides a Unicode character string.
Q_CORE_EXPORT int qrand()
The QObject class is the base class of all Qt objects.
bool rename(const QString &newName)
Reimplemented Function
QChar * data()
Returns a pointer to the data stored in the QString.
void setFileName(const QString &file)
Reimplemented Function
NativePath nativeFilePath() const
qint64 read(char *data, qint64 maxlen)
Reads at most maxSize bytes from the device into data, and returns the number of bytes read...
bool rename(const QString &newName)
Reimplemented Function
void setFileName(const QString &file)
Reimplemented Function
#define QT_BEGIN_NAMESPACE
This macro expands to.
static QFileSystemEntry absoluteName(const QFileSystemEntry &entry)
bool isOpen() const
Returns true if the device is open; otherwise returns false.
void setFileTemplate(const QString &fileTemplate)
bool open(QIODevice::OpenMode openMode)
Reimplemented Function
The QAbstractFileEngine class provides an abstraction for accessing the filesystem.
static qint64 applicationPid()
Returns the current process ID for the application.
bool seek(qint64)
Reimplemented Function
QFile::FileError error() const
Returns the QFile::FileError that resulted from the last failed operation.
qint64 pos() const
Reimplemented Function
bool close()
Reimplemented Function
static QString tempPath()
Returns the absolute path of the system's temporary directory.
#define Q_DECLARE_PUBLIC(Class)
QString & append(QChar c)
QString fileTemplate() const
Returns the set file template.
bool open(QIODevice::OpenMode flags)
Reimplemented Function
The QFile class provides an interface for reading from and writing to files.
QObject * parent() const
Returns a pointer to the parent object.
QString fileName() const
Returns the complete unique filename backing the QTemporaryFile object.
bool autoRemove() const
Returns true if the QTemporaryFile is in auto remove mode.
virtual QAbstractFileEngine * fileEngine() const
QTemporaryFile()
Constructs a QTemporaryFile in QDir::tempPath(), using the file template "qt_temp.XXXXXX".
bool remove()
Reimplemented Function
bool remove()
Reimplemented Function
#define Q_DECLARE_PRIVATE(Class)
void setFileTemplate(const QString &name)
Sets the static portion of the file name to name.
qint64 write(const char *data, qint64 len)
Writes at most maxSize bytes of data from data to the device.
virtual void close()
Calls QFile::flush() and closes the file.
bool seek(qint64 offset)
For random-access devices, this function sets the current position to pos, returning true on success...
bool close()
Reimplemented Function
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
const QChar * constData() const
Returns a pointer to the data stored in the QString.
The QFSFileEngine class implements Qt's default file engine.