Qt 4.8
Public Functions | Public Variables | List of all members
QTemporaryFileEngine Class Reference
Inheritance diagram for QTemporaryFileEngine:
QFSFileEngine QAbstractFileEngine

Public Functions

bool close ()
 Reimplemented Function More...
 
bool isReallyOpen ()
 
bool open (QIODevice::OpenMode flags)
 Reimplemented Function More...
 
 QTemporaryFileEngine (const QString &file, bool fileIsTemplate=true)
 
bool remove ()
 Reimplemented Function More...
 
bool rename (const QString &newName)
 Reimplemented Function More...
 
void setFileName (const QString &file)
 Reimplemented Function More...
 
void setFileTemplate (const QString &fileTemplate)
 
 ~QTemporaryFileEngine ()
 
- Public Functions inherited from QFSFileEngine
IteratorbeginEntryList (QDir::Filters filters, const QStringList &filterNames)
 
bool caseSensitive () const
 Returns true for Windows, false for Unix. More...
 
bool copy (const QString &newName)
 For windows, copy the file to file copyName. More...
 
IteratorendEntryList ()
 
QStringList entryList (QDir::Filters filters, const QStringList &filterNames) const
 
bool extension (Extension extension, const ExtensionOption *option=0, ExtensionReturn *output=0)
 Reimplemented Function More...
 
FileFlags fileFlags (FileFlags type) const
 Reimplemented Function More...
 
QString fileName (FileName file) const
 Reimplemented Function More...
 
QDateTime fileTime (FileTime time) const
 Reimplemented Function More...
 
bool flush ()
 Reimplemented Function More...
 
int handle () const
 Reimplemented Function More...
 
bool isRelativePath () const
 Reimplemented Function More...
 
bool isSequential () const
 Reimplemented Function More...
 
bool link (const QString &newName)
 Creates a link from the file currently specified by fileName() to newName. More...
 
bool mkdir (const QString &dirName, bool createParentDirectories) const
 Reimplemented Function More...
 
bool open (QIODevice::OpenMode flags, FILE *fh)
 Opens the file handle fh in openMode mode. More...
 
bool open (QIODevice::OpenMode flags, int fd)
 Opens the file descriptor fd in openMode mode. More...
 
bool open (QIODevice::OpenMode flags, int fd, QFile::FileHandleFlags handleFlags)
 Opens the file descriptor fd in openMode mode. More...
 
bool open (QIODevice::OpenMode flags, FILE *fh, QFile::FileHandleFlags handleFlags)
 Opens the file handle fh in openMode mode. More...
 
QString owner (FileOwner) const
 Reimplemented Function More...
 
uint ownerId (FileOwner) const
 In Unix, if stat() is successful, the uid is returned if own is the owner. More...
 
qint64 pos () const
 Reimplemented Function More...
 
 QFSFileEngine ()
 Constructs a QFSFileEngine. More...
 
 QFSFileEngine (const QString &file)
 Constructs a QFSFileEngine for the file name file. More...
 
qint64 read (char *data, qint64 maxlen)
 Reimplemented Function More...
 
qint64 readLine (char *data, qint64 maxlen)
 Reimplemented Function More...
 
bool rmdir (const QString &dirName, bool recurseParentDirectories) const
 Reimplemented Function More...
 
bool seek (qint64)
 Reimplemented Function More...
 
bool setPermissions (uint perms)
 Reimplemented Function More...
 
bool setSize (qint64 size)
 Reimplemented Function More...
 
qint64 size () const
 Reimplemented Function More...
 
bool supportsExtension (Extension extension) const
 Reimplemented Function More...
 
qint64 write (const char *data, qint64 len)
 Reimplemented Function More...
 
 ~QFSFileEngine ()
 Destructs the QFSFileEngine. More...
 
- Public Functions inherited from QAbstractFileEngine
bool atEnd () const
 Returns true if the current position is at the end of the file; otherwise, returns false. More...
 
QFile::FileError error () const
 Returns the QFile::FileError that resulted from the last failed operation. More...
 
QString errorString () const
 Returns the human-readable message appropriate to the current error reported by error(). More...
 
ucharmap (qint64 offset, qint64 size, QFile::MemoryMapFlags flags)
 Maps size bytes of the file into memory starting at offset. More...
 
bool unmap (uchar *ptr)
 Unmaps the memory address. More...
 
virtual ~QAbstractFileEngine ()
 Destroys the QAbstractFileEngine. More...
 

Public Variables

bool filePathIsTemplate
 

Additional Inherited Members

- Public Types inherited from QAbstractFileEngine
enum  Extension { AtEndExtension, FastReadLineExtension, MapExtension, UnMapExtension }
 This enum describes the types of extensions that the file engine can support. More...
 
enum  FileFlag {
  ReadOwnerPerm = 0x4000, WriteOwnerPerm = 0x2000, ExeOwnerPerm = 0x1000, ReadUserPerm = 0x0400,
  WriteUserPerm = 0x0200, ExeUserPerm = 0x0100, ReadGroupPerm = 0x0040, WriteGroupPerm = 0x0020,
  ExeGroupPerm = 0x0010, ReadOtherPerm = 0x0004, WriteOtherPerm = 0x0002, ExeOtherPerm = 0x0001,
  LinkType = 0x10000, FileType = 0x20000, DirectoryType = 0x40000, BundleType = 0x80000,
  HiddenFlag = 0x0100000, LocalDiskFlag = 0x0200000, ExistsFlag = 0x0400000, RootFlag = 0x0800000,
  Refresh = 0x1000000, PermsMask = 0x0000FFFF, TypesMask = 0x000F0000, FlagsMask = 0x0FF00000,
  FileInfoAll = FlagsMask | PermsMask | TypesMask
}
 The permissions and types of a file, suitable for OR'ing together. More...
 
enum  FileName {
  DefaultName, BaseName, PathName, AbsoluteName,
  AbsolutePathName, LinkName, CanonicalName, CanonicalPathName,
  BundleName, NFileNames = 9
}
 These values are used to request a file name in a particular format. More...
 
enum  FileOwner { OwnerUser, OwnerGroup }
 
enum  FileTime { CreationTime, ModificationTime, AccessTime }
 These are used by the fileTime() function. More...
 
typedef QAbstractFileEngineIterator Iterator
 
- Static Public Functions inherited from QFSFileEngine
static QString currentPath (const QString &path=QString())
 For Unix, returns the current working directory for the file engine. More...
 
static QFileInfoList drives ()
 For Windows, returns the list of drives in the file system as a list of QFileInfo objects. More...
 
static QString homePath ()
 Returns the home path of the current user. More...
 
static QString rootPath ()
 Returns the root path. More...
 
static bool setCurrentPath (const QString &path)
 Sets the current path (e. More...
 
static QString tempPath ()
 Returns the temporary path (i. More...
 
- Static Public Functions inherited from QAbstractFileEngine
static QAbstractFileEnginecreate (const QString &fileName)
 Creates and returns a QAbstractFileEngine suitable for processing fileName. More...
 
- Protected Functions inherited from QFSFileEngine
 QFSFileEngine (QFSFileEnginePrivate &dd)
 
- Protected Functions inherited from QAbstractFileEngine
 QAbstractFileEngine ()
 Constructs a new QAbstractFileEngine that does not refer to any file or directory. More...
 
 QAbstractFileEngine (QAbstractFileEnginePrivate &)
 Constructs a QAbstractFileEngine. More...
 
void setError (QFile::FileError error, const QString &str)
 Sets the error type to error, and the error string to errorString. More...
 
- Protected Variables inherited from QAbstractFileEngine
QScopedPointer< QAbstractFileEnginePrivated_ptr
 

Detailed Description

Definition at line 251 of file qtemporaryfile.cpp.

Constructors and Destructors

◆ QTemporaryFileEngine()

QTemporaryFileEngine::QTemporaryFileEngine ( const QString file,
bool  fileIsTemplate = true 
)
inline

Definition at line 255 of file qtemporaryfile.cpp.

256  : QFSFileEngine(), filePathIsTemplate(fileIsTemplate)
257  {
259  d->fileEntry = QFileSystemEntry(file);
260 
261  if (!filePathIsTemplate)
263  }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
void setFileName(const QString &file)
Reimplemented Function
QFSFileEngine()
Constructs a QFSFileEngine.
The QFSFileEngine class implements Qt&#39;s default file engine.
Definition: qfsfileengine.h:60

◆ ~QTemporaryFileEngine()

QTemporaryFileEngine::~QTemporaryFileEngine ( )

Definition at line 279 of file qtemporaryfile.cpp.

Referenced by QTemporaryFileEngine().

280 {
282 }
bool close()
Reimplemented Function

Functions

◆ close()

bool QTemporaryFileEngine::close ( )
virtual

Reimplemented Function

Reimplemented from QFSFileEngine.

Definition at line 428 of file qtemporaryfile.cpp.

Referenced by QTemporaryFileEngine().

429 {
430  // Don't close the file, just seek to the front.
431  seek(0);
433  return true;
434 }
void setError(QFile::FileError error, const QString &str)
Sets the error type to error, and the error string to errorString.
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool seek(qint64)
Reimplemented Function

◆ isReallyOpen()

bool QTemporaryFileEngine::isReallyOpen ( )

Definition at line 284 of file qtemporaryfile.cpp.

Referenced by open(), and QTemporaryFileEngine().

285 {
287 
288  if (!((0 == d->fh) && (-1 == d->fd)
289 #if defined (Q_OS_SYMBIAN)
290  && (0 == d->symbianFile.SubSessionHandle())
291 #endif
292 #if defined Q_OS_WIN
293  && (INVALID_HANDLE_VALUE == d->fileHandle)
294 #endif
295  ))
296  return true;
297 
298  return false;
299 
300 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
#define Q_OS_WIN
Definition: qglobal.h:270
The QFSFileEngine class implements Qt&#39;s default file engine.
Definition: qfsfileengine.h:60

◆ open()

bool QTemporaryFileEngine::open ( QIODevice::OpenMode  openMode)
virtual

Reimplemented Function

Reimplemented from QFSFileEngine.

Definition at line 316 of file qtemporaryfile.cpp.

Referenced by QTemporaryFileEngine().

317 {
320 
321  openMode |= QIODevice::ReadWrite;
322 
323  if (!filePathIsTemplate)
324  return QFSFileEngine::open(openMode);
325 
326  QString qfilename = d->fileEntry.filePath();
327 
328  // Ensure there is a placeholder mask
329  uint phPos = qfilename.length();
330  uint phLength = 0;
331 
332  while (phPos != 0) {
333  --phPos;
334 
335  if (qfilename[phPos] == QLatin1Char('X')) {
336  ++phLength;
337  continue;
338  }
339 
340  if (phLength >= 6
341  || qfilename[phPos] == QLatin1Char('/')) {
342  ++phPos;
343  break;
344  }
345 
346  // start over
347  phLength = 0;
348  }
349 
350  if (phLength < 6)
351  qfilename.append(QLatin1String(".XXXXXX"));
352 
353  // "Nativify" :-)
356  .nativeFilePath();
357 
358  // Find mask in native path
359  phPos = filename.length();
360  phLength = 0;
361  while (phPos != 0) {
362  --phPos;
363 
364  if (filename[phPos] == Latin1Char('X')) {
365  ++phLength;
366  continue;
367  }
368 
369  if (phLength >= 6) {
370  ++phPos;
371  break;
372  }
373 
374  // start over
375  phLength = 0;
376  }
377 
378  Q_ASSERT(phLength >= 6);
379 
381 #if defined(Q_OS_WIN)
382  NativeFileHandle &file = d->fileHandle;
383 #elif defined(Q_OS_SYMBIAN)
384  NativeFileHandle &file = d->symbianFile;
385 #else // POSIX
386  NativeFileHandle &file = d->fd;
387 #endif
388 
389  if (!createFileFromTemplate(file, filename, phPos, phLength, error)) {
391  return false;
392  }
393 
394  d->fileEntry = QFileSystemEntry(filename, QFileSystemEntry::FromNativePath());
395 
396 #if !defined(Q_OS_WIN)
397  d->closeFileHandle = true;
398 #endif
399 
400  filePathIsTemplate = false;
401 
402  d->openMode = openMode;
403  d->lastFlushFailed = false;
404  d->tried_stat = 0;
405 
406  return true;
407 }
void setError(QFile::FileError error, const QString &str)
Sets the error type to error, and the error string to errorString.
double d
Definition: qnumeric_p.h:62
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.
static Char Latin1Char(char ch)
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
NativePath nativeFilePath() const
static QFileSystemEntry absoluteName(const QFileSystemEntry &entry)
bool open(QIODevice::OpenMode openMode)
Reimplemented Function
unsigned int uint
Definition: qglobal.h:996
QFile::FileError error() const
Returns the QFile::FileError that resulted from the last failed operation.
QString & append(QChar c)
Definition: qstring.cpp:1777
QString toString()
HANDLE NativeFileHandle
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
The QFSFileEngine class implements Qt&#39;s default file engine.
Definition: qfsfileengine.h:60

◆ remove()

bool QTemporaryFileEngine::remove ( )
virtual

Reimplemented Function

Reimplemented from QFSFileEngine.

Definition at line 409 of file qtemporaryfile.cpp.

410 {
412  // Since the QTemporaryFileEngine::close() does not really close the file,
413  // we must explicitly call QFSFileEngine::close() before we remove it.
415  if (QFSFileEngine::remove()) {
416  d->fileEntry.clear();
417  return true;
418  }
419  return false;
420 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
bool remove()
Reimplemented Function
bool close()
Reimplemented Function
The QFSFileEngine class implements Qt&#39;s default file engine.
Definition: qfsfileengine.h:60

◆ rename()

bool QTemporaryFileEngine::rename ( const QString newName)
virtual

Reimplemented Function

Reimplemented from QFSFileEngine.

Definition at line 422 of file qtemporaryfile.cpp.

Referenced by QTemporaryFileEngine().

423 {
425  return QFSFileEngine::rename(newName);
426 }
bool rename(const QString &newName)
Reimplemented Function
bool close()
Reimplemented Function

◆ setFileName()

void QTemporaryFileEngine::setFileName ( const QString file)
virtual

Reimplemented Function

Reimplemented from QFSFileEngine.

Definition at line 302 of file qtemporaryfile.cpp.

Referenced by QTemporaryFileEngine().

303 {
304  // Really close the file, so we don't leak
307 }
void setFileName(const QString &file)
Reimplemented Function
bool close()
Reimplemented Function

◆ setFileTemplate()

void QTemporaryFileEngine::setFileTemplate ( const QString fileTemplate)

Definition at line 309 of file qtemporaryfile.cpp.

Referenced by QTemporaryFileEngine().

310 {
312  if (filePathIsTemplate)
313  d->fileEntry = QFileSystemEntry(fileTemplate);
314 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QFSFileEngine class implements Qt&#39;s default file engine.
Definition: qfsfileengine.h:60

Properties

◆ filePathIsTemplate

bool QTemporaryFileEngine::filePathIsTemplate

Definition at line 276 of file qtemporaryfile.cpp.

Referenced by open(), QTemporaryFileEngine(), and setFileTemplate().


The documentation for this class was generated from the following file: