diff options
author | Thiago Macieira <thiago.macieira@nokia.com> | 2009-08-31 19:34:10 +0200 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@nokia.com> | 2009-08-31 19:34:10 +0200 |
commit | 0d411622521a89c04a416e2aaf3da44b6015b183 (patch) | |
tree | 51e61cea6b56b40d359a8914f59bf3297a5e0d3e /src/corelib/io/qtemporaryfile.cpp | |
parent | 3b65bb32fda7e34373b64f416ea92a3fa6eb266c (diff) | |
parent | 20cc50a21eb5841b3a3e8546877e805f5a4df528 (diff) | |
download | qt4-tools-0d411622521a89c04a416e2aaf3da44b6015b183.tar.gz |
Merge branch '4.5' into 4.6
Diffstat (limited to 'src/corelib/io/qtemporaryfile.cpp')
-rw-r--r-- | src/corelib/io/qtemporaryfile.cpp | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp index 48f34d6ff6..fa3ed09645 100644 --- a/src/corelib/io/qtemporaryfile.cpp +++ b/src/corelib/io/qtemporaryfile.cpp @@ -292,14 +292,20 @@ class QTemporaryFileEngine : public QFSFileEngine Q_DECLARE_PRIVATE(QFSFileEngine) public: QTemporaryFileEngine(const QString &file, bool fileIsTemplate = true) - : QFSFileEngine(file), filePathIsTemplate(fileIsTemplate) + : QFSFileEngine(), filePathIsTemplate(fileIsTemplate) { + Q_D(QFSFileEngine); + d->filePath = file; + + if (!filePathIsTemplate) + QFSFileEngine::setFileName(file); } ~QTemporaryFileEngine(); bool isReallyOpen(); void setFileName(const QString &file); + void setFileTemplate(const QString &fileTemplate); bool open(QIODevice::OpenMode flags); bool remove(); @@ -336,6 +342,13 @@ void QTemporaryFileEngine::setFileName(const QString &file) QFSFileEngine::setFileName(file); } +void QTemporaryFileEngine::setFileTemplate(const QString &fileTemplate) +{ + Q_D(QFSFileEngine); + if (filePathIsTemplate) + d->filePath = fileTemplate; +} + bool QTemporaryFileEngine::open(QIODevice::OpenMode openMode) { Q_D(QFSFileEngine); @@ -382,12 +395,19 @@ bool QTemporaryFileEngine::open(QIODevice::OpenMode openMode) return false; } + QString template_ = d->filePath; d->filePath = QString::fromLocal8Bit(filename); - filePathIsTemplate = false; d->nativeInitFileName(); - d->closeFileHandle = true; delete [] filename; - return QFSFileEngine::open(openMode); + + if (QFSFileEngine::open(openMode)) { + filePathIsTemplate = false; + return true; + } + + d->filePath = template_; + d->nativeFilePath.clear(); + return false; #endif } @@ -533,7 +553,8 @@ QTemporaryFile::QTemporaryFile() QTemporaryFile::QTemporaryFile(const QString &templateName) : QFile(*new QTemporaryFilePrivate, 0) { - setFileTemplate(templateName); + Q_D(QTemporaryFile); + d->templateName = templateName; } /*! @@ -567,7 +588,8 @@ QTemporaryFile::QTemporaryFile(QObject *parent) QTemporaryFile::QTemporaryFile(const QString &templateName, QObject *parent) : QFile(*new QTemporaryFilePrivate, parent) { - setFileTemplate(templateName); + Q_D(QTemporaryFile); + d->templateName = templateName; } #endif @@ -671,10 +693,10 @@ QString QTemporaryFile::fileTemplate() const */ void QTemporaryFile::setFileTemplate(const QString &name) { - Q_ASSERT(!isOpen()); Q_D(QTemporaryFile); - fileEngine()->setFileName(name); d->templateName = name; + if (d->fileEngine) + static_cast<QTemporaryFileEngine*>(d->fileEngine)->setFileTemplate(name); } /*! |