]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/kfileitemlistwidget.cpp
Fix bug 303375 - Dots in directory names treated as file extension.
[dolphin.git] / src / kitemviews / kfileitemlistwidget.cpp
index c99da383fcc13298e3240a6eb3dba6aab34343fa..3a7724134373a9e21c935d996515cd6b3aea8a33 100644 (file)
@@ -19,6 +19,7 @@
 
 #include "kfileitemlistwidget.h"
 
+#include <kmimetype.h>
 #include <KDebug>
 #include <KGlobal>
 #include <KLocale>
@@ -101,4 +102,34 @@ QFont KFileItemListWidget::customizedFont(const QFont& baseFont) const
     return font;
 }
 
+int KFileItemListWidget::selectionLength(const QString& text) const
+{
+    // Select the text without MIME-type extension
+    int selectionLength = text.length();
+
+    // If item is a directory, use the whole text length for
+    // selection (ignore all points)
+    if(data().value("isDir").toBool()) {
+        return selectionLength;
+    }
+
+    const QString extension = KMimeType::extractKnownExtension(text);
+    if (extension.isEmpty()) {
+        // For an unknown extension just exclude the extension after
+        // the last point. This does not work for multiple extensions like
+        // *.tar.gz but usually this is anyhow a known extension.
+        selectionLength = text.lastIndexOf(QLatin1Char('.'));
+
+        // If no point could be found, use whole text length for selection.
+        if (selectionLength < 1) {
+            selectionLength = text.length();
+        }
+
+    } else {
+        selectionLength -= extension.length() + 1;
+    }
+
+    return selectionLength;
+}
+
 #include "kfileitemlistwidget.moc"