File: standardpathsmodel.cpp

package info (click to toggle)
gammaray 3.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 21,612 kB
  • sloc: cpp: 94,643; ansic: 2,227; sh: 336; python: 164; yacc: 90; lex: 82; xml: 61; makefile: 26
file content (117 lines) | stat: -rw-r--r-- 2,897 bytes parent folder | download
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
108
109
110
111
112
113
114
115
116
117
/*
  standardpathsmodel.cpp

  This file is part of GammaRay, the Qt application inspection and manipulation tool.

  SPDX-FileCopyrightText: 2012 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
  Author: Volker Krause <volker.krause@kdab.com>

  SPDX-License-Identifier: GPL-2.0-or-later

  Contact KDAB at <info@kdab.com> for commercial licensing options.
*/

#include "standardpathsmodel.h"

#include <QStandardPaths>

using namespace GammaRay;

struct standard_path_t
{
    QStandardPaths::StandardLocation location;
    const char *locationName;
};

#define P(x)                  \
    {                         \
        QStandardPaths::x, #x \
    }

static const standard_path_t standard_paths[] = {
    P(DesktopLocation),
    P(DocumentsLocation),
    P(FontsLocation),
    P(ApplicationsLocation),
    P(MusicLocation),
    P(MoviesLocation),
    P(PicturesLocation),
    P(TempLocation),
    P(HomeLocation),
    P(CacheLocation),
    P(GenericDataLocation),
    P(RuntimeLocation),
    P(ConfigLocation),
    P(DownloadLocation),
    P(GenericCacheLocation),
    P(GenericConfigLocation),
    P(AppDataLocation),
    P(AppConfigLocation),
};

#undef P

static const int standard_path_count = sizeof(standard_paths) / sizeof(standard_path_t);

StandardPathsModel::StandardPathsModel(QObject *parent)
    : QAbstractTableModel(parent)
{
}

StandardPathsModel::~StandardPathsModel() = default;

QVariant StandardPathsModel::data(const QModelIndex &index, int role) const
{
    if (!index.isValid())
        return QVariant();

    if (role == Qt::TextAlignmentRole)
        return static_cast<int>(Qt::AlignLeft | Qt::AlignTop);

    if (role == Qt::DisplayRole) {
        const QStandardPaths::StandardLocation loc = standard_paths[index.row()].location;
        switch (index.column()) {
        case 0:
            return QString::fromLatin1(standard_paths[index.row()].locationName);
        case 1:
            return QStandardPaths::displayName(loc);
        case 2:
            return QStandardPaths::standardLocations(loc).join(QLatin1Char('\n'));
        case 3:
            return QStandardPaths::writableLocation(loc);
        }
    }

    return QVariant();
}

int StandardPathsModel::columnCount(const QModelIndex &parent) const
{
    Q_UNUSED(parent);
    return 4;
}

int StandardPathsModel::rowCount(const QModelIndex &parent) const
{
    if (parent.isValid())
        return 0;
    return standard_path_count;
}

QVariant StandardPathsModel::headerData(int section, Qt::Orientation orientation, int role) const
{
    if (orientation == Qt::Vertical || role != Qt::DisplayRole)
        return QVariant();

    switch (section) {
    case 0:
        return tr("Type");
    case 1:
        return tr("Display Name");
    case 2:
        return tr("Standard Locations");
    case 3:
        return tr("Writable Location");
    }
    return QVariant();
}