]> cloud.milkyroute.net Git - dolphin.git/commitdiff
fixed issue that when renaming "Open office.org writer documentation.pdf" that only...
authorPeter Penz <peter.penz19@gmail.com>
Sat, 23 Feb 2008 11:59:57 +0000 (11:59 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Sat, 23 Feb 2008 11:59:57 +0000 (11:59 +0000)
BUG: 158228

svn path=/trunk/KDE/kdebase/apps/; revision=778329

src/renamedialog.cpp
src/tests/renamedialogtest.cpp

index fa5bf60e06278659e71ab70c24e6bc2802ecc8df..3e9b39327d9907012c92a679180ae2d8054907e2 100644 (file)
@@ -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;
index aeca0a0c4efd5196aa3035bf323237a784b5db57..dc2adffd95f271e8b26c5e347c54f7394e30112d 100644 (file)
@@ -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"