[gnome-games/wip/exalm/rebrand: 32/124] Move import and export to primary menu




commit 64031f1fa52d7c8dce17807ea05458f6cbbcc3b2
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Wed Mar 24 20:17:39 2021 +0500

    Move import and export to primary menu
    
    Since Steam, desktop and LÖVE platforms are gone, we don't need to warn
    about export anymore. Replace the import warning with a simple dialog.

 src/meson.build                                    |  1 -
 src/org.gnome.Games.gresource.xml                  |  1 -
 src/preferences/preferences-page-import-export.ui  | 54 -------------
 .../preferences-page-import-export.vala            | 74 ------------------
 src/preferences/preferences-window.ui              | 10 ---
 src/ui/application.vala                            | 91 ++++++++++++++++++++++
 src/ui/collection-view.ui                          | 10 +++
 7 files changed, 101 insertions(+), 140 deletions(-)
---
diff --git a/src/meson.build b/src/meson.build
index 00eede56..783ad1e3 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -91,7 +91,6 @@ vala_sources = [
 
   'preferences/preferences-page.vala',
   'preferences/preferences-page-controllers.vala',
-  'preferences/preferences-page-import-export.vala',
   'preferences/preferences-page-platforms.vala',
   'preferences/preferences-page-platforms-retro-row.vala',
   'preferences/preferences-page-video.vala',
diff --git a/src/org.gnome.Games.gresource.xml b/src/org.gnome.Games.gresource.xml
index ae879acc..03c71149 100644
--- a/src/org.gnome.Games.gresource.xml
+++ b/src/org.gnome.Games.gresource.xml
@@ -27,7 +27,6 @@
 
     <file preprocess="xml-stripblanks">preferences/preferences-page.ui</file>
     <file preprocess="xml-stripblanks">preferences/preferences-page-controllers.ui</file>
-    <file preprocess="xml-stripblanks">preferences/preferences-page-import-export.ui</file>
     <file preprocess="xml-stripblanks">preferences/preferences-page-platforms.ui</file>
     <file preprocess="xml-stripblanks">preferences/preferences-page-video.ui</file>
     <file preprocess="xml-stripblanks">preferences/preferences-subpage-gamepad.ui</file>
diff --git a/src/preferences/preferences-window.ui b/src/preferences/preferences-window.ui
index a4402358..0f113e96 100644
--- a/src/preferences/preferences-window.ui
+++ b/src/preferences/preferences-window.ui
@@ -67,16 +67,6 @@
                     <property name="icon-name">view-list-bullet-symbolic</property>
                   </packing>
                 </child>
-                <child>
-                  <object class="GamesPreferencesPageImportExport" id="import_export_page">
-                    <property name="visible">True</property>
-                    <property name="window">GamesPreferencesWindow</property>
-                  </object>
-                  <packing>
-                    <property name="title" translatable="yes">Import &amp; Export</property>
-                    <property name="icon-name">package-x-generic-symbolic</property>
-                  </packing>
-                </child>
               </object>
             </child>
             <child>
diff --git a/src/ui/application.vala b/src/ui/application.vala
index ddb11f9e..4a1aee06 100644
--- a/src/ui/application.vala
+++ b/src/ui/application.vala
@@ -28,6 +28,8 @@ public class Games.Application : Gtk.Application {
                { "about",          about            },
                { "quit",           quit_application },
                { "add-game-files", add_game_files   },
+               { "import-saves",   import_saves     },
+               { "export-saves",   export_saves     },
        };
 
        private const OptionEntry[] option_entries = {
@@ -183,6 +185,95 @@ public class Games.Application : Gtk.Application {
                chooser.destroy ();
        }
 
+       private void import_saves () {
+               import_saves_async.begin ();
+       }
+
+       private async void import_saves_async () {
+               var dialog = new Gtk.MessageDialog (
+                       window,
+                       Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,
+                       Gtk.MessageType.WARNING,
+                       Gtk.ButtonsType.CANCEL,
+                       _("Import save data?")
+               );
+
+               dialog.format_secondary_text (_("This will replace existing saves and cannot be undone."));
+               dialog.show ();
+
+               var btn = dialog.add_button (_("_Import"), Gtk.ResponseType.ACCEPT);
+               btn.get_style_context ().add_class ("destructive-action");
+
+               var response = yield DialogUtils.run_async (dialog);
+
+               dialog.destroy ();
+
+               if (response != Gtk.ResponseType.ACCEPT)
+                       return;
+
+               var chooser = new Gtk.FileChooserNative (
+                       _("Import save data"),
+                       window,
+                       Gtk.FileChooserAction.OPEN,
+                       _("_Import"),
+                       _("_Cancel")
+               );
+
+               response = yield DialogUtils.run_native_async (chooser);
+
+               if (response == Gtk.ResponseType.ACCEPT) {
+                       var archive_name = chooser.get_filename ();
+
+                       try {
+                               import_from (archive_name);
+                       }
+                       catch (ExtractionError e) {
+                               var msg = _("Couldn’t import save data: %s").printf (e.message);
+                               window.show_error (msg);
+                       }
+               }
+
+               chooser.destroy ();
+       }
+
+       private void export_saves () {
+               export_saves_async.begin ();
+       }
+
+       private async void export_saves_async () {
+               var chooser = new Gtk.FileChooserNative (
+                       _("Export save data"),
+                       window,
+                       Gtk.FileChooserAction.SAVE,
+                       _("_Export"),
+                       _("_Cancel")
+               );
+
+               chooser.do_overwrite_confirmation = true;
+
+               var current_time = new DateTime.now_local ();
+               var creation_time = current_time.format ("%c");
+               var archive_filename = "gnome-games-save-data-%s.tar.gz".printf (creation_time);
+
+               chooser.set_current_name (archive_filename);
+
+               var response = yield DialogUtils.run_native_async (chooser);
+
+               if (response == Gtk.ResponseType.ACCEPT) {
+                       var filename = chooser.get_filename ();
+
+                       try {
+                               export_to (filename);
+                       }
+                       catch (CompressionError e) {
+                               var msg = _("Couldn’t export save data: %s").printf (e.message);
+                               window.show_error (msg);
+                       }
+               }
+
+               chooser.destroy ();
+       }
+
        protected override void open (File[] files, string hint) {
                activate ();
 
diff --git a/src/ui/collection-view.ui b/src/ui/collection-view.ui
index a9b379d0..fb5eb816 100644
--- a/src/ui/collection-view.ui
+++ b/src/ui/collection-view.ui
@@ -639,6 +639,16 @@
     </swipeables>
   </object>
   <menu id="primary_menu">
+    <section>
+      <item>
+        <attribute name="label" translatable="yes">_Import Save Data…</attribute>
+        <attribute name="action">app.import-saves</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">E_xport Save Data…</attribute>
+        <attribute name="action">app.export-saves</attribute>
+      </item>
+    </section>
     <section>
       <item>
         <attribute name="label" translatable="yes">Pr_eferences</attribute>


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