/* * icons.[ch] written by Paolo Bacchilega, who writes: * "There is no problem for me, you can license my code * under whatever licence you wish :)" * */ #include "IconCache.h" #include "GtkCompat.h" #include #include #include #include #include #include using namespace std::literals; using IconCache = std::map, std::less<>>; std::string_view const DirectoryMimeType = "folder"sv; std::string_view const UnknownMimeType = "unknown"sv; Glib::RefPtr gtr_get_mime_type_icon(std::string_view mime_type) { static IconCache cache; if (auto mime_it = cache.find(mime_type); mime_it != std::end(cache)) { return mime_it->second; } auto mime_type_str = std::string{ mime_type }; auto icon = Gio::content_type_get_icon(mime_type_str); if (icon != nullptr) { cache.try_emplace(std::move(mime_type_str), icon); } return icon; }