]> cloud.milkyroute.net Git - dolphin.git/blob - src/views/additionalinfoaccessor.cpp
Sourcecode hierarchy cleanup: Move class PixmapViewer from "src" to "src/panels/infor...
[dolphin.git] / src / views / additionalinfoaccessor.cpp
1 /***************************************************************************
2 * Copyright (C) 2010 by Peter Penz <peter.penz19@gmail.com> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
19
20 #include "additionalinfoaccessor.h"
21
22 #include "dolphinmodel.h"
23 #include <kglobal.h>
24 #include <klocale.h>
25
26 class AdditionalInfoAccessorSingleton
27 {
28 public:
29 AdditionalInfoAccessor instance;
30 };
31 K_GLOBAL_STATIC(AdditionalInfoAccessorSingleton, s_additionalInfoManager)
32
33 AdditionalInfoAccessor& AdditionalInfoAccessor::instance()
34 {
35 return s_additionalInfoManager->instance;
36 }
37
38 KFileItemDelegate::InformationList AdditionalInfoAccessor::keys() const
39 {
40 return m_informations;
41 }
42
43 KFileItemDelegate::Information AdditionalInfoAccessor::keyForColumn(int columnIndex) const
44 {
45 KFileItemDelegate::Information info = KFileItemDelegate::NoInformation;
46
47 switch (columnIndex) {
48 case DolphinModel::Size: info = KFileItemDelegate::Size; break;
49 case DolphinModel::ModifiedTime: info = KFileItemDelegate::ModificationTime; break;
50 case DolphinModel::Permissions: info = KFileItemDelegate::Permissions; break;
51 case DolphinModel::Owner: info = KFileItemDelegate::Owner; break;
52 case DolphinModel::Group: info = KFileItemDelegate::OwnerAndGroup; break;
53 case DolphinModel::Type: info = KFileItemDelegate::FriendlyMimeType; break;
54 case DolphinModel::LinkDest: info = KFileItemDelegate::LinkDest; break;
55 case DolphinModel::LocalPathOrUrl: info = KFileItemDelegate::LocalPathOrUrl; break;
56 default: break;
57 }
58
59 return info;
60 }
61
62 QString AdditionalInfoAccessor::actionCollectionName(KFileItemDelegate::Information info,
63 ActionCollectionType type) const
64 {
65 QString name;
66 switch (type) {
67 case SortByType:
68 name = QLatin1String("sort_by_") + QLatin1String(m_map[info]->actionCollectionName);
69 break;
70
71 case AdditionalInfoType:
72 name = QLatin1String("show_") + QLatin1String(m_map[info]->actionCollectionName);
73 break;
74 }
75
76 return name;
77 }
78
79 QString AdditionalInfoAccessor::translation(KFileItemDelegate::Information info) const
80 {
81 return i18nc(m_map[info]->context, m_map[info]->translation);
82 }
83
84 DolphinView::Sorting AdditionalInfoAccessor::sorting(KFileItemDelegate::Information info) const
85 {
86 return m_map[info]->sorting;
87 }
88
89 int AdditionalInfoAccessor::bitValue(KFileItemDelegate::Information info) const
90 {
91 return m_map[info]->bitValue;
92 }
93
94 AdditionalInfoAccessor::AdditionalInfoAccessor() :
95 m_informations(),
96 m_map()
97 {
98 static const AdditionalInfoAccessor::AdditionalInfo additionalInfos[] = {
99 { "size", I18N_NOOP2_NOSTRIP("@label", "Size"), DolphinView::SortBySize, 1 },
100 { "date", I18N_NOOP2_NOSTRIP("@label", "Date"), DolphinView::SortByDate, 2 },
101 { "permissions", I18N_NOOP2_NOSTRIP("@label", "Permissions"), DolphinView::SortByPermissions, 4 },
102 { "owner", I18N_NOOP2_NOSTRIP("@label", "Owner"), DolphinView::SortByOwner, 8 },
103 { "group", I18N_NOOP2_NOSTRIP("@label", "Group"), DolphinView::SortByGroup, 16 },
104 { "type", I18N_NOOP2_NOSTRIP("@label", "Type"), DolphinView::SortByType, 32 },
105 { "destination", I18N_NOOP2_NOSTRIP("@label", "Link Destination"), DolphinView::SortByDestination, 64 },
106 { "path", I18N_NOOP2_NOSTRIP("@label", "Path"), DolphinView::SortByPath, 128 }
107 };
108
109 m_map.insert(KFileItemDelegate::Size, &additionalInfos[0]);
110 m_map.insert(KFileItemDelegate::ModificationTime, &additionalInfos[1]);
111 m_map.insert(KFileItemDelegate::Permissions, &additionalInfos[2]);
112 m_map.insert(KFileItemDelegate::Owner, &additionalInfos[3]);
113 m_map.insert(KFileItemDelegate::OwnerAndGroup, &additionalInfos[4]);
114 m_map.insert(KFileItemDelegate::FriendlyMimeType, &additionalInfos[5]);
115 m_map.insert(KFileItemDelegate::LinkDest, &additionalInfos[6]);
116 m_map.insert(KFileItemDelegate::LocalPathOrUrl, &additionalInfos[7]);
117
118 // The m_informations list defines all available keys and the sort order
119 // (don't use m_informations = m_map.keys(), as the order is undefined).
120 m_informations.append(KFileItemDelegate::Size);
121 m_informations.append(KFileItemDelegate::ModificationTime);
122 m_informations.append(KFileItemDelegate::Permissions);
123 m_informations.append(KFileItemDelegate::Owner);
124 m_informations.append(KFileItemDelegate::OwnerAndGroup);
125 m_informations.append(KFileItemDelegate::FriendlyMimeType);
126 m_informations.append(KFileItemDelegate::LinkDest);
127 m_informations.append(KFileItemDelegate::LocalPathOrUrl);
128 }
129
130 AdditionalInfoAccessor::~AdditionalInfoAccessor()
131 {
132 }