]> cloud.milkyroute.net Git - dolphin.git/blob - src/views/additionalinfoaccessor.cpp
cafc4fa23d4e604149ac5acd8c16ce481b985854
[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_information;
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 QString AdditionalInfoAccessor::value(KFileItemDelegate::Information info) const
85 {
86 return m_map[info]->value;
87 }
88
89 DolphinView::Sorting AdditionalInfoAccessor::sorting(KFileItemDelegate::Information info) const
90 {
91 return m_map[info]->sorting;
92 }
93
94 int AdditionalInfoAccessor::bitValue(KFileItemDelegate::Information info) const
95 {
96 return m_map[info]->bitValue;
97 }
98
99 AdditionalInfoAccessor::AdditionalInfoAccessor() :
100 m_information(),
101 m_map()
102 {
103 static const AdditionalInfoAccessor::AdditionalInfo additionalInfo[] = {
104 // Entries for view-properties version 1:
105 { "size", I18N_NOOP2_NOSTRIP("@label", "Size"), "Size", DolphinView::SortBySize, 1 },
106 { "date", I18N_NOOP2_NOSTRIP("@label", "Date"), "Date", DolphinView::SortByDate, 2 },
107 { "permissions", I18N_NOOP2_NOSTRIP("@label", "Permissions"), "Permissions", DolphinView::SortByPermissions, 4 },
108 { "owner", I18N_NOOP2_NOSTRIP("@label", "Owner"), "Owner", DolphinView::SortByOwner, 8 },
109 { "group", I18N_NOOP2_NOSTRIP("@label", "Group"), "Group", DolphinView::SortByGroup, 16 },
110 { "type", I18N_NOOP2_NOSTRIP("@label", "Type"), "Type", DolphinView::SortByType, 32 },
111 { "destination", I18N_NOOP2_NOSTRIP("@label", "Link Destination"), "LinkDestination", DolphinView::SortByDestination, 64 },
112 { "path", I18N_NOOP2_NOSTRIP("@label", "Path"), "Path", DolphinView::SortByPath, 128 }
113 // Entries for view-properties version >= 2 (the last column can be set to 0):
114 };
115
116 m_map.insert(KFileItemDelegate::Size, &additionalInfo[0]);
117 m_map.insert(KFileItemDelegate::ModificationTime, &additionalInfo[1]);
118 m_map.insert(KFileItemDelegate::Permissions, &additionalInfo[2]);
119 m_map.insert(KFileItemDelegate::Owner, &additionalInfo[3]);
120 m_map.insert(KFileItemDelegate::OwnerAndGroup, &additionalInfo[4]);
121 m_map.insert(KFileItemDelegate::FriendlyMimeType, &additionalInfo[5]);
122 m_map.insert(KFileItemDelegate::LinkDest, &additionalInfo[6]);
123 m_map.insert(KFileItemDelegate::LocalPathOrUrl, &additionalInfo[7]);
124
125 // The m_information list defines all available keys and the sort order
126 // (don't use m_information = m_map.keys(), as the order is undefined).
127 m_information.append(KFileItemDelegate::Size);
128 m_information.append(KFileItemDelegate::ModificationTime);
129 m_information.append(KFileItemDelegate::Permissions);
130 m_information.append(KFileItemDelegate::Owner);
131 m_information.append(KFileItemDelegate::OwnerAndGroup);
132 m_information.append(KFileItemDelegate::FriendlyMimeType);
133 m_information.append(KFileItemDelegate::LinkDest);
134 m_information.append(KFileItemDelegate::LocalPathOrUrl);
135 }
136
137 AdditionalInfoAccessor::~AdditionalInfoAccessor()
138 {
139 }