Further work on snapshots

This commit is contained in:
Heliguy
2024-09-03 16:42:37 -04:00
parent b6a6c9ca36
commit bae9c0d955
8 changed files with 48 additions and 51 deletions

View File

@@ -1,7 +1,7 @@
from gi.repository import Adw, Gtk, GLib, Gio, Pango
from .host_info import HostInfo
@Gtk.Template(resource_path="/io/github/flattool/Warehouse/packages_page/app_row.ui")
@Gtk.Template(resource_path="/io/github/flattool/Warehouse/gtk/app_row.ui")
class AppRow(Adw.ActionRow):
__gtype_name__ = 'AppRow'
gtc = Gtk.Template.Child
@@ -18,7 +18,8 @@ class AppRow(Adw.ActionRow):
self.image.set_from_file(self.package.icon_path)
def gesture_handler(self, *args):
self.on_long_press(self)
if self.on_long_press:
self.on_long_press(self)
def __init__(self, package, on_long_press=None, **kwargs):
super().__init__(**kwargs)
@@ -38,4 +39,4 @@ class AppRow(Adw.ActionRow):
# Connections
self.rclick_gesture.connect("released", self.gesture_handler)
self.long_press_gesture.connect("pressed", self.gesture_handler)
self.long_press_gesture.connect("pressed", self.gesture_handler)

View File

@@ -4,7 +4,7 @@ gnome = import('gnome')
blueprints = custom_target('blueprints',
input: files(
'packages_page/app_row.blp',
'gtk/app_row.blp',
'gtk/help-overlay.blp',
'gtk/loading_status.blp',
'main_window/window.blp',
@@ -73,7 +73,7 @@ warehouse_sources = [
'gtk/sidebar_button.py',
'gtk/loading_status.py',
'main_window/window.py',
'packages_page/app_row.py',
'gtk/app_row.py',
'packages_page/uninstall_dialog.py',
'packages_page/packages_page.py',
'packages_page/filters_page.py',

View File

@@ -61,5 +61,4 @@ class SnapshotBox(Gtk.Box):
self.json_path = f"{snapshots_path}{folder.replace('tar.zst', 'json')}"
self.rename_button.connect("clicked", self.json_handler)
print(self.json_path)

View File

@@ -14,23 +14,13 @@ template $SnapshotPage : Adw.BreakpointBin {
}
}
// Adw.Breakpoint bp2 {
// condition ("max-width: 700")
// setters {
// header_bar.title-widget: null;
// switcher_bar.reveal: true;
// }
// }
Adw.ToastOverlay toast_overlay {
Adw.NavigationSplitView split_view {
sidebar-width-fraction: 0.5;
max-sidebar-width: 999999999;
sidebar:
Adw.NavigationPage sidebar_navpage {
title: _("Snapshots");
Adw.NavigationSplitView split_view {
sidebar-width-fraction: 0.5;
max-sidebar-width: 999999999;
sidebar:
Adw.NavigationPage sidebar_navpage {
title: _("Snapshots");
Adw.ToastOverlay toast_overlay {
Adw.ToolbarView sidebar_tbv {
[top]
Adw.HeaderBar header_bar {
@@ -41,6 +31,11 @@ template $SnapshotPage : Adw.BreakpointBin {
icon-name: "loupe-large-symbolic";
tooltip-text: _("Search Packages");
}
[start]
Button open_button {
icon-name: "folder-open-symbolic";
tooltip-text: _("Open Snapshots Folder");
}
[end]
Button new_button {
icon-name: "plus-large-symbolic";
@@ -63,9 +58,17 @@ template $SnapshotPage : Adw.BreakpointBin {
// ;
// }
Adw.StatusPage no_snapshots {
title: _("No Snapshots Found");
description: _("Warehouse cannot see the list of snapshots or you don't have any snapshots");
icon-name: "error-symbolic";
title: _("No Snapshots");
description: _("Create a Snapshot to save the state of any Flatpak application");
icon-name: "snapshots-alt-symbolic";
Button status_new_button {
styles ["suggested-action", "pill"]
halign: center;
Adw.ButtonContent {
icon-name: "plus-large-symbolic";
label: _("New Snapshot");
}
}
}
Adw.StatusPage no_results {
title: _("No Results Found");
@@ -133,7 +136,7 @@ template $SnapshotPage : Adw.BreakpointBin {
}
}
}
;
}
}
;
}
}

View File

@@ -41,6 +41,7 @@ class SnapshotPage(Adw.BreakpointBin):
no_snapshots = gtc()
no_results = gtc()
scrolled_window = gtc()
open_button = gtc()
# Referred to in the main window
# It is used to determine if a new page should be made or not
@@ -98,7 +99,6 @@ class SnapshotPage(Adw.BreakpointBin):
self.active_box.set_visible(True)
first_row = self.active_listbox.get_row_at_index(0)
self.active_listbox.select_row(first_row)
self.stack.set_visible_child(self.scrolled_window)
else:
self.active_box.set_visible(False)
@@ -125,7 +125,6 @@ class SnapshotPage(Adw.BreakpointBin):
self.list_page.set_snapshots(row.folder, row.get_title())
def start_loading(self):
# self.list_page.start_loading()
self.active_box.set_visible(True)
self.active_listbox.remove_all()
self.leftover_box.set_visible(True)
@@ -137,28 +136,19 @@ class SnapshotPage(Adw.BreakpointBin):
self.generate_active_list()
self.generate_leftover_list()
if (not self.active_box.get_visible()) and (not self.leftover_box.get_visible()):
self.stack.set_visible_child(self.no_snapshots)
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
GLib.idle_add(lambda *_: self.stack.set_visible_child(self.no_snapshots))
else:
GLib.idle_add(lambda *_: self.stack.set_visible_child(self.scrolled_window))
Gio.Task.new(None, None, callback).run_in_thread(self.sort_snapshots)
def open_snapshots_folder(self, button):
try:
Gio.AppInfo.launch_default_for_uri(f"file://{self.snapshots_path}", None)
self.toast_overlay.add_toast(Adw.Toast.new(_("Opened snapshots folder")))
except Exception as e:
self.toast_overlay.add_toast(ErrorToast(_("Could not open folder"), str(e)).toast)
def __init__(self, main_window, **kwargs):
super().__init__(**kwargs)
@@ -175,6 +165,7 @@ class SnapshotPage(Adw.BreakpointBin):
# Connections
self.active_listbox.connect("row-activated", self.active_select_handler)
self.leftover_listbox.connect("row-activated", self.leftover_select_handler)
self.open_button.connect("clicked", self.open_snapshots_folder)
# Apply
self.stack.add_child(self.loading_snapshots)

View File

@@ -17,6 +17,9 @@ class SnapshotsListPage(Adw.NavigationPage):
def thread(self, *args):
for snapshot in os.listdir(folder := f"{self.snapshots_path}{self.current_folder}/"):
if snapshot.endswith(".json"):
continue
row = SnapshotBox(snapshot, folder, self.toast_overlay)
self.snapshots_rows.append(row)
@@ -40,4 +43,4 @@ class SnapshotsListPage(Adw.NavigationPage):
super().__init__(**kwargs)
self.current_folder = None
self.snapshots_rows = []
self.snapshots_rows = []

View File

@@ -4,7 +4,7 @@
<file>../data/style.css</file>
<file preprocess="xml-stripblanks">gtk/help-overlay.ui</file>
<file preprocess="xml-stripblanks">gtk/loading_status.ui</file>
<file preprocess="xml-stripblanks">packages_page/app_row.ui</file>
<file preprocess="xml-stripblanks">gtk/app_row.ui</file>
<file preprocess="xml-stripblanks">main_window/window.ui</file>
<file preprocess="xml-stripblanks">packages_page/packages_page.ui</file>
<file preprocess="xml-stripblanks">packages_page/filters_page.ui</file>