[gnome-games] ui: Split ApplicationWindow.run_game_with_cancellable()
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games] ui: Split ApplicationWindow.run_game_with_cancellable()
- Date: Wed, 17 Aug 2016 18:56:20 +0000 (UTC)
commit f60edd7dafdb8ae4b6fe537691d35b0a7b5e9b9c
Author: Adrien Plazas <kekun plazas laposte net>
Date: Wed Aug 17 01:17:56 2016 +0200
ui: Split ApplicationWindow.run_game_with_cancellable()
This make it more readable and hence maintainable.
https://bugzilla.gnome.org/show_bug.cgi?id=770004
src/ui/application-window.vala | 115 +++++++++++++++++++++------------------
1 files changed, 62 insertions(+), 53 deletions(-)
---
diff --git a/src/ui/application-window.vala b/src/ui/application-window.vala
index 4b0f514..8547274 100644
--- a/src/ui/application-window.vala
+++ b/src/ui/application-window.vala
@@ -178,92 +178,101 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
}
private void run_game_with_cancellable (Game game, Cancellable cancellable) {
- ui_state = UiState.DISPLAY;
display_header_bar.game_title = game.name;
display_box.header_bar.game_title = game.name;
+ ui_state = UiState.DISPLAY;
+
+ var runner = try_get_runner (game);
+ if (runner == null)
+ return;
+ display_header_bar.can_fullscreen = runner.can_fullscreen;
+ display_box.header_bar.can_fullscreen = runner.can_fullscreen;
+ display_box.runner = runner;
+
+ bool resume = false;
+ if (runner.can_resume)
+ resume = prompt_resume_with_cancellable (cancellable);
+
+ if (!try_run_with_cancellable (runner, resume, cancellable))
+ prompt_resume_fail_with_cancellable (runner, cancellable);
+ }
+
+ private Runner? try_get_runner (Game game) {
try {
- display_box.runner = get_runner_for_game (game);
- display_header_bar.can_fullscreen = display_box.runner.can_fullscreen;
- display_box.header_bar.can_fullscreen = display_box.runner.can_fullscreen;
+ return get_runner_for_game (game);
}
catch (Error e) {
- display_box.runner = null;
- display_header_bar.can_fullscreen = false;
- display_box.header_bar.can_fullscreen = false;
-
- warning (e.message);
+ warning ("%s\n", e.message);
display_box.display_running_game_failed (e, game);
- return;
+ return null;
}
+ }
- var resume = false;
-
- if (display_box.runner.can_resume) {
- var dialog = new ResumeDialog ();
- dialog.set_transient_for (this);
-
- cancellable.cancelled.connect (() => {
- dialog.destroy ();
- });
+ private bool prompt_resume_with_cancellable (Cancellable cancellable) {
+ var dialog = new ResumeDialog ();
+ dialog.set_transient_for (this);
- var response = dialog.run ();
+ cancellable.cancelled.connect (() => {
dialog.destroy ();
+ });
- if (cancellable.is_cancelled ())
- response = Gtk.ResponseType.CANCEL;
+ var response = dialog.run ();
+ dialog.destroy ();
- switch (response) {
- case Gtk.ResponseType.CANCEL:
- resume = false;
+ if (cancellable.is_cancelled ())
+ response = Gtk.ResponseType.CANCEL;
- break;
- case Gtk.ResponseType.ACCEPT:
- default:
- resume = true;
+ if (response == Gtk.ResponseType.CANCEL)
+ return false;
- break;
- }
- }
+ return true;
+ }
+ private bool try_run_with_cancellable (Runner runner, bool resume, Cancellable cancellable) {
try {
if (resume)
display_box.runner.resume ();
else
- display_box.runner.start ();
+ runner.start ();
+
+ return true;
}
catch (Error e) {
- warning (@"$(e.message)\n");
+ warning (e.message);
- var dialog = new ResumeFailedDialog ();
- dialog.set_transient_for (this);
+ return false;
+ }
+ }
- cancellable.cancelled.connect (() => {
- dialog.destroy ();
- });
+ private void prompt_resume_fail_with_cancellable (Runner runner, Cancellable cancellable) {
+ var dialog = new ResumeFailedDialog ();
+ dialog.set_transient_for (this);
- var response = dialog.run ();
+ cancellable.cancelled.connect (() => {
dialog.destroy ();
+ });
- if (cancellable.is_cancelled ())
- response = Gtk.ResponseType.CANCEL;
-
- switch (response) {
- case Gtk.ResponseType.CANCEL:
- display_box.runner = null;
- ui_state = UiState.COLLECTION;
+ var response = dialog.run ();
+ dialog.destroy ();
- return;
- case Gtk.ResponseType.ACCEPT:
- default:
- display_box.runner.start ();
+ if (cancellable.is_cancelled ())
+ response = Gtk.ResponseType.CANCEL;
- break;
- }
+ if (response == Gtk.ResponseType.CANCEL) {
+ display_box.runner = null;
+ ui_state = UiState.COLLECTION;
return;
}
+
+ try {
+ runner.start ();
+ }
+ catch (Error e) {
+ warning (e.message);
+ }
}
public bool quit_game_with_cancellable (Cancellable cancellable) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]