Add a game counter to total games
This commit is contained in:
@@ -203,6 +203,7 @@ class PreferencesWindow(Adw.PreferencesWindow):
|
||||
self.file_chooser.select_folder(self.win, None, callback, callback_data)
|
||||
|
||||
def undo_remove_all(self, *_args):
|
||||
shared.win.get_application().state = shared.AppState.UNDO_REMOVE_ALL_GAMES
|
||||
for game in self.removed_games:
|
||||
game.removed = False
|
||||
game.save()
|
||||
@@ -210,8 +211,11 @@ class PreferencesWindow(Adw.PreferencesWindow):
|
||||
|
||||
self.removed_games = set()
|
||||
self.toast.dismiss()
|
||||
shared.win.get_application().state = shared.AppState.DEFAULT
|
||||
shared.win.create_source_rows()
|
||||
|
||||
def remove_all_games(self, *_args):
|
||||
shared.win.get_application().state = shared.AppState.REMOVE_ALL_GAMES
|
||||
for game in shared.store:
|
||||
if not game.removed:
|
||||
self.removed_games.add(game)
|
||||
@@ -223,6 +227,8 @@ class PreferencesWindow(Adw.PreferencesWindow):
|
||||
self.win.navigation_view.pop()
|
||||
|
||||
self.add_toast(self.toast)
|
||||
shared.win.get_application().state = shared.AppState.DEFAULT
|
||||
shared.win.create_source_rows()
|
||||
|
||||
def reset_app(self, *_args):
|
||||
rmtree(shared.data_dir / "cartridges", True)
|
||||
|
||||
@@ -28,6 +28,8 @@ class AppState(IntEnum):
|
||||
DEFAULT = auto()
|
||||
LOAD_FROM_DISK = auto()
|
||||
IMPORT = auto()
|
||||
REMOVE_ALL_GAMES = auto()
|
||||
UNDO_REMOVE_ALL_GAMES = auto()
|
||||
|
||||
|
||||
APP_ID = "@APP_ID@"
|
||||
|
||||
@@ -31,7 +31,9 @@ class CartridgesWindow(Adw.ApplicationWindow):
|
||||
navigation_view = Gtk.Template.Child()
|
||||
sidebar = Gtk.Template.Child()
|
||||
all_games_row_box = Gtk.Template.Child()
|
||||
all_games_no_label = Gtk.Template.Child()
|
||||
added_row_box = Gtk.Template.Child()
|
||||
added_games_no_label = Gtk.Template.Child()
|
||||
toast_overlay = Gtk.Template.Child()
|
||||
primary_menu_button = Gtk.Template.Child()
|
||||
show_sidebar_button = Gtk.Template.Child()
|
||||
@@ -89,6 +91,7 @@ class CartridgesWindow(Adw.ApplicationWindow):
|
||||
(count,) if (count := sum(removed)) != len(removed) else False
|
||||
) # Return a tuple because 0 == False and 1 == True
|
||||
|
||||
total_games_no = 0
|
||||
restored = False
|
||||
|
||||
selected_id = (
|
||||
@@ -102,9 +105,14 @@ class CartridgesWindow(Adw.ApplicationWindow):
|
||||
restored = True
|
||||
|
||||
if added_missing := (
|
||||
not shared.store.source_games.get("imported") or not get_removed("imported")
|
||||
not shared.store.source_games.get("imported")
|
||||
or not (removed := get_removed("imported"))
|
||||
):
|
||||
self.sidebar.select_row(self.all_games_row_box.get_parent())
|
||||
else:
|
||||
games_no = len(shared.store.source_games["imported"]) - removed[0]
|
||||
self.added_games_no_label.set_label(str(games_no))
|
||||
total_games_no += games_no
|
||||
self.added_row_box.get_parent().set_visible(not added_missing)
|
||||
|
||||
self.sidebar.get_row_at_index(2).set_visible(False)
|
||||
@@ -118,15 +126,14 @@ class CartridgesWindow(Adw.ApplicationWindow):
|
||||
if not (removed := get_removed(source_id)):
|
||||
continue
|
||||
|
||||
row = Gtk.Box()
|
||||
row = Gtk.Box(margin_top=12, margin_bottom=12)
|
||||
games_no = len(shared.store.source_games[source_id]) - removed[0]
|
||||
total_games_no += games_no
|
||||
|
||||
row.append(
|
||||
Gtk.Label(
|
||||
label=self.get_application().get_source_name(source_id),
|
||||
halign=Gtk.Align.START,
|
||||
margin_top=12,
|
||||
margin_bottom=12,
|
||||
margin_start=6,
|
||||
margin_end=6,
|
||||
)
|
||||
@@ -137,9 +144,7 @@ class CartridgesWindow(Adw.ApplicationWindow):
|
||||
label=games_no,
|
||||
hexpand=True,
|
||||
halign=Gtk.Align.END,
|
||||
margin_top=12,
|
||||
margin_bottom=12,
|
||||
margin_end=12,
|
||||
margin_end=6,
|
||||
)
|
||||
)
|
||||
|
||||
@@ -166,8 +171,10 @@ class CartridgesWindow(Adw.ApplicationWindow):
|
||||
|
||||
self.sidebar.get_row_at_index(2).set_visible(True)
|
||||
|
||||
if not restored:
|
||||
self.sidebar.select_row(self.all_games_row_box.get_parent())
|
||||
self.all_games_no_label.set_label(str(total_games_no))
|
||||
|
||||
if not restored:
|
||||
self.sidebar.select_row(self.all_games_row_box.get_parent())
|
||||
|
||||
def row_selected(self, _widget, row):
|
||||
if not row:
|
||||
|
||||
Reference in New Issue
Block a user