Skip to content

Commit

Permalink
Add properties to trashed items
Browse files Browse the repository at this point in the history
  • Loading branch information
kra-mo committed Dec 25, 2023
1 parent 23fe1e9 commit 81b9b10
Showing 1 changed file with 54 additions and 8 deletions.
62 changes: 54 additions & 8 deletions hyperplane/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ def __init__(self, gfile: Gio.File, **kwargs) -> None:
)
)

# TODO: Add trash date and origin path

attributes = {
# Basic info
Gio.FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME,
Expand All @@ -64,6 +62,9 @@ def __init__(self, gfile: Gio.File, **kwargs) -> None:
Gio.FILE_ATTRIBUTE_ACCESS_CAN_WRITE,
Gio.FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE,
Gio.FILE_ATTRIBUTE_SELINUX_CONTEXT,
# Trashed files
Gio.FILE_ATTRIBUTE_TRASH_DELETION_DATE,
Gio.FILE_ATTRIBUTE_TRASH_ORIG_PATH,
}

file_info = gfile.query_info(",".join(attributes), Gio.FileQueryInfoFlags.NONE)
Expand All @@ -84,6 +85,8 @@ def __init__(self, gfile: Gio.File, **kwargs) -> None:
can_write = file_info.get_attribute_as_string(Gio.FILE_ATTRIBUTE_ACCESS_CAN_WRITE)
can_execute = file_info.get_attribute_as_string(Gio.FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE)
security_context = file_info.get_attribute_as_string(Gio.FILE_ATTRIBUTE_SELINUX_CONTEXT)
deletion_date = file_info.get_deletion_date()
orig_path = file_info.get_attribute_byte_string(Gio.FILE_ATTRIBUTE_TRASH_ORIG_PATH)
# fmt: on

page = Adw.PreferencesPage()
Expand Down Expand Up @@ -257,11 +260,12 @@ def stop_loading(thread: GLib.Thread):

trash_group.add(
trash_items_row := Adw.ActionRow(
title=_("Items"), subtitle=str(shared.trash_list.get_n_items())
title=_("Items"),
subtitle=str(shared.trash_list.get_n_items()),
subtitle_selectable=True,
)
)
trash_items_row.add_css_class("property")
trash_items_row.set_subtitle_selectable(True)

trash_group.add(
empty_trash_button := Gtk.Button(
Expand All @@ -287,10 +291,10 @@ def empty(*_args: Any) -> None:
recent_items_row := Adw.ActionRow(
title=_("Items"),
subtitle=str(len(shared.recent_manager.get_items())),
subtitle_selectable=True,
)
)
recent_items_row.add_css_class("property")
recent_items_row.set_subtitle_selectable(True)

recent_group.add(
clear_recents_button := Gtk.Button(
Expand Down Expand Up @@ -329,6 +333,48 @@ def clear(*_args: Any) -> None:
)
tags_row.add_css_class("property")

if deletion_date or orig_path:
page.add(deleted_group := Adw.PreferencesGroup())

if orig_path:
if (
orig_gfile := Gio.File.new_for_path(orig_path)
).has_parent() and path_represents_tags(
orig_gfile.get_parent().get_path()
):
deleted_group.add(
orig_tags_row := Adw.ActionRow(
title=_("Original Categories"),
subtitle=", ".join(
shared.home.get_relative_path(
orig_gfile.get_parent()
)
.strip("/")
.split("/")
),
subtitle_selectable=True,
)
)
orig_tags_row.add_css_class("property")
else:
deleted_group.add(
orig_path_row := Adw.ActionRow(
title=_("Original Path"),
subtitle=orig_path,
subtitle_selectable=True,
)
)
orig_path_row.add_css_class("property")

if deletion_date:
trashed_row = Adw.ActionRow(
title=_("Trashed On"),
subtitle=access.format(r"%c"),
subtitle_selectable=True,
)
trashed_row.add_css_class("property")
deleted_group.add(trashed_row)

if access or modified or created:
page.add(history_group := Adw.PreferencesGroup())

Expand All @@ -338,13 +384,13 @@ def clear(*_args: Any) -> None:
created: _("Created"),
}.items():
if date:
access_row = Adw.ActionRow(
date_row = Adw.ActionRow(
title=title,
subtitle=access.format(r"%c"),
subtitle_selectable=True,
)
access_row.add_css_class("property")
history_group.add(access_row)
date_row.add_css_class("property")
history_group.add(date_row)

can_be_executable = content_type and Gio.content_type_can_be_executable(
content_type
Expand Down

0 comments on commit 81b9b10

Please sign in to comment.