From: Peter Penz Date: Sat, 23 Feb 2008 11:59:57 +0000 (+0000) Subject: fixed issue that when renaming "Open office.org writer documentation.pdf" that only... X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/3db4843c35b7380cdb2072e9df3ac5811db87e48 fixed issue that when renaming "Open office.org writer documentation.pdf" that only "Open office" is selected and ".org writer documentation" is handled as extension BUG: 158228 svn path=/trunk/KDE/kdebase/apps/; revision=778329 --- diff --git a/src/renamedialog.cpp b/src/renamedialog.cpp index fa5bf60e0..3e9b39327 100644 --- a/src/renamedialog.cpp +++ b/src/renamedialog.cpp @@ -128,24 +128,30 @@ void RenameDialog::slotButtonClicked(int button) QString RenameDialog::extensionString(const QString& name) { QString extension; - bool foundExtension = false; // true if at least one valid file extension - // like "gif", "txt", ... has been found - QStringList strings = name.split('.'); + const QStringList strings = name.split('.'); const int size = strings.size(); - for (int i = 1; i < size; ++i) { + for (int i = size - 1; i >= 0; --i) { const QString& str = strings.at(i); - if (!foundExtension) { - // Sub strings like "9", "12", "99", ... which contain only - // numbers don't count as extension. Usually they are version - // numbers like in "cmake-2.4.5". - bool ok = false; - str.toInt(&ok); - foundExtension = !ok; + + // Sub strings like "9", "12", "99", ... which contain only + // numbers don't count as extension. Usually they are version + // numbers like in "cmake-2.4.5". + bool isNumeric = false; + str.toInt(&isNumeric); + if (isNumeric) { + break; } - if (foundExtension) { - extension += '.' + str; + + // Extensions may not contain a space and the maximum length + // should not exceed 4 characters. This prevents that strings like + // "Open office.org writer documentation.pdf" get ".org writer documentation.pdf" + // as extension. + if (str.contains(' ') || (str.length() > 4)) { + break; } + + extension.insert(0, '.' + str); } return extension; diff --git a/src/tests/renamedialogtest.cpp b/src/tests/renamedialogtest.cpp index aeca0a0c4..dc2adffd9 100644 --- a/src/tests/renamedialogtest.cpp +++ b/src/tests/renamedialogtest.cpp @@ -40,7 +40,16 @@ void RenameDialogTest::testExtensionString() QCOMPARE(result, QString(".gif")); result = RenameDialog::extensionString("Image.tar.1.12.gz"); - QCOMPARE(result, QString(".tar.1.12.gz")); + QCOMPARE(result, QString(".gz")); + + result = RenameDialog::extensionString("Open office.org writer documentation.pdf"); + QCOMPARE(result, QString(".pdf")); + + result = RenameDialog::extensionString("Test.toolongextension.pdf"); + QCOMPARE(result, QString(".pdf")); + + result = RenameDialog::extensionString("Test.x x.pdf"); + QCOMPARE(result, QString(".pdf")); } #include "renamedialogtest.moc"