Commit b79ac774 authored by Franz Baumgärtner's avatar Franz Baumgärtner Committed by Bhushan Shah

fix autoincrement of %d for templates with subdirs

in case the filename to save a screenshot to contains subdirectories,
the auto-increment of any %d placeholders was broken.

For a template of '%Y/%M/screen-%d' and '%Y/%M/screen-1.png' already existing
this now results in '%Y/%M/screen-2.png' being created instead of '%Y/%M/screen-1-1.png'.
parent 817f9e28
......@@ -172,7 +172,7 @@ QString ExportManager::formatFilename(const QString &nameTemplate)
const QDateTime timestamp = mPixmapTimestamp;
QString baseName = nameTemplate;
const QString baseDir = defaultSaveLocation();
QString baseDir = defaultSaveLocation();
QString title;
if (mCaptureMode == Spectacle::CaptureMode::ActiveWindow ||
......@@ -201,7 +201,9 @@ QString ExportManager::formatFilename(const QString &nameTemplate)
QRegularExpressionMatchIterator it = paddingRE.globalMatch(result);
if (it.hasNext()) {
QString resultCopy = QRegularExpression::escape(result);
// strip any subdirectories from the template to construct the filename matching regex
// we are matching filenames only, not paths
QString resultCopy = QRegularExpression::escape(result.section(QLatin1Char('/'), -1));
QVector<QRegularExpressionMatch> matches;
while (it.hasNext()) {
QRegularExpressionMatch paddingMatch =;
......@@ -214,6 +216,12 @@ QString ExportManager::formatFilename(const QString &nameTemplate)
QString escapedMatch = QRegularExpression::escape(paddingMatch.captured());
resultCopy.replace(escapedMatch, QStringLiteral("(\\d{%1,})").arg(QString::number(paddedLength)));
if (result.contains(QLatin1Char('/'))) {
// In case the filename template contains a subdirectory,
// we need to search for files in the subdirectory instead of the baseDir.
// so let's add that to baseDir before we search for files.
baseDir += QStringLiteral("/%1").arg(result.section(QLatin1Char('/'), 0, -2));
// search save directory for files
QDir dir(baseDir);
const QStringList fileNames = dir.entryList(QDir::Files, QDir::Name);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment