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>
This commit is contained in:
parent
84251f84b6
commit
c7a0fd0950
@ -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()
|
||||
*/
|
||||
|
@ -111,6 +111,7 @@ void tst_QTemporaryFile::initTestCase()
|
||||
{
|
||||
// For QTBUG_4796
|
||||
QVERIFY(QDir("test-XXXXXX").exists() || QDir().mkdir("test-XXXXXX"));
|
||||
QCoreApplication::setApplicationName("tst_qtemporaryfile");
|
||||
}
|
||||
|
||||
void tst_QTemporaryFile::cleanupTestCase()
|
||||
@ -221,8 +222,9 @@ void tst_QTemporaryFile::fileName()
|
||||
file.setAutoRemove(true);
|
||||
file.open();
|
||||
QString fileName = file.fileName();
|
||||
QVERIFY2(fileName.contains("/tst_qtemporaryfile."), qPrintable(fileName));
|
||||
QVERIFY(QFile::exists(fileName));
|
||||
// Get path to the temp file, whithout the file name.
|
||||
// Get path to the temp file, without the file name.
|
||||
QString absoluteFilePath = QFileInfo(fileName).absolutePath();
|
||||
#if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN)
|
||||
absoluteFilePath = absoluteFilePath.toLower();
|
||||
|
Loading…
Reference in New Issue
Block a user