Changeset View
Changeset View
Standalone View
Standalone View
src/core/kioglobal_p.cpp
Show All 12 Lines | |||||
13 | You should have received a copy of the GNU Library General Public License | 13 | You should have received a copy of the GNU Library General Public License | ||
14 | along with this library; see the file COPYING.LIB. If not, write to | 14 | along with this library; see the file COPYING.LIB. If not, write to | ||
15 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 15 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
16 | Boston, MA 02110-1301, USA. | 16 | Boston, MA 02110-1301, USA. | ||
17 | */ | 17 | */ | ||
18 | 18 | | |||
19 | #include "kioglobal_p.h" | 19 | #include "kioglobal_p.h" | ||
20 | 20 | | |||
21 | #include <klocalizedstring.h> | ||||
22 | | ||||
21 | #include <QStandardPaths> | 23 | #include <QStandardPaths> | ||
22 | 24 | | |||
23 | static QMap<QString, QString> standardLocationsMap() | 25 | static QMap<QString, QString> standardLocationsMap() | ||
24 | { | 26 | { | ||
25 | static const | 27 | static const | ||
26 | struct { QStandardPaths::StandardLocation location; | 28 | struct { QStandardPaths::StandardLocation location; | ||
27 | QString name; } | 29 | QString name; } | ||
28 | mapping[] = { | 30 | standardPathMapping[] = { | ||
29 | { QStandardPaths::MusicLocation, QStringLiteral("folder-music") }, | 31 | { QStandardPaths::MusicLocation, QStringLiteral("folder-music") }, | ||
30 | { QStandardPaths::MoviesLocation, QStringLiteral("folder-videos") }, | 32 | { QStandardPaths::MoviesLocation, QStringLiteral("folder-videos") }, | ||
31 | { QStandardPaths::PicturesLocation, QStringLiteral("folder-pictures") }, | 33 | { QStandardPaths::PicturesLocation, QStringLiteral("folder-pictures") }, | ||
32 | { QStandardPaths::TempLocation, QStringLiteral("folder-temp") }, | 34 | { QStandardPaths::TempLocation, QStringLiteral("folder-temp") }, | ||
33 | { QStandardPaths::DownloadLocation, QStringLiteral("folder-download") }, | 35 | { QStandardPaths::DownloadLocation, QStringLiteral("folder-download") }, | ||
34 | // Order matters here as paths can be reused for multiple purposes | 36 | // Order matters here as paths can be reused for multiple purposes | ||
35 | // We essentially want more generic choices to trump more specific | 37 | // We essentially want more generic choices to trump more specific | ||
36 | // ones. | 38 | // ones. | ||
37 | // home > desktop > documents > *. | 39 | // home > desktop > documents > *. | ||
38 | { QStandardPaths::DocumentsLocation, QStringLiteral("folder-documents") }, | 40 | { QStandardPaths::DocumentsLocation, QStringLiteral("folder-documents") }, | ||
39 | { QStandardPaths::DesktopLocation, QStringLiteral("user-desktop") }, | 41 | { QStandardPaths::DesktopLocation, QStringLiteral("user-desktop") }, | ||
40 | { QStandardPaths::HomeLocation, QStringLiteral("user-home") } }; | 42 | { QStandardPaths::HomeLocation, QStringLiteral("user-home") } }; | ||
41 | static const int count = sizeof mapping / sizeof *mapping; | 43 | static const int standardPathMappingCount = sizeof standardPathMapping / sizeof *standardPathMapping; | ||
44 | | ||||
45 | | ||||
46 | // Now we add additional paths not in the XDG spec, but for which we nonetheless | ||||
47 | // have an appropriate icon that could be used by default. For these, we match | ||||
48 | // not only the translated string but also the English string literal, because | ||||
49 | // some people like to use English names even with a different locale | ||||
50 | const QString homePath = QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + QStringLiteral("/"); | ||||
51 | const QMap<QString, QString> additionalPathMapping { | ||||
52 | { homePath + QStringLiteral("Games"), QStringLiteral("folder-games") }, | ||||
53 | { homePath + i18n("Games"), QStringLiteral("folder-games") } | ||||
54 | }; | ||||
55 | | ||||
42 | 56 | | |||
43 | QMap<QString, QString> map; | 57 | QMap<QString, QString> map; | ||
44 | for (int i = 0 ; i < count; ++i) { | 58 | for (int i = 0 ; i < standardPathMappingCount; ++i) { | ||
45 | auto locations = QStandardPaths::standardLocations(mapping[i].location); | 59 | auto standardLocations = QStandardPaths::standardLocations(standardPathMapping[i].location); | ||
46 | Q_FOREACH(const QString &location, locations) { | 60 | for (const QString location : standardLocations) { | ||
47 | map.insert(location, mapping[i].name); | 61 | map.insert(location, standardPathMapping[i].name); | ||
62 | } | ||||
48 | } | 63 | } | ||
64 | for (const QString location : additionalPathMapping.keys()) { | ||||
65 | map.insert(location, additionalPathMapping.value(location)); | ||||
49 | } | 66 | } | ||
50 | return map; | 67 | return map; | ||
51 | } | 68 | } | ||
52 | 69 | | |||
53 | QString KIOPrivate::iconForStandardPath(const QString &localDirectory) | 70 | QString KIOPrivate::iconForStandardPath(const QString &localDirectory) | ||
54 | { | 71 | { | ||
55 | static auto map = standardLocationsMap(); | 72 | static auto map = standardLocationsMap(); | ||
56 | return map.value(localDirectory, QString()); | 73 | return map.value(localDirectory, QString()); | ||
57 | } | 74 | } |