[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdebase/apps/dolphin/src
From: Peter Penz <peter.penz () gmx ! at>
Date: 2007-06-22 16:42:39
Message-ID: 1182530559.984455.21317.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 678957 by ppenz:
Implement sorting by "tags". Same performance problems occur as when using sorting by \
"rating", but we must get a feeling first how we use the Nepomuk API before thinking \
about caching...
M +12 -10 dolphinitemcategorizer.cpp
M +43 -2 dolphinsortfilterproxymodel.cpp
M +9 -1 dolphinsortfilterproxymodel.h
--- trunk/KDE/kdebase/apps/dolphin/src/dolphinitemcategorizer.cpp #678956:678957
@@ -21,6 +21,7 @@
#include "dolphinitemcategorizer.h"
#include "dolphinview.h"
+#include "dolphinsortfilterproxymodel.h"
#ifdef HAVE_NEPOMUK
#include <config-nepomuk.h>
@@ -34,7 +35,8 @@
#include <klocale.h>
#include <kurl.h>
-#include <QtGui/QSortFilterProxyModel>
+#include <QList>
+#include <QSortFilterProxyModel>
DolphinItemCategorizer::DolphinItemCategorizer() :
KItemCategorizer()
@@ -164,19 +166,19 @@
#ifdef HAVE_NEPOMUK
case DolphinView::SortByRating: {
- KFileItem* item = dirModel->itemForIndex(index);
- if (item != 0) {
- const Nepomuk::Resource resource(item->url().url(), \
Nepomuk::NFO::File());
- const quint32 rating = resource.rating();
- if (!rating)
- retString = i18n("Not yet rated");
- else
- retString = i18np("1 star", "%1 stars", rating);
+ const quint32 rating = \
DolphinSortFilterProxyModel::ratingForIndex(index); + if (rating) {
+ retString = i18np("1 star", "%1 stars", rating);
+ } else {
+ retString = i18n("Not yet rated");
}
break;
}
- case DolphinView::SortByTags:
+
+ case DolphinView::SortByTags: {
+ retString = DolphinSortFilterProxyModel::tagsForIndex(index);
break;
+ }
#endif
}
--- trunk/KDE/kdebase/apps/dolphin/src/dolphinsortfilterproxymodel.cpp #678956:678957
@@ -26,11 +26,13 @@
#include <config-nepomuk.h>
#include <nepomuk/global.h>
#include <nepomuk/resource.h>
+#include <nepomuk/tag.h>
#endif
#include <kdirmodel.h>
#include <kfileitem.h>
#include <kdatetime.h>
+#include <klocale.h>
static DolphinView::Sorting sortingTypeTable[] =
{
@@ -173,6 +175,9 @@
const quint32 rightRating = ratingForIndex(right);
return leftRating > rightRating;
}
+ case DolphinView::SortByTags: {
+ return naturalCompare(tagsForIndex(left), tagsForIndex(right)) < 0;
+ }
#endif
default:
break;
@@ -331,6 +336,10 @@
return leftRating > rightRating;
}
+
+ case DolphinView::SortByTags: {
+ return naturalCompare(tagsForIndex(left), tagsForIndex(right)) < 0;
+ }
#endif
}
@@ -339,12 +348,12 @@
return QSortFilterProxyModel::lessThan(left, right);
}
-quint32 DolphinSortFilterProxyModel::ratingForIndex(const QModelIndex& index) const
+quint32 DolphinSortFilterProxyModel::ratingForIndex(const QModelIndex& index)
{
#ifdef HAVE_NEPOMUK
quint32 rating = 0;
- const KDirModel* dirModel = static_cast<const KDirModel*>(sourceModel());
+ const KDirModel* dirModel = static_cast<const KDirModel*>(index.model());
KFileItem* item = dirModel->itemForIndex(index);
if (item != 0) {
const Nepomuk::Resource resource(item->url().url(), Nepomuk::NFO::File());
@@ -357,6 +366,38 @@
#endif
}
+QString DolphinSortFilterProxyModel::tagsForIndex(const QModelIndex& index)
+{
+#ifdef HAVE_NEPOMUK
+ QString tagsString;
+
+ const KDirModel* dirModel = static_cast<const KDirModel*>(index.model());
+ KFileItem* item = dirModel->itemForIndex(index);
+ if (item != 0) {
+ const Nepomuk::Resource resource(item->url().url(), Nepomuk::NFO::File());
+ const QList<Nepomuk::Tag> tags = resource.tags();
+ QStringList stringList;
+ foreach (const Nepomuk::Tag& tag, tags) {
+ stringList.append(tag.label());
+ }
+ stringList.sort();
+
+ foreach (const QString& str, stringList) {
+ tagsString += str;
+ tagsString += ' ';
+ }
+ }
+
+ if (tagsString.isEmpty()) {
+ tagsString = i18n("(no tags)");
+ }
+
+ return tagsString;
+#else
+ return QString();
+#endif
+}
+
int DolphinSortFilterProxyModel::naturalCompare(const QString& a,
const QString& b)
{
--- trunk/KDE/kdebase/apps/dolphin/src/dolphinsortfilterproxymodel.h #678956:678957
@@ -87,13 +87,21 @@
* Returns the rating for the item with the index \a index. 0 is
* returned if no item could be found.
*/
- quint32 ratingForIndex(const QModelIndex& index) const;
+ static quint32 ratingForIndex(const QModelIndex& index);
+ /**
+ * Returns the tags for the item with the index \a index. If no
+ * tag is applied, a predefined string will be returned.
+ */
+ static QString tagsForIndex(const QModelIndex& index);
+
static int naturalCompare(const QString& a, const QString& b);
private:
DolphinView::Sorting m_sorting;
Qt::SortOrder m_sortOrder;
+
+ friend class DolphinItemCategorizer;
};
DolphinView::Sorting DolphinSortFilterProxyModel::sorting() const
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic