[gnome-boxes] machine: Add schedule_autosave()
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-boxes] machine: Add schedule_autosave()
- Date: Wed, 12 Nov 2014 14:46:18 +0000 (UTC)
commit 0461fd35cca2841fa836713da480edecb84b9468
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date: Tue Nov 11 20:48:28 2014 +0000
machine: Add schedule_autosave()
Add a method to autosave the machine after 1 minute.
https://bugzilla.gnome.org/show_bug.cgi?id=694931
src/machine.vala | 22 ++++++++++++++++++++++
1 files changed, 22 insertions(+), 0 deletions(-)
---
diff --git a/src/machine.vala b/src/machine.vala
index e419ca0..d8ba8b1 100644
--- a/src/machine.vala
+++ b/src/machine.vala
@@ -3,6 +3,8 @@ using Gdk;
using Gtk;
private abstract class Boxes.Machine: Boxes.CollectionItem, Boxes.IPropertiesProvider {
+ const uint AUTOSAVE_TIMEOUT = 60; // seconds
+
public Boxes.CollectionSource source;
public Boxes.BoxConfig config;
public Gdk.Pixbuf? pixbuf { get; set; }
@@ -252,6 +254,18 @@ private abstract class Boxes.Machine: Boxes.CollectionItem, Boxes.IPropertiesPro
this.info = info;
}
+ public void schedule_autosave () {
+ if (!can_save)
+ return;
+
+ debug ("Scheduling autosave for '%s'", name);
+ Timeout.add_seconds (AUTOSAVE_TIMEOUT, () => {
+ try_save.begin ();
+
+ return false;
+ });
+ }
+
protected virtual async void save_real () throws GLib.Error {
}
@@ -621,4 +635,12 @@ private abstract class Boxes.Machine: Boxes.CollectionItem, Boxes.IPropertiesPro
else
return -1; // Machines are listed before non-machines
}
+
+ private async void try_save () {
+ try {
+ yield save ();
+ } catch (GLib.Error error) {
+ warning ("Failed to save '%s': %s", name, error.message);
+ }
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]