MCPcopy Create free account
hub / github.com/KDE/kdevelop / iconNameForPath

Method iconNameForPath

kdevplatform/project/projectmodel.cpp:729–767  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

727{
728public:
729 QString iconNameForPath(const Path& path, QStringView fileName)
730 {
731 // find icon name based on file extension, if possible
732 QString extension;
733 int extensionStart = fileName.lastIndexOf(QLatin1Char('.'));
734 if( extensionStart != -1 && fileName.length() - extensionStart - 1 <= maximumCacheExtensionLength ) {
735 auto extRef = fileName.sliced(extensionStart + 1);
736 if( isNumeric(extRef) ) {
737 // don't cache numeric extensions
738 extRef = {};
739 }
740 if( !extRef.isEmpty() ) {
741 extension = extRef.toString();
742 QMutexLocker lock(&mutex);
743 QHash< QString, QString >::const_iterator it = fileExtensionToIcon.constFind( extension );
744 if( it != fileExtensionToIcon.constEnd() ) {
745 return *it;
746 }
747 }
748 }
749
750 QMimeType mime = QMimeDatabase().mimeTypeForFile(path.lastPathSegment(), QMimeDatabase::MatchExtension); // no I/O
751 QMutexLocker lock(&mutex);
752 QHash< QString, QString >::const_iterator it = mimeToIcon.constFind(mime.name());
753 QString iconName;
754 if ( it == mimeToIcon.constEnd() ) {
755 iconName = mime.iconName();
756 if (iconName.isEmpty()) {
757 iconName = QStringLiteral("none");
758 }
759 mimeToIcon.insert(mime.name(), iconName);
760 } else {
761 iconName = *it;
762 }
763 if ( !extension.isEmpty() ) {
764 fileExtensionToIcon.insert(extension, iconName);
765 }
766 return iconName;
767 }
768 QMutex mutex;
769 QHash<QString, QString> mimeToIcon;
770 QHash<QString, QString> fileExtensionToIcon;

Callers 1

iconNameMethod · 0.80

Calls 10

constEndMethod · 0.80
lastPathSegmentMethod · 0.80
isNumericFunction · 0.70
lengthMethod · 0.45
isEmptyMethod · 0.45
toStringMethod · 0.45
constFindMethod · 0.45
nameMethod · 0.45
iconNameMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected