[gnome-boxes] Unified way to set & flush deferred property changes
- From: Christophe Fergeau <teuf src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-boxes] Unified way to set & flush deferred property changes
- Date: Mon, 3 Sep 2012 14:19:10 +0000 (UTC)
commit 2c36aebcbff282af5538388dcfb075e39e5bd307
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date: Fri Aug 31 05:48:21 2012 +0300
Unified way to set & flush deferred property changes
Add new API to Boxes.Property class to easily schedule deferred changes
to it and to flush it when needed.
https://bugzilla.gnome.org/show_bug.cgi?id=672554
src/i-properties-provider.vala | 36 ++++++++++++++++++++++++++++++++++++
src/libvirt-machine.vala | 19 +++++--------------
src/properties.vala | 13 +++++++++++++
3 files changed, 54 insertions(+), 14 deletions(-)
---
diff --git a/src/i-properties-provider.vala b/src/i-properties-provider.vala
index b0195fb..a471133 100644
--- a/src/i-properties-provider.vala
+++ b/src/i-properties-provider.vala
@@ -6,9 +6,45 @@ private class Boxes.Property: GLib.Object {
public Gtk.Widget widget { get; construct set; }
public bool reboot_required { get; set; }
+ public uint defer_interval { get; set; default = 1; } // In seconds
+
+ private uint deferred_change_id;
+ private SourceFunc? _deferred_change;
+ public SourceFunc? deferred_change {
+ get {
+ return _deferred_change;
+ }
+
+ owned set {
+ if (deferred_change_id != 0) {
+ Source.remove (deferred_change_id);
+ deferred_change_id = 0;
+ }
+
+ _deferred_change = (owned) value;
+ if (_deferred_change == null)
+ return;
+
+ deferred_change_id = Timeout.add_seconds (defer_interval, () => {
+ flush ();
+
+ return false;
+ });
+ }
+ }
+
public Property (string description, Gtk.Widget widget) {
base (description: description, widget: widget);
}
+
+ public void flush () {
+ if (deferred_change == null)
+ return;
+
+ deferred_change ();
+
+ deferred_change = null;
+ }
}
private delegate void PropertyStringChanged (Boxes.Property property, string value) throws Boxes.Error;
diff --git a/src/libvirt-machine.vala b/src/libvirt-machine.vala
index 17393d7..c1b6fbe 100644
--- a/src/libvirt-machine.vala
+++ b/src/libvirt-machine.vala
@@ -48,8 +48,6 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
double net_write;
}
- private uint ram_update_timeout = 0;
- private uint storage_update_timeout = 0;
private uint stats_update_timeout;
private Cancellable stats_cancellable;
@@ -523,10 +521,7 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
private void on_ram_changed (Boxes.Property property, uint64 value) {
// Ensure that we don't end-up changing RAM like a 1000 times a second while user moves the slider..
- if (ram_update_timeout != 0)
- Source.remove (ram_update_timeout);
-
- ram_update_timeout = Timeout.add_seconds (1, () => {
+ property.deferred_change = () => {
try {
var config = domain.get_config (GVir.DomainXMLFlags.INACTIVE);
config.memory = value;
@@ -539,11 +534,11 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
value,
error.message);
}
- ram_update_timeout = 0;
+
update_ram_property (property);
return false;
- });
+ };
}
public async void start () {
@@ -615,10 +610,7 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
private void on_storage_changed (Boxes.Property property, uint64 value) {
// Ensure that we don't end-up changing storage like a 1000 times a second while user moves the slider..
- if (storage_update_timeout != 0)
- Source.remove (storage_update_timeout);
-
- storage_update_timeout = Timeout.add_seconds (1, () => {
+ property.deferred_change = () => {
if (storage_volume == null)
return false;
@@ -637,9 +629,8 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
value,
error.message);
}
- storage_update_timeout = 0;
return false;
- });
+ };
}
}
diff --git a/src/properties.vala b/src/properties.vala
index aa96ac2..01de259 100644
--- a/src/properties.vala
+++ b/src/properties.vala
@@ -118,6 +118,11 @@ private class Boxes.Properties: Boxes.UI {
grid.show_all ();
widget = grid;
}
+
+ public void flush_changes () {
+ foreach (var property in properties)
+ property.flush ();
+ }
}
public Properties () {
@@ -261,6 +266,14 @@ private class Boxes.Properties: Boxes.UI {
populate ();
opacity = 255;
break;
+ default:
+ if (previous_ui_state == UIState.PROPERTIES)
+ for (var i = 0; i < PropertiesPage.LAST; i++) {
+ var page = notebook.get_data<PageWidget> (@"boxes-property-$i");
+
+ page.flush_changes ();
+ }
+ break;
}
fade_actor (actor, opacity);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]