]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Small fixes, but that have an impact of how things are visualized.
authorRafael Fernández López <ereslibre@kde.org>
Sat, 23 Jun 2007 00:43:20 +0000 (00:43 +0000)
committerRafael Fernández López <ereslibre@kde.org>
Sat, 23 Jun 2007 00:43:20 +0000 (00:43 +0000)
* Move "not tagged" elements to the end. We sort the rest (when they have tags), but keep untagged elements (the category) at the end of the view, since the user had
"less" interest on them.

* Break the law again of "dirs first". If we have on a folder only a tagged file (and is a file) and the rest are folders, that file goes first, since it was tagged.

* If we are on the same category, dirs go first. Here we make them citizens of first class.

* Commas instead of spaces when building categories for tags, they make it more readable and less error-prone (we can have tags "a", "dog" and "a dog" as tags, right?,
so spaces here make the thing a bit hard to distinguish, I have two tags "a", "dog", or the tag "a dog") ;)

* Return an empty string when the item is not tagged at the method tagsForIndex. This way we always show untagged items the latest ones very easily (without nasty string
checks). We will let the categorizer put a fancy name for them, if the returned string was empty.

CCMAIL: peter.penz@gmx.at

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

src/dolphinitemcategorizer.cpp
src/dolphinsortfilterproxymodel.cpp

index c83f9383f2bf3d2d35cec291149e0ead3fdfdbde..dfb3840624548550809b8a92a4bdc95043485e5f 100644 (file)
@@ -177,6 +177,10 @@ QString DolphinItemCategorizer::categoryForItem(const QModelIndex& index,
 
         case DolphinView::SortByTags: {
             retString = DolphinSortFilterProxyModel::tagsForIndex(index);
+
+            if (retString.isEmpty())
+                retString = i18n("Not yet tagged");
+
             break;
         }
 #endif
index e30a73d50f439c58e69be3f07c93f4d84473d345..2e321d7ecc89770cbf6d2b641025bbe64fe95719 100644 (file)
@@ -176,6 +176,14 @@ bool DolphinSortFilterProxyModel::lessThanGeneralPurpose(const QModelIndex &left
         return leftRating > rightRating;
     }
     case DolphinView::SortByTags: {
+        const QString leftTags = tagsForIndex(left);
+        const QString rightTags = tagsForIndex(right);
+
+        if (leftTags.isEmpty() && !rightTags.isEmpty())
+            return false;
+        else if (!leftTags.isEmpty() && rightTags.isEmpty())
+            return true;
+
         return naturalCompare(tagsForIndex(left), tagsForIndex(right)) < 0;
     }
 #endif
@@ -194,8 +202,9 @@ bool DolphinSortFilterProxyModel::lessThan(const QModelIndex& left,
     const KFileItem* rightFileItem = dirModel->itemForIndex(right);
 
     // If we are sorting by rating, folders and files are citizens of the same
-    // class
-    if (sortRole() != DolphinView::SortByRating)
+    // class. Same if we are sorting by tags.
+    if ((sortRole() != DolphinView::SortByRating) &&
+        (sortRole() != DolphinView::SortByTags))
     {
         // On our priority, folders go above regular files.
         if (leftFileItem->isDir() && !rightFileItem->isDir()) {
@@ -323,6 +332,11 @@ bool DolphinSortFilterProxyModel::lessThan(const QModelIndex& left,
 
         if (leftRating == rightRating) {
             // On our priority, folders go above regular files.
+            // This checks are needed (don't think it's the same doing it here
+            // than above). Here we make dirs citizens of first class because
+            // we know we are on the same category. On the check we do on the
+            // top of the method we don't know, so we remove that check when we
+            // are sorting by rating. (ereslibre)
             if (leftFileItem->isDir() && !rightFileItem->isDir()) {
                 return true;
             } else if (!leftFileItem->isDir() && rightFileItem->isDir()) {
@@ -338,7 +352,28 @@ bool DolphinSortFilterProxyModel::lessThan(const QModelIndex& left,
     }
 
     case DolphinView::SortByTags: {
-        return naturalCompare(tagsForIndex(left), tagsForIndex(right)) < 0;
+        const QString leftTags = tagsForIndex(left);
+        const QString rightTags = tagsForIndex(right);
+
+        if (leftTags == rightTags) {
+            // On our priority, folders go above regular files.
+            // This checks are needed (don't think it's the same doing it here
+            // than above). Here we make dirs citizens of first class because
+            // we know we are on the same category. On the check we do on the
+            // top of the method we don't know, so we remove that check when we
+            // are sorting by tags. (ereslibre)
+            if (leftFileItem->isDir() && !rightFileItem->isDir()) {
+                return true;
+            } else if (!leftFileItem->isDir() && rightFileItem->isDir()) {
+                return false;
+            }
+
+            return sortCaseSensitivity() ?
+                   (naturalCompare(leftFileItem->name(), rightFileItem->name()) < 0) :
+                   (naturalCompare(leftFileItem->name().toLower(), rightFileItem->name().toLower()) < 0);
+        }
+
+        return naturalCompare(leftTags, rightTags) < 0;
     }
 #endif
     }
@@ -384,12 +419,11 @@ QString DolphinSortFilterProxyModel::tagsForIndex(const QModelIndex& index)
 
         foreach (const QString& str, stringList) {
             tagsString += str;
-            tagsString += ' ';
+            tagsString += ", ";
         }
-    }
 
-    if (tagsString.isEmpty()) {
-        tagsString = i18n("(no tags)");
+        if (!tagsString.isEmpty())
+            tagsString.resize(tagsString.size() - 2);
     }
 
     return tagsString;