[gnome-boxes] display-config: store a unique uuid
- From: Marc-Andre Lureau <malureau src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-boxes] display-config: store a unique uuid
- Date: Mon, 13 Aug 2012 12:20:58 +0000 (UTC)
commit 839eed884bb5db7198a14d49872949272dbf117d
Author: Marc-Andrà Lureau <marcandre lureau gmail com>
Date: Sat Aug 4 23:31:16 2012 +0200
display-config: store a unique uuid
Move the DisplayConfig () constructor out of its class, since it has
some logic and can now generate UUID if it's not provided. This also
allows to simplify a little bit the code.
https://bugzilla.gnome.org/show_bug.cgi?id=681246
src/display-config.vala | 20 ++++++++++----------
src/libvirt-machine.vala | 2 +-
src/machine.vala | 22 ++++++++++++++++++++++
src/remote-machine.vala | 2 +-
4 files changed, 34 insertions(+), 12 deletions(-)
---
diff --git a/src/display-config.vala b/src/display-config.vala
index bcffc7d..1a72f17 100644
--- a/src/display-config.vala
+++ b/src/display-config.vala
@@ -19,7 +19,12 @@ private class Boxes.DisplayConfig: GLib.Object, Boxes.IConfig {
public string? last_seen_name {
owned get { return get_string (group, "last-seen-name"); }
- private set { keyfile.set_string (group, "last-seen-name", value); }
+ set { keyfile.set_string (group, "last-seen-name", value); }
+ }
+
+ public string? uuid {
+ owned get { return get_string (group, "uuid"); }
+ set { keyfile.set_string (group, "uuid", value); }
}
public string[]? categories {
@@ -27,16 +32,11 @@ private class Boxes.DisplayConfig: GLib.Object, Boxes.IConfig {
set { keyfile.set_string_list (group, "categories", value); }
}
- public DisplayConfig (CollectionSource source, string last_seen_name, string? subgroup = null) {
+ public DisplayConfig.with_group (CollectionSource source, string group) {
this.source = source;
- this.group = "display";
- if (subgroup != null)
- this.group += " " + subgroup;
- if (this.last_seen_name != last_seen_name) {
- this.last_seen_name = last_seen_name;
- save ();
- }
+ warn_if_fail (group.has_prefix ("display"));
+ this.group = group;
}
public void add_category (string category) {
diff --git a/src/libvirt-machine.vala b/src/libvirt-machine.vala
index 4b3b35c..b6084f1 100644
--- a/src/libvirt-machine.vala
+++ b/src/libvirt-machine.vala
@@ -87,7 +87,7 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
base (source, item_name);
debug ("new libvirt machine: " + domain.get_name ());
- this.config = new DisplayConfig (source, this.name, domain.get_uuid ());
+ create_display_config (domain.get_uuid ());
this.connection = connection;
this.domain = domain;
diff --git a/src/machine.vala b/src/machine.vala
index 7a0ccb0..d63f5bd 100644
--- a/src/machine.vala
+++ b/src/machine.vala
@@ -208,6 +208,28 @@ private abstract class Boxes.Machine: Boxes.CollectionItem, Boxes.IPropertiesPro
display = null;
}
+ protected void create_display_config (string? uuid = null)
+ requires (this.config == null)
+ ensures (this.config != null) {
+
+ var group = "display";
+ if (uuid != null)
+ group += " " + uuid;
+
+ config = new DisplayConfig.with_group (source, group);
+ if (config.last_seen_name != name)
+ config.last_seen_name = name;
+
+ if (uuid != null &&
+ config.uuid != uuid)
+ config.uuid = uuid;
+
+ if (config.uuid == null)
+ config.uuid = uuid_generate ();
+
+ config.save ();
+ }
+
public bool is_running () {
return state == MachineState.RUNNING;
}
diff --git a/src/remote-machine.vala b/src/remote-machine.vala
index e7393a3..11c0d76 100644
--- a/src/remote-machine.vala
+++ b/src/remote-machine.vala
@@ -9,7 +9,7 @@ private class Boxes.RemoteMachine: Boxes.Machine, Boxes.IPropertiesProvider {
// assume the remote is running for now
state = MachineState.RUNNING;
- config = new DisplayConfig (source, this.name);
+ create_display_config ();
source.bind_property ("name", this, "name", BindingFlags.DEFAULT);
load_screenshot ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]