]>
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>
28 #include <QtGui/QSortFilterProxyModel>
30 DolphinItemCategorizer::DolphinItemCategorizer() :
35 DolphinItemCategorizer::~DolphinItemCategorizer()
39 QString
DolphinItemCategorizer::categoryForItem(const QModelIndex
& index
,
49 // KDirModel checks columns to know to which role are
51 QModelIndex theIndex
= index
.model()->index(index
.row(),
55 if (!theIndex
.isValid()) {
59 QVariant data
= theIndex
.model()->data(theIndex
, Qt::DisplayRole
);
61 const KDirModel
*dirModel
= qobject_cast
<const KDirModel
*>(index
.model());
62 KFileItem
*item
= dirModel
->itemForIndex(index
);
68 if (data
.toString().size())
70 if (!item
->isHidden() && data
.toString().at(0).isLetter())
71 retString
= data
.toString().toUpper().at(0);
72 else if (item
->isHidden() && data
.toString().at(0) == '.' &&
73 data
.toString().at(1).isLetter())
74 retString
= data
.toString().toUpper().at(1);
75 else if (item
->isHidden() && data
.toString().at(0) == '.' &&
76 !data
.toString().at(1).isLetter())
77 retString
= i18n("Others");
78 else if (item
->isHidden() && data
.toString().at(0) != '.')
79 retString
= data
.toString().toUpper().at(0);
80 else if (item
->isHidden())
81 retString
= data
.toString().toUpper().at(0);
83 retString
= i18n("Others");
88 fileSize
= (item
) ? item
->size() : -1;
89 if (item
&& item
->isDir()) {
90 retString
= i18n("Folders");
91 } else if (fileSize
< 5242880) {
92 retString
= i18nc("Size", "Small");
93 } else if (fileSize
< 10485760) {
94 retString
= i18nc("Size", "Medium");
96 retString
= i18nc("Size", "Big");
100 case KDirModel::Type
:
101 retString
= item
->mimeComment();