Add option to remove all games
This commit is contained in:
@@ -42,7 +42,25 @@ template PreferencesWindow : Adw.PreferencesWindow {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Adw.PreferencesGroup danger_zone_group {
|
||||
title: _("Danger Zone");
|
||||
|
||||
Adw.ActionRow {
|
||||
title: _("Remove All Games");
|
||||
|
||||
Button remove_all_games_button {
|
||||
label: _("Remove");
|
||||
valign: center;
|
||||
|
||||
styles [
|
||||
"destructive-action",
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Adw.PreferencesPage import_page {
|
||||
name: "import";
|
||||
title: _("Import");
|
||||
|
||||
@@ -192,8 +192,8 @@ class CartridgesApplication(Adw.Application):
|
||||
if self.win.stack.get_visible_child() == self.win.overview:
|
||||
self.win.on_go_back_action(None, None)
|
||||
|
||||
# The variable is the title of the game
|
||||
title = self.win.games[game_id].name
|
||||
# The variable is the title of the game
|
||||
toast = Adw.Toast.new(_(f"{title} removed"))
|
||||
toast.set_button_label(_("Undo"))
|
||||
toast.connect("button-clicked", self.win.on_undo_remove_action, game_id)
|
||||
|
||||
@@ -22,6 +22,8 @@ import os
|
||||
from gi.repository import Adw, Gio, GLib, Gtk
|
||||
|
||||
from .create_dialog import create_dialog
|
||||
from .get_games import get_games
|
||||
from .save_game import save_game
|
||||
|
||||
|
||||
class ImportPreferences:
|
||||
@@ -88,6 +90,7 @@ class PreferencesWindow(Adw.PreferencesWindow):
|
||||
exit_after_launch_switch = Gtk.Template.Child()
|
||||
cover_launches_game_switch = Gtk.Template.Child()
|
||||
high_quality_images_switch = Gtk.Template.Child()
|
||||
remove_all_games_button = Gtk.Template.Child()
|
||||
|
||||
steam_expander_row = Gtk.Template.Child()
|
||||
steam_file_chooser_button = Gtk.Template.Child()
|
||||
@@ -111,6 +114,20 @@ class PreferencesWindow(Adw.PreferencesWindow):
|
||||
self.file_chooser = Gtk.FileDialog()
|
||||
self.set_transient_for(parent_widget)
|
||||
|
||||
self.toast = Adw.Toast.new(_("All games removed"))
|
||||
self.toast.set_button_label(_("Undo"))
|
||||
self.toast.connect("button-clicked", self.undo_remove_all, None)
|
||||
self.toast.set_priority(Adw.ToastPriority.HIGH)
|
||||
shortcut_controller = Gtk.ShortcutController()
|
||||
shortcut_controller.add_shortcut(
|
||||
Gtk.Shortcut.new(
|
||||
Gtk.ShortcutTrigger.parse_string("<primary>z"),
|
||||
Gtk.CallbackAction.new(self.undo_remove_all),
|
||||
)
|
||||
)
|
||||
self.add_controller(shortcut_controller)
|
||||
self.removed_games = []
|
||||
|
||||
# General
|
||||
self.schema.bind(
|
||||
"exit-after-launch",
|
||||
@@ -131,6 +148,8 @@ class PreferencesWindow(Adw.PreferencesWindow):
|
||||
Gio.SettingsBindFlags.DEFAULT,
|
||||
)
|
||||
|
||||
self.remove_all_games_button.connect("clicked", self.remove_all_games)
|
||||
|
||||
# Steam
|
||||
ImportPreferences(
|
||||
self,
|
||||
@@ -219,3 +238,26 @@ class PreferencesWindow(Adw.PreferencesWindow):
|
||||
|
||||
def choose_folder(self, _widget, function):
|
||||
self.file_chooser.select_folder(self.parent_widget, None, function, None)
|
||||
|
||||
def undo_remove_all(self, _widget, _unused):
|
||||
for game_id in self.removed_games:
|
||||
data = get_games([game_id])[game_id]
|
||||
if "removed" in data.keys():
|
||||
data.pop("removed")
|
||||
save_game(data)
|
||||
self.parent_widget.update_games(self.removed_games)
|
||||
self.removed_games = []
|
||||
self.toast.dismiss()
|
||||
|
||||
def remove_all_games(self, _widget):
|
||||
for game in get_games().values():
|
||||
if not "removed" in game.keys():
|
||||
self.removed_games.append(game["game_id"])
|
||||
game["removed"] = True
|
||||
save_game(game)
|
||||
|
||||
self.parent_widget.update_games(self.parent_widget.games)
|
||||
if self.parent_widget.stack.get_visible_child() == self.parent_widget.overview:
|
||||
self.parent_widget.on_go_back_action(None, None)
|
||||
|
||||
self.add_toast(self.toast)
|
||||
|
||||
@@ -17,15 +17,15 @@
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from gi.repository import Adw, Gtk
|
||||
from gi.repository import Adw
|
||||
|
||||
|
||||
def create_dialog(parent_widget, heading, body, extra_option=None, extra_label=None):
|
||||
dialog = Adw.MessageDialog.new(parent_widget, _(heading), body)
|
||||
dialog = Adw.MessageDialog.new(parent_widget, heading, body)
|
||||
dialog.add_response("dismiss", _("Dismiss"))
|
||||
|
||||
if extra_option:
|
||||
dialog.add_response(extra_option, _(extra_label))
|
||||
|
||||
Gtk.Window.present(dialog)
|
||||
dialog.present()
|
||||
return dialog
|
||||
|
||||
@@ -76,7 +76,7 @@ class Importer:
|
||||
create_dialog(
|
||||
self.parent_widget,
|
||||
_("No Games Found"),
|
||||
_("No new games were found on your device."),
|
||||
_("No new games were found on your system."),
|
||||
"open_preferences",
|
||||
_("Preferences"),
|
||||
).connect("response", response)
|
||||
|
||||
Reference in New Issue
Block a user