mirror of
https://github.com/transmission/transmission
synced 2024-12-24 16:52:39 +00:00
c75c6bf5c8
* Make compact mode switch work for both GTK 3 and 4 * Implement GTK 4-specific view gesture handling * Fix torrents view context menu on GTK 4 * Explicitly show/hide menubar on startup/teardown * Switch from `Gtk::Pixbuf` to `Gio::Icon` for views * Support GTK 4 exceptions based on `std::exception` * Fix options menu setup with GTK 4 * Use `delete-event` (GTK 3) and `close-request` (GTK 4) signals to handle window clousure * Add custom file chooser button implementation GTK 4 drops FileChooserButton widget and suggests implementing it using Button. * Add helpers to set X11 hints with GTK 4 * Remove `HigWorkarea` class that's no longer used * Make main menu shortcuts work with GTK 4 * Make drops work in main window and make dialog with GTK 4 * Remove unused `gtr_action_get_widget()` helper * Fix text direction mark setup with GTK 4 (due to switch to enum class) * Fix file tree font size calculation with GTK 4 * Fix crash during shutdown with GTK 4 * Switch from `RadioButton` to `CheckButton` for compatibility with GTK 4 * Fix opening files with GTK 4 * Rework torrent cell renderer to support both GTK 3 and 4 * Disable system tray icon support with GTK 4 * Fix windows positioning with GTK 4 * Fix focus event handling with GTK 4 * Adapt to tree model row/iterator changes in GTK 4 * Adapt to toplevel/root window changes in GTK 4 * Adapt to clipboard changes in GTK 4 * Adapt to icon/theme changes in GTK 4 * Adapt to file/path changes in GTK 4 * Random leftover fixes for GTK 4 compatibility * Clean up unused code * Move GTK 3 *.ui files into a subdirectory * Add GTK 4 *.ui files * Search for both GTK 3 and 4 during configuration
44 lines
1,014 B
C++
44 lines
1,014 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 <algorithm>
|
|
#include <map>
|
|
#include <string>
|
|
#include <string_view>
|
|
#include <utility>
|
|
|
|
#include <glibmm.h>
|
|
#include <giomm.h>
|
|
|
|
#include "IconCache.h"
|
|
#include "Utils.h"
|
|
|
|
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;
|
|
}
|