[gnome-boxes] Add Machine.is_on() helper



commit ee4dbeee3b61c47f7b688bbaad236afc7f72fd47
Author: Alexander Larsson <alexl redhat com>
Date:   Thu Oct 4 16:34:09 2012 +0200

    Add Machine.is_on() helper
    
    This simplifies some code in LibvirtMachine.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=685383

 src/libvirt-machine.vala |    4 ++--
 src/machine.vala         |    6 ++++++
 2 files changed, 8 insertions(+), 2 deletions(-)
---
diff --git a/src/libvirt-machine.vala b/src/libvirt-machine.vala
index a5f3deb..e0007dc 100644
--- a/src/libvirt-machine.vala
+++ b/src/libvirt-machine.vala
@@ -546,7 +546,7 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
                     config.set ("current-memory", value);
                 domain.set_config (config);
                 debug ("RAM changed to %llu", value);
-                if (state == MachineState.RUNNING || state == MachineState.PAUSED || state == MachineState.SLEEPING)
+                if (is_on ())
                     notify_reboot_required ();
             } catch (GLib.Error error) {
                 warning ("Failed to change RAM of box '%s' to %llu: %s",
@@ -555,7 +555,7 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
                          error.message);
             }
 
-            if (state == MachineState.RUNNING || state == MachineState.PAUSED || state == MachineState.SLEEPING)
+            if (is_on ())
                 update_ram_property (property);
 
             return false;
diff --git a/src/machine.vala b/src/machine.vala
index 8b3b1a8..103e91b 100644
--- a/src/machine.vala
+++ b/src/machine.vala
@@ -256,6 +256,12 @@ private abstract class Boxes.Machine: Boxes.CollectionItem, Boxes.IPropertiesPro
         return state == MachineState.RUNNING;
     }
 
+    public bool is_on () {
+        return state == MachineState.RUNNING ||
+            state == MachineState.PAUSED ||
+            state == MachineState.SLEEPING;
+    }
+
     private void save_pixbuf_as_screenshot (Gdk.Pixbuf? pixbuf) {
         try {
             pixbuf.save (get_screenshot_filename (), "png");



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