]>
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"
26 #include <config-nepomuk.h>
27 #include <nepomuk/global.h>
28 #include <nepomuk/resource.h>
31 #include <kdatetime.h>
32 #include <kdirmodel.h>
33 #include <kfileitem.h>
37 #include <QtGui/QSortFilterProxyModel>
39 DolphinItemCategorizer::DolphinItemCategorizer() :
44 DolphinItemCategorizer::~DolphinItemCategorizer()
48 QString
DolphinItemCategorizer::categoryForItem(const QModelIndex
& index
,
58 const KDirModel
*dirModel
= qobject_cast
<const KDirModel
*>(index
.model());
59 KFileItem
*item
= dirModel
->itemForIndex(index
);
63 case DolphinView::SortByName
:
65 // KDirModel checks columns to know to which role are
67 QModelIndex theIndex
= index
.model()->index(index
.row(),
71 if (!theIndex
.isValid()) {
75 QVariant data
= theIndex
.model()->data(theIndex
, Qt::DisplayRole
);
76 if (data
.toString().size())
78 if (!item
->isHidden() && data
.toString().at(0).isLetter())
79 retString
= data
.toString().toUpper().at(0);
80 else if (item
->isHidden() && data
.toString().at(0) == '.' &&
81 data
.toString().at(1).isLetter())
82 retString
= data
.toString().toUpper().at(1);
83 else if (item
->isHidden() && data
.toString().at(0) == '.' &&
84 !data
.toString().at(1).isLetter())
85 retString
= i18n("Others");
86 else if (item
->isHidden() && data
.toString().at(0) != '.')
87 retString
= data
.toString().toUpper().at(0);
88 else if (item
->isHidden())
89 retString
= data
.toString().toUpper().at(0);
92 bool validCategory
= false;
94 const QString
str(data
.toString().toUpper());
95 const QChar
* currA
= str
.unicode();
96 while (!currA
->isNull() && !validCategory
) {
97 if (currA
->isLetter())
99 else if (currA
->isDigit())
100 return i18n("Others");
106 retString
= i18n("Others");
114 case DolphinView::SortByDate
:
116 KDateTime modifiedTime
;
117 modifiedTime
.setTime_t(item
->time(KIO::UDS_MODIFICATION_TIME
));
118 modifiedTime
= modifiedTime
.toLocalZone();
120 if (modifiedTime
.daysTo(KDateTime::currentLocalDateTime()) == 0)
121 retString
= i18n("Today");
122 else if (modifiedTime
.daysTo(KDateTime::currentLocalDateTime()) == 1)
123 retString
= i18n("Yesterday");
124 else if (modifiedTime
.daysTo(KDateTime::currentLocalDateTime()) < 7)
125 retString
= i18n("Less than a week");
126 else if (modifiedTime
.daysTo(KDateTime::currentLocalDateTime()) < 31)
127 retString
= i18n("Less than a month");
128 else if (modifiedTime
.daysTo(KDateTime::currentLocalDateTime()) < 365)
129 retString
= i18n("Less than a year");
131 retString
= i18n("More than a year");
135 case DolphinView::SortByPermissions
:
136 retString
= item
->permissionsString();
139 case DolphinView::SortByOwner
:
140 retString
= item
->user();
143 case DolphinView::SortByGroup
:
144 retString
= item
->group();
147 case DolphinView::SortBySize
: {
148 const int fileSize
= item
? item
->size() : -1;
149 if (item
&& item
->isDir()) {
150 retString
= i18n("Folders");
151 } else if (fileSize
< 5242880) {
152 retString
= i18nc("Size", "Small");
153 } else if (fileSize
< 10485760) {
154 retString
= i18nc("Size", "Medium");
156 retString
= i18nc("Size", "Big");
161 case DolphinView::SortByType
:
162 retString
= item
->mimeComment();
166 case DolphinView::SortByRating
: {
167 KFileItem
* item
= dirModel
->itemForIndex(index
);
169 const Nepomuk::Resource
resource(item
->url().url(), Nepomuk::NFO::File());
170 const quint32 rating
= resource
.rating();
171 retString
= i18np("1 star", "%1 stars", rating
);
175 case DolphinView::SortByTags
: