[gnome-boxes] Allow to open a machine from command line



commit 82955dcda09835955df8816155a297c270bce4e6
Author: Marc-Andrà Lureau <marcandre lureau gmail com>
Date:   Wed May 23 13:22:31 2012 +0200

    Allow to open a machine from command line
    
    If the name is not a file or a URI, lookup the machine
    from the collection and open it.
    
    This allows calling "gnome-boxes xp" to start and open
    that VM for example.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=676631

 src/app.vala             |   19 +++++++++++++++++--
 src/collection-view.vala |    4 ++++
 src/main.vala            |    9 +++++++--
 3 files changed, 28 insertions(+), 4 deletions(-)
---
diff --git a/src/app.vala b/src/app.vala
index cfaefe4..d2d955e 100644
--- a/src/app.vala
+++ b/src/app.vala
@@ -145,12 +145,27 @@ private class Boxes.App: Boxes.UI {
         return application.run ();
     }
 
+    public bool open (string name) {
+        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.name != name)
+                continue;
+
+            return select_item (item);
+        }
+
+        return false;
+    }
+
     public void set_category (Category category) {
         topbar.label.set_text (category.name);
         view.category = category;
     }
 
-    public LibvirtMachine? add_domain (CollectionSource source, GVir.Connection connection, GVir.Domain domain) {
+   public LibvirtMachine? add_domain (CollectionSource source, GVir.Connection connection, GVir.Domain domain) {
         var machine = domain.get_data<LibvirtMachine> ("machine");
         if (machine != null)
             return machine; // Already added
@@ -431,6 +446,7 @@ private class Boxes.App: Boxes.UI {
                 machine.update_screenshot.begin ();
             }
             fullscreen = false;
+            view.visible = true;
             break;
 
         case UIState.PROPERTIES:
@@ -542,4 +558,3 @@ private class Boxes.App: Boxes.UI {
         return false;
     }
 }
-
diff --git a/src/collection-view.vala b/src/collection-view.vala
index 954c6b2..2c5c6dd 100644
--- a/src/collection-view.vala
+++ b/src/collection-view.vala
@@ -25,6 +25,10 @@ private class Boxes.CollectionView: Boxes.UI {
     }
     private Gtk.ListStore model;
 
+    public bool visible {
+        set { icon_view.visible = value; }
+    }
+
     public CollectionView (App app, Category category) {
         this.app = app;
         this.category = category;
diff --git a/src/main.vala b/src/main.vala
index e940c15..697784b 100644
--- a/src/main.vala
+++ b/src/main.vala
@@ -93,8 +93,13 @@ public int main (string[] args) {
     app.ready.connect ((first_time) => {
         if (uris != null) {
             // FIXME: We only handle a single URI from commandline
-            var file = File.new_for_commandline_arg (uris[0]);
-            app.wizard.open_with_uri (file.get_uri ());
+            var arg = uris[0];
+            var file = File.new_for_commandline_arg (arg);
+
+            if (file.query_exists () || Uri.parse_scheme (arg) != null)
+                app.wizard.open_with_uri (file.get_uri ());
+            else
+                app.open (arg);
         } else if (first_time) {
             app.ui_state = Boxes.UIState.WIZARD;
         }



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