diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-07-31 07:09:35 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-07-31 07:09:35 +0200 |
commit | 993ab84a0d07591352f7a02ba0c2b3269b44ca1e (patch) | |
tree | b8009d3e4220fdc5594c31c95a465c581f841af6 /Libraries | |
parent | 10b4c92e214bbe17bca0e7e7c2c6893555e65ba4 (diff) | |
download | serenity-993ab84a0d07591352f7a02ba0c2b3269b44ca1e.zip |
GDirectoryModel: Add "modification time" column.
Fixes #373.
Diffstat (limited to 'Libraries')
-rw-r--r-- | Libraries/LibGUI/GDirectoryModel.cpp | 24 | ||||
-rw-r--r-- | Libraries/LibGUI/GDirectoryModel.h | 2 |
2 files changed, 25 insertions, 1 deletions
diff --git a/Libraries/LibGUI/GDirectoryModel.cpp b/Libraries/LibGUI/GDirectoryModel.cpp index 2034cfa0be..2510fef65c 100644 --- a/Libraries/LibGUI/GDirectoryModel.cpp +++ b/Libraries/LibGUI/GDirectoryModel.cpp @@ -3,12 +3,13 @@ #include <AK/StringBuilder.h> #include <LibCore/CDirIterator.h> #include <LibCore/CLock.h> -#include <LibGUI/GPainter.h> #include <LibDraw/GraphicsBitmap.h> +#include <LibGUI/GPainter.h> #include <dirent.h> #include <grp.h> #include <pwd.h> #include <stdio.h> +#include <time.h> #include <unistd.h> static CLockable<HashMap<String, RefPtr<GraphicsBitmap>>>& thumbnail_cache() @@ -106,6 +107,8 @@ String GDirectoryModel::column_name(int column) const return "Group"; case Column::Permissions: return "Mode"; + case Column::ModificationTime: + return "Modified"; case Column::Inode: return "Inode"; } @@ -125,6 +128,8 @@ GModel::ColumnMetadata GDirectoryModel::column_metadata(int column) const return { 50, TextAlignment::CenterLeft }; case Column::Group: return { 50, TextAlignment::CenterLeft }; + case Column::ModificationTime: + return { 110, TextAlignment::CenterLeft }; case Column::Permissions: return { 60, TextAlignment::CenterLeft }; case Column::Inode: @@ -161,6 +166,18 @@ GIcon GDirectoryModel::icon_for(const Entry& entry) const return m_file_icon; } +static String timestamp_string(time_t timestamp) +{ + auto* tm = localtime(×tamp); + return String::format("%4u-%02u-%02u %02u:%02u:%02u", + tm->tm_year + 1900, + tm->tm_mon + 1, + tm->tm_mday, + tm->tm_hour, + tm->tm_min, + tm->tm_sec); +} + static String permission_string(mode_t mode) { StringBuilder builder; @@ -232,6 +249,8 @@ GVariant GDirectoryModel::data(const GModelIndex& index, Role role) const return name_for_gid(entry.gid); case Column::Permissions: return permission_string(entry.mode); + case Column::ModificationTime: + return entry.mtime; case Column::Inode: return (int)entry.inode; } @@ -251,6 +270,8 @@ GVariant GDirectoryModel::data(const GModelIndex& index, Role role) const return name_for_gid(entry.gid); case Column::Permissions: return permission_string(entry.mode); + case Column::ModificationTime: + return timestamp_string(entry.mtime); case Column::Inode: return (int)entry.inode; } @@ -289,6 +310,7 @@ void GDirectoryModel::update() entry.uid = st.st_uid; entry.gid = st.st_gid; entry.inode = st.st_ino; + entry.mtime = st.st_mtime; auto& entries = S_ISDIR(st.st_mode) ? m_directories : m_files; entries.append(move(entry)); diff --git a/Libraries/LibGUI/GDirectoryModel.h b/Libraries/LibGUI/GDirectoryModel.h index 8787a56d17..e031c9aa69 100644 --- a/Libraries/LibGUI/GDirectoryModel.h +++ b/Libraries/LibGUI/GDirectoryModel.h @@ -19,6 +19,7 @@ public: Owner, Group, Permissions, + ModificationTime, Inode, __Count, }; @@ -43,6 +44,7 @@ public: uid_t uid { 0 }; uid_t gid { 0 }; ino_t inode { 0 }; + time_t mtime { 0 }; mutable RefPtr<GraphicsBitmap> thumbnail; bool is_directory() const { return S_ISDIR(mode); } bool is_executable() const { return mode & S_IXUSR; } |