Change in kio[master]: Revert "Fix replace dialog's name suggestion"

Jan Kundrát (Code Review) noreply at kde.org
Thu Dec 25 10:40:32 UTC 2014


Jan Kundrát has uploaded a new change for review.

  https://gerrit.vesnicky.cesnet.cz/r/269

Change subject: Revert "Fix replace dialog's name suggestion"
......................................................................

Revert "Fix replace dialog's name suggestion"

A regression got introduced by this commit, the tests no longer pass.

This reverts commit b75d94bfe399b2764e7947c1a4cb7f668af5d54c.

Change-Id: I3eea8cf0917471c8d1e8474da3cc48de6667ba07
---
M autotests/globaltest.cpp
M src/core/global.cpp
2 files changed, 18 insertions(+), 20 deletions(-)


  git pull ssh://gerrit.vesnicky.cesnet.cz:29418/kio refs/changes/69/269/1

diff --git a/autotests/globaltest.cpp b/autotests/globaltest.cpp
index 9bd8d07..06cb500 100644
--- a/autotests/globaltest.cpp
+++ b/autotests/globaltest.cpp
@@ -93,10 +93,8 @@
     QTest::newRow("with_space") << "foo bar" << QStringList("foo bar") << "foo bar 1";
     QTest::newRow("dot_at_beginning") << ".aFile.tar.gz" << QStringList() << ".aFile 1.tar.gz";
     QTest::newRow("dots_at_beginning") << "..aFile.tar.gz" << QStringList() << "..aFile 1.tar.gz";
-    QTest::newRow("empty_basename") << ".txt" << QStringList() << ".txt 1";
-    QTest::newRow("hidden_file") << ".foo" << QStringList() << ".foo 1";
-    QTest::newRow("empty_basename_2dots") << "..txt" << QStringList() << "..txt 1";
-    QTest::newRow("hidden_file_2dots") << "..foo" << QStringList() << "..foo 1";
+    QTest::newRow("empty_basename") << ".txt" << QStringList() << "1.txt";
+    QTest::newRow("empty_basename_2dots") << "..txt" << QStringList() << ".1.txt";
 }
 
 void GlobalTest::testSuggestName()
diff --git a/src/core/global.cpp b/src/core/global.cpp
index 1dfcb6d..f18ac10 100644
--- a/src/core/global.cpp
+++ b/src/core/global.cpp
@@ -389,24 +389,24 @@
 {
     QString dotSuffix, suggestedName;
     QString basename = oldName;
-    const QString spacer = QChar(' ');
+    QString spacer = QChar(' ');
 
-    const QMimeDatabase db;
-    const QString suffix = db.suffixForFileName(oldName);
+    //ignore dots at the beginning, that way "..aFile.tar.gz" will become "..aFile 1.tar.gz" instead of " 1..aFile.tar.gz"
+    int start = 0;
+    while (start < basename.length()-1 && basename.at(start) == '.') {
+        ++start;
+    }
+    // find next dot
+    int index = basename.indexOf('.', start);
+    if (index == -1 && start > 0) {
+        // last chance, using one of the leading dots we skipped, if any
+        index = start - 1;
+        spacer.clear();
+    }
 
-    if (!suffix.isEmpty()) {
-        dotSuffix = '.' + suffix;
-        basename.chop(dotSuffix.length());
-
-        const bool containsOnlyDots = std::all_of(basename.cbegin(),
-                                                  basename.cend(),
-                                                  [](QChar c) {return c == QLatin1Char('.');});
-
-        // ".foo" -> ".foo 1" and "..foo" -> "..foo 1"
-        if (basename.isEmpty() || containsOnlyDots) {
-            basename += dotSuffix;
-            dotSuffix.clear();
-        }
+    if (index != -1) {
+        dotSuffix = basename.mid(index);
+        basename.truncate(index);
     }
 
     int pos = basename.lastIndexOf(spacer);

-- 
To view, visit https://gerrit.vesnicky.cesnet.cz/r/269
To unsubscribe, visit https://gerrit.vesnicky.cesnet.cz/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3eea8cf0917471c8d1e8474da3cc48de6667ba07
Gerrit-PatchSet: 1
Gerrit-Project: kio
Gerrit-Branch: master
Gerrit-Owner: Jan Kundrát <jkt at kde.org>
Gerrit-Reviewer: Arjun AK <arjunak234 at gmail.com>


More information about the Kde-frameworks-devel mailing list