┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/additionalinfoaccessor.cpp
blob: 505da3f4c98b6fe0c2377d0df830da67f7865599 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/***************************************************************************
 *   Copyright (C) 2010 by Peter Penz <[email protected]>             *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
 ***************************************************************************/

#include "additionalinfoaccessor.h"

#include "dolphinmodel.h"
#include <kglobal.h>
#include <klocale.h>

class AdditionalInfoAccessorSingleton
{
public:
    AdditionalInfoAccessor instance;
};
K_GLOBAL_STATIC(AdditionalInfoAccessorSingleton, s_additionalInfoManager)

AdditionalInfoAccessor& AdditionalInfoAccessor::instance()
{
    return s_additionalInfoManager->instance;
}

KFileItemDelegate::InformationList AdditionalInfoAccessor::keys() const
{
    return m_informations;
}

KFileItemDelegate::Information AdditionalInfoAccessor::keyForColumn(int columnIndex) const
{
    KFileItemDelegate::Information info = KFileItemDelegate::NoInformation;

    switch (columnIndex) {
    case DolphinModel::Size:           info = KFileItemDelegate::Size; break;
    case DolphinModel::ModifiedTime:   info = KFileItemDelegate::ModificationTime; break;
    case DolphinModel::Permissions:    info = KFileItemDelegate::Permissions; break;
    case DolphinModel::Owner:          info = KFileItemDelegate::Owner; break;
    case DolphinModel::Group:          info = KFileItemDelegate::OwnerAndGroup; break;
    case DolphinModel::Type:           info = KFileItemDelegate::FriendlyMimeType; break;
    case DolphinModel::LinkDest:       info = KFileItemDelegate::LinkDest; break;
    case DolphinModel::LocalPathOrUrl: info = KFileItemDelegate::LocalPathOrUrl; break;
    default: break;
    }

    return info;
}

QString AdditionalInfoAccessor::actionCollectionName(KFileItemDelegate::Information info) const
{
    return QLatin1String(m_map[info]->actionCollectionName);
}

QString AdditionalInfoAccessor::translation(KFileItemDelegate::Information info) const
{
    return i18n(m_map[info]->translation);
}

int AdditionalInfoAccessor::bitValue(KFileItemDelegate::Information info) const
{
    return m_map[info]->bitValue;
}

AdditionalInfoAccessor::AdditionalInfoAccessor() :
    m_informations(),
    m_map()
{
    static const AdditionalInfoAccessor::AdditionalInfo additionalInfos[] = {
        { "size",        I18N_NOOP2("@label", "Size"),          1 },
        { "date",        I18N_NOOP2("@label", "Date"),          2 },
        { "permissions", I18N_NOOP2("@label", "Permissions"),   4 },
        { "owner",       I18N_NOOP2("@label", "Owner"),         8 },
        { "group",       I18N_NOOP2("@label", "Group"),        16 },
        { "type",        I18N_NOOP2("@label", "Type"),         32 },
        { "destination", I18N_NOOP2("@label", "Destination"),  64 },
        { "path",        I18N_NOOP2("@label", "Path"),        128 }
    };

    m_map.insert(KFileItemDelegate::Size, &additionalInfos[0]);
    m_map.insert(KFileItemDelegate::ModificationTime, &additionalInfos[1]);
    m_map.insert(KFileItemDelegate::Permissions, &additionalInfos[2]);
    m_map.insert(KFileItemDelegate::Owner, &additionalInfos[3]);
    m_map.insert(KFileItemDelegate::OwnerAndGroup, &additionalInfos[4]);
    m_map.insert(KFileItemDelegate::FriendlyMimeType, &additionalInfos[5]);
    m_map.insert(KFileItemDelegate::LinkDest, &additionalInfos[6]);
    m_map.insert(KFileItemDelegate::LocalPathOrUrl, &additionalInfos[7]);

    m_informations = m_map.keys();
}

AdditionalInfoAccessor::~AdditionalInfoAccessor()
{
}