File indexing completed on 2024-03-24 03:57:57

0001 /*
0002     This file is part of the KDE libraries
0003     SPDX-FileCopyrightText: 2015 Harald Sitter <sitter@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-only
0006 */
0007 
0008 #include "kioglobal_p.h"
0009 
0010 #include <QStandardPaths>
0011 
0012 using LocationMap = QMap<QString, QString>;
0013 
0014 static QMap<QString, QString> standardLocationsMap()
0015 {
0016     struct LocationInfo {
0017         QStandardPaths::StandardLocation location;
0018         const char *iconName;
0019     };
0020     static const LocationInfo mapping[] = {
0021         {QStandardPaths::TemplatesLocation, "folder-templates"},
0022         {QStandardPaths::PublicShareLocation, "folder-public"},
0023         {QStandardPaths::MusicLocation, "folder-music"},
0024         {QStandardPaths::MoviesLocation, "folder-videos"},
0025         {QStandardPaths::PicturesLocation, "folder-pictures"},
0026         {QStandardPaths::TempLocation, "folder-temp"},
0027         {QStandardPaths::DownloadLocation, "folder-download"},
0028         // Order matters here as paths can be reused for multiple purposes
0029         // We essentially want more generic choices to trump more specific
0030         // ones.
0031         // home > desktop > documents > *.
0032         {QStandardPaths::DocumentsLocation, "folder-documents"},
0033         {QStandardPaths::DesktopLocation, "user-desktop"},
0034         {QStandardPaths::HomeLocation, "user-home"},
0035     };
0036 
0037     LocationMap map;
0038 
0039     for (const auto &row : mapping) {
0040         const QStringList locations = QStandardPaths::standardLocations(row.location);
0041         for (const QString &location : locations) {
0042             map.insert(location, QLatin1String(row.iconName));
0043         }
0044     }
0045     return map;
0046 }
0047 
0048 QString KIOPrivate::iconForStandardPath(const QString &localDirectory)
0049 {
0050     static auto map = standardLocationsMap();
0051     return map.value(localDirectory, QString());
0052 }