1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-30 19:46:56 +00:00
transmission/gtk/IconCache.cc
Mike Gelfand 192a76b621
Move GTK compatibility definitions into a separate header (#4493)
* Move GTK compatibility macros into a separate header

* Fix Cairo compatibility checks

* Move Glib-namespaced definitions to GtkCompat header

* Remove unused stringify definitions since we're using fmtlib
2022-12-29 02:42:20 +00:00

44 lines
1,011 B
C++

/*
* 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 <giomm/contenttype.h>
#include <algorithm>
#include <map>
#include <string>
#include <string_view>
#include <utility>
using namespace std::literals;
using IconCache = std::map<std::string, Glib::RefPtr<Gio::Icon>, std::less<>>;
std::string_view const DirectoryMimeType = "folder"sv;
std::string_view const UnknownMimeType = "unknown"sv;
Glib::RefPtr<Gio::Icon> 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;
}