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
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 QString
AdditionalInfoAccessor::value(KFileItemDelegate::Information info
) const
86 return m_map
[info
]->value
;
89 DolphinView::Sorting
AdditionalInfoAccessor::sorting(KFileItemDelegate::Information info
) const
91 return m_map
[info
]->sorting
;
94 int AdditionalInfoAccessor::bitValue(KFileItemDelegate::Information info
) const
96 return m_map
[info
]->bitValue
;
99 AdditionalInfoAccessor::AdditionalInfoAccessor() :
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):
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]);
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
);
137 AdditionalInfoAccessor::~AdditionalInfoAccessor()