]>
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 <kdirmodel.h>
27 #include <kdatetime.h>
29 #include <QtGui/QSortFilterProxyModel>
31 DolphinItemCategorizer::DolphinItemCategorizer() :
36 DolphinItemCategorizer::~DolphinItemCategorizer()
40 QString
DolphinItemCategorizer::categoryForItem(const QModelIndex
& index
,
54 case DolphinView::SortByName
: // KDirModel::Name
55 column
= KDirModel::Name
;
57 case DolphinView::SortBySize
: // KDirModel::Size
58 column
= KDirModel::Size
;
60 case DolphinView::SortByDate
: // KDirModel::ModifiedTime
61 column
= KDirModel::ModifiedTime
;
63 case DolphinView::SortByPermissions
: // KDirModel::Permissions
64 column
= KDirModel::Permissions
;
66 case DolphinView::SortByOwner
: // KDirModel::Owner
67 column
= KDirModel::Owner
;
69 case DolphinView::SortByGroup
: // KDirModel::Group
70 column
= KDirModel::Group
;
72 case DolphinView::SortByType
: // KDirModel::Type
73 column
= KDirModel::Type
;
76 column
= KDirModel::Name
;
79 // KDirModel checks columns to know to which role are
81 QModelIndex theIndex
= index
.model()->index(index
.row(),
85 if (!theIndex
.isValid()) {
89 QVariant data
= theIndex
.model()->data(theIndex
, Qt::DisplayRole
);
91 const KDirModel
*dirModel
= qobject_cast
<const KDirModel
*>(index
.model());
92 KFileItem
*item
= dirModel
->itemForIndex(index
);
95 KDateTime modifiedTime
;
98 case DolphinView::SortByName
:
99 if (data
.toString().size())
101 if (!item
->isHidden() && data
.toString().at(0).isLetter())
102 retString
= data
.toString().toUpper().at(0);
103 else if (item
->isHidden() && data
.toString().at(0) == '.' &&
104 data
.toString().at(1).isLetter())
105 retString
= data
.toString().toUpper().at(1);
106 else if (item
->isHidden() && data
.toString().at(0) == '.' &&
107 !data
.toString().at(1).isLetter())
108 retString
= i18n("Others");
109 else if (item
->isHidden() && data
.toString().at(0) != '.')
110 retString
= data
.toString().toUpper().at(0);
111 else if (item
->isHidden())
112 retString
= data
.toString().toUpper().at(0);
115 bool validCategory
= false;
117 const QChar
* currA
= data
.toString().toUpper().unicode(); // iterator over a
118 while (!currA
->isNull() && !validCategory
) {
119 if (currA
->isLetter())
120 validCategory
= true;
121 else if (currA
->isDigit())
122 return i18n("Others");
128 retString
= i18n("Others");
135 case DolphinView::SortByDate
:
136 modifiedTime
.setTime_t(item
->time(KIO::UDS_MODIFICATION_TIME
));
137 modifiedTime
= modifiedTime
.toLocalZone();
139 if (modifiedTime
.daysTo(KDateTime::currentLocalDateTime()) == 0)
140 retString
= i18n("Today");
141 else if (modifiedTime
.daysTo(KDateTime::currentLocalDateTime()) == 1)
142 retString
= i18n("Yesterday");
143 else if (modifiedTime
.daysTo(KDateTime::currentLocalDateTime()) < 7)
144 retString
= i18n("Less than a week");
145 else if (modifiedTime
.daysTo(KDateTime::currentLocalDateTime()) < 31)
146 retString
= i18n("Less than a month");
147 else if (modifiedTime
.daysTo(KDateTime::currentLocalDateTime()) < 365)
148 retString
= i18n("Less than a year");
150 retString
= i18n("More than a year");
153 case DolphinView::SortByPermissions
:
154 retString
= item
->permissionsString();
157 case DolphinView::SortByOwner
:
158 retString
= item
->user();
161 case DolphinView::SortByGroup
:
162 retString
= item
->group();
165 case DolphinView::SortBySize
:
166 fileSize
= (item
) ? item
->size() : -1;
167 if (item
&& item
->isDir()) {
168 retString
= i18n("Folders");
169 } else if (fileSize
< 5242880) {
170 retString
= i18nc("Size", "Small");
171 } else if (fileSize
< 10485760) {
172 retString
= i18nc("Size", "Medium");
174 retString
= i18nc("Size", "Big");
178 case DolphinView::SortByType
:
179 retString
= item
->mimeComment();