[gnome-games] ui: Add the 'add-game-files' action



commit c75aafdeb35eaa239a8a1b544a54e434914e21a5
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Sun May 21 15:35:47 2017 +0200

    ui: Add the 'add-game-files' action
    
    The action will be used in the next commit to triggers a game file
    chooser, letting the user select files to add to the games collection.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=782824

 src/ui/application.vala |   28 ++++++++++++++++++++++++++++
 1 files changed, 28 insertions(+), 0 deletions(-)
---
diff --git a/src/ui/application.vala b/src/ui/application.vala
index 25695a0..b0a4c56 100644
--- a/src/ui/application.vala
+++ b/src/ui/application.vala
@@ -36,6 +36,10 @@ public class Games.Application : Gtk.Application {
                SimpleAction quit_action = new SimpleAction ("quit", null);
                quit_action.activate.connect (quit_application);
                add_action (quit_action);
+
+               SimpleAction add_game_files_action = new SimpleAction ("add-game-files", null);
+               add_game_files_action.activate.connect (add_game_files);
+               add_action (add_game_files_action);
        }
 
        private void add_signal_handlers () {
@@ -107,6 +111,30 @@ public class Games.Application : Gtk.Application {
                return @"$data_dir/medias";
        }
 
+       public void add_game_files () {
+               add_game_files_async.begin ();
+       }
+
+       public async void add_game_files_async () {
+               var chooser = new Gtk.FileChooserDialog (
+                       _("Select game files"), window, Gtk.FileChooserAction.OPEN,
+                       "_Cancel", Gtk.ResponseType.CANCEL,
+                       "_Add", Gtk.ResponseType.ACCEPT);
+
+               chooser.select_multiple = true;
+
+               var filter = new Gtk.FileFilter ();
+               chooser.set_filter (filter);
+               foreach (var mime_type in game_collection.get_accepted_mime_types ())
+                       filter.add_mime_type (mime_type);
+
+               if (chooser.run () == Gtk.ResponseType.ACCEPT)
+                       foreach (unowned string uri in chooser.get_uris ())
+                               yield game_collection.add_uri (new Uri (uri));
+
+               chooser.close ();
+       }
+
        protected override void open (File[] files, string hint) {
                open_async.begin (files, hint);
        }


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