]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinitemcategorizer.cpp
Fix small problems with enums. Sort by type works like a charm :)
[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 {
46 return retString;
47 }
48
49 // KDirModel checks columns to know to which role are
50 // we talking about
51 QModelIndex theIndex = index.model()->index(index.row(),
52 sortRole,
53 index.parent());
54
55 if (!theIndex.isValid()) {
56 return retString;
57 }
58
59 QVariant data = theIndex.model()->data(theIndex, Qt::DisplayRole);
60
61 const KDirModel *dirModel = qobject_cast<const KDirModel*>(index.model());
62 KFileItem *item = dirModel->itemForIndex(index);
63 int fileSize;
64
65 switch (sortRole)
66 {
67 case KDirModel::Name:
68 if (data.toString().size())
69 {
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);
82 else
83 retString = i18n("Others");
84 }
85 break;
86
87 case KDirModel::Size:
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");
95 } else {
96 retString = i18nc("Size", "Big");
97 }
98 break;
99
100 case KDirModel::Type:
101 retString = item->mimeComment();
102 break;
103 }
104
105 return retString;
106 }