1 | /* |
2 | This file is part of the KDE libraries |
3 | SPDX-FileCopyrightText: 2015 Harald Sitter <sitter@kde.org> |
4 | |
5 | SPDX-License-Identifier: LGPL-2.0-only |
6 | */ |
7 | |
8 | #include "kioglobal_p.h" |
9 | |
10 | #include <QStandardPaths> |
11 | |
12 | using LocationMap = QMap<QString, QString>; |
13 | |
14 | static QMap<QString, QString> standardLocationsMap() |
15 | { |
16 | struct LocationInfo { |
17 | QStandardPaths::StandardLocation location; |
18 | const char *iconName; |
19 | }; |
20 | static const LocationInfo mapping[] = { |
21 | {.location: QStandardPaths::TemplatesLocation, .iconName: "folder-templates" }, |
22 | {.location: QStandardPaths::PublicShareLocation, .iconName: "folder-public" }, |
23 | {.location: QStandardPaths::MusicLocation, .iconName: "folder-music" }, |
24 | {.location: QStandardPaths::MoviesLocation, .iconName: "folder-videos" }, |
25 | {.location: QStandardPaths::PicturesLocation, .iconName: "folder-pictures" }, |
26 | {.location: QStandardPaths::TempLocation, .iconName: "folder-temp" }, |
27 | {.location: QStandardPaths::DownloadLocation, .iconName: "folder-download" }, |
28 | // Order matters here as paths can be reused for multiple purposes |
29 | // We essentially want more generic choices to trump more specific |
30 | // ones. |
31 | // home > desktop > documents > *. |
32 | {.location: QStandardPaths::DocumentsLocation, .iconName: "folder-documents" }, |
33 | {.location: QStandardPaths::DesktopLocation, .iconName: "user-desktop" }, |
34 | {.location: QStandardPaths::HomeLocation, .iconName: "user-home" }, |
35 | }; |
36 | |
37 | LocationMap map; |
38 | |
39 | for (const auto &row : mapping) { |
40 | const QStringList locations = QStandardPaths::standardLocations(type: row.location); |
41 | for (const QString &location : locations) { |
42 | map.insert(key: location, value: QLatin1String(row.iconName)); |
43 | } |
44 | } |
45 | return map; |
46 | } |
47 | |
48 | QString KIOPrivate::iconForStandardPath(const QString &localDirectory) |
49 | { |
50 | static auto map = standardLocationsMap(); |
51 | QString path = localDirectory; |
52 | if (path.endsWith(c: QLatin1Char('/'))) { |
53 | path.chop(n: 1); |
54 | } |
55 | return map.value(key: path, defaultValue: QString()); |
56 | } |
57 | |