mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 02:47:35 +00:00
LibGUI: Make GUI::FileIconProvider::icon_for_executable() a public API
This way we can use it instead of icon_for_path() in a bunch of places and avoid loading the full FileIconProvider configuration.
This commit is contained in:
parent
a49fd0ff5e
commit
ffa241250b
6 changed files with 20 additions and 6 deletions
|
@ -46,7 +46,7 @@ namespace FileManager {
|
||||||
|
|
||||||
NonnullRefPtr<GUI::Action> LauncherHandler::create_launch_action(Function<void(const LauncherHandler&)> launch_handler)
|
NonnullRefPtr<GUI::Action> LauncherHandler::create_launch_action(Function<void(const LauncherHandler&)> launch_handler)
|
||||||
{
|
{
|
||||||
auto icon = GUI::FileIconProvider::icon_for_path(details().executable).bitmap_for_size(16);
|
auto icon = GUI::FileIconProvider::icon_for_executable(details().executable).bitmap_for_size(16);
|
||||||
return GUI::Action::create(details().name, move(icon), [this, launch_handler = move(launch_handler)](auto&) {
|
return GUI::Action::create(details().name, move(icon), [this, launch_handler = move(launch_handler)](auto&) {
|
||||||
launch_handler(*this);
|
launch_handler(*this);
|
||||||
});
|
});
|
||||||
|
|
|
@ -276,7 +276,7 @@ GUI::Variant ProcessModel::data(const GUI::ModelIndex& index, GUI::ModelRole rol
|
||||||
if (role == GUI::ModelRole::Display) {
|
if (role == GUI::ModelRole::Display) {
|
||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
case Column::Icon: {
|
case Column::Icon: {
|
||||||
auto icon = GUI::FileIconProvider::icon_for_path(thread.current_state.executable);
|
auto icon = GUI::FileIconProvider::icon_for_executable(thread.current_state.executable);
|
||||||
if (auto* bitmap = icon.bitmap_for_size(16))
|
if (auto* bitmap = icon.bitmap_for_size(16))
|
||||||
return *bitmap;
|
return *bitmap;
|
||||||
return *m_generic_process_icon;
|
return *m_generic_process_icon;
|
||||||
|
|
|
@ -58,6 +58,15 @@ static RefPtr<Gfx::Bitmap> s_symlink_emblem_small;
|
||||||
static HashMap<String, Icon> s_filetype_icons;
|
static HashMap<String, Icon> s_filetype_icons;
|
||||||
static HashMap<String, Vector<String>> s_filetype_patterns;
|
static HashMap<String, Vector<String>> s_filetype_patterns;
|
||||||
|
|
||||||
|
static void initialize_executable_icon_if_needed()
|
||||||
|
{
|
||||||
|
static bool initialized = false;
|
||||||
|
if (initialized)
|
||||||
|
return;
|
||||||
|
initialized = true;
|
||||||
|
s_executable_icon = Icon::default_icon("filetype-executable");
|
||||||
|
}
|
||||||
|
|
||||||
static void initialize_if_needed()
|
static void initialize_if_needed()
|
||||||
{
|
{
|
||||||
static bool s_initialized = false;
|
static bool s_initialized = false;
|
||||||
|
@ -78,9 +87,11 @@ static void initialize_if_needed()
|
||||||
s_file_icon = Icon::default_icon("filetype-unknown");
|
s_file_icon = Icon::default_icon("filetype-unknown");
|
||||||
s_symlink_icon = Icon::default_icon("filetype-symlink");
|
s_symlink_icon = Icon::default_icon("filetype-symlink");
|
||||||
s_socket_icon = Icon::default_icon("filetype-socket");
|
s_socket_icon = Icon::default_icon("filetype-socket");
|
||||||
s_executable_icon = Icon::default_icon("filetype-executable");
|
|
||||||
s_filetype_image_icon = Icon::default_icon("filetype-image");
|
s_filetype_image_icon = Icon::default_icon("filetype-image");
|
||||||
|
|
||||||
|
initialize_executable_icon_if_needed();
|
||||||
|
|
||||||
for (auto& filetype : config->keys("Icons")) {
|
for (auto& filetype : config->keys("Icons")) {
|
||||||
s_filetype_icons.set(filetype, Icon::default_icon(String::formatted("filetype-{}", filetype)));
|
s_filetype_icons.set(filetype, Icon::default_icon(String::formatted("filetype-{}", filetype)));
|
||||||
s_filetype_patterns.set(filetype, config->read_entry("Icons", filetype).split(','));
|
s_filetype_patterns.set(filetype, config->read_entry("Icons", filetype).split(','));
|
||||||
|
@ -127,13 +138,15 @@ Icon FileIconProvider::icon_for_path(const String& path)
|
||||||
return icon_for_path(path, stat.st_mode);
|
return icon_for_path(path, stat.st_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Icon icon_for_executable(const String& path)
|
Icon FileIconProvider::icon_for_executable(const String& path)
|
||||||
{
|
{
|
||||||
static HashMap<String, Icon> app_icon_cache;
|
static HashMap<String, Icon> app_icon_cache;
|
||||||
|
|
||||||
if (auto it = app_icon_cache.find(path); it != app_icon_cache.end())
|
if (auto it = app_icon_cache.find(path); it != app_icon_cache.end())
|
||||||
return it->value;
|
return it->value;
|
||||||
|
|
||||||
|
initialize_executable_icon_if_needed();
|
||||||
|
|
||||||
// If the icon for an app isn't in the cache we attempt to load the file as an ELF image and extract
|
// If the icon for an app isn't in the cache we attempt to load the file as an ELF image and extract
|
||||||
// the serenity_app_icon_* sections which should contain the icons as raw PNG data. In the future it would
|
// the serenity_app_icon_* sections which should contain the icons as raw PNG data. In the future it would
|
||||||
// be better if the binary signalled the image format being used or we deduced it, e.g. using magic bytes.
|
// be better if the binary signalled the image format being used or we deduced it, e.g. using magic bytes.
|
||||||
|
|
|
@ -36,6 +36,7 @@ class FileIconProvider {
|
||||||
public:
|
public:
|
||||||
static Icon icon_for_path(const String&, mode_t);
|
static Icon icon_for_path(const String&, mode_t);
|
||||||
static Icon icon_for_path(const String&);
|
static Icon icon_for_path(const String&);
|
||||||
|
static Icon icon_for_executable(const String&);
|
||||||
|
|
||||||
static Icon filetype_image_icon();
|
static Icon filetype_image_icon();
|
||||||
static Icon directory_icon();
|
static Icon directory_icon();
|
||||||
|
|
|
@ -55,7 +55,7 @@ void RunningProcessesModel::update()
|
||||||
Process process;
|
Process process;
|
||||||
process.pid = it.value.pid;
|
process.pid = it.value.pid;
|
||||||
process.uid = it.value.uid;
|
process.uid = it.value.uid;
|
||||||
process.icon = FileIconProvider::icon_for_path(it.value.executable).bitmap_for_size(16);
|
process.icon = FileIconProvider::icon_for_executable(it.value.executable).bitmap_for_size(16);
|
||||||
process.name = it.value.name;
|
process.name = it.value.name;
|
||||||
m_processes.append(move(process));
|
m_processes.append(move(process));
|
||||||
}
|
}
|
||||||
|
|
|
@ -141,7 +141,7 @@ NonnullRefPtr<GUI::Menu> build_system_menu()
|
||||||
// Then we create and insert all the app menu items into the right place.
|
// Then we create and insert all the app menu items into the right place.
|
||||||
int app_identifier = 0;
|
int app_identifier = 0;
|
||||||
for (const auto& app : g_apps) {
|
for (const auto& app : g_apps) {
|
||||||
auto icon = GUI::FileIconProvider::icon_for_path(app.executable).bitmap_for_size(16);
|
auto icon = GUI::FileIconProvider::icon_for_executable(app.executable).bitmap_for_size(16);
|
||||||
|
|
||||||
#ifdef SYSTEM_MENU_DEBUG
|
#ifdef SYSTEM_MENU_DEBUG
|
||||||
if (icon)
|
if (icon)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue