]>
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 <QSortFilterProxyModel>
30 DolphinItemCategorizer::DolphinItemCategorizer() :
34 DolphinItemCategorizer::~DolphinItemCategorizer()
37 QString
DolphinItemCategorizer::categoryForItem(const QModelIndex
& index
,
42 if (!index
.isValid()) {
46 // KDirModel checks columns to know to which role are
48 QModelIndex theIndex
= index
.model()->index(index
.row(),
52 const QSortFilterProxyModel
* proxyModel
= static_cast<const QSortFilterProxyModel
*>(index
.model());
53 const KDirModel
* dirModel
= static_cast<const KDirModel
*>(proxyModel
->sourceModel());
55 QVariant data
= theIndex
.model()->data(theIndex
, Qt::DisplayRole
);
57 QModelIndex mappedIndex
= proxyModel
->mapToSource(theIndex
);
58 KFileItem
* item
= dirModel
->itemForIndex(mappedIndex
);
61 case DolphinView::SortByName
:
62 retString
= data
.toString().toUpper().at(0);
64 case DolphinView::SortBySize
:
65 int fileSize
= (item
) ? item
->size() : -1;
66 if (item
&& item
->isDir()) {
67 retString
= i18n("Unknown");
68 } else if (fileSize
< 5242880) {
69 retString
= i18n("Small");
70 } else if (fileSize
< 10485760) {
71 retString
= i18n("Medium");
73 retString
= i18n("Big");