1 /***************************************************************************
2 * Copyright (C) 2010 by Peter Penz <peter.penz19@gmail.com> *
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. *
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. *
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 ***************************************************************************/
20 #include "additionalinfoaccessor.h"
22 #include "dolphinmodel.h"
26 class AdditionalInfoAccessorSingleton
29 AdditionalInfoAccessor instance
;
31 K_GLOBAL_STATIC(AdditionalInfoAccessorSingleton
, s_additionalInfoManager
)
33 AdditionalInfoAccessor
& AdditionalInfoAccessor::instance()
35 return s_additionalInfoManager
->instance
;
38 KFileItemDelegate::InformationList
AdditionalInfoAccessor::keys() const
40 return m_informations
;
43 KFileItemDelegate::Information
AdditionalInfoAccessor::keyForColumn(int columnIndex
) const
45 KFileItemDelegate::Information info
= KFileItemDelegate::NoInformation
;
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;
62 QString
AdditionalInfoAccessor::actionCollectionName(KFileItemDelegate::Information info
,
63 ActionCollectionType type
) const
68 name
= QLatin1String("sort_by_") + QLatin1String(m_map
[info
]->actionCollectionName
);
71 case AdditionalInfoType
:
72 name
= QLatin1String("show_") + QLatin1String(m_map
[info
]->actionCollectionName
);
79 QString
AdditionalInfoAccessor::translation(KFileItemDelegate::Information info
) const
81 return i18nc(m_map
[info
]->context
, m_map
[info
]->translation
);
84 DolphinView::Sorting
AdditionalInfoAccessor::sorting(KFileItemDelegate::Information info
) const
86 return m_map
[info
]->sorting
;
89 int AdditionalInfoAccessor::bitValue(KFileItemDelegate::Information info
) const
91 return m_map
[info
]->bitValue
;
94 AdditionalInfoAccessor::AdditionalInfoAccessor() :
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 }
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]);
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
);
130 AdditionalInfoAccessor::~AdditionalInfoAccessor()