#pragma once #include #include #include class DirectoryModel final : public GModel { friend int thumbnail_thread(void*); public: static Retained create() { return adopt(*new DirectoryModel); } virtual ~DirectoryModel() override; enum Column { Icon = 0, Name, Size, Owner, Group, Permissions, Inode, __Count, }; virtual int row_count(const GModelIndex& = GModelIndex()) const override; virtual int column_count(const GModelIndex& = GModelIndex()) const override; virtual String column_name(int column) const override; virtual ColumnMetadata column_metadata(int column) const override; virtual GVariant data(const GModelIndex&, Role = Role::Display) const override; virtual void update() override; virtual void activate(const GModelIndex&) override; String path() const { return m_path; } void open(const String& path); size_t bytes_in_files() const { return m_bytes_in_files; } Function on_thumbnail_progress; private: DirectoryModel(); String name_for_uid(uid_t) const; String name_for_gid(gid_t) const; struct Entry { String name; size_t size { 0 }; mode_t mode { 0 }; uid_t uid { 0 }; uid_t gid { 0 }; ino_t inode { 0 }; mutable RetainPtr thumbnail; bool is_directory() const { return S_ISDIR(mode); } bool is_executable() const { return mode & S_IXUSR; } String full_path(const DirectoryModel& model) const { return String::format("%s/%s", model.path().characters(), name.characters()); } }; const Entry& entry(int index) const { if (index < m_directories.size()) return m_directories[index]; return m_files[index - m_directories.size()]; } GIcon icon_for(const Entry& entry) const; String m_path; Vector m_files; Vector m_directories; size_t m_bytes_in_files; GIcon m_directory_icon; GIcon m_file_icon; GIcon m_symlink_icon; GIcon m_socket_icon; GIcon m_executable_icon; GIcon m_filetype_image_icon; HashMap m_user_names; HashMap m_group_names; };