mirror of
https://github.com/morgan9e/warehouse
synced 2026-04-14 00:04:08 +09:00
Sync current work
This commit is contained in:
@@ -35,7 +35,7 @@ template $FiltersPage : Adw.NavigationPage {
|
||||
|
||||
Adw.PreferencesGroup remotes_group {
|
||||
title: _("Filter by Remotes");
|
||||
description: _("Showing packages from selected remotes");
|
||||
description: _("Show packages from selected remotes");
|
||||
header-suffix:
|
||||
Switch all_remotes_switch {
|
||||
valign: center;
|
||||
@@ -45,6 +45,7 @@ template $FiltersPage : Adw.NavigationPage {
|
||||
visible: bind all_remotes_switch.active inverted;
|
||||
[child]
|
||||
Box {
|
||||
spacing: 3;
|
||||
orientation: vertical;
|
||||
Label {
|
||||
margin-top: 7;
|
||||
@@ -78,6 +79,7 @@ template $FiltersPage : Adw.NavigationPage {
|
||||
visible: bind all_runtimes_switch.active inverted;
|
||||
[child]
|
||||
Box {
|
||||
spacing: 3;
|
||||
orientation: vertical;
|
||||
Label {
|
||||
margin-top: 7;
|
||||
|
||||
@@ -12,21 +12,21 @@ template $SnapshotBox : Gtk.Box {
|
||||
Box {
|
||||
orientation: vertical;
|
||||
Label title {
|
||||
label: "A Snapshot";
|
||||
label: _("No Name Set");
|
||||
wrap: true;
|
||||
justify: left;
|
||||
halign: start;
|
||||
styles ["title-4"]
|
||||
}
|
||||
Label date {
|
||||
label: "2024-04-03 4:30 PM";
|
||||
label: _("No date found");
|
||||
wrap: true;
|
||||
justify: left;
|
||||
halign: start;
|
||||
}
|
||||
}
|
||||
Label version {
|
||||
label: "Version: 45.3";
|
||||
label: _("No version found");
|
||||
wrap: true;
|
||||
justify: right;
|
||||
hexpand: true;
|
||||
@@ -38,27 +38,27 @@ template $SnapshotBox : Gtk.Box {
|
||||
margin-bottom: 6;
|
||||
spacing: 3;
|
||||
homogeneous: true;
|
||||
Button {
|
||||
Button apply_button {
|
||||
Adw.ButtonContent {
|
||||
label: "Apply";
|
||||
label: _("Apply");
|
||||
icon-name: "check-plain-symbolic";
|
||||
can-shrink: true;
|
||||
}
|
||||
hexpand: true;
|
||||
styles ["flat"]
|
||||
}
|
||||
Button {
|
||||
Button rename_button {
|
||||
Adw.ButtonContent {
|
||||
label: "Rename";
|
||||
label: _("Rename");
|
||||
icon-name: "dot-symbolic";
|
||||
can-shrink: true;
|
||||
}
|
||||
hexpand: true;
|
||||
styles ["flat"]
|
||||
}
|
||||
Button {
|
||||
Button trash_button {
|
||||
Adw.ButtonContent {
|
||||
label: "Trash";
|
||||
label: _("Trash");
|
||||
icon-name: "user-trash-symbolic";
|
||||
can-shrink: true;
|
||||
}
|
||||
@@ -66,4 +66,6 @@ template $SnapshotBox : Gtk.Box {
|
||||
styles ["flat"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Adw.AlertDialog name_dialog {}
|
||||
@@ -1,13 +1,65 @@
|
||||
from gi.repository import Adw, Gtk, GLib, Gio
|
||||
from .host_info import HostInfo
|
||||
from .error_toast import ErrorToast
|
||||
import os
|
||||
import os, json
|
||||
|
||||
@Gtk.Template(resource_path="/io/github/flattool/Warehouse/snapshot_page/snapshot_box.ui")
|
||||
class SnapshotBox(Gtk.Box):
|
||||
__gtype_name__ = "SnapshotBox"
|
||||
gtc = Gtk.Template.Child
|
||||
|
||||
def __init__(self, folder, **kwargs):
|
||||
title = gtc()
|
||||
date = gtc()
|
||||
version = gtc()
|
||||
apply_button = gtc()
|
||||
rename_button = gtc()
|
||||
trash_button = gtc()
|
||||
|
||||
def create_json(self):
|
||||
try:
|
||||
data = {
|
||||
'snapshot_version': 1,
|
||||
'name': '',
|
||||
}
|
||||
with open(self.json_path, 'w') as file:
|
||||
json.dump(data, file, indent=4)
|
||||
return None
|
||||
except Exception as e:
|
||||
self.toast_overlay.add_toast(ErrorToast(_("Could not write data"), str(e)).toast)
|
||||
|
||||
def update_json(self):
|
||||
try:
|
||||
with open(self.json_path, 'r+') as file:
|
||||
data = json.load(file)
|
||||
data['name'] = "updated"
|
||||
file.seek(0)
|
||||
json.dump(data, file, indent=4)
|
||||
file.truncate()
|
||||
|
||||
except Exception as e:
|
||||
self.toast_overlay.add_toast(ErrorToast(_("Could not write data"), str(e)).toast)
|
||||
|
||||
def json_handler(self, *args):
|
||||
if not os.path.exists(self.json_path):
|
||||
self.create_json()
|
||||
|
||||
self.update_json()
|
||||
|
||||
def __init__(self, folder, snapshots_path, toast_overlay, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
|
||||
print(folder)
|
||||
self.toast_overlay = toast_overlay
|
||||
|
||||
split_folder = folder.split('_')
|
||||
if len(split_folder) < 2:
|
||||
return
|
||||
|
||||
date_data = GLib.DateTime.new_from_unix_local(int(split_folder[0])).format("%x %X")
|
||||
self.date.set_label(date_data)
|
||||
self.version.set_label(split_folder[1].replace(".tar.zst", ""))
|
||||
|
||||
self.json_path = f"{snapshots_path}{folder.replace('tar.zst', 'json')}"
|
||||
|
||||
self.rename_button.connect("clicked", self.json_handler)
|
||||
print(self.json_path)
|
||||
|
||||
@@ -55,60 +55,81 @@ template $SnapshotPage : Adw.BreakpointBin {
|
||||
tooltip-text: _("Select Packages");
|
||||
}
|
||||
}
|
||||
ScrolledWindow scrolled_window {
|
||||
Box {
|
||||
orientation: vertical;
|
||||
|
||||
Box active_box {
|
||||
Stack stack {
|
||||
Adw.StatusPage loading_snapshots {
|
||||
title: _("Loading Snapshot");
|
||||
description: _("This should only take a moment");
|
||||
child:
|
||||
Spinner {
|
||||
spinning: true;
|
||||
}
|
||||
;
|
||||
}
|
||||
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";
|
||||
}
|
||||
Adw.StatusPage no_results {
|
||||
title: _("No Results Found");
|
||||
description: _("Try a different search");
|
||||
icon-name: "system-search-symbolic";
|
||||
}
|
||||
ScrolledWindow scrolled_window {
|
||||
Box {
|
||||
orientation: vertical;
|
||||
|
||||
Label {
|
||||
label: _("Active Snapshots");
|
||||
halign: start;
|
||||
styles ["heading"]
|
||||
margin-top: 3;
|
||||
margin-bottom: 6;
|
||||
margin-start: 12;
|
||||
margin-end: 12;
|
||||
wrap: true;
|
||||
Box active_box {
|
||||
orientation: vertical;
|
||||
|
||||
Label {
|
||||
label: _("Active Snapshots");
|
||||
halign: start;
|
||||
styles ["heading"]
|
||||
margin-top: 3;
|
||||
margin-bottom: 6;
|
||||
margin-start: 12;
|
||||
margin-end: 12;
|
||||
wrap: true;
|
||||
}
|
||||
Label {
|
||||
label: _("Snapshots of installed apps");
|
||||
halign: start;
|
||||
styles ["dim-label"]
|
||||
margin-start: 12;
|
||||
margin-end: 12;
|
||||
wrap: true;
|
||||
}
|
||||
ListBox active_listbox {
|
||||
styles ["navigation-sidebar"]
|
||||
valign: start;
|
||||
}
|
||||
}
|
||||
Label {
|
||||
label: _("Snapshots of installed apps");
|
||||
halign: start;
|
||||
styles ["dim-label"]
|
||||
margin-start: 12;
|
||||
margin-end: 12;
|
||||
wrap: true;
|
||||
}
|
||||
ListBox active_listbox {
|
||||
styles ["navigation-sidebar"]
|
||||
valign: start;
|
||||
}
|
||||
}
|
||||
Box leftover_box {
|
||||
orientation: vertical;
|
||||
|
||||
Label {
|
||||
label: _("Leftover Snapshots");
|
||||
halign: start;
|
||||
styles ["heading"]
|
||||
margin-top: 3;
|
||||
margin-bottom: 6;
|
||||
margin-start: 12;
|
||||
margin-end: 12;
|
||||
wrap: true;
|
||||
}
|
||||
Label {
|
||||
label: _("Snapshots of apps that are no longer installed");
|
||||
halign: start;
|
||||
styles ["dim-label"]
|
||||
margin-start: 12;
|
||||
margin-end: 12;
|
||||
wrap: true;
|
||||
}
|
||||
ListBox leftover_listbox {
|
||||
styles ["navigation-sidebar"]
|
||||
valign: start;
|
||||
Box leftover_box {
|
||||
orientation: vertical;
|
||||
|
||||
Label {
|
||||
label: _("Leftover Snapshots");
|
||||
halign: start;
|
||||
styles ["heading"]
|
||||
margin-top: 3;
|
||||
margin-bottom: 6;
|
||||
margin-start: 12;
|
||||
margin-end: 12;
|
||||
wrap: true;
|
||||
}
|
||||
Label {
|
||||
label: _("Snapshots of apps that are no longer installed");
|
||||
halign: start;
|
||||
styles ["dim-label"]
|
||||
margin-start: 12;
|
||||
margin-end: 12;
|
||||
wrap: true;
|
||||
}
|
||||
ListBox leftover_listbox {
|
||||
styles ["navigation-sidebar"]
|
||||
valign: start;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,11 +30,17 @@ class SnapshotPage(Adw.BreakpointBin):
|
||||
gtc = Gtk.Template.Child
|
||||
|
||||
sidebar_button = gtc()
|
||||
toast_overlay = gtc()
|
||||
active_box = gtc()
|
||||
active_listbox = gtc()
|
||||
leftover_box = gtc()
|
||||
leftover_listbox = gtc()
|
||||
split_view = gtc()
|
||||
stack = gtc()
|
||||
loading_snapshots = gtc()
|
||||
no_snapshots = gtc()
|
||||
no_results = gtc()
|
||||
scrolled_window = gtc()
|
||||
|
||||
# Referred to in the main window
|
||||
# It is used to determine if a new page should be made or not
|
||||
@@ -46,6 +52,13 @@ class SnapshotPage(Adw.BreakpointBin):
|
||||
self.active_snapshot_paks.clear()
|
||||
self.leftover_snapshots.clear()
|
||||
bad_folders = []
|
||||
|
||||
if not os.path.exists(self.snapshots_path):
|
||||
try:
|
||||
os.makedirs(self.snapshots_path)
|
||||
except Exception as e:
|
||||
self.toast_overlay.add_toast(ErrorToast(_("Could not load Snapshots"), str(e)).toast)
|
||||
return
|
||||
|
||||
for folder in os.listdir(self.snapshots_path):
|
||||
if folder.count('.') < 2 or ' ' in folder:
|
||||
@@ -83,20 +96,21 @@ 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)
|
||||
|
||||
def generate_leftover_list(self):
|
||||
for folder in self.leftover_snapshots:
|
||||
row = LeftoverSnapshotRow(folder)
|
||||
|
||||
self.leftover_listbox.append(row)
|
||||
|
||||
if len(self.leftover_snapshots) > 0:
|
||||
self.leftover_box.set_visible(True)
|
||||
if len(self.active_snapshot_paks) == 0:
|
||||
first_row = self.leftover_box.get_row_at_index(0)
|
||||
self.leftover_box.select_row(first_row)
|
||||
self.stack.set_visible_child(self.scrolled_window)
|
||||
first_row = self.leftover_listbox.get_row_at_index(0)
|
||||
self.leftover_listbox.select_row(first_row)
|
||||
else:
|
||||
self.leftover_box.set_visible(False)
|
||||
|
||||
@@ -114,12 +128,32 @@ class SnapshotPage(Adw.BreakpointBin):
|
||||
self.active_listbox.remove_all()
|
||||
self.leftover_box.set_visible(True)
|
||||
self.leftover_listbox.remove_all()
|
||||
self.stack.set_visible_child(self.loading_snapshots)
|
||||
|
||||
def end_loading(self):
|
||||
def callback(*args):
|
||||
self.generate_active_list()
|
||||
self.generate_leftover_list()
|
||||
# self.list_page.end_loading()
|
||||
if (not self.active_box.get_visible()) and (not self.leftover_box.get_visible()):
|
||||
self.stack.set_visible_child(self.no_snapshots)
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
|
||||
Gio.Task.new(None, None, callback).run_in_thread(self.sort_snapshots)
|
||||
|
||||
@@ -144,4 +178,4 @@ class SnapshotPage(Adw.BreakpointBin):
|
||||
|
||||
# Apply
|
||||
self.sidebar_button.set_active(ms.get_show_sidebar())
|
||||
self.split_view.set_content(self.list_page)
|
||||
self.split_view.set_content(self.list_page)##
|
||||
@@ -3,7 +3,7 @@ using Adw 1;
|
||||
|
||||
template $SnapshotsListPage : Adw.NavigationPage {
|
||||
title: _("Snapshots List");
|
||||
Adw.ToastOverlay {
|
||||
Adw.ToastOverlay toast_overlay {
|
||||
Adw.ToolbarView {
|
||||
[top]
|
||||
Adw.HeaderBar {
|
||||
|
||||
@@ -11,12 +11,13 @@ class SnapshotsListPage(Adw.NavigationPage):
|
||||
gtc = Gtk.Template.Child
|
||||
|
||||
listbox = gtc()
|
||||
toast_overlay = gtc()
|
||||
|
||||
snapshots_path = f"{HostInfo.home}/.var/app/io.github.flattool.Warehouse/data/Snapshots/"
|
||||
|
||||
def thread(self, *args):
|
||||
for snapshot in os.listdir(f"{self.snapshots_path}{self.current_folder}"):
|
||||
row = SnapshotBox(snapshot)
|
||||
for snapshot in os.listdir(folder := f"{self.snapshots_path}{self.current_folder}/"):
|
||||
row = SnapshotBox(snapshot, folder, self.toast_overlay)
|
||||
self.snapshots_rows.append(row)
|
||||
|
||||
def callback(self, *args):
|
||||
@@ -25,6 +26,9 @@ class SnapshotsListPage(Adw.NavigationPage):
|
||||
self.listbox.get_row_at_index(i).set_activatable(False)
|
||||
|
||||
def set_snapshots(self, folder, title):
|
||||
if self.current_folder == folder:
|
||||
return
|
||||
|
||||
self.current_folder = folder
|
||||
self.set_title(_("{} Snapshots").format(title))
|
||||
self.snapshots_rows.clear()
|
||||
|
||||
Reference in New Issue
Block a user