]>
cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinitemcategorizer.cpp
2 * This file is part of the KDE project
3 * Copyright (C) 2007 Rafael Fernández López <ereslibre@gmail.com>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
21 #include "dolphinitemcategorizer.h"
23 #include "dolphinview.h"
24 #include "dolphinsortfilterproxymodel.h"
27 #include <config-nepomuk.h>
28 #include <nepomuk/global.h>
29 #include <nepomuk/resource.h>
32 #include <kdatetime.h>
33 #include <kdirmodel.h>
34 #include <kfileitem.h>
39 #include <QSortFilterProxyModel>
41 DolphinItemCategorizer::DolphinItemCategorizer() :
46 DolphinItemCategorizer::~DolphinItemCategorizer()
50 QString
DolphinItemCategorizer::categoryForItem(const QModelIndex
& index
,
60 const KDirModel
*dirModel
= qobject_cast
<const KDirModel
*>(index
.model());
61 KFileItem
*item
= dirModel
->itemForIndex(index
);
65 case DolphinView::SortByName
:
67 // KDirModel checks columns to know to which role are
69 QModelIndex theIndex
= index
.model()->index(index
.row(),
73 if (!theIndex
.isValid()) {
77 QVariant data
= theIndex
.model()->data(theIndex
, Qt::DisplayRole
);
78 if (data
.toString().size())
80 if (!item
->isHidden() && data
.toString().at(0).isLetter())
81 retString
= data
.toString().toUpper().at(0);
82 else if (item
->isHidden() && data
.toString().at(0) == '.' &&
83 data
.toString().at(1).isLetter())
84 retString
= data
.toString().toUpper().at(1);
85 else if (item
->isHidden() && data
.toString().at(0) == '.' &&
86 !data
.toString().at(1).isLetter())
87 retString
= i18n("Others");
88 else if (item
->isHidden() && data
.toString().at(0) != '.')
89 retString
= data
.toString().toUpper().at(0);
90 else if (item
->isHidden())
91 retString
= data
.toString().toUpper().at(0);
94 bool validCategory
= false;
96 const QString
str(data
.toString().toUpper());
97 const QChar
* currA
= str
.unicode();
98 while (!currA
->isNull() && !validCategory
) {
99 if (currA
->isLetter())
100 validCategory
= true;
101 else if (currA
->isDigit())
102 return i18n("Others");
108 retString
= i18n("Others");
116 case DolphinView::SortByDate
:
118 KDateTime modifiedTime
;
119 modifiedTime
.setTime_t(item
->time(KIO::UDS_MODIFICATION_TIME
));
120 modifiedTime
= modifiedTime
.toLocalZone();
122 if (modifiedTime
.daysTo(KDateTime::currentLocalDateTime()) == 0)
123 retString
= i18n("Today");
124 else if (modifiedTime
.daysTo(KDateTime::currentLocalDateTime()) == 1)
125 retString
= i18n("Yesterday");
126 else if (modifiedTime
.daysTo(KDateTime::currentLocalDateTime()) < 7)
127 retString
= i18n("Less than a week");
128 else if (modifiedTime
.daysTo(KDateTime::currentLocalDateTime()) < 31)
129 retString
= i18n("Less than a month");
130 else if (modifiedTime
.daysTo(KDateTime::currentLocalDateTime()) < 365)
131 retString
= i18n("Less than a year");
133 retString
= i18n("More than a year");
137 case DolphinView::SortByPermissions
:
138 retString
= item
->permissionsString();
141 case DolphinView::SortByOwner
:
142 retString
= item
->user();
145 case DolphinView::SortByGroup
:
146 retString
= item
->group();
149 case DolphinView::SortBySize
: {
150 const int fileSize
= item
? item
->size() : -1;
151 if (item
&& item
->isDir()) {
152 retString
= i18n("Folders");
153 } else if (fileSize
< 5242880) {
154 retString
= i18nc("Size", "Small");
155 } else if (fileSize
< 10485760) {
156 retString
= i18nc("Size", "Medium");
158 retString
= i18nc("Size", "Big");
163 case DolphinView::SortByType
:
164 retString
= item
->mimeComment();
168 case DolphinView::SortByRating
: {
169 const quint32 rating
= DolphinSortFilterProxyModel::ratingForIndex(index
);
171 retString
= i18np("1 star", "%1 stars", rating
);
173 retString
= i18n("Not yet rated");
178 case DolphinView::SortByTags
: {
179 retString
= DolphinSortFilterProxyModel::tagsForIndex(index
);
181 if (retString
.isEmpty())
182 retString
= i18n("Not yet tagged");