diff options
author | Linus Groh <mail@linusgroh.de> | 2020-04-25 19:41:05 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-04-26 01:12:14 +0200 |
commit | 9de184d883a595e06bd9ea544becba14f3806a34 (patch) | |
tree | af5aeb020c1071b3afd4ae7c19ff38e90554b249 /Libraries | |
parent | a36ceffb569aefdef2aa6d8165c7b90377022b41 (diff) | |
download | serenity-9de184d883a595e06bd9ea544becba14f3806a34.zip |
LibGUI: Use enumerator macros for filetype icons
Diffstat (limited to 'Libraries')
-rw-r--r-- | Libraries/LibGUI/FileSystemModel.cpp | 43 | ||||
-rw-r--r-- | Libraries/LibGUI/FileSystemModel.h | 26 |
2 files changed, 29 insertions, 40 deletions
diff --git a/Libraries/LibGUI/FileSystemModel.cpp b/Libraries/LibGUI/FileSystemModel.cpp index 3f029b6f18..5d1deb036c 100644 --- a/Libraries/LibGUI/FileSystemModel.cpp +++ b/Libraries/LibGUI/FileSystemModel.cpp @@ -206,16 +206,11 @@ FileSystemModel::FileSystemModel(const StringView& root_path, Mode mode) m_symlink_icon = Icon::default_icon("filetype-symlink"); m_socket_icon = Icon::default_icon("filetype-socket"); m_executable_icon = Icon::default_icon("filetype-executable"); - m_filetype_image_icon = Icon::default_icon("filetype-image"); - m_filetype_sound_icon = Icon::default_icon("filetype-sound"); - m_filetype_html_icon = Icon::default_icon("filetype-html"); - m_filetype_cplusplus_icon = Icon::default_icon("filetype-cplusplus"); - m_filetype_java_icon = Icon::default_icon("filetype-java"); - m_filetype_javascript_icon = Icon::default_icon("filetype-javascript"); - m_filetype_text_icon = Icon::default_icon("filetype-text"); - m_filetype_pdf_icon = Icon::default_icon("filetype-pdf"); - m_filetype_library_icon = Icon::default_icon("filetype-library"); - m_filetype_object_icon = Icon::default_icon("filetype-object"); + +#define __ENUMERATE_FILETYPE(filetype_name, ...) \ + m_filetype_##filetype_name##_icon = Icon::default_icon("filetype-" #filetype_name); + ENUMERATE_FILETYPES +#undef __ENUMERATE_FILETYPE setpwent(); while (auto* passwd = getpwent()) @@ -431,26 +426,14 @@ Icon FileSystemModel::icon_for_file(const mode_t mode, const String& name) const return m_socket_icon; if (mode & (S_IXUSR | S_IXGRP | S_IXOTH)) return m_executable_icon; - if (name.to_lowercase().ends_with(".wav")) - return m_filetype_sound_icon; - if (name.to_lowercase().ends_with(".html")) - return m_filetype_html_icon; - if (name.to_lowercase().ends_with(".png")) - return m_filetype_image_icon; - if (name.to_lowercase().ends_with(".cpp")) - return m_filetype_cplusplus_icon; - if (name.to_lowercase().ends_with(".java")) - return m_filetype_java_icon; - if (name.to_lowercase().ends_with(".js")) - return m_filetype_javascript_icon; - if (name.to_lowercase().ends_with(".txt")) - return m_filetype_text_icon; - if (name.to_lowercase().ends_with(".pdf")) - return m_filetype_pdf_icon; - if (name.to_lowercase().ends_with(".o") || name.to_lowercase().ends_with(".obj")) - return m_filetype_object_icon; - if (name.to_lowercase().ends_with(".so") || name.to_lowercase().ends_with(".a")) - return m_filetype_library_icon; + +#define __ENUMERATE_FILETYPE(filetype_name, filetype_extensions...) \ + for (auto& extension : Vector<String> { filetype_extensions }) { \ + if (name.to_lowercase().ends_with(extension)) \ + return m_filetype_##filetype_name##_icon; \ + } + ENUMERATE_FILETYPES +#undef __ENUMERATE_FILETYPE return m_file_icon; } diff --git a/Libraries/LibGUI/FileSystemModel.h b/Libraries/LibGUI/FileSystemModel.h index a190919bb0..03e07546be 100644 --- a/Libraries/LibGUI/FileSystemModel.h +++ b/Libraries/LibGUI/FileSystemModel.h @@ -35,6 +35,17 @@ #include <sys/stat.h> #include <time.h> +#define ENUMERATE_FILETYPES \ + __ENUMERATE_FILETYPE(cplusplus, ".cpp") \ + __ENUMERATE_FILETYPE(html, ".html") \ + __ENUMERATE_FILETYPE(image, ".png") \ + __ENUMERATE_FILETYPE(java, ".java") \ + __ENUMERATE_FILETYPE(javascript, ".js") \ + __ENUMERATE_FILETYPE(library, ".so", ".a") \ + __ENUMERATE_FILETYPE(object, ".o", ".obj") \ + __ENUMERATE_FILETYPE(pdf, ".pdf") \ + __ENUMERATE_FILETYPE(sound, ".wav") \ + __ENUMERATE_FILETYPE(text, ".txt") namespace GUI { class FileSystemModel @@ -160,16 +171,11 @@ private: GUI::Icon m_symlink_icon; GUI::Icon m_socket_icon; GUI::Icon m_executable_icon; - GUI::Icon m_filetype_image_icon; - GUI::Icon m_filetype_sound_icon; - GUI::Icon m_filetype_html_icon; - GUI::Icon m_filetype_cplusplus_icon; - GUI::Icon m_filetype_java_icon; - GUI::Icon m_filetype_javascript_icon; - GUI::Icon m_filetype_text_icon; - GUI::Icon m_filetype_pdf_icon; - GUI::Icon m_filetype_library_icon; - GUI::Icon m_filetype_object_icon; + +#define __ENUMERATE_FILETYPE(filetype_name, ...) \ + GUI::Icon m_filetype_##filetype_name##_icon; + ENUMERATE_FILETYPES +#undef __ENUMERATE_FILETYPE unsigned m_thumbnail_progress { 0 }; unsigned m_thumbnail_progress_total { 0 }; |