]>
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
,
53 case DolphinView::SortByName
:
54 indexColumn
= KDirModel::Name
;
56 case DolphinView::SortBySize
:
57 indexColumn
= KDirModel::Size
;
63 // KDirModel checks columns to know to which role are
65 QModelIndex theIndex
= index
.model()->index(index
.row(),
69 if (!theIndex
.isValid()) {
73 QVariant data
= theIndex
.model()->data(theIndex
, Qt::DisplayRole
);
75 const KDirModel
*dirModel
= qobject_cast
<const KDirModel
*>(index
.model());
76 KFileItem
* item
= dirModel
->itemForIndex(index
);
80 case DolphinView::SortByName
:
81 if (data
.toString().size())
83 if (!item
->isHidden() && data
.toString().at(0).isLetter())
84 retString
= data
.toString().toUpper().at(0);
85 else if (item
->isHidden() && data
.toString().at(0) == '.' &&
86 data
.toString().at(1).isLetter())
87 retString
= data
.toString().toUpper().at(1);
88 else if (item
->isHidden() && data
.toString().at(0) == '.' &&
89 !data
.toString().at(1).isLetter())
90 retString
= i18n("Others");
91 else if (item
->isHidden() && data
.toString().at(0) != '.')
92 retString
= data
.toString().toUpper().at(0);
93 else if (item
->isHidden())
94 retString
= data
.toString().toUpper().at(0);
96 retString
= i18n("Others");
99 case DolphinView::SortBySize
:
100 int fileSize
= (item
) ? item
->size() : -1;
101 if (item
&& item
->isDir()) {
102 retString
= i18n("Folders");
103 } else if (fileSize
< 5242880) {
104 retString
= i18n("Small");
105 } else if (fileSize
< 10485760) {
106 retString
= i18n("Medium");
108 retString
= i18n("Big");