[gnome-games/wip/exalm/search-provider: 3/7] application: Handle command line file opening manually



commit 175bacfdebe1298fdcc24a948873f6a2a0e0b387
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Wed Feb 12 13:48:27 2020 +0500

    application: Handle command line file opening manually
    
    Set HANDLES_COMMAND_LINE and implement command_line(). This will allow to
    add more command line options later.

 src/ui/application.vala | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)
---
diff --git a/src/ui/application.vala b/src/ui/application.vala
index 6278f78b..2c54c6f5 100644
--- a/src/ui/application.vala
+++ b/src/ui/application.vala
@@ -25,9 +25,14 @@ public class Games.Application : Gtk.Application {
                { "add-game-files", add_game_files   },
        };
 
+       private const OptionEntry[] option_entries = {
+               { "", 0, 0, OptionArg.FILENAME_ARRAY },
+               { null },
+       };
+
        internal Application () {
                Object (application_id: Config.APPLICATION_ID,
-                       flags: ApplicationFlags.HANDLES_OPEN);
+                       flags: ApplicationFlags.HANDLES_OPEN | ApplicationFlags.HANDLES_COMMAND_LINE);
        }
 
        construct {
@@ -37,6 +42,7 @@ public class Games.Application : Gtk.Application {
                Environment.set_variable ("PULSE_PROP_media.role", "game", true);
                Environment.set_variable ("PULSE_PROP_application.icon_name", Config.APPLICATION_ID, true);
 
+               add_main_option_entries (option_entries);
                add_actions ();
                add_signal_handlers ();
 
@@ -212,6 +218,25 @@ public class Games.Application : Gtk.Application {
                cover_loader = new CoverLoader ();
        }
 
+       protected override int command_line (ApplicationCommandLine command_line) {
+               var options = command_line.get_options_dict ();
+
+               activate ();
+
+               var files_variant = options.lookup_value ("", VariantType.BYTESTRING_ARRAY);
+               if (files_variant != null) {
+                       var filenames = files_variant.get_bytestring_array ();
+                       File[] files = {};
+
+                       foreach (var filename in filenames)
+                               files += command_line.create_file_for_arg (filename);
+
+                       open (files, "");
+               }
+
+               return 0;
+       }
+
        protected override void activate () {
                if (window != null) {
                        window.present_with_time (Gtk.get_current_event_time ());


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