diff options
author | David Faure <faure@kde.org> | 2011-09-28 13:32:36 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-09-28 14:02:08 +0200 |
commit | c7a0fd0950179ed9ae0aa1e5b02df9b6a383c709 (patch) | |
tree | e3bc872b3ab66e7daf71d31e1eb66979f86b2c77 /src/corelib/io/qtemporaryfile.cpp | |
parent | 84251f84b6e7deadb7d50527b877d13cea74ad4b (diff) |
QTemporaryFile: use QCoreApplication::applicationName() as base filename
Merge-request: 57
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@nokia.com>
Change-Id: I2a29b2ba925ea92a5299272b80164658775e9c0e
Reviewed-on: http://codereview.qt-project.org/5713
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@nokia.com>
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Diffstat (limited to 'src/corelib/io/qtemporaryfile.cpp')
-rw-r--r-- | src/corelib/io/qtemporaryfile.cpp | 44 |
1 files changed, 31 insertions, 13 deletions
diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp index 0855d93962..ad7d7e6e0f 100644 --- a/src/corelib/io/qtemporaryfile.cpp +++ b/src/corelib/io/qtemporaryfile.cpp @@ -364,6 +364,8 @@ protected: QTemporaryFilePrivate(); ~QTemporaryFilePrivate(); + QString defaultTemplateName() const; + bool autoRemove; QString templateName; }; @@ -376,6 +378,18 @@ QTemporaryFilePrivate::~QTemporaryFilePrivate() { } +QString QTemporaryFilePrivate::defaultTemplateName() const +{ + QString baseName; +#if defined(QT_BUILD_CORE_LIB) + baseName = QCoreApplication::applicationName(); + if (baseName.isEmpty()) +#endif + baseName = QLatin1String("qt_temp"); + + return QDir::tempPath() + QLatin1Char('/') + baseName + QLatin1String(".XXXXXX"); +} + //************* QTemporaryFile /*! @@ -409,11 +423,11 @@ QTemporaryFilePrivate::~QTemporaryFilePrivate() returns an empty string before this. A temporary file will have some static part of the name and some - part that is calculated to be unique. The default filename \c - qt_temp will be placed into the temporary path as returned by - QDir::tempPath(). If you specify your own filename, a relative - file path will not be placed in the temporary directory by - default, but be relative to the current working directory. + part that is calculated to be unique. The default filename will be + determined from QCoreApplication::applicationName() (otherwise \c qt_temp) and will + be placed into the temporary path as returned by QDir::tempPath(). + If you specify your own filename, a relative file path will not be placed in the + temporary directory by default, but be relative to the current working directory. Specified filenames can contain the following template \c XXXXXX (six upper case "X" characters), which will be replaced by the @@ -429,7 +443,7 @@ QTemporaryFile::QTemporaryFile() : QFile(*new QTemporaryFilePrivate) { Q_D(QTemporaryFile); - d->templateName = QDir::tempPath() + QLatin1String("/qt_temp.XXXXXX"); + d->templateName = d->defaultTemplateName(); } QTemporaryFile::QTemporaryFile(const QString &templateName) @@ -441,8 +455,10 @@ QTemporaryFile::QTemporaryFile(const QString &templateName) #else /*! - Constructs a QTemporaryFile in QDir::tempPath(), using the file template - "qt_temp.XXXXXX". The file is stored in the system's temporary directory. + Constructs a QTemporaryFile using as file template + the application name returned by QCoreApplication::applicationName() + (otherwise \c qt_temp) followed by ".XXXXXX". + The file is stored in the system's temporary directory, QDir::tempPath(). \sa setFileTemplate(), QDir::tempPath() */ @@ -450,7 +466,7 @@ QTemporaryFile::QTemporaryFile() : QFile(*new QTemporaryFilePrivate, 0) { Q_D(QTemporaryFile); - d->templateName = QDir::tempPath() + QLatin1String("/qt_temp.XXXXXX"); + d->templateName = d->defaultTemplateName(); } /*! @@ -475,8 +491,10 @@ QTemporaryFile::QTemporaryFile(const QString &templateName) } /*! - Constructs a QTemporaryFile (with the given \a parent) in - QDir::tempPath(), using the file template "qt_temp.XXXXXX". + Constructs a QTemporaryFile (with the given \a parent) + using as file template the application name returned by QCoreApplication::applicationName() + (otherwise \c qt_temp) followed by ".XXXXXX". + The file is stored in the system's temporary directory, QDir::tempPath(). \sa setFileTemplate() */ @@ -484,7 +502,7 @@ QTemporaryFile::QTemporaryFile(QObject *parent) : QFile(*new QTemporaryFilePrivate, parent) { Q_D(QTemporaryFile); - d->templateName = QDir::tempPath() + QLatin1String("/qt_temp.XXXXXX"); + d->templateName = d->defaultTemplateName(); } /*! @@ -586,7 +604,7 @@ QString QTemporaryFile::fileName() const /*! Returns the set file template. The default file template will be - called qt_temp and be placed in QDir::tempPath(). + called qcoreappname.XXXXXX and be placed in QDir::tempPath(). \sa setFileTemplate() */ |