[gnome-boxes/wip/resize-snapshots2: 5/6] libvirt-machine-props: Fetch snapshots at construction



commit a1c5a74d2c8cbc48caa94125798c87bab54a178d
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Wed Apr 6 23:31:42 2016 +0100

    libvirt-machine-props: Fetch snapshots at construction
    
    Instead of fetching snapshots at runtime, do so as part of
    LibvirtMachineProperties construction (which in turn happens as part of
    LibvirtMachine construction). This implies we re-fetch them each time a
    snapshot is added or removed to keep the list up2date.
    
    This change is needed because fetching of snapshots is an async
    operation (and we want to keep it that way to avoid hanging the UI) and
    we'll need access to snapshots during the sync operation of properties
    construction, in a following patch.

 src/libvirt-machine-properties.vala |    2 ++
 src/snapshots-property.vala         |   29 ++++++++++++++++-------------
 2 files changed, 18 insertions(+), 13 deletions(-)
---
diff --git a/src/libvirt-machine-properties.vala b/src/libvirt-machine-properties.vala
index 8feaa33..886fc0a 100644
--- a/src/libvirt-machine-properties.vala
+++ b/src/libvirt-machine-properties.vala
@@ -13,6 +13,8 @@ private class Boxes.LibvirtMachineProperties: GLib.Object, Boxes.IPropertiesProv
         machine.notify["name"].connect (() => {
             save_machine_name_change ();
         });
+
+        yield fetch_snapshots (null);
     }
 
     private bool save_machine_name_change () {
diff --git a/src/snapshots-property.vala b/src/snapshots-property.vala
index 970303e..702cf6e 100644
--- a/src/snapshots-property.vala
+++ b/src/snapshots-property.vala
@@ -55,7 +55,7 @@ private class Boxes.SnapshotsProperty : Boxes.Property {
         snapshot_list.set_size_request (-1, 250);
         snapshot_list.set_sort_func (config_sort_func);
         added_id = snapshot_list.add.connect (update_snapshot_stack_page);
-        removed_id = snapshot_list.remove.connect (update_snapshot_stack_page);
+        removed_id = snapshot_list.remove.connect (on_snapshot_removed);
         snapshot_stack.add (snapshot_list);
 
         empty_label = new Gtk.Label (_("No snapshots created yet. Create one using the button below."));
@@ -83,21 +83,16 @@ private class Boxes.SnapshotsProperty : Boxes.Property {
 
         flushed.connect (on_flushed);
 
-        fetch_snapshots.begin ();
+        fetch_snapshots ();
     }
 
-    private async void fetch_snapshots () {
-        try {
-            yield machine.properties.fetch_snapshots (null);
-            var snapshots = machine.properties.get_snapshots ();
+    private void fetch_snapshots () {
+        var snapshots = machine.properties.get_snapshots ();
 
-            foreach (var snapshot in snapshots) {
-                var row = new SnapshotListRow (snapshot, machine);
-                row.notify["activity-message"].connect (row_activity_changed);
-                snapshot_list.add (row);
-            }
-        } catch (GLib.Error e) {
-            warning ("Could not fetch snapshots: %s", e.message);
+        foreach (var snapshot in snapshots) {
+            var row = new SnapshotListRow (snapshot, machine);
+            row.notify["activity-message"].connect (row_activity_changed);
+            snapshot_list.add (row);
         }
 
         update_snapshot_stack_page ();
@@ -126,6 +121,8 @@ private class Boxes.SnapshotsProperty : Boxes.Property {
             var new_row = new SnapshotListRow (new_snapshot, machine);
             new_row.notify["activity-message"].connect (row_activity_changed);
             snapshot_list.add (new_row);
+
+            yield machine.properties.fetch_snapshots (null);
         } catch (GLib.Error e) {
             var msg = _("Failed to create snapshot of %s").printf (machine.name);
             machine.window.notificationbar.display_error (msg);
@@ -147,6 +144,12 @@ private class Boxes.SnapshotsProperty : Boxes.Property {
             snapshot_stack.visible_child = empty_label;
     }
 
+    private void on_snapshot_removed () {
+        update_snapshot_stack_page ();
+
+        machine.properties.fetch_snapshots.begin (null);
+    }
+
     private void on_flushed () {
         if (added_id != 0) {
             snapshot_list.disconnect (added_id);


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