From a802222b068d395c1b90c91cdeba36edb792ff98 Mon Sep 17 00:00:00 2001 From: Le Tan Date: Sun, 2 Jul 2017 17:52:11 +0800 Subject: [PATCH] constrain the length of the inserted image file --- src/utils/vutils.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/utils/vutils.cpp b/src/utils/vutils.cpp index 7ae0c0f9..9f741ace 100644 --- a/src/utils/vutils.cpp +++ b/src/utils/vutils.cpp @@ -105,7 +105,13 @@ QString VUtils::generateImageFileName(const QString &path, const QString &title, Q_ASSERT(!title.isEmpty()); QRegExp regExp("\\W"); QString baseName(title.toLower()); + + // Remove non-character chars. baseName.remove(regExp); + + // Constrain the length of the name. + baseName.truncate(10); + baseName.prepend('_'); // Add current time and random number to make the name be most likely unique @@ -116,11 +122,12 @@ QString VUtils::generateImageFileName(const QString &path, const QString &title, QString filePath = QDir(path).filePath(imageName); int index = 1; - while (QFile(filePath).exists()) { + while (QFileInfo::exists(filePath)) { imageName = QString("%1_%2.%3").arg(baseName).arg(index++) .arg(format.toLower()); filePath = QDir(path).filePath(imageName); } + return imageName; }