From 9ec552dd3894eb06f6b9be18d2b7714b0a646a72 Mon Sep 17 00:00:00 2001 From: Heliguy Date: Mon, 23 Sep 2024 14:46:03 -0400 Subject: [PATCH] Sort snapshot list by date and time created --- src/snapshot_page/snapshot_box.py | 3 ++- src/snapshot_page/snapshots_list_page.py | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/snapshot_page/snapshot_box.py b/src/snapshot_page/snapshot_box.py index 05788cf..88a14ad 100644 --- a/src/snapshot_page/snapshot_box.py +++ b/src/snapshot_page/snapshot_box.py @@ -123,7 +123,8 @@ class SnapshotBox(Gtk.Box): self.parent_page = parent_page self.folder = folder self.snapshots_path = snapshots_path - date_data = GLib.DateTime.new_from_unix_local(int(split_folder[0])).format("%x %X") + self.epoch = int(split_folder[0]) + date_data = GLib.DateTime.new_from_unix_local(self.epoch).format("%x %X") self.date.set_label(date_data) self.version.set_label(_("Version: {}").format(split_folder[1].replace(".tar.zst", ""))) self.json_path = f"{snapshots_path}{folder.replace('tar.zst', 'json')}" diff --git a/src/snapshot_page/snapshots_list_page.py b/src/snapshot_page/snapshots_list_page.py index 889e39c..988985b 100644 --- a/src/snapshot_page/snapshots_list_page.py +++ b/src/snapshot_page/snapshots_list_page.py @@ -70,6 +70,11 @@ class SnapshotsListPage(Adw.NavigationPage): dialog = NewSnapshotDialog(self.parent_page, self.parent_page.snapshotting_status, self.on_done, self.package_or_folder) dialog.create_button.connect("clicked", lambda *_: self.parent_page.status_stack.set_visible_child(self.parent_page.snapshotting_view)) dialog.present(HostInfo.main_window) + + def sort_func(self, row1, row2): + row1 = row1.get_child() + row2 = row2.get_child() + return row1.epoch > row2.epoch def __init__(self, parent_page, **kwargs): super().__init__(**kwargs) @@ -86,3 +91,4 @@ class SnapshotsListPage(Adw.NavigationPage): self.new_button.connect("clicked", self.on_new) # Apply + self.listbox.set_sort_func(self.sort_func)