FileName FileName::addExtension(const QString &newExtension) const { FileName result = *this; if (result.extension() != newExtension) { QString attributesStr = result.attributes(); if (attributesStr == "") result = FileName(result.originalPath() + "/" + result.name() + "." + newExtension); else result = FileName(result.originalPath() + "/" + result.name() + "." + newExtension + "+" + attributesStr); } return result; }
FileName FileName::createTempFile(FileName templateFileName) { QString preppedFileName = QString("%1/%2XXXXXX.%3").arg(templateFileName.path()) .arg(templateFileName.baseName()).arg(templateFileName.extension()); QTemporaryFile tempFile(preppedFileName); tempFile.setAutoRemove(false); if (!tempFile.open()) { throw IException(IException::Io, QObject::tr("Could not create a unique temporary file name based on [%1]") .arg(templateFileName.original()), _FILEINFO_); } // We want to set the 'original' path as correctly as possible. So let's use the input original // path with the output temp file's file name in our result. FileName result; QString newTempFileNameStr = templateFileName.originalPath() + "/" + QFileInfo(tempFile.fileName()).fileName(); result = FileName(newTempFileNameStr); return result; }