]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinitemcategorizer.cpp
Make use of the error messages coming from the places model.
[dolphin.git] / src / dolphinitemcategorizer.cpp
1 /**
2 * This file is part of the KDE project
3 * Copyright (C) 2007 Rafael Fernández López <ereslibre@gmail.com>
4 *
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.
9 *
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.
14 *
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.
19 */
20
21 #include "dolphinitemcategorizer.h"
22
23 #include "dolphinview.h"
24
25 #include <klocale.h>
26 #include <kdirmodel.h>
27
28 #include <QtGui/QSortFilterProxyModel>
29
30 DolphinItemCategorizer::DolphinItemCategorizer() :
31 KItemCategorizer()
32 {
33 }
34
35 DolphinItemCategorizer::~DolphinItemCategorizer()
36 {
37 }
38
39 QString DolphinItemCategorizer::categoryForItem(const QModelIndex& index,
40 int sortRole)
41 {
42 QString retString;
43
44 if (!index.isValid()) {
45 return retString;
46 }
47
48 // KDirModel checks columns to know to which role are
49 // we talking about
50 QModelIndex theIndex = index.model()->index(index.row(),
51 sortRole,
52 index.parent());
53
54 const QSortFilterProxyModel* proxyModel = static_cast<const QSortFilterProxyModel*>(index.model());
55 const KDirModel* dirModel = static_cast<const KDirModel*>(proxyModel->sourceModel());
56
57 QVariant data = theIndex.model()->data(theIndex, Qt::DisplayRole);
58
59 QModelIndex mappedIndex = proxyModel->mapToSource(theIndex);
60 KFileItem* item = dirModel->itemForIndex(mappedIndex);
61
62 switch (sortRole) {
63 case DolphinView::SortByName:
64 retString = data.toString().toUpper().at(0);
65 break;
66 case DolphinView::SortBySize:
67 int fileSize = (item) ? item->size() : -1;
68 if (item && item->isDir()) {
69 retString = i18n("Unknown");
70 } else if (fileSize < 5242880) {
71 retString = i18n("Small");
72 } else if (fileSize < 10485760) {
73 retString = i18n("Medium");
74 } else {
75 retString = i18n("Big");
76 }
77 break;
78 }
79
80 return retString;
81 }