[gnome-boxes] machine: is_running() now a property



commit de970500ee8b28afb55e5733146a3fb4d54f71be
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Mon Jul 6 09:08:54 2015 +0200

    machine: is_running() now a property
    
    This is needed to make how the machine's state is checked, consistent.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=752007

 src/actions-popover.vala            |    2 +-
 src/collection-view.vala            |    2 +-
 src/libvirt-machine-properties.vala |   10 +++++-----
 src/machine.vala                    |   14 ++++++++------
 4 files changed, 15 insertions(+), 13 deletions(-)
---
diff --git a/src/actions-popover.vala b/src/actions-popover.vala
index 287959c..a33a2b5 100644
--- a/src/actions-popover.vala
+++ b/src/actions-popover.vala
@@ -50,7 +50,7 @@ private class Boxes.ActionsPopover: Gtk.Popover {
         if (machine is LibvirtMachine) {
             section.append (_("Force Shutdown"), "box.force_shutdown");
             var action = action_group.lookup_action ("force_shutdown") as GLib.SimpleAction;
-            action.set_enabled (machine.is_running ());
+            action.set_enabled (machine.is_running);
         }
 
         // Pause
diff --git a/src/collection-view.vala b/src/collection-view.vala
index 823c5ba..ac64cfa 100644
--- a/src/collection-view.vala
+++ b/src/collection-view.vala
@@ -406,7 +406,7 @@ private class Boxes.CollectionView: Gd.MainView, Boxes.UI {
                 CollectionItem item;
                 store.get (iter, ModelColumns.ITEM, out item);
                 selected = item != null && item is Machine &&
-                    (item as Machine).is_running ();
+                    (item as Machine).is_running;
                 break;
             }
             store.set (iter, ModelColumns.SELECTED, selected);
diff --git a/src/libvirt-machine-properties.vala b/src/libvirt-machine-properties.vala
index 4299804..1164362 100644
--- a/src/libvirt-machine-properties.vala
+++ b/src/libvirt-machine-properties.vala
@@ -424,7 +424,7 @@ private class Boxes.LibvirtMachineProperties: GLib.Object, Boxes.IPropertiesProv
             machine.restart ();
             machine.window.props_window.revert_state ();
         });
-        restart_button.sensitive = machine.is_running ();
+        restart_button.sensitive = machine.is_running;
         inner_grid.attach (restart_button, 1, 0, 1, 1);
 
         var shutdown_button = new Gtk.Button.with_label (_("Force Shutdown"));
@@ -433,12 +433,12 @@ private class Boxes.LibvirtMachineProperties: GLib.Object, Boxes.IPropertiesProv
             machine.force_shutdown ();
             machine.window.props_window.revert_state ();
         });
-        shutdown_button.sensitive = machine.is_running ();
+        shutdown_button.sensitive = machine.is_running;
         inner_grid.attach (shutdown_button, 2, 0, 1, 1);
 
         var state_notify_id = machine.notify["state"].connect (() => {
-            restart_button.sensitive = machine.is_running ();
-            shutdown_button.sensitive = machine.is_running ();
+            restart_button.sensitive = machine.is_running;
+            shutdown_button.sensitive = machine.is_running;
         });
 
         var log_button = new Gtk.Button.with_label (_("Troubleshooting Log"));
@@ -589,7 +589,7 @@ private class Boxes.LibvirtMachineProperties: GLib.Object, Boxes.IPropertiesProv
                 return false;
 
             try {
-                if (machine.is_running ()) {
+                if (machine.is_running) {
                     var disk = machine.get_domain_disk ();
                     if (disk != null) {
                         var size = (value + Osinfo.KIBIBYTES - 1) / Osinfo.KIBIBYTES;
diff --git a/src/machine.vala b/src/machine.vala
index d3dc05f..b07e98a 100644
--- a/src/machine.vala
+++ b/src/machine.vala
@@ -21,7 +21,7 @@ private abstract class Boxes.Machine: Boxes.CollectionItem, Boxes.IPropertiesPro
 
     protected virtual bool should_autosave {
         get {
-            return (can_save && is_running () && autosave_timeout_id == 0);
+            return (can_save && is_running && autosave_timeout_id == 0);
         }
     }
 
@@ -34,6 +34,12 @@ private abstract class Boxes.Machine: Boxes.CollectionItem, Boxes.IPropertiesPro
         }
     }
 
+    public bool is_running {
+        get {
+            return state == MachineState.RUNNING;
+        }
+    }
+
     private ulong show_id;
     private ulong hide_id;
     private ulong disconnected_id;
@@ -379,10 +385,6 @@ private abstract class Boxes.Machine: Boxes.CollectionItem, Boxes.IPropertiesPro
             info = null;
     }
 
-    public bool is_running () {
-        return state == MachineState.RUNNING;
-    }
-
     public bool is_on () {
         return state == MachineState.RUNNING ||
             state == MachineState.PAUSED ||
@@ -495,7 +497,7 @@ private abstract class Boxes.Machine: Boxes.CollectionItem, Boxes.IPropertiesPro
         context.set_operator (Cairo.Operator.SOURCE);
         context.paint ();
 
-        if (!is_running ()) {
+        if (!is_running) {
             context.set_source_rgba (1, 1, 1, 1);
             context.set_operator (Cairo.Operator.HSL_SATURATION);
             context.paint ();


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