diff options
author | Andreas Kling <kling@serenityos.org> | 2020-09-18 18:21:28 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-09-18 21:29:01 +0200 |
commit | e4c23b0151622e101b8dbbcb72ecbeaf02ebc986 (patch) | |
tree | 4dee08bd82684b9226cda649139966924238b63d /Libraries | |
parent | fad6b8f26792e35b31670a363a4c99d91ffe213f (diff) | |
download | serenity-e4c23b0151622e101b8dbbcb72ecbeaf02ebc986.zip |
iLibGUI+Base: Show inaccessible directories with special icon in views
Diffstat (limited to 'Libraries')
-rw-r--r-- | Libraries/LibGUI/FileIconProvider.cpp | 4 | ||||
-rw-r--r-- | Libraries/LibGUI/FileSystemModel.cpp | 6 | ||||
-rw-r--r-- | Libraries/LibGUI/FileSystemModel.h | 1 |
3 files changed, 10 insertions, 1 deletions
diff --git a/Libraries/LibGUI/FileIconProvider.cpp b/Libraries/LibGUI/FileIconProvider.cpp index 7698b3222c..dfcf89774f 100644 --- a/Libraries/LibGUI/FileIconProvider.cpp +++ b/Libraries/LibGUI/FileIconProvider.cpp @@ -61,6 +61,7 @@ ENUMERATE_FILETYPES(__ENUMERATE_FILETYPE) static Icon s_hard_disk_icon; static Icon s_directory_icon; static Icon s_directory_open_icon; +static Icon s_inaccessible_directory_icon; static Icon s_home_directory_icon; static Icon s_home_directory_open_icon; static Icon s_file_icon; @@ -76,6 +77,7 @@ static void initialize_if_needed() s_hard_disk_icon = Icon::default_icon("hard-disk"); s_directory_icon = Icon::default_icon("filetype-folder"); s_directory_open_icon = Icon::default_icon("filetype-folder-open"); + s_inaccessible_directory_icon = Icon::default_icon("filetype-folder-inaccessible"); s_home_directory_icon = Icon::default_icon("home-directory"); s_home_directory_open_icon = Icon::default_icon("home-directory-open"); s_file_icon = Icon::default_icon("filetype-unknown"); @@ -137,6 +139,8 @@ Icon FileIconProvider::icon_for_path(const String& path, mode_t mode) if (S_ISDIR(mode)) { if (path == Core::StandardPaths::home_directory()) return s_home_directory_icon; + if (access(path.characters(), R_OK | X_OK) < 0) + return s_inaccessible_directory_icon; return s_directory_icon; } if (S_ISLNK(mode)) diff --git a/Libraries/LibGUI/FileSystemModel.cpp b/Libraries/LibGUI/FileSystemModel.cpp index 0fd614a7e0..33bb32923a 100644 --- a/Libraries/LibGUI/FileSystemModel.cpp +++ b/Libraries/LibGUI/FileSystemModel.cpp @@ -82,6 +82,10 @@ bool FileSystemModel::Node::fetch_data(const String& full_path, bool is_root) perror("readlink"); } + if (S_ISDIR(mode)) { + is_accessible_directory = access(full_path.characters(), R_OK | X_OK) == 0; + } + return true; } @@ -480,7 +484,7 @@ Icon FileSystemModel::icon_for(const Node& node) const return FileIconProvider::home_directory_open_icon(); return FileIconProvider::home_directory_icon(); } - if (node.is_selected()) + if (node.is_selected() && node.is_accessible_directory) return FileIconProvider::directory_open_icon(); } diff --git a/Libraries/LibGUI/FileSystemModel.h b/Libraries/LibGUI/FileSystemModel.h index 1afe6946e2..693c41d7d2 100644 --- a/Libraries/LibGUI/FileSystemModel.h +++ b/Libraries/LibGUI/FileSystemModel.h @@ -73,6 +73,7 @@ public: gid_t gid { 0 }; ino_t inode { 0 }; time_t mtime { 0 }; + bool is_accessible_directory { false }; size_t total_size { 0 }; |