Add a game counter to total games
This commit is contained in:
@@ -93,7 +93,6 @@ template $CartridgesWindow : Adw.ApplicationWindow {
|
|||||||
margin-top: 12;
|
margin-top: 12;
|
||||||
margin-bottom: 12;
|
margin-bottom: 12;
|
||||||
margin-start: 6;
|
margin-start: 6;
|
||||||
margin-end: 6;
|
|
||||||
spacing: 12;
|
spacing: 12;
|
||||||
|
|
||||||
Image {
|
Image {
|
||||||
@@ -102,13 +101,20 @@ template $CartridgesWindow : Adw.ApplicationWindow {
|
|||||||
Label {
|
Label {
|
||||||
halign: start;
|
halign: start;
|
||||||
label: _("All Games");
|
label: _("All Games");
|
||||||
|
margin-end: 6;
|
||||||
|
}
|
||||||
|
Label all_games_no_label {
|
||||||
|
hexpand: true;
|
||||||
|
halign: end;
|
||||||
|
margin-end: 6;
|
||||||
|
|
||||||
|
styles ["dim-label"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Box added_row_box {
|
Box added_row_box {
|
||||||
margin-top: 12;
|
margin-top: 12;
|
||||||
margin-bottom: 12;
|
margin-bottom: 12;
|
||||||
margin-start: 6;
|
margin-start: 6;
|
||||||
margin-end: 6;
|
|
||||||
spacing: 12;
|
spacing: 12;
|
||||||
|
|
||||||
Image {
|
Image {
|
||||||
@@ -117,6 +123,14 @@ template $CartridgesWindow : Adw.ApplicationWindow {
|
|||||||
Label {
|
Label {
|
||||||
halign: start;
|
halign: start;
|
||||||
label: _("Added");
|
label: _("Added");
|
||||||
|
margin-end: 6;
|
||||||
|
}
|
||||||
|
Label added_games_no_label {
|
||||||
|
hexpand: true;
|
||||||
|
halign: end;
|
||||||
|
margin-end: 6;
|
||||||
|
|
||||||
|
styles ["dim-label"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ListBoxRow {
|
ListBoxRow {
|
||||||
|
|||||||
@@ -203,6 +203,7 @@ class PreferencesWindow(Adw.PreferencesWindow):
|
|||||||
self.file_chooser.select_folder(self.win, None, callback, callback_data)
|
self.file_chooser.select_folder(self.win, None, callback, callback_data)
|
||||||
|
|
||||||
def undo_remove_all(self, *_args):
|
def undo_remove_all(self, *_args):
|
||||||
|
shared.win.get_application().state = shared.AppState.UNDO_REMOVE_ALL_GAMES
|
||||||
for game in self.removed_games:
|
for game in self.removed_games:
|
||||||
game.removed = False
|
game.removed = False
|
||||||
game.save()
|
game.save()
|
||||||
@@ -210,8 +211,11 @@ class PreferencesWindow(Adw.PreferencesWindow):
|
|||||||
|
|
||||||
self.removed_games = set()
|
self.removed_games = set()
|
||||||
self.toast.dismiss()
|
self.toast.dismiss()
|
||||||
|
shared.win.get_application().state = shared.AppState.DEFAULT
|
||||||
|
shared.win.create_source_rows()
|
||||||
|
|
||||||
def remove_all_games(self, *_args):
|
def remove_all_games(self, *_args):
|
||||||
|
shared.win.get_application().state = shared.AppState.REMOVE_ALL_GAMES
|
||||||
for game in shared.store:
|
for game in shared.store:
|
||||||
if not game.removed:
|
if not game.removed:
|
||||||
self.removed_games.add(game)
|
self.removed_games.add(game)
|
||||||
@@ -223,6 +227,8 @@ class PreferencesWindow(Adw.PreferencesWindow):
|
|||||||
self.win.navigation_view.pop()
|
self.win.navigation_view.pop()
|
||||||
|
|
||||||
self.add_toast(self.toast)
|
self.add_toast(self.toast)
|
||||||
|
shared.win.get_application().state = shared.AppState.DEFAULT
|
||||||
|
shared.win.create_source_rows()
|
||||||
|
|
||||||
def reset_app(self, *_args):
|
def reset_app(self, *_args):
|
||||||
rmtree(shared.data_dir / "cartridges", True)
|
rmtree(shared.data_dir / "cartridges", True)
|
||||||
|
|||||||
@@ -28,6 +28,8 @@ class AppState(IntEnum):
|
|||||||
DEFAULT = auto()
|
DEFAULT = auto()
|
||||||
LOAD_FROM_DISK = auto()
|
LOAD_FROM_DISK = auto()
|
||||||
IMPORT = auto()
|
IMPORT = auto()
|
||||||
|
REMOVE_ALL_GAMES = auto()
|
||||||
|
UNDO_REMOVE_ALL_GAMES = auto()
|
||||||
|
|
||||||
|
|
||||||
APP_ID = "@APP_ID@"
|
APP_ID = "@APP_ID@"
|
||||||
|
|||||||
@@ -31,7 +31,9 @@ class CartridgesWindow(Adw.ApplicationWindow):
|
|||||||
navigation_view = Gtk.Template.Child()
|
navigation_view = Gtk.Template.Child()
|
||||||
sidebar = Gtk.Template.Child()
|
sidebar = Gtk.Template.Child()
|
||||||
all_games_row_box = Gtk.Template.Child()
|
all_games_row_box = Gtk.Template.Child()
|
||||||
|
all_games_no_label = Gtk.Template.Child()
|
||||||
added_row_box = Gtk.Template.Child()
|
added_row_box = Gtk.Template.Child()
|
||||||
|
added_games_no_label = Gtk.Template.Child()
|
||||||
toast_overlay = Gtk.Template.Child()
|
toast_overlay = Gtk.Template.Child()
|
||||||
primary_menu_button = Gtk.Template.Child()
|
primary_menu_button = Gtk.Template.Child()
|
||||||
show_sidebar_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
|
(count,) if (count := sum(removed)) != len(removed) else False
|
||||||
) # Return a tuple because 0 == False and 1 == True
|
) # Return a tuple because 0 == False and 1 == True
|
||||||
|
|
||||||
|
total_games_no = 0
|
||||||
restored = False
|
restored = False
|
||||||
|
|
||||||
selected_id = (
|
selected_id = (
|
||||||
@@ -102,9 +105,14 @@ class CartridgesWindow(Adw.ApplicationWindow):
|
|||||||
restored = True
|
restored = True
|
||||||
|
|
||||||
if added_missing := (
|
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())
|
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.added_row_box.get_parent().set_visible(not added_missing)
|
||||||
|
|
||||||
self.sidebar.get_row_at_index(2).set_visible(False)
|
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)):
|
if not (removed := get_removed(source_id)):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
row = Gtk.Box()
|
row = Gtk.Box(margin_top=12, margin_bottom=12)
|
||||||
games_no = len(shared.store.source_games[source_id]) - removed[0]
|
games_no = len(shared.store.source_games[source_id]) - removed[0]
|
||||||
|
total_games_no += games_no
|
||||||
|
|
||||||
row.append(
|
row.append(
|
||||||
Gtk.Label(
|
Gtk.Label(
|
||||||
label=self.get_application().get_source_name(source_id),
|
label=self.get_application().get_source_name(source_id),
|
||||||
halign=Gtk.Align.START,
|
halign=Gtk.Align.START,
|
||||||
margin_top=12,
|
|
||||||
margin_bottom=12,
|
|
||||||
margin_start=6,
|
margin_start=6,
|
||||||
margin_end=6,
|
margin_end=6,
|
||||||
)
|
)
|
||||||
@@ -137,9 +144,7 @@ class CartridgesWindow(Adw.ApplicationWindow):
|
|||||||
label=games_no,
|
label=games_no,
|
||||||
hexpand=True,
|
hexpand=True,
|
||||||
halign=Gtk.Align.END,
|
halign=Gtk.Align.END,
|
||||||
margin_top=12,
|
margin_end=6,
|
||||||
margin_bottom=12,
|
|
||||||
margin_end=12,
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -166,8 +171,10 @@ class CartridgesWindow(Adw.ApplicationWindow):
|
|||||||
|
|
||||||
self.sidebar.get_row_at_index(2).set_visible(True)
|
self.sidebar.get_row_at_index(2).set_visible(True)
|
||||||
|
|
||||||
if not restored:
|
self.all_games_no_label.set_label(str(total_games_no))
|
||||||
self.sidebar.select_row(self.all_games_row_box.get_parent())
|
|
||||||
|
if not restored:
|
||||||
|
self.sidebar.select_row(self.all_games_row_box.get_parent())
|
||||||
|
|
||||||
def row_selected(self, _widget, row):
|
def row_selected(self, _widget, row):
|
||||||
if not row:
|
if not row:
|
||||||
|
|||||||
Reference in New Issue
Block a user