[gnome-boxes] main: add --open-uuid



commit ff2fa2dc294a3bf2eb6b6a16e110b2ac9b592158
Author: Marc-Andrà Lureau <marcandre lureau gmail com>
Date:   Sat Aug 4 23:32:45 2012 +0200

    main: add --open-uuid
    
    Allow to open a Box with its UUID. This is needed for reliably opening
    a box from GNOME Shell search results.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=681246

 src/app.vala  |   20 ++++++++++++++++++++
 src/main.vala |   13 +++++++++++--
 2 files changed, 31 insertions(+), 2 deletions(-)
---
diff --git a/src/app.vala b/src/app.vala
index e41e78e..2eece1c 100644
--- a/src/app.vala
+++ b/src/app.vala
@@ -173,6 +173,26 @@ private class Boxes.App: Boxes.UI {
         }
     }
 
+    public bool open_uuid (string uuid) {
+        ui_state = UIState.COLLECTION;
+        view.visible = false; // to avoid some glitches
+
+        // after "ready" all items should be listed
+        foreach (var item in collection.items.data) {
+            if (!(item is Boxes.Machine))
+                continue;
+            var machine = item as Boxes.Machine;
+
+            if (machine.config.uuid != uuid)
+                continue;
+
+            select_item (item);
+            return true;
+        }
+
+        return false;
+    }
+
     public LibvirtMachine add_domain (CollectionSource source, GVir.Connection connection, GVir.Domain domain)
                                       throws GLib.Error {
         var machine = domain.get_data<LibvirtMachine> ("machine");
diff --git a/src/main.vala b/src/main.vala
index 20a9934..83ddcdb 100644
--- a/src/main.vala
+++ b/src/main.vala
@@ -5,12 +5,14 @@ using Posix;
 private static bool version;
 private static bool fullscreen;
 private static bool checks;
+private static string open_uuid;
 private static string[] uris;
 
 private const OptionEntry[] options = {
     { "version", 0, 0, OptionArg.NONE, ref version, N_("Display version number"), null },
     { "full-screen", 'f', 0, OptionArg.NONE, ref fullscreen, N_("Open in full screen"), null },
     { "checks", 0, 0, OptionArg.NONE, ref checks, N_("Check virtualization capabilities"), null },
+    { "open-uuid", 0, 0, OptionArg.STRING, ref open_uuid, N_("Open box with UUID"), null },
     // A 'broker' is a virtual-machine manager (could be local or remote). Currently libvirt is the only one supported.
     { "", 0, 0, OptionArg.STRING_ARRAY, ref uris, N_("URI to display, broker or installer media"), null },
     { null }
@@ -37,6 +39,12 @@ private static void parse_args (ref unowned string[] args) {
         warning (error.message);
     }
 
+    if (uris.length > 1 ||
+        (open_uuid != null && uris != null)) {
+        GLib.stderr.printf (_("Too many command line arguments specified.\n"));
+        exit (1);
+    }
+
     if (version) {
         GLib.stdout.printf ("%s\n", Config.BUILD_VERSION);
         exit (0);
@@ -105,8 +113,9 @@ public int main (string[] args) {
     var app = new Boxes.App ();
 
     app.ready.connect ((first_time) => {
-        if (uris != null) {
-            // FIXME: We only handle a single URI from commandline
+        if (open_uuid != null) {
+            app.open_uuid (open_uuid);
+        } else if (uris != null) {
             var arg = uris[0];
             var file = File.new_for_commandline_arg (arg);
 



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