Merge pull request 'clan-vm-manager: make joining clan url more logical' (#687) from Mic92-wayland-update into main
All checks were successful
checks / test (push) Successful in 34s
checks-impure / test (push) Successful in 1m13s

This commit is contained in:
clan-bot 2024-01-04 16:18:29 +00:00
commit dbfbbf8670
3 changed files with 28 additions and 24 deletions

View File

@ -1,5 +1,6 @@
from collections import OrderedDict
from dataclasses import dataclass
from enum import StrEnum
from pathlib import Path
from typing import Any
@ -16,12 +17,17 @@ from gi.repository import GdkPixbuf
from clan_vm_manager import assets
class VMStatus(StrEnum):
RUNNING = "Running"
STOPPED = "Stopped"
@dataclass(frozen=True)
class VMBase:
icon: Path | GdkPixbuf.Pixbuf
name: str
url: str
status: bool
status: VMStatus
_flake_attr: str
@staticmethod
@ -31,7 +37,7 @@ class VMBase:
"Icon": GdkPixbuf.Pixbuf,
"Name": str,
"URL": str,
"Online": bool,
"Status": str,
"_FlakeAttr": str,
}
)
@ -46,7 +52,7 @@ class VMBase:
"Icon": str(self.icon),
"Name": self.name,
"URL": self.url,
"Online": self.status,
"Status": self.status,
"_FlakeAttr": self._flake_attr,
}
)
@ -75,9 +81,9 @@ def get_initial_vms(
if entry.flake.icon is not None:
icon = entry.flake.icon
status = False
status = VMStatus.STOPPED
if entry.flake.flake_url in running_vms:
status = True
status = VMStatus.RUNNING
base = VMBase(
icon=icon,

View File

@ -107,7 +107,7 @@ class ClanList(Gtk.Box):
on_start_clicked=self.on_start_clicked,
on_stop_clicked=self.on_stop_clicked,
on_edit_clicked=self.on_edit_clicked,
on_new_clicked=self.on_new_clicked,
on_join_clan_clicked=self.on_join_clan_clicked,
on_flash_clicked=self.on_flash_clicked,
)
self.toolbar.set_is_selected(self.selected_vm is not None)
@ -139,7 +139,7 @@ class ClanList(Gtk.Box):
self.cbs.stop_vm(self.selected_vm.url, self.selected_vm._flake_attr)
self.remount_list_view()
def on_new_clicked(self, widget: Gtk.Widget) -> None:
def on_join_clan_clicked(self, widget: Gtk.Widget) -> None:
self.show_join()
def on_edit_clicked(self, widget: Gtk.Widget) -> None:
@ -163,7 +163,7 @@ class ClanListToolbar(Gtk.Toolbar):
on_start_clicked: Callable[[Gtk.Widget], None],
on_stop_clicked: Callable[[Gtk.Widget], None],
on_edit_clicked: Callable[[Gtk.Widget], None],
on_new_clicked: Callable[[Gtk.Widget], None],
on_join_clan_clicked: Callable[[Gtk.Widget], None],
on_flash_clicked: Callable[[Gtk.Widget], None],
) -> None:
super().__init__(orientation=Gtk.Orientation.HORIZONTAL)
@ -180,9 +180,9 @@ class ClanListToolbar(Gtk.Toolbar):
self.edit_button.connect("clicked", on_edit_clicked)
self.add(self.edit_button)
self.new_button = Gtk.ToolButton(label="New")
self.new_button.connect("clicked", on_new_clicked)
self.add(self.new_button)
self.join_clan_button = Gtk.ToolButton(label="Join Clan")
self.join_clan_button.connect("clicked", on_join_clan_clicked)
self.add(self.join_clan_button)
self.flash_button = Gtk.ToolButton(label="Write to USB")
self.flash_button.connect("clicked", on_flash_clicked)

View File

@ -38,15 +38,14 @@ class Trust(Gtk.Box):
)
layout = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, expand=True)
layout.set_border_width(20)
upper = Gtk.Box(orientation="vertical")
upper.set_spacing(20)
layout.set_spacing(20)
if self.url is not None:
self.entry = Gtk.Label(label=str(self.url))
upper.add(Gtk.Label(label="Clan URL"))
layout.add(icon)
layout.add(Gtk.Label(label="Clan URL"))
else:
upper.add(Gtk.Label(label="Enter Clan URL"))
layout.add(Gtk.Label(label="Enter Clan URL"))
self.entry = Gtk.Entry()
# Autocomplete
# TODO: provide intelligent suggestions
@ -61,17 +60,16 @@ class Trust(Gtk.Box):
self.entry.set_completion(completion)
self.entry.set_placeholder_text("clan://")
upper.add(icon)
upper.add(self.entry)
layout.add(self.entry)
if self.url is None:
trust_button = Gtk.Button(label="Load cLAN-URL")
else:
trust_button = Gtk.Button(label="Trust cLAN-URL")
lower = Gtk.Box(orientation="vertical")
lower.set_spacing(20)
trust_button = Gtk.Button(label="Trust")
trust_button.connect("clicked", self.on_trust_clicked)
lower.add(trust_button)
layout.add(trust_button)
layout.pack_start(upper, expand=True, fill=True, padding=0)
layout.pack_end(lower, expand=True, fill=True, padding=0)
self.set_center_widget(layout)
def on_trust_clicked(self, widget: Gtk.Widget) -> None: