[gnome-games] ui: Handle failures when resuming



commit 77ee9bde7ef5095cc369ddf30acc7d3bfffa7b19
Author: Mathieu Bridon <bochecha daitauha fr>
Date:   Sun Aug 14 23:26:37 2016 +0200

    ui: Handle failures when resuming
    
    Sometimes, resuming the saved state of a game won't work, because the
    snapshot will be corrupted.
    
    When that happens, we now inform the user that something went wrong, and
    offer them to restart the game from the main menu.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=769938

 data/Makefile.am                   |    1 +
 data/org.gnome.Games.gresource.xml |    1 +
 data/ui/resume-failed-dialog.ui    |   43 ++++++++++++++++++++++++++++++++++++
 po/POTFILES.in                     |    1 +
 src/Makefile.am                    |    1 +
 src/ui/application-window.vala     |   26 +++++++++++++++++++++
 src/ui/resume-failed-dialog.vala   |    8 ++++++
 7 files changed, 81 insertions(+), 0 deletions(-)
---
diff --git a/data/Makefile.am b/data/Makefile.am
index c0e2342..edfe579 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -20,6 +20,7 @@ EXTRA_DIST = \
        ui/quit-dialog.ui \
        ui/remote-display.ui \
        ui/resume-dialog.ui \
+       ui/resume-failed-dialog.ui \
        $(NULL)
 
 CLEANFILES = \
diff --git a/data/org.gnome.Games.gresource.xml b/data/org.gnome.Games.gresource.xml
index 461cf37..01f0c5d 100644
--- a/data/org.gnome.Games.gresource.xml
+++ b/data/org.gnome.Games.gresource.xml
@@ -20,6 +20,7 @@
     <file preprocess="xml-stripblanks">ui/quit-dialog.ui</file>
     <file preprocess="xml-stripblanks">ui/remote-display.ui</file>
     <file preprocess="xml-stripblanks">ui/resume-dialog.ui</file>
+    <file preprocess="xml-stripblanks">ui/resume-failed-dialog.ui</file>
     <file preprocess="xml-stripblanks">ui/search-bar.ui</file>
   </gresource>
 </gresources>
diff --git a/data/ui/resume-failed-dialog.ui b/data/ui/resume-failed-dialog.ui
new file mode 100644
index 0000000..6862530
--- /dev/null
+++ b/data/ui/resume-failed-dialog.ui
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <requires lib="gtk+" version="3.16"/>
+  <template class="GamesResumeFailedDialog" parent="GtkDialog">
+    <property name="use-header-bar">1</property>
+    <property name="modal">True</property>
+    <property name="destroy-with-parent">True</property>
+    <child internal-child="vbox">"
+      <object class="GtkBox" id="vbox">
+    <child>
+      <object class="GtkLabel" id="label">
+        <property name="visible">True</property>
+        <property name="hexpand">True</property>
+        <property name="vexpand">True</property>
+        <property name="margin-top">12</property>
+        <property name="margin-bottom">12</property>
+        <property name="margin-start">21</property>
+        <property name="margin-end">21</property>
+        <property name="label" translatable="yes">Resuming failed. Do you want to to restart the 
game?</property>
+      </object>
+    </child>
+      </object>
+    </child>
+
+    <child type="action">
+      <object class="GtkButton" id="button_reset">
+        <property name="visible">True</property>
+        <property name="can-default">True</property>
+        <property name="label" translatable="yes">Reset</property>
+      </object>
+    </child>
+    <child type="action">
+      <object class="GtkButton" id="button_cancel">
+        <property name="visible">True</property>
+        <property name="label" translatable="yes">Cancel</property>
+      </object>
+    </child>
+    <action-widgets>
+      <action-widget response="accept" default="true">button_reset</action-widget>
+      <action-widget response="cancel">button_cancel</action-widget>
+    </action-widgets>
+  </template>
+</interface>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 31c757f..ac46741 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -12,6 +12,7 @@ data/org.gnome.Games.desktop.in
 [type: gettext/glade]data/ui/quit-dialog.ui
 [type: gettext/glade]data/ui/remote-display.ui
 [type: gettext/glade]data/ui/resume-dialog.ui
+[type: gettext/glade]data/ui/resume-dialog-dialog.ui
 plugins/desktop/src/desktop-tracker-query.vala
 plugins/dreamcast/src/dreamcast-header.vala
 plugins/game-boy/src/game-boy-header.vala
diff --git a/src/Makefile.am b/src/Makefile.am
index 4ca5887..ab8d1f8 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -105,6 +105,7 @@ gnome_games_SOURCES = \
        ui/quit-dialog.vala \
        ui/remote-display.vala \
        ui/resume-dialog.vala \
+       ui/resume-failed-dialog.vala \
        ui/search-bar.vala \
        ui/ui-state.vala \
        \
diff --git a/src/ui/application-window.vala b/src/ui/application-window.vala
index 604d401..ec43863 100644
--- a/src/ui/application-window.vala
+++ b/src/ui/application-window.vala
@@ -230,6 +230,32 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
                catch (Error e) {
                        warning (@"$(e.message)\n");
 
+                       var dialog = new ResumeFailedDialog ();
+                       dialog.set_transient_for (this);
+
+                       cancellable.cancelled.connect (() => {
+                               dialog.destroy ();
+                       });
+
+                       var response = dialog.run ();
+                       dialog.destroy ();
+
+                       if (cancellable.is_cancelled ())
+                               response = Gtk.ResponseType.CANCEL;
+
+                       switch (response) {
+                       case Gtk.ResponseType.CANCEL:
+                               display_box.runner = null;
+                               ui_state = UiState.COLLECTION;
+
+                               return;
+                       case Gtk.ResponseType.ACCEPT:
+                       default:
+                               runner.start ();
+
+                               break;
+                       }
+
                        return;
                }
        }
diff --git a/src/ui/resume-failed-dialog.vala b/src/ui/resume-failed-dialog.vala
new file mode 100644
index 0000000..dfad8eb
--- /dev/null
+++ b/src/ui/resume-failed-dialog.vala
@@ -0,0 +1,8 @@
+// This file is part of GNOME Games. License: GPLv3
+
+[GtkTemplate (ui = "/org/gnome/Games/ui/resume-failed-dialog.ui")]
+private class Games.ResumeFailedDialog : Gtk.Dialog {
+        construct {
+                use_header_bar = 1; // FIXME: Why doesn't this work from UI file?
+        }
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]